This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Add branch prediction favouring normal numbers


Hi,

Attached patch adds branch prediction to the mp to double conversion
code to favour normal numbers.  This speeds up code by about a tenth
of a second when tested using the program in the following blog:

http://entropymine.com/imageworsener/slowpow/

as follows:

time ./powtest 1000000 1.0000000000000020 1.5000000000500000

Tested to verify that this does not cause regressions on x86_64.  OK
for 2.18?

Siddhesh

ChangeLog:

	* sysdeps/ieee754/dbl-64/mpa.c (__mp_dbl): Favour normal
	numbers.

diff --git a/sysdeps/ieee754/dbl-64/mpa.c b/sysdeps/ieee754/dbl-64/mpa.c
index 1c93bdc..12e9dda 100644
--- a/sysdeps/ieee754/dbl-64/mpa.c
+++ b/sysdeps/ieee754/dbl-64/mpa.c
@@ -248,9 +248,10 @@ void __mp_dbl(const mp_no *x, double *y, int p) {
 
   if (X[0] == ZERO)  {*y = ZERO;  return; }
 
-  if      (EX> -42)                 norm(x,y,p);
-  else if (EX==-42 && X[1]>=TWO10)  norm(x,y,p);
-  else                              denorm(x,y,p);
+  if (__builtin_expect (EX> -42 || (EX==-42 && X[1]>=TWO10), 1))
+    norm(x,y,p);
+  else
+    denorm(x,y,p);
 }
 #endif
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]