Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libm/noieee_src Avoid strict aliasing problems
details: https://anonhg.NetBSD.org/src/rev/b54b58095feb
branches: trunk
changeset: 328018:b54b58095feb
user: martin <martin%NetBSD.org@localhost>
date: Sun Mar 23 15:26:47 2014 +0000
description:
Avoid strict aliasing problems
diffstat:
lib/libm/noieee_src/n_exp2.c | 17 ++++++++++-------
lib/libm/noieee_src/n_exp2f.c | 16 +++++++++-------
2 files changed, 19 insertions(+), 14 deletions(-)
diffs (104 lines):
diff -r 052966c6aca5 -r b54b58095feb lib/libm/noieee_src/n_exp2.c
--- a/lib/libm/noieee_src/n_exp2.c Sun Mar 23 15:21:15 2014 +0000
+++ b/lib/libm/noieee_src/n_exp2.c Sun Mar 23 15:26:47 2014 +0000
@@ -25,13 +25,14 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: n_exp2.c,v 1.2 2014/03/12 19:42:18 martin Exp $");
+__RCSID("$NetBSD: n_exp2.c,v 1.3 2014/03/23 15:26:47 martin Exp $");
#ifdef __FBSDID
__FBSDID("$FreeBSD: src/lib/msun/src/s_exp2.c,v 1.7 2008/02/22 02:27:34 das Exp $");
#endif
#include <stdint.h>
#include <float.h>
+#include <string.h>
#include "math.h"
@@ -344,11 +345,11 @@
exp2(double x)
{
double r, t, twopk, z;
- uint32_t hx, ix, i0;
+ uint32_t hx, ix, i0, temp;
int k, big;
/* Filter out exceptional cases. */
- hx = ((uint32_t*)&x)[0];
+ memcpy(&hx, &x, sizeof(hx));
ix = hx & 0x7fffffff; /* high word of |x| */
if(ix >= 0x40900000) { /* |x| >= 1024 */
if(x >= 0x1.0p10)
@@ -373,11 +374,13 @@
z -= tbl[i0 + 1]; /* eps[i0] */
big = k >= -1021 << 20;
if (big) {
- ((uint32_t*)&twopk)[0] = 0x3ff00000+k;
- ((uint32_t*)&twopk)[1] = 0;
+ temp = 0x3ff00000+k;
+ twopk = 0.0;
+ memcpy(&twopk, &temp, sizeof(temp));
} else {
- ((uint32_t*)&twopk)[0] = 0x3ff00000+k + (1000 << 20);
- ((uint32_t*)&twopk)[1] = 0;
+ temp = 0x3ff00000+k + (1000 << 20);
+ twopk = 0.0;
+ memcpy(&twopk, &temp, sizeof(temp));
}
r = t + t * z * (P1 + z * (P2 + z * (P3 + z * (P4 + z * P5))));
diff -r 052966c6aca5 -r b54b58095feb lib/libm/noieee_src/n_exp2f.c
--- a/lib/libm/noieee_src/n_exp2f.c Sun Mar 23 15:21:15 2014 +0000
+++ b/lib/libm/noieee_src/n_exp2f.c Sun Mar 23 15:26:47 2014 +0000
@@ -25,13 +25,14 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: n_exp2f.c,v 1.1 2014/03/06 10:55:57 martin Exp $");
+__RCSID("$NetBSD: n_exp2f.c,v 1.2 2014/03/23 15:26:47 martin Exp $");
#ifdef __FBSDID
__FBSDID("$FreeBSD: src/lib/msun/src/s_exp2f.c,v 1.9 2008/02/22 02:27:34 das Exp $");
#endif
#include <stdint.h>
#include <float.h>
+#include <string.h>
#include "math.h"
@@ -99,10 +100,10 @@
double tv, twopk, u, z;
float t;
uint32_t hx, ix, i0;
- int32_t k;
+ int32_t k, temp;
/* Filter out exceptional cases. */
- hx = *((uint32_t*)&x);
+ memcpy(&hx, &x, sizeof(hx));
ix = hx & 0x7fffffff; /* high word of |x| */
if(ix >= 0x43000000) { /* |x| >= 128 */
if(x >= 0x1.0p7f)
@@ -114,15 +115,16 @@
}
/* Reduce x, computing z, i0, and k. */
- *((volatile float*)&t) = x + redux;
- i0 = *((uint32_t*)&t);
+ i0 = x + redux;
+ memcpy(&t, &i0, sizeof(t));
i0 += TBLSIZE / 2;
k = (i0 >> TBLBITS) << 20;
i0 &= TBLSIZE - 1;
t -= redux;
z = x - t;
- ((uint32_t*)&twopk)[0] = 0x3ff00000+k;
- ((uint32_t*)&twopk)[1] = 0;
+ temp = 0x3ff00000+k;
+ twopk = 0.0;
+ memcpy(&twopk, &temp, sizeof(temp));
/* Compute r = exp2(y) = exp2ft[i0] * p(z). */
tv = exp2ft[i0];
Home |
Main Index |
Thread Index |
Old Index