Remove open-coded ilog2() implementations
authorH. Peter Anvin <hpa@linux.intel.com>
Wed, 21 Apr 2010 23:46:57 +0000 (16:46 -0700)
committerH. Peter Anvin <hpa@linux.intel.com>
Wed, 21 Apr 2010 23:46:57 +0000 (16:46 -0700)
When we need integer log2, use the new library routine.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
output/outcoff.c
output/outmacho32.c
output/outmacho64.c

index 43ada7b..841e5fe 100644 (file)
@@ -391,13 +391,7 @@ static int32_t coff_section_names(char *name, int pass, int *bits)
                               " to better than 64-byte boundaries");
                     else {
                         align_and = ~0x00F00000L;
-                        align_or = (align == 1 ? 0x00100000L :
-                                    align == 2 ? 0x00200000L :
-                                    align == 4 ? 0x00300000L :
-                                    align == 8 ? 0x00400000L :
-                                    align == 16 ? 0x00500000L :
-                                    align ==
-                                    32 ? 0x00600000L : 0x00700000L);
+                       align_or  = ilog2_32(align) << 20;
                     }
                 }
             }
index b0c9560..16a6958 100644 (file)
@@ -229,35 +229,6 @@ uint32_t rel_padcnt = 0;
 static void debug_reloc (struct reloc *);
 static void debug_section_relocs (struct section *) _unused;
 
-static int exact_log2 (uint32_t align)
-{
-    if (align == 0) {
-       return 0;
-    } else if (align & (align-1)) {
-       return -1;              /* Not a power of 2 */
-    } else {
-#ifdef HAVE_GNUC_4
-       return __builtin_ctzl (align);
-#else
-       uint32_t result = 0;
-
-       /* We know exactly one bit is set at this point. */
-       if (align & 0xffff0000)
-           result |= 16;
-       if (align & 0xff00ff00)
-           result |= 8;
-       if (align & 0xf0f0f0f0)
-           result |= 4;
-       if (align & 0xcccccccc)
-           result |= 2;
-       if (align & 0xaaaaaaaa)
-           result |= 1;
-
-       return result;
-#endif
-    }
-}
-
 static struct section *get_section_by_name(const char *segname,
                                            const char *sectname)
 {
@@ -569,7 +540,7 @@ static int32_t macho_section(char *name, int pass, int *bits)
                         int newAlignment, value;
 
                         value = strtoul(currentAttribute + 6, (char**)&end, 0);
-                        newAlignment = exact_log2(value);
+                        newAlignment = alignlog2_32(value);
 
                         if (0 != *end) {
                             nasm_error(ERR_PANIC,
index f949881..4de5300 100644 (file)
@@ -235,35 +235,6 @@ uint64_t rel_padcnt64 = 0;
 static void debug_reloc (struct reloc *);
 static void debug_section_relocs (struct section *) _unused;
 
-static int exact_log2 (uint32_t align)
-{
-    if (align == 0) {
-       return 0;
-    } else if (align & (align-1)) {
-       return -1;              /* Not a power of 2 */
-    } else {
-#ifdef HAVE_GNUC_4
-       return __builtin_ctzl (align);
-#else
-       uint32_t result = 0;
-
-       /* We know exactly one bit is set at this point. */
-       if (align & 0xffff0000)
-           result |= 16;
-       if (align & 0xff00ff00)
-           result |= 8;
-       if (align & 0xf0f0f0f0)
-           result |= 4;
-       if (align & 0xcccccccc)
-           result |= 2;
-       if (align & 0xaaaaaaaa)
-           result |= 1;
-
-       return result;
-#endif
-    }
-}
-
 static struct section *get_section_by_name(const char *segname,
                                            const char *sectname)
 {
@@ -704,7 +675,7 @@ static int32_t macho_section(char *name, int pass, int *bits)
                         int newAlignment, value;
 
                         value = strtoul(currentAttribute + 6, (char**)&end, 0);
-                        newAlignment = exact_log2(value);
+                        newAlignment = alignlog2_32(value);
 
                         if (0 != *end) {
                             nasm_error(ERR_PANIC,