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 12/27/2012 11:41 AM, Siddhesh Poyarekar wrote:
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


Both changes look fine to me, thanks,

Andreas

--
 Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
  SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
   GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
    GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126


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