mirror of
https://github.com/netwide-assembler/nasm.git
synced 2024-11-27 08:10:07 +08:00
Remove open-coded ilog2() implementations
When we need integer log2, use the new library routine. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
parent
084b13227e
commit
35c30da61b
@ -391,13 +391,7 @@ static int32_t coff_section_names(char *name, int pass, int *bits)
|
|||||||
" to better than 64-byte boundaries");
|
" to better than 64-byte boundaries");
|
||||||
else {
|
else {
|
||||||
align_and = ~0x00F00000L;
|
align_and = ~0x00F00000L;
|
||||||
align_or = (align == 1 ? 0x00100000L :
|
align_or = ilog2_32(align) << 20;
|
||||||
align == 2 ? 0x00200000L :
|
|
||||||
align == 4 ? 0x00300000L :
|
|
||||||
align == 8 ? 0x00400000L :
|
|
||||||
align == 16 ? 0x00500000L :
|
|
||||||
align ==
|
|
||||||
32 ? 0x00600000L : 0x00700000L);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -229,35 +229,6 @@ uint32_t rel_padcnt = 0;
|
|||||||
static void debug_reloc (struct reloc *);
|
static void debug_reloc (struct reloc *);
|
||||||
static void debug_section_relocs (struct section *) _unused;
|
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,
|
static struct section *get_section_by_name(const char *segname,
|
||||||
const char *sectname)
|
const char *sectname)
|
||||||
{
|
{
|
||||||
@ -569,7 +540,7 @@ static int32_t macho_section(char *name, int pass, int *bits)
|
|||||||
int newAlignment, value;
|
int newAlignment, value;
|
||||||
|
|
||||||
value = strtoul(currentAttribute + 6, (char**)&end, 0);
|
value = strtoul(currentAttribute + 6, (char**)&end, 0);
|
||||||
newAlignment = exact_log2(value);
|
newAlignment = alignlog2_32(value);
|
||||||
|
|
||||||
if (0 != *end) {
|
if (0 != *end) {
|
||||||
nasm_error(ERR_PANIC,
|
nasm_error(ERR_PANIC,
|
||||||
|
@ -235,35 +235,6 @@ uint64_t rel_padcnt64 = 0;
|
|||||||
static void debug_reloc (struct reloc *);
|
static void debug_reloc (struct reloc *);
|
||||||
static void debug_section_relocs (struct section *) _unused;
|
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,
|
static struct section *get_section_by_name(const char *segname,
|
||||||
const char *sectname)
|
const char *sectname)
|
||||||
{
|
{
|
||||||
@ -704,7 +675,7 @@ static int32_t macho_section(char *name, int pass, int *bits)
|
|||||||
int newAlignment, value;
|
int newAlignment, value;
|
||||||
|
|
||||||
value = strtoul(currentAttribute + 6, (char**)&end, 0);
|
value = strtoul(currentAttribute + 6, (char**)&end, 0);
|
||||||
newAlignment = exact_log2(value);
|
newAlignment = alignlog2_32(value);
|
||||||
|
|
||||||
if (0 != *end) {
|
if (0 != *end) {
|
||||||
nasm_error(ERR_PANIC,
|
nasm_error(ERR_PANIC,
|
||||||
|
Loading…
Reference in New Issue
Block a user