[PATCH] use magic wl_fixed_t to/from double only on x86-64

Pavel Vasin rat4vier at gmail.com
Wed May 16 02:34:42 PDT 2012


My results on Intel(R) Core(TM)2 Duo CPU     T5800  @ 2.00GHz

on x86:
benchmarked magic:	14.048889885s
benchmarked div:	5.426952392s
benchmarked mul:	4.034106976s

on x86-64:
benchmarked magic:	2.467789582s
benchmarked div:	9.748067755s
benchmarked mul:	8.665307997s

---
 src/wayland-util.h |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/wayland-util.h b/src/wayland-util.h
index fa5c6c5..919da34 100644
--- a/src/wayland-util.h
+++ b/src/wayland-util.h
@@ -168,6 +168,7 @@ void wl_array_copy(struct wl_array *array, struct wl_array *source);
 
 typedef int32_t wl_fixed_t;
 
+#ifdef __x86_64__
 static inline double
 wl_fixed_to_double (wl_fixed_t f)
 {
@@ -180,7 +181,15 @@ wl_fixed_to_double (wl_fixed_t f)
 
 	return u.d - (3LL << 43);
 }
+#else
+static inline double
+wl_fixed_to_double (wl_fixed_t f)
+{
+	return (double) f / 256.0;
+}
+#endif
 
+#ifdef __x86_64__
 static inline wl_fixed_t
 wl_fixed_from_double(double d)
 {
@@ -193,6 +202,13 @@ wl_fixed_from_double(double d)
 
 	return u.i;
 }
+#else
+static inline wl_fixed_t
+wl_fixed_from_double(double d)
+{
+	return (wl_fixed_t) round (d * 256.0);
+}
+#endif
 
 static inline int wl_fixed_to_int(wl_fixed_t f)
 {
-- 
1.7.10.2



More information about the wayland-devel mailing list