Last active
May 10, 2017 06:40
-
-
Save staticfloat/d357b985eab757f393fa7e5ff1ee4101 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To see correct behavior, run the output of: | |
// gcc -o gcc_710_mwe -O1 -Wall -Werror -march=pentium4 -m32 -fno-gnu89-inline -fno-builtin -std=c99 -fPIC gcc_710_mwe.c | |
// To see broken behavior, run the output of: | |
// gcc -o gcc_710_mwe -O1 -fpeephole2 -Wall -Werror -march=pentium4 -m32 -fno-gnu89-inline -fno-builtin -std=c99 -fPIC gcc_710_mwe.c | |
typedef union { | |
double value; | |
struct { | |
int lsw; | |
int msw; | |
} parts; | |
} ieee_double_shape_type; | |
double a, b = -3.25565818622400915405e-01, c = -4.00555345006794114027e-02, | |
d = -2.40339491173441421878e00, e = -6.88283971605453293030e-01, p, q, | |
r, t, u, v, w; | |
int f, g, h, i, j, l, x; | |
unsigned k, m; | |
ieee_double_shape_type n, o; | |
double fn1(double p1) { | |
n.value = p1; | |
f = n.parts.msw; | |
l = n.parts.lsw; | |
i = n.parts.msw >> 20; | |
i -= 1023; | |
f = (f & 1048575) | 1048576; | |
i >>= 1; | |
f += f + (2147483648 >> 31); | |
l += l; | |
k = 2097152; | |
while (k) { | |
j = g + k; | |
if (j <= f) { | |
g = j + k; | |
f -= j; | |
h += k; | |
} | |
f += f + ((l & 2147483648) >> 31); | |
l += l; | |
k >>= 1; | |
} | |
k = 2147483648; | |
while (k) { | |
j = g; | |
if (j < f) { | |
g++; | |
f -= j; | |
m += k; | |
} | |
f += f; | |
k >>= 1; | |
} | |
f = (h >> 1) + 1071644672; | |
l = m >> 1; | |
f += i << 20; | |
o.parts.msw = f; | |
o.parts.lsw = l; | |
return o.value; | |
} | |
double fn2(double p1) { | |
double s; | |
if (x) | |
return a * t; | |
p = (1.00000000000000000000e00 - p1) * 0.5; | |
s = fn1(p); | |
ieee_double_shape_type z; | |
z.value = s; | |
z.parts.lsw = 0; | |
w = z.value; | |
v = (p - z.value * z.value) / (s + z.value); | |
q = p * (1.66666666666666657415e-01 + | |
p * (b + | |
p * (2.01212532134862925881e-01 + | |
p * (c + | |
p * (7.91534994289814532176e-04 + | |
p * 3.47933107596021167570e-05))))); | |
r = 1.00000000000000000000e00 + | |
p * (d + | |
p * (2.02094576023350569471e00 + | |
p * (e + p * 7.70381505559019352791e-02))); | |
t = q / r; | |
u = t * s + v; | |
return 2.0 * (z.value + u); | |
} | |
void printf(); | |
int main() { | |
double y = fn2(0.8); | |
printf("%.16f\n", y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment