2 /* Test conversions between 64- and 80- bit quiet NaNs. Uses
3 "canonical forms" for qNaNs. It also tests sNaNs but it's not
4 clear what the canonical form of them should be, so the results are
5 pretty much irrelevant. Failure to do this right is the cause
6 of https://bugzilla.mozilla.org/show_bug.cgi?id=738117
14 typedef unsigned char UChar
;
17 void do_64_to_80 ( UChar
* dst
, UChar
* src
)
20 "fldl (%0); fstpt (%1)"
21 : : "r"(src
), "r"(dst
) : "memory"
25 void do_80_to_64 ( UChar
* dst
, UChar
* src
)
28 "fldt (%0); fstpl (%1)"
29 : : "r"(src
), "r"(dst
) : "memory"
33 void print80 ( char* s
, UChar
* v
)
37 for (i
= 9; i
>= 0; i
--)
38 printf("%02x", (unsigned int)v
[i
]);
42 void print64 ( char* s
, UChar
* v
)
46 for (i
= 7; i
>= 0; i
--) {
47 printf("%02x", (unsigned int)v
[i
]);
53 void gen_qnan_64 ( UChar
* dst
)
59 #define SWAPC(_xx,_yy) { UChar tmp = _xx; _xx = _yy; _yy = tmp; }
61 static void rev64 ( UChar
* f64
)
63 SWAPC( f64
[0], f64
[7] );
64 SWAPC( f64
[1], f64
[6] );
65 SWAPC( f64
[2], f64
[5] );
66 SWAPC( f64
[3], f64
[4] );
69 static void rev80 ( UChar
* f80
)
71 SWAPC( f80
[0], f80
[9] );
72 SWAPC( f80
[1], f80
[8] );
73 SWAPC( f80
[2], f80
[7] );
74 SWAPC( f80
[3], f80
[6] );
75 SWAPC( f80
[4], f80
[5] );
83 = { 0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
86 = { 0x7f, 0xf4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
89 = { 0x7f, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
92 = { 0x7f, 0xff, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
99 UChar
* res
= malloc(10);
100 #define ZAP memset(res, 0x55, 10)
104 for (pass
= 1; pass
<= 2; pass
++) {
106 ZAP
; do_64_to_80( res
, ref_qnan64
);
107 print64( "src = qnan64: ", ref_qnan64
);
108 print80( "dst = qnan80: ", res
);
111 ZAP
; do_64_to_80( res
, ref_snan64
);
112 print64( "src = snan64: ", ref_snan64
);
113 print80( "dst = snan80: ", res
);
116 ZAP
; do_80_to_64( res
, ref_qnan80
);
117 print80( "src = qnan80: ", ref_qnan80
);
118 print64( "dst = qnan64: ", res
);
121 ZAP
; do_80_to_64( res
, ref_snan80
);
122 print80( "src = snan80: ", ref_snan80
);
123 print64( "dst = snan64: ", res
);
126 /* now make all the reference inputs negative and do it again */
128 ref_qnan64
[7] ^= 0x80;
129 ref_snan64
[7] ^= 0x80;
131 ref_qnan80
[9] ^= 0x80;
132 ref_snan80
[9] ^= 0x80;