]> granicus.if.org Git - yasm/commitdiff
Make life a little easier by adding an is_exp2() macro.
authorPeter Johnson <peter@tortall.net>
Sat, 11 Nov 2006 05:47:09 +0000 (05:47 -0000)
committerPeter Johnson <peter@tortall.net>
Sat, 11 Nov 2006 05:47:09 +0000 (05:47 -0000)
svn path=/trunk/yasm/; revision=1682

modules/objfmts/bin/bin-objfmt.c
modules/objfmts/coff/coff-objfmt.c
modules/objfmts/elf/elf-objfmt.c
modules/objfmts/rdf/rdf-objfmt.c
modules/objfmts/xdf/xdf-objfmt.c
util.h

index 4ed8cde6c0a4bb0b5773e62f9aa1474980913626..5ebea8c67de9a65a8c1e951073fe220e9882448b 100644 (file)
@@ -433,14 +433,14 @@ bin_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams,
                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);
index ad67543ae34cc46954cd17f5092fa420aff60417..e7ae8611e77d54be6bb98a07aa29113772e435e8 100644 (file)
@@ -1515,14 +1515,14 @@ coff_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams,
                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);
index c5947c5a2cfc4e25835c97a89db7eabcbebf86d9..142e3955aeae79473ecf9f1924fc1a452e87dbe5 100644 (file)
@@ -248,7 +248,7 @@ elf_objfmt_output_align(FILE *f, unsigned int align)
 {
     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);
@@ -920,14 +920,14 @@ elf_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams,
             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);
@@ -1078,13 +1078,13 @@ elf_objfmt_common_declare(yasm_objfmt *objfmt, const char *name,
                 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;
index 7529b64824423d168ea51bb9c12977266fc4930e..25a42444c49a525629424f6a3d12d96d88566680 100644 (file)
@@ -1057,13 +1057,13 @@ rdf_objfmt_common_declare(yasm_objfmt *objfmt, const char *name,
                 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;
index 27efe4d3b0fec0ddf1437bc7263788189b2982b6..81b6050f01905fcec889fe0620fa558741377e15 100644 (file)
@@ -739,14 +739,14 @@ xdf_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams,
            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);
diff --git a/util.h b/util.h
index 01b200f9f95bead18195a23e9795e65408dbcb3a..2384e008843e5d466419f9a7693eb873cab74390 100644 (file)
--- a/util.h
+++ b/util.h
        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