align_expr = yasm_expr_get_intnum(&vp->param, 0);
if (!align_expr) {
yasm_error_set(YASM_ERROR_VALUE,
- N_("argument to `%s' is not a power of two"),
+ N_("argument to `%s' is not an integer"),
vp->val);
return NULL;
}
align = yasm_intnum_get_uint(align_expr);
/* Alignments must be a power of two. */
- if ((align & (align - 1)) != 0) {
+ if (!is_exp2(align)) {
yasm_error_set(YASM_ERROR_VALUE,
N_("argument to `%s' is not a power of two"),
vp->val);
align_expr = yasm_expr_get_intnum(&vp->param, 0);
if (!align_expr) {
yasm_error_set(YASM_ERROR_VALUE,
- N_("argument to `%s' is not a power of two"),
+ N_("argument to `%s' is not an integer"),
vp->val);
return NULL;
}
align = yasm_intnum_get_uint(align_expr);
/* Alignments must be a power of two. */
- if ((align & (align - 1)) != 0) {
+ if (!is_exp2(align)) {
yasm_error_set(YASM_ERROR_VALUE,
N_("argument to `%s' is not a power of two"),
vp->val);
{
long pos;
unsigned long delta;
- if ((align & (align-1)) != 0)
+ if (!is_exp2(align))
yasm_internal_error("requested alignment not a power of two");
pos = ftell(f);
align_expr = yasm_expr_get_intnum(&vp->param, 0);
if (!align_expr) {
yasm_error_set(YASM_ERROR_VALUE,
- N_("argument to `%s' is not a power of two"),
+ N_("argument to `%s' is not an integer"),
vp->val);
return NULL;
}
align = yasm_intnum_get_uint(align_expr);
/* Alignments must be a power of two. */
- if ((align & (align - 1)) != 0) {
+ if (!is_exp2(align)) {
yasm_error_set(YASM_ERROR_VALUE,
N_("argument to `%s' is not a power of two"),
vp->val);
align_expr = yasm_expr_get_intnum(&vp->param, 0);
if (!align_expr) {
yasm_error_set(YASM_ERROR_VALUE,
- N_("alignment constraint is not a power of two"));
+ N_("alignment constraint is not an integer"));
return sym;
}
addralign = yasm_intnum_get_uint(align_expr);
/* Alignments must be a power of two. */
- if ((addralign & (addralign - 1)) != 0) {
+ if (!is_exp2(addralign)) {
yasm_error_set(YASM_ERROR_VALUE,
N_("alignment constraint is not a power of two"));
return sym;
align_expr = yasm_expr_get_intnum(&vp->param, 0);
if (!align_expr) {
yasm_error_set(YASM_ERROR_VALUE,
- N_("alignment constraint is not a power of two"));
+ N_("alignment constraint is not an integer"));
return sym;
}
addralign = yasm_intnum_get_uint(align_expr);
/* Alignments must be a power of two. */
- if ((addralign & (addralign - 1)) != 0) {
+ if (!is_exp2(addralign)) {
yasm_error_set(YASM_ERROR_VALUE,
N_("alignment constraint is not a power of two"));
return sym;
align_expr = yasm_expr_get_intnum(&vp->param, 0);
if (!align_expr) {
yasm_error_set(YASM_ERROR_VALUE,
- N_("argument to `%s' is not a power of two"),
+ N_("argument to `%s' is not an integer"),
vp->val);
return NULL;
}
align = yasm_intnum_get_uint(align_expr);
/* Alignments must be a power of two. */
- if ((align & (align - 1)) != 0) {
+ if (!is_exp2(align)) {
yasm_error_set(YASM_ERROR_VALUE,
N_("argument to `%s' is not a power of two"),
vp->val);
d = BC_COUNT(d, 4); \
} while (0)
+/** Determine if a value is exactly a power of 2. Zero is treated as a power
+ * of two.
+ * \param x value
+ * \return Nonzero if x is a power of 2.
+ */
+#define is_exp2(x) ((x & (x - 1)) == 0)
+
#ifndef NELEMS
/** Get the number of elements in an array.
* \internal