summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToomas Soome <tsoome@me.com>2017-02-15 22:45:42 +0200
committerDan McDonald <danmcd@joyent.com>2017-08-04 10:47:43 -0400
commitd626ebd403efade415c36352e0c012082508b3ca (patch)
treef7bc9587780a046ac479eb9ba1c9e4e3f1fc210b
parent9b4fe9cb6a3fd5b562f036d9bf405f30c095808e (diff)
downloadillumos-joyent-d626ebd403efade415c36352e0c012082508b3ca.tar.gz
8030 libmvect: uninitialized variable
Reviewed by: Marcel Telka <marcel@telka.sk> Reviewed by: Robert Mustacchi <rm@joyent.com> Approved by: Dan McDonald <danmcd@joyent.com>
-rw-r--r--usr/src/lib/libmvec/common/__vhypotf.c149
1 files changed, 74 insertions, 75 deletions
diff --git a/usr/src/lib/libmvec/common/__vhypotf.c b/usr/src/lib/libmvec/common/__vhypotf.c
index c8215aadfb..5fcd7a80c2 100644
--- a/usr/src/lib/libmvec/common/__vhypotf.c
+++ b/usr/src/lib/libmvec/common/__vhypotf.c
@@ -30,52 +30,57 @@
#include "libm_inlines.h"
#ifdef __RESTRICT
-#define restrict _Restrict
+#define restrict _Restrict
#else
-#define restrict
+#define restrict
#endif
extern double sqrt(double);
+/*
+ * Instead of type punning, use union type.
+ */
+typedef union h32 {
+ float f;
+ unsigned u;
+} h32;
+
void
-__vhypotf(int n, float * restrict x, int stridex, float * restrict y,
- int stridey, float * restrict z, int stridez)
+__vhypotf(int n, float *restrict x, int stridex, float *restrict y,
+ int stridey, float *restrict z, int stridez)
{
float x0, x1, x2, y0, y1, y2, z0, z1, z2, *pz0, *pz1, *pz2;
- unsigned hx0, hx1, hx2, hy0, hy1, hy2;
- int i, j0, j1, j2;
+ h32 hx0, hx1, hx2, hy0, hy1, hy2;
+ int i, j0, j1, j2;
- do
- {
+ do {
LOOP0:
- hx0 = *(unsigned*)x & ~0x80000000;
- hy0 = *(unsigned*)y & ~0x80000000;
- *(unsigned*)&x0 = hx0;
- *(unsigned*)&y0 = hy0;
- if (hy0 > hx0)
- {
- i = hy0 - hx0;
- j0 = hy0 & 0x7f800000;
- if (hx0 == 0)
+ hx0.f = *x;
+ hy0.f = *y;
+ hx0.u &= ~0x80000000;
+ hy0.u &= ~0x80000000;
+ x0 = hx0.f;
+ y0 = hy0.f;
+ if (hy0.u > hx0.u) {
+ i = hy0.u - hx0.u;
+ j0 = hy0.u & 0x7f800000;
+ if (hx0.u == 0)
i = 0x7f800000;
- }
- else
- {
- i = hx0 - hy0;
- j0 = hx0 & 0x7f800000;
- if (hy0 == 0)
+ } else {
+ i = hx0.u - hy0.u;
+ j0 = hx0.u & 0x7f800000;
+ if (hy0.u == 0)
i = 0x7f800000;
- else if (hx0 == 0)
+ else if (hx0.u == 0)
i = 0x7f800000;
}
- if (i >= 0x0c800000 || j0 >= 0x7f800000)
- {
+ if (i >= 0x0c800000 || j0 >= 0x7f800000) {
z0 = x0 + y0;
- if (hx0 == 0x7f800000)
+ if (hx0.u == 0x7f800000)
z0 = x0;
- else if (hy0 == 0x7f800000)
+ else if (hy0.u == 0x7f800000)
z0 = y0;
- else if (hx0 > 0x7f800000 || hy0 > 0x7f800000)
+ else if (hx0.u > 0x7f800000 || hy0.u > 0x7f800000)
z0 = *x + *y;
*z = z0;
x += stridex;
@@ -95,34 +100,32 @@ LOOP0:
break;
LOOP1:
- hx1 = *(unsigned*)x & ~0x80000000;
- hy1 = *(unsigned*)y & ~0x80000000;
- *(unsigned*)&x1 = hx1;
- *(unsigned*)&y1 = hy1;
- if (hy1 > hx1)
- {
- i = hy1 - hx1;
- j1 = hy1 & 0x7f800000;
- if (hx1 == 0)
+ hx1.f = *x;
+ hy1.f = *y;
+ hx1.u &= ~0x80000000;
+ hy1.u &= ~0x80000000;
+ x1 = hx1.f;
+ y1 = hy1.f;
+ if (hy1.u > hx1.u) {
+ i = hy1.u - hx1.u;
+ j1 = hy1.u & 0x7f800000;
+ if (hx1.u == 0)
i = 0x7f800000;
- }
- else
- {
- i = hx1 - hy1;
- j1 = hx1 & 0x7f800000;
- if (hy1 == 0)
+ } else {
+ i = hx1.u - hy1.u;
+ j1 = hx1.u & 0x7f800000;
+ if (hy1.u == 0)
i = 0x7f800000;
- else if (hx1 == 0)
+ else if (hx1.u == 0)
i = 0x7f800000;
}
- if (i >= 0x0c800000 || j1 >= 0x7f800000)
- {
+ if (i >= 0x0c800000 || j1 >= 0x7f800000) {
z1 = x1 + y1;
- if (hx1 == 0x7f800000)
+ if (hx1.u == 0x7f800000)
z1 = x1;
- else if (hy1 == 0x7f800000)
+ else if (hy1.u == 0x7f800000)
z1 = y1;
- else if (hx1 > 0x7f800000 || hy1 > 0x7f800000)
+ else if (hx1.u > 0x7f800000 || hy1.u > 0x7f800000)
z1 = *x + *y;
*z = z1;
x += stridex;
@@ -142,34 +145,32 @@ LOOP1:
break;
LOOP2:
- hx2 = *(unsigned*)x & ~0x80000000;
- hy2 = *(unsigned*)y & ~0x80000000;
- *(unsigned*)&x2 = hx2;
- *(unsigned*)&y2 = hy2;
- if (hy2 > hx2)
- {
- i = hy2 - hx2;
- j2 = hy2 & 0x7f800000;
- if (hx2 == 0)
+ hx2.f = *x;
+ hy2.f = *y;
+ hx2.u &= ~0x80000000;
+ hy2.u &= ~0x80000000;
+ x2 = hx2.f;
+ y2 = hy2.f;
+ if (hy2.u > hx2.u) {
+ i = hy2.u - hx2.u;
+ j2 = hy2.u & 0x7f800000;
+ if (hx2.u == 0)
i = 0x7f800000;
- }
- else
- {
- i = hx2 - hy2;
- j2 = hx2 & 0x7f800000;
- if (hy2 == 0)
+ } else {
+ i = hx2.u - hy2.u;
+ j2 = hx2.u & 0x7f800000;
+ if (hy2.u == 0)
i = 0x7f800000;
- else if (hx2 == 0)
+ else if (hx2.u == 0)
i = 0x7f800000;
}
- if (i >= 0x0c800000 || j2 >= 0x7f800000)
- {
+ if (i >= 0x0c800000 || j2 >= 0x7f800000) {
z2 = x2 + y2;
- if (hx2 == 0x7f800000)
+ if (hx2.u == 0x7f800000)
z2 = x2;
- else if (hy2 == 0x7f800000)
+ else if (hy2.u == 0x7f800000)
z2 = y2;
- else if (hx2 > 0x7f800000 || hy2 > 0x7f800000)
+ else if (hx2.u > 0x7f800000 || hy2.u > 0x7f800000)
z2 = *x + *y;
*z = z2;
x += stridex;
@@ -195,10 +196,8 @@ LOOP2:
i = 0;
} while (--n > 0);
- if (i > 0)
- {
- if (i > 1)
- {
+ if (i > 0) {
+ if (i > 1) {
z1 = sqrt(x1 * (double)x1 + y1 * (double)y1);
*pz1 = z1;
}