diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2010-02-15 10:46:37 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2010-02-15 19:19:10 -0500 |
commit | 68caaa745ab1df22a4b9c52235f40d19d2084f35 (patch) | |
tree | 0b052458bd2107cce730a7a76e2f10c3c6c07bc6 | |
parent | 42157c8b96c59211f536606dc17be01e36bab790 (diff) | |
download | seabios-68caaa745ab1df22a4b9c52235f40d19d2084f35.tar.gz |
Optimize ntohl() code.
Use the assembler bswapl instruction if the value is not constant.
-rw-r--r-- | src/util.h | 22 |
1 files changed, 15 insertions, 7 deletions
@@ -101,6 +101,21 @@ static inline u32 __fls(u32 word) return word; } +static inline u16 __htons_constant(u16 val) { + return (val<<8) | (val>>8); +} +static inline u32 __htonl_constant(u32 val) { + return (val<<24) | ((val&0xff00)<<8) | ((val&0xff0000)>>8) | (val>>24); +} +static inline u32 __htonl(u32 val) { + asm("bswapl %0" : "+r"(val)); + return val; +} +#define htonl(x) (__builtin_constant_p((u32)(x)) ? __htonl_constant(x) : __htonl(x)) +#define ntohl(x) htonl(x) +#define htons(x) __htons_constant(x) +#define ntohs(x) htons(x) + static inline u32 getesp(void) { u32 esp; asm("movl %%esp, %0" : "=rm"(esp)); @@ -395,11 +410,4 @@ extern u8 BiosChecksum; // version (auto generated file out/version.c) extern const char VERSION[]; -// XXX - optimize -#define ntohl(x) ((((x)&0xff)<<24) | (((x)&0xff00)<<8) | \ - (((x)&0xff0000) >> 8) | (((x)&0xff000000) >> 24)) -#define htonl(x) ntohl(x) -#define ntohs(x) ((((x)&0xff)<<8) | (((x)&0xff00)>>8)) -#define htons(x) ntohs(x) - #endif // util.h |