summaryrefslogtreecommitdiff
path: root/output
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2007-04-13 19:58:42 +0000
committerH. Peter Anvin <hpa@zytor.com>2007-04-13 19:58:42 +0000
commitc1494ac5abcdbdb1a6b4c56eb845b0d7694a853b (patch)
tree640c70ac3d99faeef56be65b4588e97658e934de /output
parenta6dfa78b7805673b2b4955a9f34e21825730f79d (diff)
downloadnasm-c1494ac5abcdbdb1a6b4c56eb845b0d7694a853b.tar.gz
nasm-c1494ac5abcdbdb1a6b4c56eb845b0d7694a853b.tar.bz2
nasm-c1494ac5abcdbdb1a6b4c56eb845b0d7694a853b.zip
Macroize any compiler-specific code; macros defined in "compiler.h"
Move anything compiler-specific to "compiler.h". There was an unguarded use of __attribute__(()) in outmacho.c; also require gcc 4+ for __builtin_ctlz(). Speed up the open-coded version, too.
Diffstat (limited to 'output')
-rw-r--r--output/outmacho.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/output/outmacho.c b/output/outmacho.c
index 5e71900..8c3ff79 100644
--- a/output/outmacho.c
+++ b/output/outmacho.c
@@ -19,6 +19,7 @@
#include "nasm.h"
#include "nasmlib.h"
#include "outform.h"
+#include "compiler.h"
#if defined(OF_MACHO)
@@ -199,20 +200,31 @@ uint32_t rel_padcnt = 0;
align(x, sizeof(int32_t)) /* align x to int32_t boundary */
static void debug_reloc (struct reloc *);
-static void debug_section_relocs (struct section *) __attribute__ ((unused));
+static void debug_section_relocs (struct section *) _unused;
-static int exact_log2 (uint32_t align) {
- if (align != (align & -align)) {
- return -1;
+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 __GNUC__
- return (align ? __builtin_ctzl (align) : 0);
+#ifdef HAVE_GNUC_4
+ return __builtin_ctzl (align);
#else
uint32_t result = 0;
- while (align >>= 1) {
- ++result;
- }
+ /* 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