public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* libdecnumber/bid/bid2dpd_dpd2bid.c: Simplify code
@ 2017-05-26 15:08 Sylvestre Ledru
  2017-06-26 13:24 ` Sylvestre Ledru
  2017-06-29 17:35 ` Jeff Law
  0 siblings, 2 replies; 3+ messages in thread
From: Sylvestre Ledru @ 2017-05-26 15:08 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 433 bytes --]

Hello,

The attach patch (dup.diff) performs the following changes:

        * bid/bid2dpd_dpd2bid.c: Remove identical code for different
branches (CID 1286836, 1286837, 1286838)
          Remove some useless } else { declaration as we are returning
          Remove some whitespace changes & tab

i attached the word diff to highlight the change.

No functional changes! The identical code has been found by coverity.

Thanks!

S



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: dup.diff --]
[-- Type: text/x-patch; name="dup.diff", Size: 12841 bytes --]

libdecnumber/ChangeLog:

2017-05-26  Sylvestre Ledru  <sylvestre@debian.org>

	* bid/bid2dpd_dpd2bid.c: Remove identical code for different branches (CID 1286836, 1286837, 1286838)
          Remove some useless } else { declaration as we are returning
          Remove some whitespace changes & tab

Index: libdecnumber/bid/bid2dpd_dpd2bid.c
===================================================================
--- libdecnumber/bid/bid2dpd_dpd2bid.c	(révision 248086)
+++ libdecnumber/bid/bid2dpd_dpd2bid.c	(copie de travail)
@@ -114,10 +114,10 @@
   b1 = b01 - 1000 * b0;
   dcoeff = b2d[b2] | b2d2[b1];
   if (b0 >= 8) { /* is b0 8 or 9? */
-    res = sign | ((0x600 | ((exp >> 6) << 7) | 
+    res = sign | ((0x600 | ((exp >> 6) << 7) |
         ((b0 & 1) << 6) | (exp & 0x3f)) << 20) | dcoeff;
   } else { /* else b0 is 0..7 */
-    res = sign | ((((exp >> 6) << 9) | (b0 << 6) | 
+    res = sign | ((((exp >> 6) << 9) | (b0 << 6) |
         (exp & 0x3f)) << 20) | dcoeff;
   }
   *pres = res;
@@ -138,30 +138,30 @@
   if ((x & 0x78000000) == 0x78000000) {
     *pres = x;
     return;
-  } else { /* normal number */
-    if ((x & 0x60000000) == 0x60000000) { /* G0..G1 = 11 -> d0 = 8 + G4 */
-      d0 = d2b3[((x >> 26) & 1) | 8]; /* d0 = (comb & 0x0100 ? 9 : 8); */
-      exp = (x >> 27) & 3; /* exp leading bits are G2..G3 */
-    } else {
-      d0 = d2b3[(x >> 26) & 0x7];
-      exp = (x >> 29) & 3; /* exp loading bits are G0..G1 */
-    }
-    d1 = d2b2[(trailing >> 10) & 0x3ff];
-    d2 = d2b[(trailing) & 0x3ff];
-    bcoeff = d2 + d1 + d0;
-    exp = (exp << 6) + ((x >> 20) & 0x3f);
-    if (bcoeff < (1 << 23)) {
-      r = exp;
-      r <<= 23;
-      r |= (bcoeff | sign);
-    } else {
-      r = exp;
-      r <<= 21;
-      r |= (sign | 0x60000000ul);
-      /* add coeff, without leading bits */
-      r |= (((unsigned int) bcoeff) & 0x1fffff);
-    }
   }
+  /* normal number */
+  if ((x & 0x60000000) == 0x60000000) { /* G0..G1 = 11 -> d0 = 8 + G4 */
+    d0 = d2b3[((x >> 26) & 1) | 8]; /* d0 = (comb & 0x0100 ? 9 : 8); */
+    exp = (x >> 27) & 3; /* exp leading bits are G2..G3 */
+  } else {
+    d0 = d2b3[(x >> 26) & 0x7];
+    exp = (x >> 29) & 3; /* exp loading bits are G0..G1 */
+  }
+  d1 = d2b2[(trailing >> 10) & 0x3ff];
+  d2 = d2b[(trailing) & 0x3ff];
+  bcoeff = d2 + d1 + d0;
+  exp = (exp << 6) + ((x >> 20) & 0x3f);
+  if (bcoeff < (1 << 23)) {
+    r = exp;
+    r <<= 23;
+    r |= (bcoeff | sign);
+  } else {
+    r = exp;
+    r <<= 21;
+    r |= (sign | 0x60000000ul);
+    /* add coeff, without leading bits */
+    r |= (((unsigned int) bcoeff) & 0x1fffff);
+  }
   *pres = r;
 }
 
@@ -184,40 +184,40 @@
   if ((comb & 0xf00) == 0xf00) {
     *pres = x;
     return;
-  } else { /* Normal number */
-    if ((comb & 0xc00) == 0xc00) { /* G0..G1 = 11 -> exp is G2..G11 */
-      exp = (comb) & 0x3ff;
-      bcoeff = (x & 0x0007ffffffffffffull) | 0x0020000000000000ull;
-    } else {
-      exp = (comb >> 2) & 0x3ff;
-      bcoeff = (x & 0x001fffffffffffffull);
-    }
-    D61 = 2305843009ull; /* Floor(2^61 / 10^9) */
-    /* Multiply the binary coefficient by ceil(2^64 / 1000), and take the upper
-       64-bits in order to compute a division by 1000. */
-    yhi = (D61 * (UINT64)(bcoeff >> (UINT64)27)) >> (UINT64)34;
-    ylo = bcoeff - 1000000000ull * yhi;
-    if (ylo >= 1000000000) {
-      ylo = ylo - 1000000000;
-      yhi = yhi + 1;
-    }
-    d103 = 0x4189374c;
-    B34 = ((UINT64) ylo * d103) >> (32 + 8);
-    B01 = ((UINT64) yhi * d103) >> (32 + 8);
-    b5 = ylo - B34 * 1000;
-    b2 = yhi - B01 * 1000;
-    b3 = ((UINT64) B34 * d103) >> (32 + 8);
-    b0 = ((UINT64) B01 * d103) >> (32 + 8);
-    b4 = (unsigned int) B34 - (unsigned int) b3 *1000;
-    b1 = (unsigned int) B01 - (unsigned int) dm103[b0];
-    dcoeff = b2d[b5] | b2d2[b4] | b2d3[b3] | b2d4[b2] | b2d5[b1];
-    if (b0 >= 8) /* is b0 8 or 9? */
-      res = sign | ((0x1800 | ((exp >> 8) << 9) | ((b0 & 1) << 8) | 
-          (exp & 0xff)) << 50) | dcoeff;
-    else /* else b0 is 0..7 */
-      res = sign | ((((exp >> 8) << 11) | (b0 << 8) | 
-          (exp & 0xff)) << 50) | dcoeff;
   }
+  /* Normal number */
+  if ((comb & 0xc00) == 0xc00) { /* G0..G1 = 11 -> exp is G2..G11 */
+    exp = (comb) & 0x3ff;
+    bcoeff = (x & 0x0007ffffffffffffull) | 0x0020000000000000ull;
+  } else {
+    exp = (comb >> 2) & 0x3ff;
+    bcoeff = (x & 0x001fffffffffffffull);
+  }
+  D61 = 2305843009ull; /* Floor(2^61 / 10^9) */
+  /* Multiply the binary coefficient by ceil(2^64 / 1000), and take the upper
+     64-bits in order to compute a division by 1000. */
+  yhi = (D61 * (UINT64)(bcoeff >> (UINT64)27)) >> (UINT64)34;
+  ylo = bcoeff - 1000000000ull * yhi;
+  if (ylo >= 1000000000) {
+    ylo = ylo - 1000000000;
+    yhi = yhi + 1;
+  }
+  d103 = 0x4189374c;
+  B34 = ((UINT64) ylo * d103) >> (32 + 8);
+  B01 = ((UINT64) yhi * d103) >> (32 + 8);
+  b5 = ylo - B34 * 1000;
+  b2 = yhi - B01 * 1000;
+  b3 = ((UINT64) B34 * d103) >> (32 + 8);
+  b0 = ((UINT64) B01 * d103) >> (32 + 8);
+  b4 = (unsigned int) B34 - (unsigned int) b3 *1000;
+  b1 = (unsigned int) B01 - (unsigned int) dm103[b0];
+  dcoeff = b2d[b5] | b2d2[b4] | b2d3[b3] | b2d4[b2] | b2d5[b1];
+  if (b0 >= 8) /* is b0 8 or 9? */
+    res = sign | ((0x1800 | ((exp >> 8) << 9) | ((b0 & 1) << 8) |
+                   (exp & 0xff)) << 50) | dcoeff;
+  else /* else b0 is 0..7 */
+    res = sign | ((((exp >> 8) << 11) | (b0 << 8) |
+                     (exp & 0xff)) << 50) | dcoeff;
   *pres = res;
 }
 
@@ -237,49 +237,41 @@
   comb = (x & 0x7ffc000000000000ull) >> 50;
   trailing = (x & 0x0003ffffffffffffull);
   if ((comb & 0x1e00) == 0x1e00) {
-    if ((comb & 0x1f00) == 0x1f00) { /* G0..G4 = 11111 -> NaN */
-      if (comb & 0x0100) { /* G5 = 1 -> sNaN */
-        *pres = x;
-      } else { /* G5 = 0 -> qNaN */
-        *pres = x;
-      }
-    } else { /*if ((comb & 0x1e00) == 0x1e00); G0..G4 = 11110 -> INF */
-      *pres = x;
-    }
+    *pres = x;
     return;
-  } else { /* normal number */
-    if ((comb & 0x1800) == 0x1800) { /* G0..G1 = 11 -> d0 = 8 + G4 */
-      d0 = d2b6[((comb >> 8) & 1) | 8]; /* d0 = (comb & 0x0100 ? 9 : 8); */
-      exp = (comb & 0x600) >> 1; /* exp = (comb & 0x0400 ? 1 : 0) * 0x200 + 
-          (comb & 0x0200 ? 1 : 0) * 0x100; exp leading bits are G2..G3 */
-    } else {
-      d0 = d2b6[(comb >> 8) & 0x7];
-      exp = (comb & 0x1800) >> 3; /* exp = (comb & 0x1000 ? 1 : 0) * 0x200 + 
-          (comb & 0x0800 ? 1 : 0) * 0x100; exp loading bits are G0..G1 */
-    }
-    d1 = d2b5[(trailing >> 40) & 0x3ff];
-    d2 = d2b4[(trailing >> 30) & 0x3ff];
-    d3 = d2b3[(trailing >> 20) & 0x3ff];
-    d4 = d2b2[(trailing >> 10) & 0x3ff];
-    d5 = d2b[(trailing) & 0x3ff];
-    bcoeff = (d5 + d4 + d3) + d2 + d1 + d0;
-    exp += (comb & 0xff);
-    mask = 1;
-    mask <<= 53;
-    if (bcoeff < mask) { /* check whether coefficient fits in 10*5+3 bits */
-      res = exp;
-      res <<= 53;
-      res |= (bcoeff | sign);
-      *pres = res;
-      return;
-    }
-    /* special format */
-    res = (exp << 51) | (sign | 0x6000000000000000ull);
-    /* add coeff, without leading bits */
-    mask = (mask >> 2) - 1;
-    bcoeff &= mask;
-    res |= bcoeff;
   }
+  /* normal number */
+  if ((comb & 0x1800) == 0x1800) { /* G0..G1 = 11 -> d0 = 8 + G4 */
+    d0 = d2b6[((comb >> 8) & 1) | 8]; /* d0 = (comb & 0x0100 ? 9 : 8); */
+    exp = (comb & 0x600) >> 1; /* exp = (comb & 0x0400 ? 1 : 0) * 0x200 +
+        (comb & 0x0200 ? 1 : 0) * 0x100; exp leading bits are G2..G3 */
+  } else {
+    d0 = d2b6[(comb >> 8) & 0x7];
+    exp = (comb & 0x1800) >> 3; /* exp = (comb & 0x1000 ? 1 : 0) * 0x200 +
+        (comb & 0x0800 ? 1 : 0) * 0x100; exp loading bits are G0..G1 */
+  }
+  d1 = d2b5[(trailing >> 40) & 0x3ff];
+  d2 = d2b4[(trailing >> 30) & 0x3ff];
+  d3 = d2b3[(trailing >> 20) & 0x3ff];
+  d4 = d2b2[(trailing >> 10) & 0x3ff];
+  d5 = d2b[(trailing) & 0x3ff];
+  bcoeff = (d5 + d4 + d3) + d2 + d1 + d0;
+  exp += (comb & 0xff);
+  mask = 1;
+  mask <<= 53;
+  if (bcoeff < mask) { /* check whether coefficient fits in 10*5+3 bits */
+    res = exp;
+    res <<= 53;
+    res |= (bcoeff | sign);
+    *pres = res;
+    return;
+  }
+  /* special format */
+  res = (exp << 51) | (sign | 0x6000000000000000ull);
+  /* add coeff, without leading bits */
+  mask = (mask >> 2) - 1;
+  bcoeff &= mask;
+  res |= bcoeff;
   *pres = res;
 }
 
@@ -304,15 +296,7 @@
   comb = (x.w[1] /*& 0x7fffc00000000000ull */ ) >> 46;
   exp = 0;
   if ((comb & 0x1e000) == 0x1e000) {
-    if ((comb & 0x1f000) == 0x1f000) { /* G0..G4 = 11111 -> NaN */
-      if (comb & 0x01000) { /* G5 = 1 -> sNaN */
-        res = x;
-      } else { /* G5 = 0 -> qNaN */
-        res = x;
-      }
-    } else { /* G0..G4 = 11110 -> INF */
-      res = x;
-    }
+    res = x;
   } else { /* normal number */
     exp = ((x.w[1] & 0x7fff000000000000ull) >> 49) & 0x3fff;
     bcoeff.w[1] = (x.w[1] & 0x0001ffffffffffffull);
@@ -347,16 +331,16 @@
     BLL32 -= (unsigned int) k9 *1000000;
     k10 = ((UINT64) BLL32 * d103) >> (32 + 8);
     k11 = BLL32 - (unsigned int) k10 *1000;
-    dcoeff.w[1] = (b2d[k5] >> 4) | (b2d[k4] << 6) | (b2d[k3] << 16) | 
-        (b2d[k2] << 26) | (b2d[k1] << 36);
-    dcoeff.w[0] = b2d[k11] | (b2d[k10] << 10) | (b2d[k9] << 20) | 
-        (b2d[k8] << 30) | (b2d[k7] << 40) | (b2d[k6] << 50) | (b2d[k5] << 60);
+    dcoeff.w[1] = (b2d[k5] >> 4) | (b2d[k4] << 6) | (b2d[k3] << 16) |
+      (b2d[k2] << 26) | (b2d[k1] << 36);
+    dcoeff.w[0] = b2d[k11] | (b2d[k10] << 10) | (b2d[k9] << 20) |
+      (b2d[k8] << 30) | (b2d[k7] << 40) | (b2d[k6] << 50) | (b2d[k5] << 60);
     res.w[0] = dcoeff.w[0];
     if (k0 >= 8) {
-      res.w[1] = sign.w[1] | ((0x18000 | ((exp >> 12) << 13) | 
+      res.w[1] = sign.w[1] | ((0x18000 | ((exp >> 12) << 13) |
           ((k0 & 1) << 12) | (exp & 0xfff)) << 46) | dcoeff.w[1];
     } else {
-      res.w[1] = sign.w[1] | ((((exp >> 12) << 15) | (k0 << 12) | 
+      res.w[1] = sign.w[1] | ((((exp >> 12) << 15) | (k0 << 12) |
           (exp & 0xfff)) << 46) | dcoeff.w[1];
     }
   }
@@ -382,42 +366,33 @@
   trailing.w[1] = x.w[1];
   trailing.w[0] = x.w[0];
   if ((comb & 0x1e000) == 0x1e000) {
-    if ((comb & 0x1f000) == 0x1f000) { /* G0..G4 = 11111 -> NaN */
-      if (comb & 0x01000) { /* G5 = 1 -> sNaN */
-        *pres = x;
-      } else { /* G5 = 0 -> qNaN */
-        *pres = x;
-      }
-    } else { /* G0..G4 = 11110 -> INF */
       *pres = x;
-    }
-    return;
-  } else { /* Normal number */
-    if ((comb & 0x18000) == 0x18000) { /* G0..G1 = 11 -> d0 = 8 + G4 */
-      d0 = d2b6[8 + ((comb & 0x01000) >> 12)];
-      exp = (comb & 0x06000) >> 1;  /* exp leading bits are G2..G3 */
-    } else {
-      d0 = d2b6[((comb & 0x07000) >> 12)];
-      exp = (comb & 0x18000) >> 3;  /* exp loading bits are G0..G1 */
-    }
-    d11 = d2b[(trailing.w[0]) & 0x3ff];
-    d10 = d2b2[(trailing.w[0] >> 10) & 0x3ff];
-    d9 = d2b3[(trailing.w[0] >> 20) & 0x3ff];
-    d8 = d2b4[(trailing.w[0] >> 30) & 0x3ff];
-    d7 = d2b5[(trailing.w[0] >> 40) & 0x3ff];
-    d6 = d2b6[(trailing.w[0] >> 50) & 0x3ff];
-    d5 = d2b[(trailing.w[0] >> 60) | ((trailing.w[1] & 0x3f) << 4)];
-    d4 = d2b2[(trailing.w[1] >> 6) & 0x3ff];
-    d3 = d2b3[(trailing.w[1] >> 16) & 0x3ff];
-    d2 = d2b4[(trailing.w[1] >> 26) & 0x3ff];
-    d1 = d2b5[(trailing.w[1] >> 36) & 0x3ff];
-    tl = d11 + d10 + d9 + d8 + d7 + d6;
-    th = d5 + d4 + d3 + d2 + d1 + d0;
-    __mul_64x64_to_128 (bcoeff, th, 1000000000000000000ull);
-    __add_128_64 (bcoeff, bcoeff, tl);
-    exp += (comb & 0xfff);
-    res.w[0] = bcoeff.w[0];
-    res.w[1] = (exp << 49) | sign.w[1] | bcoeff.w[1];
+      return;
   }
+  if ((comb & 0x18000) == 0x18000) { /* G0..G1 = 11 -> d0 = 8 + G4 */
+    d0 = d2b6[8 + ((comb & 0x01000) >> 12)];
+    exp = (comb & 0x06000) >> 1;  /* exp leading bits are G2..G3 */
+  } else {
+    d0 = d2b6[((comb & 0x07000) >> 12)];
+    exp = (comb & 0x18000) >> 3;  /* exp loading bits are G0..G1 */
+  }
+  d11 = d2b[(trailing.w[0]) & 0x3ff];
+  d10 = d2b2[(trailing.w[0] >> 10) & 0x3ff];
+  d9 = d2b3[(trailing.w[0] >> 20) & 0x3ff];
+  d8 = d2b4[(trailing.w[0] >> 30) & 0x3ff];
+  d7 = d2b5[(trailing.w[0] >> 40) & 0x3ff];
+  d6 = d2b6[(trailing.w[0] >> 50) & 0x3ff];
+  d5 = d2b[(trailing.w[0] >> 60) | ((trailing.w[1] & 0x3f) << 4)];
+  d4 = d2b2[(trailing.w[1] >> 6) & 0x3ff];
+  d3 = d2b3[(trailing.w[1] >> 16) & 0x3ff];
+  d2 = d2b4[(trailing.w[1] >> 26) & 0x3ff];
+  d1 = d2b5[(trailing.w[1] >> 36) & 0x3ff];
+  tl = d11 + d10 + d9 + d8 + d7 + d6;
+  th = d5 + d4 + d3 + d2 + d1 + d0;
+  __mul_64x64_to_128 (bcoeff, th, 1000000000000000000ull);
+  __add_128_64 (bcoeff, bcoeff, tl);
+  exp += (comb & 0xfff);
+  res.w[0] = bcoeff.w[0];
+  res.w[1] = (exp << 49) | sign.w[1] | bcoeff.w[1];
   *pres = res;
 }

[-- Attachment #3: dup-word-diff.dif --]
[-- Type: video/dv, Size: 11689 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: libdecnumber/bid/bid2dpd_dpd2bid.c: Simplify code
  2017-05-26 15:08 libdecnumber/bid/bid2dpd_dpd2bid.c: Simplify code Sylvestre Ledru
@ 2017-06-26 13:24 ` Sylvestre Ledru
  2017-06-29 17:35 ` Jeff Law
  1 sibling, 0 replies; 3+ messages in thread
From: Sylvestre Ledru @ 2017-06-26 13:24 UTC (permalink / raw)
  To: gcc-patches



Le 26/05/2017 à 15:34, Sylvestre Ledru a écrit :
> Hello,
>
> The attach patch (dup.diff) performs the following changes:
>
>         * bid/bid2dpd_dpd2bid.c: Remove identical code for different
> branches (CID 1286836, 1286837, 1286838)
>           Remove some useless } else { declaration as we are returning
>           Remove some whitespace changes & tab
>
> i attached the word diff to highlight the change.
>
> No functional changes! The identical code has been found by coverity.
>
> Thanks!
>
> S
>
>
ping?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: libdecnumber/bid/bid2dpd_dpd2bid.c: Simplify code
  2017-05-26 15:08 libdecnumber/bid/bid2dpd_dpd2bid.c: Simplify code Sylvestre Ledru
  2017-06-26 13:24 ` Sylvestre Ledru
@ 2017-06-29 17:35 ` Jeff Law
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff Law @ 2017-06-29 17:35 UTC (permalink / raw)
  To: Sylvestre Ledru, gcc-patches

On 05/26/2017 07:34 AM, Sylvestre Ledru wrote:
> Hello,
> 
> The attach patch (dup.diff) performs the following changes:
> 
>         * bid/bid2dpd_dpd2bid.c: Remove identical code for different
> branches (CID 1286836, 1286837, 1286838)
>           Remove some useless } else { declaration as we are returning
>           Remove some whitespace changes & tab
> 
> i attached the word diff to highlight the change.
> 
> No functional changes! The identical code has been found by coverity.
> 
> Thanks!
> 
> S
> 
> 
> 
> dup.diff
> 
> 
> libdecnumber/ChangeLog:
> 
> 2017-05-26  Sylvestre Ledru  <sylvestre@debian.org>
> 
> 	* bid/bid2dpd_dpd2bid.c: Remove identical code for different branches (CID 1286836, 1286837, 1286838)
>           Remove some useless } else { declaration as we are returning
>           Remove some whitespace changes & tab
I fixed up the ChangeLog and committed your change.  Thanks,

jeff

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-06-29 17:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-26 15:08 libdecnumber/bid/bid2dpd_dpd2bid.c: Simplify code Sylvestre Ledru
2017-06-26 13:24 ` Sylvestre Ledru
2017-06-29 17:35 ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).