]> sourceware.org Git - glibc.git/commitdiff
Optimize handling of denormals in logb/logbf/logbl
authorAndreas Schwab <schwab@linux-m68k.org>
Fri, 25 May 2012 09:57:33 +0000 (11:57 +0200)
committerAndreas Schwab <schwab@linux-m68k.org>
Sat, 26 May 2012 11:53:22 +0000 (13:53 +0200)
ChangeLog
sysdeps/ieee754/dbl-64/s_logb.c
sysdeps/ieee754/dbl-64/wordsize-64/s_logb.c
sysdeps/ieee754/flt-32/s_logbf.c
sysdeps/ieee754/ldbl-128/s_logbl.c
sysdeps/ieee754/ldbl-128ibm/s_logbl.c
sysdeps/ieee754/ldbl-96/s_logbl.c
sysdeps/powerpc/powerpc32/power7/fpu/s_logb.c
sysdeps/powerpc/powerpc32/power7/fpu/s_logbl.c

index a4ae9657b51219b89219d64b2796ecb773d5bfa8..68316766fd4f10aceb851bfc7057c23d7a800dbf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2012-05-26  Andreas Schwab  <schwab@linux-m68k.org>
+
+       * sysdeps/ieee754/dbl-64/s_logb.c (__logb): Optimize
+       handling of denormals.
+       * sysdeps/ieee754/dbl-64/wordsize-64/s_logb.c (__logb): Likewise.
+       * sysdeps/ieee754/flt-32/s_logbf.c (__logbf): Likewise.
+       * sysdeps/ieee754/ldbl-96/s_logbl.c (__logbl): Likewise.
+       * sysdeps/ieee754/ldbl-128/s_logbl.c (__logbl): Likewise.
+       * sysdeps/ieee754/ldbl-128ibm/s_logbl.c (__logbl): Likewise.
+       * sysdeps/powerpc/powerpc32/power7/fpu/s_logb.c (_logb): Likewise.
+       * sysdeps/powerpc/powerpc32/power7/fpu/s_logbl.c (_logbl):
+       Likewise.
+
 2012-05-25  Marek Polacek  <polacek@redhat.com>
 
        [BZ #14152]
index baa35e14d85dc6733e03e3fd26dc25e4c6677d23..17aa94b755c7403c924a29a5aa3dc88214f568e8 100644 (file)
@@ -34,10 +34,12 @@ __logb (double x)
     {
       /* POSIX specifies that denormal number is treated as
          though it were normalized.  */
-      int m1 = (ix == 0) ? 0 : __builtin_clz (ix);
-      int m2 = (lx == 0) ? 0 : __builtin_clz (lx);
-      int ma = (m1 == 0) ? m2 + 32 : m1;
-      return -1022.0 + (double)(11 - ma);
+      int ma;
+      if (ix == 0)
+       ma = __builtin_clz (lx) + 32;
+      else
+       ma = __builtin_clz (ix);
+      rix -= ma - 12;
     }
   return (double) (rix - 1023);
 }
index 185dd05be3882da3422e432681faa7ef8bb46ab2..40b8888130414ef6ba7190a1d87d446dc6251eb3 100644 (file)
@@ -36,8 +36,8 @@ __logb (double x)
     return x * x;
   if (__builtin_expect (ex == 0, 0))
     {
-      int m = (ix == 0) ? 0 : __builtin_clzll (ix);
-      return -1022.0 + (double)(11 -m);
+      int m = __builtin_clzll (ix);
+      ex -= m - 12;
     }
   return (double) (ex - 1023);
 }
index 025c70de7ecf53dc860b37d0ccff7239bba56831..e2b3aaa626c2799520f1750cc6328fa652f77358 100644 (file)
@@ -31,8 +31,7 @@ __logbf (float x)
     {
       /* POSIX specifies that denormal number is treated as
          though it were normalized.  */
-      int m = (ix == 0) ? 0 : __builtin_clz (ix);
-      return -126.0 + (float)(8 - m);
+      rix -= __builtin_clz (ix) - 9;
     }
   return (float) (rix - 127);
 }
index cf6003e055ad9ce669bc0a7ba658b86080baa30f..3ba67b7bd2c70c613b56d528bad3eec1ad04900b 100644 (file)
@@ -41,10 +41,12 @@ __logbl (long double x)
     {
       /* POSIX specifies that denormal number is treated as
          though it were normalized.  */
-      int m1 = (hx == 0) ? 0 : __builtin_clzll (hx);
-      int m2 = (lx == 0) ? 0 : __builtin_clzll (lx);
-      int ma = (m1 == 0) ? m2 + 64 : m1;
-      return -16382.0 + (long double)(15 - ma);
+      int ma;
+      if (hx == 0)
+       ma = __builtin_clzll (lx) + 64;
+      else
+       ma = __builtin_clzll (hx);
+      ex -= ma - 16;
     }
   return (long double) (ex - 16383);
 }
index 678b6cad57cbaa0b9292fcbaaaf9d1d64ee6eb07..92ce2c1896119e61c5ae626baa4340c8b20a073a 100644 (file)
@@ -30,7 +30,7 @@ __logbl (long double x)
 
   GET_LDOUBLE_WORDS64 (hx, lx, x);
   hx &= 0x7fffffffffffffffLL;  /* high |x| */
-  if ((hx | (lx & 0x7fffffffffffffffLL)) == 0)
+  if (hx == 0)
     return -1.0 / fabs (x);
   if (hx >= 0x7ff0000000000000LL)
     return x * x;
@@ -38,10 +38,7 @@ __logbl (long double x)
     {
       /* POSIX specifies that denormal number is treated as
          though it were normalized.  */
-      int m1 = (hx == 0) ? 0 : __builtin_clzll (hx);
-      int m2 = (lx == 0) ? 0 : __builtin_clzll (lx);
-      int ma = (m1 == 0) ? m2 + 64 : m1;
-      return -1022.0 + (long double)(11 - ma);
+      rhx -= __builtin_clzll (hx) - 12;
     }
   return (long double) (rhx - 1023);
 }
index d8ad4bcfcf978a86049d9cf6564f9f7afd50aa58..4289be193361dcf50fab0a8db49a5932b2bd80a9 100644 (file)
@@ -38,10 +38,12 @@ __logbl (long double x)
     {
       /* POSIX specifies that denormal number is treated as
          though it were normalized.  */
-      int m1 = (ix == 0) ? 0 : __builtin_clz (ix);
-      int m2 = (lx == 0) ? 0 : __builtin_clz (lx);
-      int ma = (m1 == 0) ? m2 + 32 : m1;
-      return -16382.0 - (long double)(ma);
+      int ma;
+      if (ix == 0)
+       ma = __builtin_clz (lx) + 32;
+      else
+       ma = __builtin_clz (ix);
+      es -= ma - 1;
     }
   return (long double) (es - 16383);
 }
index fba482290001894d56b91faba6217f4f79d6c61f..87176c34c9ee0fede3d630ef888a8b721902060c 100644 (file)
@@ -55,13 +55,14 @@ __logb (double x)
       /* POSIX specifies that denormal numbers are treated as
          though they were normalized.  */
       int32_t lx, ix;
-      int m1, m2, ma;
+      int ma;
 
-      EXTRACT_WORDS (ix , lx, x);
-      m1 = (ix == 0) ? 0 : __builtin_clz (ix);
-      m2 = (lx == 0) ? 0 : __builtin_clz (lx);
-      ma = (m1 == 0) ? m2 + 32 : m1;
-      return -1022.0 + (double)(11 - ma);
+      EXTRACT_WORDS (ix, lx, x);
+      if (ix == 0)
+       ma = __builtin_clz (lx) + 32;
+      else
+       ma = __builtin_clz (ix);
+      return (double) (-1023 - (ma - 12));
     }
   /* Test to avoid logb_downward (0.0) == -0.0.  */
   return ret == -0.0 ? 0.0 : ret;
index 03942ca53de3c96d27c163d7dab107693d7fadc6..20c7d4e6e933e9e42f1a833aa88cd607399f5efc 100644 (file)
@@ -56,14 +56,12 @@ __logbl (long double x)
     return (xh * xh);
   else if (__builtin_expect (ret == two10m1, 0))
     {
+      /* POSIX specifies that denormal number is treated as
+         though it were normalized.  */
       int64_t lx, hx;
-      int m1, m2, ma;
 
       GET_LDOUBLE_WORDS64 (hx, lx, x);
-      m1 = (hx == 0) ? 0 : __builtin_clzll (hx);
-      m2 = (lx == 0) ? 0 : __builtin_clzll (lx);
-      ma = (m1 == 0) ? m2 + 64 : m1;
-      return -1022.0 + (double)(11 - ma);
+      return (long double) (-1023 - (__builtin_clzll (hx) - 12));
     }
   /* Test to avoid logb_downward (0.0) == -0.0.  */
   return ret == -0.0 ? 0.0 : ret;
This page took 0.117861 seconds and 5 git commands to generate.