From: nasm-bot f. C. G. <gor...@gm...> - 2017-03-12 21:39:23
|
Commit-ID: e6c7c695a60b29cb35523923343d259c7e618bb6 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=e6c7c695a60b29cb35523923343d259c7e618bb6 Author: Cyrill Gorcunov <gor...@gm...> AuthorDate: Wed, 8 Mar 2017 13:03:52 +0300 Committer: Cyrill Gorcunov <gor...@gm...> CommitDate: Sun, 12 Mar 2017 11:41:44 +0300 nasmlib: Add _le helpers Signed-off-by: Cyrill Gorcunov <gor...@gm...> --- include/nasmlib.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/include/nasmlib.h b/include/nasmlib.h index dbe623b..29e55ca 100644 --- a/include/nasmlib.h +++ b/include/nasmlib.h @@ -248,6 +248,11 @@ void standard_extension(char *inname, char *outname, char *extension); #if X86_MEMORY +static inline uint8_t char_le(uint8_t v) { return v; } +static inline uint16_t short_le(uint16_t v) { return v; } +static inline uint32_t long_le(uint32_t v) { return v; } +static inline uint64_t dlong_le(uint64_t v) { return v; } + #define WRITECHAR(p,v) \ do { \ *(uint8_t *)(p) = (v); \ @@ -281,6 +286,32 @@ void standard_extension(char *inname, char *outname, char *extension); #else /* !X86_MEMORY */ +static inline uint8_t char_le(uint8_t v) +{ + return v; +} + +static inline uint16_t short_le(uint16_t v) +{ + return (v << 8) | (v >> 8); +} + +static inline uint32_t long_le(uint32_t v) +{ + v = ((v << 8) & 0xff00ff00 ) | + ((v >> 8) & 0x00ff00ff); + return (v << 16) | (v >> 16); +} + +static inline uint64_t dlong_le(uint64_t v) +{ + v = ((v << 8) & 0xff00ff00ff00ff00ull) | + ((v >> 8) & 0x00ff00ff00ff00ffull); + v = ((v << 16) & 0xffff0000ffff0000ull) | + ((v >> 16) & 0x0000ffff0000ffffull); + return (v << 32) | (v >> 32); +} + #define WRITECHAR(p,v) \ do { \ uint8_t *_wc_p = (uint8_t *)(p); \ |