From 35c30da61b13823d820f0503db5bb24fccb116f8 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 21 Apr 2010 16:46:57 -0700 Subject: Remove open-coded ilog2() implementations When we need integer log2, use the new library routine. Signed-off-by: H. Peter Anvin --- output/outcoff.c | 8 +------- output/outmacho32.c | 31 +------------------------------ output/outmacho64.c | 31 +------------------------------ 3 files changed, 3 insertions(+), 67 deletions(-) (limited to 'output') diff --git a/output/outcoff.c b/output/outcoff.c index 43ada7b..841e5fe 100644 --- a/output/outcoff.c +++ b/output/outcoff.c @@ -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; } } } diff --git a/output/outmacho32.c b/output/outmacho32.c index b0c9560..16a6958 100644 --- a/output/outmacho32.c +++ b/output/outmacho32.c @@ -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, diff --git a/output/outmacho64.c b/output/outmacho64.c index f949881..4de5300 100644 --- a/output/outmacho64.c +++ b/output/outmacho64.c @@ -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, -- cgit v1.2.3