Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libm/src Appease static analyzers by making all code pat...



details:   https://anonhg.NetBSD.org/src/rev/37614fe62d43
branches:  trunk
changeset: 821576:37614fe62d43
user:      maya <maya%NetBSD.org@localhost>
date:      Thu Feb 09 21:23:11 2017 +0000

description:
Appease static analyzers by making all code paths which assign
values into p,q sane. Get rid of redundant assignment. Indent
for legibility. NFC.

This doesn't create a functional difference, as all callers
test number >= 0x40000000 anyway.

To see this, note the following:
- consistently, hx is the high bits of x, lx is the low bits,
  x is the float.
- & 0x7fffffff zeroes the sign bit, as does fabs.

A case where it isn't easy to see that there's no functional
change is y1, which does:

ix = hx & 0x7fffffff (zero signbit of high bits of x)
y = fabs(x) (this has a zeroed signbit but otherwise same as x)
ix >= 0x40000000
  pone(y); qone(y)

qone(x) (also pone) do:
  ix = hx & 0x7fffffff

ix in qone and in the calling function are the same number,
and the comparison applies for both, and ix < 0x40000000 isn't
possible.

(Also, no explosions seem to happen when I feed it random numbers)

diffstat:

 lib/libm/src/e_j0.c  |  20 +++++++++-----------
 lib/libm/src/e_j0f.c |  20 +++++++++-----------
 lib/libm/src/e_j1.c  |  20 +++++++++-----------
 lib/libm/src/e_j1f.c |  20 +++++++++-----------
 4 files changed, 36 insertions(+), 44 deletions(-)

diffs (196 lines):

diff -r f43af175d592 -r 37614fe62d43 lib/libm/src/e_j0.c
--- a/lib/libm/src/e_j0.c       Thu Feb 09 20:42:30 2017 +0000
+++ b/lib/libm/src/e_j0.c       Thu Feb 09 21:23:11 2017 +0000
@@ -12,7 +12,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBM_SCCS) && !defined(lint)
-__RCSID("$NetBSD: e_j0.c,v 1.12 2007/08/20 16:01:38 drochner Exp $");
+__RCSID("$NetBSD: e_j0.c,v 1.13 2017/02/09 21:23:11 maya Exp $");
 #endif
 
 /* __ieee754_j0(x), __ieee754_y0(x)
@@ -277,13 +277,12 @@
        double z,r,s;
        int32_t ix;
 
-       p = q = 0;
        GET_HIGH_WORD(ix,x);
        ix &= 0x7fffffff;
-       if(ix>=0x40200000)     {p = pR8; q= pS8;}
-       else if(ix>=0x40122E8B){p = pR5; q= pS5;}
-       else if(ix>=0x4006DB6D){p = pR3; q= pS3;}
-       else if(ix>=0x40000000){p = pR2; q= pS2;}
+       if(ix>=0x40200000)         {p = pR8; q= pS8;}
+       else if(ix>=0x40122E8B)    {p = pR5; q= pS5;}
+       else if(ix>=0x4006DB6D)    {p = pR3; q= pS3;}
+       else /*if(ix>=0x40000000)*/{p = pR2; q= pS2;}
        z = one/(x*x);
        r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
        s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
@@ -375,13 +374,12 @@
        double s,r,z;
        int32_t ix;
 
-       p = q = 0;
        GET_HIGH_WORD(ix,x);
        ix &= 0x7fffffff;
-       if(ix>=0x40200000)     {p = qR8; q= qS8;}
-       else if(ix>=0x40122E8B){p = qR5; q= qS5;}
-       else if(ix>=0x4006DB6D){p = qR3; q= qS3;}
-       else if(ix>=0x40000000){p = qR2; q= qS2;}
+       if(ix>=0x40200000)         {p = qR8; q= qS8;}
+       else if(ix>=0x40122E8B)    {p = qR5; q= qS5;}
+       else if(ix>=0x4006DB6D)    {p = qR3; q= qS3;}
+       else /*if(ix>=0x40000000)*/{p = qR2; q= qS2;}
        z = one/(x*x);
        r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
        s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
diff -r f43af175d592 -r 37614fe62d43 lib/libm/src/e_j0f.c
--- a/lib/libm/src/e_j0f.c      Thu Feb 09 20:42:30 2017 +0000
+++ b/lib/libm/src/e_j0f.c      Thu Feb 09 21:23:11 2017 +0000
@@ -15,7 +15,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBM_SCCS) && !defined(lint)
-__RCSID("$NetBSD: e_j0f.c,v 1.10 2007/08/20 16:01:38 drochner Exp $");
+__RCSID("$NetBSD: e_j0f.c,v 1.11 2017/02/09 21:23:11 maya Exp $");
 #endif
 
 #include "namespace.h"
@@ -240,13 +240,12 @@
        float z,r,s;
        int32_t ix;
 
-       p = q = 0;
        GET_FLOAT_WORD(ix,x);
        ix &= 0x7fffffff;
-       if(ix>=0x41000000)     {p = pR8; q= pS8;}
-       else if(ix>=0x40f71c58){p = pR5; q= pS5;}
-       else if(ix>=0x4036db68){p = pR3; q= pS3;}
-       else if(ix>=0x40000000){p = pR2; q= pS2;}
+       if(ix>=0x41000000)         {p = pR8; q= pS8;}
+       else if(ix>=0x40f71c58)    {p = pR5; q= pS5;}
+       else if(ix>=0x4036db68)    {p = pR3; q= pS3;}
+       else /*if(ix>=0x40000000)*/{p = pR2; q= pS2;}
        z = one/(x*x);
        r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
        s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
@@ -338,13 +337,12 @@
        float s,r,z;
        int32_t ix;
 
-       p = q = 0;
        GET_FLOAT_WORD(ix,x);
        ix &= 0x7fffffff;
-       if(ix>=0x41000000)     {p = qR8; q= qS8;}
-       else if(ix>=0x40f71c58){p = qR5; q= qS5;}
-       else if(ix>=0x4036db68){p = qR3; q= qS3;}
-       else if(ix>=0x40000000){p = qR2; q= qS2;}
+       if(ix>=0x41000000)         {p = qR8; q= qS8;}
+       else if(ix>=0x40f71c58)    {p = qR5; q= qS5;}
+       else if(ix>=0x4036db68)    {p = qR3; q= qS3;}
+       else /*if(ix>=0x40000000)*/{p = qR2; q= qS2;}
        z = one/(x*x);
        r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
        s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
diff -r f43af175d592 -r 37614fe62d43 lib/libm/src/e_j1.c
--- a/lib/libm/src/e_j1.c       Thu Feb 09 20:42:30 2017 +0000
+++ b/lib/libm/src/e_j1.c       Thu Feb 09 21:23:11 2017 +0000
@@ -12,7 +12,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBM_SCCS) && !defined(lint)
-__RCSID("$NetBSD: e_j1.c,v 1.12 2007/08/20 16:01:38 drochner Exp $");
+__RCSID("$NetBSD: e_j1.c,v 1.13 2017/02/09 21:23:11 maya Exp $");
 #endif
 
 /* __ieee754_j1(x), __ieee754_y1(x)
@@ -271,13 +271,12 @@
        double z,r,s;
         int32_t ix;
 
-       p = q = 0;
        GET_HIGH_WORD(ix,x);
        ix &= 0x7fffffff;
-        if(ix>=0x40200000)     {p = pr8; q= ps8;}
-        else if(ix>=0x40122E8B){p = pr5; q= ps5;}
-        else if(ix>=0x4006DB6D){p = pr3; q= ps3;}
-        else if(ix>=0x40000000){p = pr2; q= ps2;}
+        if(ix>=0x40200000)         {p = pr8; q= ps8;}
+        else if(ix>=0x40122E8B)    {p = pr5; q= ps5;}
+        else if(ix>=0x4006DB6D)    {p = pr3; q= ps3;}
+        else /*if(ix>=0x40000000)*/{p = pr2; q= ps2;}
         z = one/(x*x);
         r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
         s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
@@ -370,13 +369,12 @@
        double  s,r,z;
        int32_t ix;
 
-       p = q = 0;
        GET_HIGH_WORD(ix,x);
        ix &= 0x7fffffff;
-       if(ix>=0x40200000)     {p = qr8; q= qs8;}
-       else if(ix>=0x40122E8B){p = qr5; q= qs5;}
-       else if(ix>=0x4006DB6D){p = qr3; q= qs3;}
-       else if(ix>=0x40000000){p = qr2; q= qs2;}
+       if(ix>=0x40200000)         {p = qr8; q= qs8;}
+       else if(ix>=0x40122E8B)    {p = qr5; q= qs5;}
+       else if(ix>=0x4006DB6D)    {p = qr3; q= qs3;}
+       else /*if(ix>=0x40000000)*/{p = qr2; q= qs2;}
        z = one/(x*x);
        r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
        s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
diff -r f43af175d592 -r 37614fe62d43 lib/libm/src/e_j1f.c
--- a/lib/libm/src/e_j1f.c      Thu Feb 09 20:42:30 2017 +0000
+++ b/lib/libm/src/e_j1f.c      Thu Feb 09 21:23:11 2017 +0000
@@ -15,7 +15,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBM_SCCS) && !defined(lint)
-__RCSID("$NetBSD: e_j1f.c,v 1.11 2007/08/20 16:01:38 drochner Exp $");
+__RCSID("$NetBSD: e_j1f.c,v 1.12 2017/02/09 21:23:11 maya Exp $");
 #endif
 
 #include "namespace.h"
@@ -232,13 +232,12 @@
        float z,r,s;
         int32_t ix;
 
-       p = q = 0;
        GET_FLOAT_WORD(ix,x);
        ix &= 0x7fffffff;
-        if(ix>=0x41000000)     {p = pr8; q= ps8;}
-        else if(ix>=0x40f71c58){p = pr5; q= ps5;}
-        else if(ix>=0x4036db68){p = pr3; q= ps3;}
-        else if(ix>=0x40000000){p = pr2; q= ps2;}
+        if(ix>=0x41000000)         {p = pr8; q= ps8;}
+        else if(ix>=0x40f71c58)    {p = pr5; q= ps5;}
+        else if(ix>=0x4036db68)    {p = pr3; q= ps3;}
+        else /*if(ix>=0x40000000)*/{p = pr2; q= ps2;}
         z = one/(x*x);
         r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
         s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
@@ -331,17 +330,16 @@
        float  s,r,z;
        int32_t ix;
 
-       p = q = 0;
        GET_FLOAT_WORD(ix,x);
        ix &= 0x7fffffff;
        /* [inf, 8]             (8      41000000) */
-       if(ix>=0x41000000)     {p = qr8; q= qs8;}
+       if(ix>=0x41000000)         {p = qr8; q= qs8;}
        /* [8, 4.5454]          (4.5454 409173eb) */
-       else if(ix>=0x409173eb){p = qr5; q= qs5;}
+       else if(ix>=0x409173eb)    {p = qr5; q= qs5;}
        /* [4.5454, 2.8570]     (2.8570 4036d917) */
-       else if(ix>=0x4036d917){p = qr3; q= qs3;}
+       else if(ix>=0x4036d917)    {p = qr3; q= qs3;}
        /* [2.8570, 2]          (2      40000000) */
-       else if(ix>=0x40000000){p = qr2; q= qs2;}
+       else /*if(ix>=0x40000000)*/{p = qr2; q= qs2;}
        z = one/(x*x);
        r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
        s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));



Home | Main Index | Thread Index | Old Index