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]

Re: [PATCH] Add branch prediction favouring normal numbers


On Wed, Dec 26, 2012 at 12:33:16PM -0500, Mike Frysinger wrote:
> 
> we have __glibc_unlikely & __glibc_likely now
> -mike

We have __glibc_unlikely, but not glibc_likely (and I realized that I
had added it ;) ).  So here's a patch to add __glibc_likely.


	* misc/sys/cdefs.h(__glibc_likely): Wrap __builtin_expect for
	TRUE case.

diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
index fb6c959..1eee54e 100644
--- a/misc/sys/cdefs.h
+++ b/misc/sys/cdefs.h
@@ -378,8 +378,10 @@
 
 #if __GNUC__ >= 3
 # define __glibc_unlikely(cond) __builtin_expect((cond), 0)
+# define __glibc_likely(cond) __builtin_expect((cond), 1)
 #else
 # define __glibc_unlikely(cond) (cond)
+# define __glibc_likely(cond) (cond)
 #endif
 
 #include <bits/wordsize.h>

---

And then, here's the updated patch for the branch prediction:


	* 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..78afd99 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 (__glibc_likely (EX> -42 || (EX==-42 && X[1]>=TWO10)))
+    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]