[PATCH] weston: Optimalize wl_fixed_to_double()

Martin Minarik minarik11 at student.fiit.stuba.sk
Fri May 11 16:03:13 PDT 2012


According to my test, using multiplication is nearly 4 times faster.

Dump of assembler code for function wl_fixed_to_double_old:
   0x080483b4 <+0>:	push   %ebp
   0x080483b5 <+1>:	mov    %esp,%ebp
   0x080483b7 <+3>:	fildl  0x8(%ebp)
   0x080483ba <+6>:	fldl   0x80484e0
   0x080483c0 <+12>:	fdivrp %st,%st(1)
=> 0x080483c2 <+14>:	pop    %ebp
   0x080483c3 <+15>:	ret
End of assembler dump.

Dump of assembler code for function wl_fixed_to_double_new:
   0x080483c4 <+0>:	push   %ebp
=> 0x080483c5 <+1>:	mov    %esp,%ebp
   0x080483c7 <+3>:	fildl  0x8(%ebp)
   0x080483ca <+6>:	fldl   0x80484e8
   0x080483d0 <+12>:	fmulp  %st,%st(1)
   0x080483d2 <+14>:	pop    %ebp
   0x080483d3 <+15>:	ret
End of assembler dump.
---
 src/wayland-util.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/wayland-util.h b/src/wayland-util.h
index 8def7ee..2ecbcc7 100644
--- a/src/wayland-util.h
+++ b/src/wayland-util.h
@@ -171,7 +171,7 @@ typedef int32_t wl_fixed_t;
 
 static inline double wl_fixed_to_double(wl_fixed_t f)
 {
-	return (double) f / 256.0;
+	return (double) f * (1.0 / 256.0);
 };
 static inline wl_fixed_t wl_fixed_from_double(double d)
 {
-- 
1.7.5.4



More information about the wayland-devel mailing list