aboutsummaryrefslogtreecommitdiff
path: root/src/util.h
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2010-02-15 10:46:37 -0500
committerKevin O'Connor <kevin@koconnor.net>2010-02-15 19:19:10 -0500
commit68caaa745ab1df22a4b9c52235f40d19d2084f35 (patch)
tree0b052458bd2107cce730a7a76e2f10c3c6c07bc6 /src/util.h
parent42157c8b96c59211f536606dc17be01e36bab790 (diff)
downloadseabios-hppa-68caaa745ab1df22a4b9c52235f40d19d2084f35.zip
seabios-hppa-68caaa745ab1df22a4b9c52235f40d19d2084f35.tar.gz
seabios-hppa-68caaa745ab1df22a4b9c52235f40d19d2084f35.tar.bz2
Optimize ntohl() code.
Use the assembler bswapl instruction if the value is not constant.
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/util.h b/src/util.h
index 4228904..eb62507 100644
--- a/src/util.h
+++ b/src/util.h
@@ -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