mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-07-24 10:25:42 -04:00
bytesex.h: more simplifications and add const
Add more simplifications where it is practical; unify WRITECHAR() as it has no need for byte swapping in any way. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
parent
df5548a40c
commit
f52ea70dd1
@ -50,83 +50,66 @@
|
|||||||
* format in memory.
|
* format in memory.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define WRITECHAR(p,v) \
|
||||||
|
do { \
|
||||||
|
uint8_t *_wc_p = (uint8_t *)(p); \
|
||||||
|
*_wc_p++ = (v); \
|
||||||
|
(p) = (void *)_wc_p; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#if X86_MEMORY
|
#if X86_MEMORY
|
||||||
|
|
||||||
#define WRITECHAR(p,v) \
|
#define WRITESHORT(p,v) \
|
||||||
do { \
|
do { \
|
||||||
uint8_t *_wc_p = (uint8_t *)(p); \
|
uint16_t *_ws_p = (uint16_t *)(p); \
|
||||||
*_wc_p = (v); \
|
*_ws_p++ = (v); \
|
||||||
(p) = (void *)(_wc_p + 1); \
|
(p) = (void *)_ws_p; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define WRITESHORT(p,v) \
|
#define WRITELONG(p,v) \
|
||||||
do { \
|
do { \
|
||||||
uint16_t *_ws_p = (uint16_t *)(p); \
|
uint32_t *_wl_p = (uint32_t *)(p); \
|
||||||
*_ws_p = (v); \
|
*_wl_p++ = (v); \
|
||||||
(p) = (void *)(_ws_p + 1); \
|
(p) = (void *)_wl_p; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define WRITELONG(p,v) \
|
#define WRITEDLONG(p,v) \
|
||||||
do { \
|
do { \
|
||||||
uint32_t *_wl_p = (uint32_t *)(p); \
|
uint64_t *_wq_p = (uint64_t *)(p); \
|
||||||
*_wl_p = (v); \
|
*_wq_p++ = (v); \
|
||||||
(p) = (void *)(_wl_p + 1); \
|
(p) = (void *)_wq_p; \
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define WRITEDLONG(p,v) \
|
|
||||||
do { \
|
|
||||||
uint64_t *_wq_p = (uint64_t *)(p); \
|
|
||||||
*_wq_p = (v); \
|
|
||||||
(p) = (void *)(_wq_p + 1); \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#else /* !X86_MEMORY */
|
#else /* !X86_MEMORY */
|
||||||
|
|
||||||
#define WRITECHAR(p,v) \
|
#define WRITESHORT(p,v) \
|
||||||
do { \
|
do { \
|
||||||
uint8_t *_wc_p = (uint8_t *)(p); \
|
uint8_t *_ws_p = (uint8_t *)(p); \
|
||||||
uint8_t _wc_v = (v); \
|
const uint16_t _ws_v = (v); \
|
||||||
_wc_p[0] = _wc_v; \
|
WRITECHAR(_ws_p, _ws_v); \
|
||||||
(p) = (void *)(_wc_p + 1); \
|
WRITECHAR(_ws_p, _ws_v >> 8); \
|
||||||
|
(p) = (void *)_ws_p; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define WRITESHORT(p,v) \
|
#define WRITELONG(p,v) \
|
||||||
do { \
|
do { \
|
||||||
uint8_t *_ws_p = (uint8_t *)(p); \
|
uint8_t *_wl_p = (uint8_t *)(p); \
|
||||||
uint16_t _ws_v = (v); \
|
const uint32_t _wl_v = (v); \
|
||||||
_ws_p[0] = _ws_v; \
|
WRITESHORT(_wl_p, _wl_v); \
|
||||||
_ws_p[1] = _ws_v >> 8; \
|
WRITESHORT(_wl_p, _wl_v >> 16); \
|
||||||
(p) = (void *)(_ws_p + 2); \
|
(p) = (void *)_wl_p; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define WRITELONG(p,v) \
|
#define WRITEDLONG(p,v) \
|
||||||
do { \
|
do { \
|
||||||
uint8_t *_wl_p = (uint8_t *)(p); \
|
uint8_t *_wq_p = (uint8_t *)(p); \
|
||||||
uint32_t _wl_v = (v); \
|
const uint64_t _wq_v = (v); \
|
||||||
_wl_p[0] = _wl_v; \
|
WRITELONG(_wq_p, _wq_v); \
|
||||||
_wl_p[1] = _wl_v >> 8; \
|
WRITELONG(_wq_p, _wq_v >> 32); \
|
||||||
_wl_p[2] = _wl_v >> 16; \
|
(p) = (void *)_wq_p; \
|
||||||
_wl_p[3] = _wl_v >> 24; \
|
|
||||||
(p) = (void *)(_wl_p + 4); \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define WRITEDLONG(p,v) \
|
#endif /* X86_MEMORY */
|
||||||
do { \
|
|
||||||
uint8_t *_wq_p = (uint8_t *)(p); \
|
|
||||||
uint64_t _wq_v = (v); \
|
|
||||||
_wq_p[0] = _wq_v; \
|
|
||||||
_wq_p[1] = _wq_v >> 8; \
|
|
||||||
_wq_p[2] = _wq_v >> 16; \
|
|
||||||
_wq_p[3] = _wq_v >> 24; \
|
|
||||||
_wq_p[4] = _wq_v >> 32; \
|
|
||||||
_wq_p[5] = _wq_v >> 40; \
|
|
||||||
_wq_p[6] = _wq_v >> 48; \
|
|
||||||
_wq_p[7] = _wq_v >> 56; \
|
|
||||||
(p) = (void *)(_wq_p + 8); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Endian control functions which work on a single integer
|
* Endian control functions which work on a single integer
|
||||||
@ -248,31 +231,31 @@ static inline uint64_t cpu_to_le64(uint64_t v)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define WRITEADDR(p,v,s) \
|
#define WRITEADDR(p,v,s) \
|
||||||
do { \
|
do { \
|
||||||
switch (is_constant(s) ? (s) : 0) { \
|
switch (is_constant(s) ? (s) : 0) { \
|
||||||
case 1: \
|
case 1: \
|
||||||
WRITECHAR(p,v); \
|
WRITECHAR(p,v); \
|
||||||
break; \
|
break; \
|
||||||
case 2: \
|
case 2: \
|
||||||
WRITESHORT(p,v); \
|
WRITESHORT(p,v); \
|
||||||
break; \
|
break; \
|
||||||
case 4: \
|
case 4: \
|
||||||
WRITELONG(p,v); \
|
WRITELONG(p,v); \
|
||||||
break; \
|
break; \
|
||||||
case 8: \
|
case 8: \
|
||||||
WRITEDLONG(p,v); \
|
WRITEDLONG(p,v); \
|
||||||
break; \
|
break; \
|
||||||
default: \
|
default: \
|
||||||
{ \
|
{ \
|
||||||
uint64_t _wa_v = cpu_to_le64(v); \
|
const uint64_t _wa_v = cpu_to_le64(v); \
|
||||||
size_t _wa_s = (s); \
|
const size_t _wa_s = (s); \
|
||||||
uint8_t *_wa_p = (uint8_t *)(p); \
|
uint8_t * const _wa_p = (uint8_t *)(p); \
|
||||||
memcpy(_wa_p, &_wa_v, _wa_s); \
|
memcpy(_wa_p, &_wa_v, _wa_s); \
|
||||||
(p) = (void *)(_wa_p + _wa_s); \
|
(p) = (void *)(_wa_p + _wa_s); \
|
||||||
} \
|
} \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#endif /* NASM_BYTESEX_H */
|
#endif /* NASM_BYTESEX_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user