summaryrefslogtreecommitdiff
path: root/include/bytesex.h
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2017-11-29 16:05:59 -0800
committerH. Peter Anvin <hpa@linux.intel.com>2017-11-29 16:05:59 -0800
commitb23062257619c7d2b4de368936c4d702516e8065 (patch)
tree8e01625a8d428798b3cf344bdcb76a15db49fa56 /include/bytesex.h
parentcb7da7e7f63f8c0dfd7baf0e970e737bf5f55cbf (diff)
downloadnasm-b23062257619c7d2b4de368936c4d702516e8065.tar.gz
bytesex.h: unify and optimize WRITEADDR()
WRITEADDR() really doesn't need multiple implementations. Unify them, and optimize the case of a constant length argument (not sure if that is currently used, however.) Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'include/bytesex.h')
-rw-r--r--include/bytesex.h42
1 files changed, 25 insertions, 17 deletions
diff --git a/include/bytesex.h b/include/bytesex.h
index ee20adff..640c4dd9 100644
--- a/include/bytesex.h
+++ b/include/bytesex.h
@@ -76,13 +76,6 @@
(p) += 8; \
} while (0)
-#define WRITEADDR(p,v,s) \
- do { \
- uint64_t _wa_v = (v); \
- memcpy((p), &_wa_v, (s)); \
- (p) += (s); \
- } while (0)
-
#else /* !X86_MEMORY */
#define WRITECHAR(p,v) \
@@ -128,16 +121,6 @@
(p) = (void *)(_wq_p + 8); \
} while (0)
-#define WRITEADDR(p,v,s) \
- do { \
- int _wa_s = (s); \
- uint64_t _wa_v = (v); \
- while (_wa_s--) { \
- WRITECHAR(p,_wa_v); \
- _wa_v >>= 8; \
- } \
- } while(0)
-
#endif
@@ -261,4 +244,29 @@ static inline uint64_t cpu_to_le64(uint64_t v)
#endif
+#define WRITEADDR(p,v,s) \
+ do { \
+ switch (is_constant(s) ? (s) : 0) { \
+ case 1: \
+ WRITECHAR(p,v); \
+ break; \
+ case 2: \
+ WRITESHORT(p,v); \
+ break; \
+ case 4: \
+ WRITELONG(p,v); \
+ break; \
+ case 8: \
+ WRITEDLONG(p,v); \
+ break; \
+ default: \
+ { \
+ uint64_t _wa_v = cpu_to_le64(v); \
+ memcpy((p), &_wa_v, (s)); \
+ (p) += (s); \
+ } \
+ break; \
+ } \
+ } while (0)
+
#endif /* NASM_BYTESEX_H */