Blame isl-0.14/isl_val_imath.c

Packit fb9d21
#include <isl_val_private.h>
Packit fb9d21
Packit fb9d21
/* Return a reference to an isl_val representing the unsigned
Packit fb9d21
 * integer value stored in the "n" chunks of size "size" at "chunks".
Packit fb9d21
 * The least significant chunk is assumed to be stored first.
Packit fb9d21
 */
Packit fb9d21
__isl_give isl_val *isl_val_int_from_chunks(isl_ctx *ctx, size_t n,
Packit fb9d21
	size_t size, const void *chunks)
Packit fb9d21
{
Packit fb9d21
	isl_val *v;
Packit fb9d21
Packit fb9d21
	v = isl_val_alloc(ctx);
Packit fb9d21
	if (!v)
Packit fb9d21
		return NULL;
Packit fb9d21
Packit fb9d21
	impz_import(v->n, n, -1, size, 0, 0, chunks);
Packit fb9d21
	isl_int_set_si(v->d, 1);
Packit fb9d21
Packit fb9d21
	return v;
Packit fb9d21
}
Packit fb9d21
Packit fb9d21
/* Store a representation of the absolute value of the numerator of "v"
Packit fb9d21
 * in terms of chunks of size "size" at "chunks".
Packit fb9d21
 * The least significant chunk is stored first.
Packit fb9d21
 * The number of chunks in the result can be obtained by calling
Packit fb9d21
 * isl_val_n_abs_num_chunks.  The user is responsible for allocating
Packit fb9d21
 * enough memory to store the results.
Packit fb9d21
 *
Packit fb9d21
 * In the special case of a zero value, isl_val_n_abs_num_chunks will
Packit fb9d21
 * return one, while impz_export will not fill in any chunks.  We therefore
Packit fb9d21
 * do it ourselves.
Packit fb9d21
 */
Packit fb9d21
int isl_val_get_abs_num_chunks(__isl_keep isl_val *v, size_t size,
Packit fb9d21
	void *chunks)
Packit fb9d21
{
Packit fb9d21
	if (!v || !chunks)
Packit fb9d21
		return -1;
Packit fb9d21
Packit fb9d21
	if (!isl_val_is_rat(v))
Packit fb9d21
		isl_die(isl_val_get_ctx(v), isl_error_invalid,
Packit fb9d21
			"expecting rational value", return -1);
Packit fb9d21
Packit fb9d21
	impz_export(chunks, NULL, -1, size, 0, 0, v->n);
Packit fb9d21
	if (isl_val_is_zero(v))
Packit fb9d21
		memset(chunks, 0, size);
Packit fb9d21
Packit fb9d21
	return 0;
Packit fb9d21
}
Packit fb9d21
Packit fb9d21
/* Return the number of chunks of size "size" required to
Packit fb9d21
 * store the absolute value of the numerator of "v".
Packit fb9d21
 */
Packit fb9d21
size_t isl_val_n_abs_num_chunks(__isl_keep isl_val *v, size_t size)
Packit fb9d21
{
Packit fb9d21
	if (!v)
Packit fb9d21
		return 0;
Packit fb9d21
Packit fb9d21
	if (!isl_val_is_rat(v))
Packit fb9d21
		isl_die(isl_val_get_ctx(v), isl_error_invalid,
Packit fb9d21
			"expecting rational value", return 0);
Packit fb9d21
Packit fb9d21
	size *= 8;
Packit fb9d21
	return (impz_sizeinbase(v->n, 2) + size - 1) / size;
Packit fb9d21
}