1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82#if defined(TARGET_XTENSA)
83
84
85
86#define NO_SIGNALING_NANS 1
87#endif
88
89
90
91
92float16 float16_default_nan(float_status *status)
93{
94#if defined(TARGET_ARM)
95 return const_float16(0x7E00);
96#else
97 if (status->snan_bit_is_one) {
98 return const_float16(0x7DFF);
99 } else {
100#if defined(TARGET_MIPS)
101 return const_float16(0x7E00);
102#else
103 return const_float16(0xFE00);
104#endif
105 }
106#endif
107}
108
109
110
111
112float32 float32_default_nan(float_status *status)
113{
114#if defined(TARGET_SPARC) || defined(TARGET_M68K)
115 return const_float32(0x7FFFFFFF);
116#elif defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_ALPHA) || \
117 defined(TARGET_XTENSA) || defined(TARGET_S390X) || defined(TARGET_TRICORE)
118 return const_float32(0x7FC00000);
119#elif defined(TARGET_HPPA)
120 return const_float32(0x7FA00000);
121#else
122 if (status->snan_bit_is_one) {
123 return const_float32(0x7FBFFFFF);
124 } else {
125#if defined(TARGET_MIPS)
126 return const_float32(0x7FC00000);
127#else
128 return const_float32(0xFFC00000);
129#endif
130 }
131#endif
132}
133
134
135
136
137float64 float64_default_nan(float_status *status)
138{
139#if defined(TARGET_SPARC) || defined(TARGET_M68K)
140 return const_float64(LIT64(0x7FFFFFFFFFFFFFFF));
141#elif defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_ALPHA) || \
142 defined(TARGET_S390X)
143 return const_float64(LIT64(0x7FF8000000000000));
144#elif defined(TARGET_HPPA)
145 return const_float64(LIT64(0x7FF4000000000000));
146#else
147 if (status->snan_bit_is_one) {
148 return const_float64(LIT64(0x7FF7FFFFFFFFFFFF));
149 } else {
150#if defined(TARGET_MIPS)
151 return const_float64(LIT64(0x7FF8000000000000));
152#else
153 return const_float64(LIT64(0xFFF8000000000000));
154#endif
155 }
156#endif
157}
158
159
160
161
162floatx80 floatx80_default_nan(float_status *status)
163{
164 floatx80 r;
165#if defined(TARGET_M68K)
166 r.low = LIT64(0xFFFFFFFFFFFFFFFF);
167 r.high = 0x7FFF;
168#else
169 if (status->snan_bit_is_one) {
170 r.low = LIT64(0xBFFFFFFFFFFFFFFF);
171 r.high = 0x7FFF;
172 } else {
173 r.low = LIT64(0xC000000000000000);
174 r.high = 0xFFFF;
175 }
176#endif
177 return r;
178}
179
180
181
182
183float128 float128_default_nan(float_status *status)
184{
185 float128 r;
186
187 if (status->snan_bit_is_one) {
188 r.low = LIT64(0xFFFFFFFFFFFFFFFF);
189 r.high = LIT64(0x7FFF7FFFFFFFFFFF);
190 } else {
191 r.low = LIT64(0x0000000000000000);
192#if defined(TARGET_S390X) || defined(TARGET_PPC)
193 r.high = LIT64(0x7FFF800000000000);
194#else
195 r.high = LIT64(0xFFFF800000000000);
196#endif
197 }
198 return r;
199}
200
201
202
203
204
205
206
207
208void float_raise(uint8_t flags, float_status *status)
209{
210 status->float_exception_flags |= flags;
211}
212
213
214
215
216typedef struct {
217 flag sign;
218 uint64_t high, low;
219} commonNaNT;
220
221#ifdef NO_SIGNALING_NANS
222int float16_is_quiet_nan(float16 a_, float_status *status)
223{
224 return float16_is_any_nan(a_);
225}
226
227int float16_is_signaling_nan(float16 a_, float_status *status)
228{
229 return 0;
230}
231#else
232
233
234
235
236
237int float16_is_quiet_nan(float16 a_, float_status *status)
238{
239 uint16_t a = float16_val(a_);
240 if (status->snan_bit_is_one) {
241 return (((a >> 9) & 0x3F) == 0x3E) && (a & 0x1FF);
242 } else {
243 return ((a & ~0x8000) >= 0x7C80);
244 }
245}
246
247
248
249
250
251
252int float16_is_signaling_nan(float16 a_, float_status *status)
253{
254 uint16_t a = float16_val(a_);
255 if (status->snan_bit_is_one) {
256 return ((a & ~0x8000) >= 0x7C80);
257 } else {
258 return (((a >> 9) & 0x3F) == 0x3E) && (a & 0x1FF);
259 }
260}
261#endif
262
263
264
265
266
267float16 float16_maybe_silence_nan(float16 a_, float_status *status)
268{
269 if (float16_is_signaling_nan(a_, status)) {
270 if (status->snan_bit_is_one) {
271 return float16_default_nan(status);
272 } else {
273 uint16_t a = float16_val(a_);
274 a |= (1 << 9);
275 return make_float16(a);
276 }
277 }
278 return a_;
279}
280
281
282
283
284
285
286
287static commonNaNT float16ToCommonNaN(float16 a, float_status *status)
288{
289 commonNaNT z;
290
291 if (float16_is_signaling_nan(a, status)) {
292 float_raise(float_flag_invalid, status);
293 }
294 z.sign = float16_val(a) >> 15;
295 z.low = 0;
296 z.high = ((uint64_t) float16_val(a)) << 54;
297 return z;
298}
299
300
301
302
303
304
305static float16 commonNaNToFloat16(commonNaNT a, float_status *status)
306{
307 uint16_t mantissa = a.high >> 54;
308
309 if (status->default_nan_mode) {
310 return float16_default_nan(status);
311 }
312
313 if (mantissa) {
314 return make_float16(((((uint16_t) a.sign) << 15)
315 | (0x1F << 10) | mantissa));
316 } else {
317 return float16_default_nan(status);
318 }
319}
320
321#ifdef NO_SIGNALING_NANS
322int float32_is_quiet_nan(float32 a_, float_status *status)
323{
324 return float32_is_any_nan(a_);
325}
326
327int float32_is_signaling_nan(float32 a_, float_status *status)
328{
329 return 0;
330}
331#else
332
333
334
335
336
337int float32_is_quiet_nan(float32 a_, float_status *status)
338{
339 uint32_t a = float32_val(a_);
340 if (status->snan_bit_is_one) {
341 return (((a >> 22) & 0x1FF) == 0x1FE) && (a & 0x003FFFFF);
342 } else {
343 return ((uint32_t)(a << 1) >= 0xFF800000);
344 }
345}
346
347
348
349
350
351
352int float32_is_signaling_nan(float32 a_, float_status *status)
353{
354 uint32_t a = float32_val(a_);
355 if (status->snan_bit_is_one) {
356 return ((uint32_t)(a << 1) >= 0xFF800000);
357 } else {
358 return (((a >> 22) & 0x1FF) == 0x1FE) && (a & 0x003FFFFF);
359 }
360}
361#endif
362
363
364
365
366
367
368float32 float32_maybe_silence_nan(float32 a_, float_status *status)
369{
370 if (float32_is_signaling_nan(a_, status)) {
371 if (status->snan_bit_is_one) {
372#ifdef TARGET_HPPA
373 uint32_t a = float32_val(a_);
374 a &= ~0x00400000;
375 a |= 0x00200000;
376 return make_float32(a);
377#else
378 return float32_default_nan(status);
379#endif
380 } else {
381 uint32_t a = float32_val(a_);
382 a |= (1 << 22);
383 return make_float32(a);
384 }
385 }
386 return a_;
387}
388
389
390
391
392
393
394
395static commonNaNT float32ToCommonNaN(float32 a, float_status *status)
396{
397 commonNaNT z;
398
399 if (float32_is_signaling_nan(a, status)) {
400 float_raise(float_flag_invalid, status);
401 }
402 z.sign = float32_val(a) >> 31;
403 z.low = 0;
404 z.high = ((uint64_t)float32_val(a)) << 41;
405 return z;
406}
407
408
409
410
411
412
413static float32 commonNaNToFloat32(commonNaNT a, float_status *status)
414{
415 uint32_t mantissa = a.high >> 41;
416
417 if (status->default_nan_mode) {
418 return float32_default_nan(status);
419 }
420
421 if (mantissa) {
422 return make_float32(
423 (((uint32_t)a.sign) << 31) | 0x7F800000 | (a.high >> 41));
424 } else {
425 return float32_default_nan(status);
426 }
427}
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446#if defined(TARGET_ARM)
447static int pickNaN(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN,
448 flag aIsLargerSignificand)
449{
450
451
452
453
454
455
456
457 if (aIsSNaN) {
458 return 0;
459 } else if (bIsSNaN) {
460 return 1;
461 } else if (aIsQNaN) {
462 return 0;
463 } else {
464 return 1;
465 }
466}
467#elif defined(TARGET_MIPS) || defined(TARGET_HPPA)
468static int pickNaN(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN,
469 flag aIsLargerSignificand)
470{
471
472
473
474
475
476
477
478
479
480
481
482
483
484 if (aIsSNaN) {
485 return 0;
486 } else if (bIsSNaN) {
487 return 1;
488 } else if (aIsQNaN) {
489 return 0;
490 } else {
491 return 1;
492 }
493}
494#elif defined(TARGET_PPC) || defined(TARGET_XTENSA)
495static int pickNaN(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN,
496 flag aIsLargerSignificand)
497{
498
499
500
501
502
503 if (aIsSNaN || aIsQNaN) {
504 return 0;
505 } else {
506 return 1;
507 }
508}
509#elif defined(TARGET_M68K)
510static int pickNaN(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN,
511 flag aIsLargerSignificand)
512{
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527 if (aIsQNaN || aIsSNaN) {
528 return 0;
529 } else {
530 return 1;
531 }
532}
533#else
534static int pickNaN(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN,
535 flag aIsLargerSignificand)
536{
537
538
539
540
541
542
543
544
545
546
547 if (aIsSNaN) {
548 if (bIsSNaN) {
549 return aIsLargerSignificand ? 0 : 1;
550 }
551 return bIsQNaN ? 1 : 0;
552 } else if (aIsQNaN) {
553 if (bIsSNaN || !bIsQNaN) {
554 return 0;
555 } else {
556 return aIsLargerSignificand ? 0 : 1;
557 }
558 } else {
559 return 1;
560 }
561}
562#endif
563
564
565
566
567
568
569
570#if defined(TARGET_ARM)
571static int pickNaNMulAdd(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN,
572 flag cIsQNaN, flag cIsSNaN, flag infzero,
573 float_status *status)
574{
575
576
577
578 if (infzero && cIsQNaN) {
579 float_raise(float_flag_invalid, status);
580 return 3;
581 }
582
583
584
585
586 if (cIsSNaN) {
587 return 2;
588 } else if (aIsSNaN) {
589 return 0;
590 } else if (bIsSNaN) {
591 return 1;
592 } else if (cIsQNaN) {
593 return 2;
594 } else if (aIsQNaN) {
595 return 0;
596 } else {
597 return 1;
598 }
599}
600#elif defined(TARGET_MIPS)
601static int pickNaNMulAdd(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN,
602 flag cIsQNaN, flag cIsSNaN, flag infzero,
603 float_status *status)
604{
605
606
607
608 if (infzero) {
609 float_raise(float_flag_invalid, status);
610 return 3;
611 }
612
613 if (status->snan_bit_is_one) {
614
615 if (aIsSNaN) {
616 return 0;
617 } else if (bIsSNaN) {
618 return 1;
619 } else if (cIsSNaN) {
620 return 2;
621 } else if (aIsQNaN) {
622 return 0;
623 } else if (bIsQNaN) {
624 return 1;
625 } else {
626 return 2;
627 }
628 } else {
629
630 if (cIsSNaN) {
631 return 2;
632 } else if (aIsSNaN) {
633 return 0;
634 } else if (bIsSNaN) {
635 return 1;
636 } else if (cIsQNaN) {
637 return 2;
638 } else if (aIsQNaN) {
639 return 0;
640 } else {
641 return 1;
642 }
643 }
644}
645#elif defined(TARGET_PPC)
646static int pickNaNMulAdd(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN,
647 flag cIsQNaN, flag cIsSNaN, flag infzero,
648 float_status *status)
649{
650
651
652
653
654 if (infzero) {
655 float_raise(float_flag_invalid, status);
656 return 2;
657 }
658
659
660
661
662 if (aIsSNaN || aIsQNaN) {
663 return 0;
664 } else if (cIsSNaN || cIsQNaN) {
665 return 2;
666 } else {
667 return 1;
668 }
669}
670#else
671
672
673
674static int pickNaNMulAdd(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN,
675 flag cIsQNaN, flag cIsSNaN, flag infzero,
676 float_status *status)
677{
678 if (aIsSNaN || aIsQNaN) {
679 return 0;
680 } else if (bIsSNaN || bIsQNaN) {
681 return 1;
682 } else {
683 return 2;
684 }
685}
686#endif
687
688
689
690
691
692
693
694static float32 propagateFloat32NaN(float32 a, float32 b, float_status *status)
695{
696 flag aIsQuietNaN, aIsSignalingNaN, bIsQuietNaN, bIsSignalingNaN;
697 flag aIsLargerSignificand;
698 uint32_t av, bv;
699
700 aIsQuietNaN = float32_is_quiet_nan(a, status);
701 aIsSignalingNaN = float32_is_signaling_nan(a, status);
702 bIsQuietNaN = float32_is_quiet_nan(b, status);
703 bIsSignalingNaN = float32_is_signaling_nan(b, status);
704 av = float32_val(a);
705 bv = float32_val(b);
706
707 if (aIsSignalingNaN | bIsSignalingNaN) {
708 float_raise(float_flag_invalid, status);
709 }
710
711 if (status->default_nan_mode) {
712 return float32_default_nan(status);
713 }
714
715 if ((uint32_t)(av << 1) < (uint32_t)(bv << 1)) {
716 aIsLargerSignificand = 0;
717 } else if ((uint32_t)(bv << 1) < (uint32_t)(av << 1)) {
718 aIsLargerSignificand = 1;
719 } else {
720 aIsLargerSignificand = (av < bv) ? 1 : 0;
721 }
722
723 if (pickNaN(aIsQuietNaN, aIsSignalingNaN, bIsQuietNaN, bIsSignalingNaN,
724 aIsLargerSignificand)) {
725 return float32_maybe_silence_nan(b, status);
726 } else {
727 return float32_maybe_silence_nan(a, status);
728 }
729}
730
731
732
733
734
735
736
737
738
739
740static float32 propagateFloat32MulAddNaN(float32 a, float32 b,
741 float32 c, flag infzero,
742 float_status *status)
743{
744 flag aIsQuietNaN, aIsSignalingNaN, bIsQuietNaN, bIsSignalingNaN,
745 cIsQuietNaN, cIsSignalingNaN;
746 int which;
747
748 aIsQuietNaN = float32_is_quiet_nan(a, status);
749 aIsSignalingNaN = float32_is_signaling_nan(a, status);
750 bIsQuietNaN = float32_is_quiet_nan(b, status);
751 bIsSignalingNaN = float32_is_signaling_nan(b, status);
752 cIsQuietNaN = float32_is_quiet_nan(c, status);
753 cIsSignalingNaN = float32_is_signaling_nan(c, status);
754
755 if (aIsSignalingNaN | bIsSignalingNaN | cIsSignalingNaN) {
756 float_raise(float_flag_invalid, status);
757 }
758
759 which = pickNaNMulAdd(aIsQuietNaN, aIsSignalingNaN,
760 bIsQuietNaN, bIsSignalingNaN,
761 cIsQuietNaN, cIsSignalingNaN, infzero, status);
762
763 if (status->default_nan_mode) {
764
765
766
767 return float32_default_nan(status);
768 }
769
770 switch (which) {
771 case 0:
772 return float32_maybe_silence_nan(a, status);
773 case 1:
774 return float32_maybe_silence_nan(b, status);
775 case 2:
776 return float32_maybe_silence_nan(c, status);
777 case 3:
778 default:
779 return float32_default_nan(status);
780 }
781}
782
783#ifdef NO_SIGNALING_NANS
784int float64_is_quiet_nan(float64 a_, float_status *status)
785{
786 return float64_is_any_nan(a_);
787}
788
789int float64_is_signaling_nan(float64 a_, float_status *status)
790{
791 return 0;
792}
793#else
794
795
796
797
798
799int float64_is_quiet_nan(float64 a_, float_status *status)
800{
801 uint64_t a = float64_val(a_);
802 if (status->snan_bit_is_one) {
803 return (((a >> 51) & 0xFFF) == 0xFFE)
804 && (a & 0x0007FFFFFFFFFFFFULL);
805 } else {
806 return ((a << 1) >= 0xFFF0000000000000ULL);
807 }
808}
809
810
811
812
813
814
815int float64_is_signaling_nan(float64 a_, float_status *status)
816{
817 uint64_t a = float64_val(a_);
818 if (status->snan_bit_is_one) {
819 return ((a << 1) >= 0xFFF0000000000000ULL);
820 } else {
821 return (((a >> 51) & 0xFFF) == 0xFFE)
822 && (a & LIT64(0x0007FFFFFFFFFFFF));
823 }
824}
825#endif
826
827
828
829
830
831
832float64 float64_maybe_silence_nan(float64 a_, float_status *status)
833{
834 if (float64_is_signaling_nan(a_, status)) {
835 if (status->snan_bit_is_one) {
836#ifdef TARGET_HPPA
837 uint64_t a = float64_val(a_);
838 a &= ~0x0008000000000000ULL;
839 a |= 0x0004000000000000ULL;
840 return make_float64(a);
841#else
842 return float64_default_nan(status);
843#endif
844 } else {
845 uint64_t a = float64_val(a_);
846 a |= LIT64(0x0008000000000000);
847 return make_float64(a);
848 }
849 }
850 return a_;
851}
852
853
854
855
856
857
858
859static commonNaNT float64ToCommonNaN(float64 a, float_status *status)
860{
861 commonNaNT z;
862
863 if (float64_is_signaling_nan(a, status)) {
864 float_raise(float_flag_invalid, status);
865 }
866 z.sign = float64_val(a) >> 63;
867 z.low = 0;
868 z.high = float64_val(a) << 12;
869 return z;
870}
871
872
873
874
875
876
877static float64 commonNaNToFloat64(commonNaNT a, float_status *status)
878{
879 uint64_t mantissa = a.high >> 12;
880
881 if (status->default_nan_mode) {
882 return float64_default_nan(status);
883 }
884
885 if (mantissa) {
886 return make_float64(
887 (((uint64_t) a.sign) << 63)
888 | LIT64(0x7FF0000000000000)
889 | (a.high >> 12));
890 } else {
891 return float64_default_nan(status);
892 }
893}
894
895
896
897
898
899
900
901static float64 propagateFloat64NaN(float64 a, float64 b, float_status *status)
902{
903 flag aIsQuietNaN, aIsSignalingNaN, bIsQuietNaN, bIsSignalingNaN;
904 flag aIsLargerSignificand;
905 uint64_t av, bv;
906
907 aIsQuietNaN = float64_is_quiet_nan(a, status);
908 aIsSignalingNaN = float64_is_signaling_nan(a, status);
909 bIsQuietNaN = float64_is_quiet_nan(b, status);
910 bIsSignalingNaN = float64_is_signaling_nan(b, status);
911 av = float64_val(a);
912 bv = float64_val(b);
913
914 if (aIsSignalingNaN | bIsSignalingNaN) {
915 float_raise(float_flag_invalid, status);
916 }
917
918 if (status->default_nan_mode) {
919 return float64_default_nan(status);
920 }
921
922 if ((uint64_t)(av << 1) < (uint64_t)(bv << 1)) {
923 aIsLargerSignificand = 0;
924 } else if ((uint64_t)(bv << 1) < (uint64_t)(av << 1)) {
925 aIsLargerSignificand = 1;
926 } else {
927 aIsLargerSignificand = (av < bv) ? 1 : 0;
928 }
929
930 if (pickNaN(aIsQuietNaN, aIsSignalingNaN, bIsQuietNaN, bIsSignalingNaN,
931 aIsLargerSignificand)) {
932 return float64_maybe_silence_nan(b, status);
933 } else {
934 return float64_maybe_silence_nan(a, status);
935 }
936}
937
938
939
940
941
942
943
944
945
946
947static float64 propagateFloat64MulAddNaN(float64 a, float64 b,
948 float64 c, flag infzero,
949 float_status *status)
950{
951 flag aIsQuietNaN, aIsSignalingNaN, bIsQuietNaN, bIsSignalingNaN,
952 cIsQuietNaN, cIsSignalingNaN;
953 int which;
954
955 aIsQuietNaN = float64_is_quiet_nan(a, status);
956 aIsSignalingNaN = float64_is_signaling_nan(a, status);
957 bIsQuietNaN = float64_is_quiet_nan(b, status);
958 bIsSignalingNaN = float64_is_signaling_nan(b, status);
959 cIsQuietNaN = float64_is_quiet_nan(c, status);
960 cIsSignalingNaN = float64_is_signaling_nan(c, status);
961
962 if (aIsSignalingNaN | bIsSignalingNaN | cIsSignalingNaN) {
963 float_raise(float_flag_invalid, status);
964 }
965
966 which = pickNaNMulAdd(aIsQuietNaN, aIsSignalingNaN,
967 bIsQuietNaN, bIsSignalingNaN,
968 cIsQuietNaN, cIsSignalingNaN, infzero, status);
969
970 if (status->default_nan_mode) {
971
972
973
974 return float64_default_nan(status);
975 }
976
977 switch (which) {
978 case 0:
979 return float64_maybe_silence_nan(a, status);
980 case 1:
981 return float64_maybe_silence_nan(b, status);
982 case 2:
983 return float64_maybe_silence_nan(c, status);
984 case 3:
985 default:
986 return float64_default_nan(status);
987 }
988}
989
990#ifdef NO_SIGNALING_NANS
991int floatx80_is_quiet_nan(floatx80 a_, float_status *status)
992{
993 return floatx80_is_any_nan(a_);
994}
995
996int floatx80_is_signaling_nan(floatx80 a_, float_status *status)
997{
998 return 0;
999}
1000#else
1001
1002
1003
1004
1005
1006
1007int floatx80_is_quiet_nan(floatx80 a, float_status *status)
1008{
1009 if (status->snan_bit_is_one) {
1010 uint64_t aLow;
1011
1012 aLow = a.low & ~0x4000000000000000ULL;
1013 return ((a.high & 0x7FFF) == 0x7FFF)
1014 && (aLow << 1)
1015 && (a.low == aLow);
1016 } else {
1017 return ((a.high & 0x7FFF) == 0x7FFF)
1018 && (LIT64(0x8000000000000000) <= ((uint64_t)(a.low << 1)));
1019 }
1020}
1021
1022
1023
1024
1025
1026
1027
1028int floatx80_is_signaling_nan(floatx80 a, float_status *status)
1029{
1030 if (status->snan_bit_is_one) {
1031 return ((a.high & 0x7FFF) == 0x7FFF)
1032 && ((a.low << 1) >= 0x8000000000000000ULL);
1033 } else {
1034 uint64_t aLow;
1035
1036 aLow = a.low & ~LIT64(0x4000000000000000);
1037 return ((a.high & 0x7FFF) == 0x7FFF)
1038 && (uint64_t)(aLow << 1)
1039 && (a.low == aLow);
1040 }
1041}
1042#endif
1043
1044
1045
1046
1047
1048
1049floatx80 floatx80_maybe_silence_nan(floatx80 a, float_status *status)
1050{
1051 if (floatx80_is_signaling_nan(a, status)) {
1052 if (status->snan_bit_is_one) {
1053 a = floatx80_default_nan(status);
1054 } else {
1055 a.low |= LIT64(0xC000000000000000);
1056 return a;
1057 }
1058 }
1059 return a;
1060}
1061
1062
1063
1064
1065
1066
1067
1068static commonNaNT floatx80ToCommonNaN(floatx80 a, float_status *status)
1069{
1070 floatx80 dflt;
1071 commonNaNT z;
1072
1073 if (floatx80_is_signaling_nan(a, status)) {
1074 float_raise(float_flag_invalid, status);
1075 }
1076 if (a.low >> 63) {
1077 z.sign = a.high >> 15;
1078 z.low = 0;
1079 z.high = a.low << 1;
1080 } else {
1081 dflt = floatx80_default_nan(status);
1082 z.sign = dflt.high >> 15;
1083 z.low = 0;
1084 z.high = dflt.low << 1;
1085 }
1086 return z;
1087}
1088
1089
1090
1091
1092
1093
1094static floatx80 commonNaNToFloatx80(commonNaNT a, float_status *status)
1095{
1096 floatx80 z;
1097
1098 if (status->default_nan_mode) {
1099 return floatx80_default_nan(status);
1100 }
1101
1102 if (a.high >> 1) {
1103 z.low = LIT64(0x8000000000000000) | a.high >> 1;
1104 z.high = (((uint16_t)a.sign) << 15) | 0x7FFF;
1105 } else {
1106 z = floatx80_default_nan(status);
1107 }
1108 return z;
1109}
1110
1111
1112
1113
1114
1115
1116
1117static floatx80 propagateFloatx80NaN(floatx80 a, floatx80 b,
1118 float_status *status)
1119{
1120 flag aIsQuietNaN, aIsSignalingNaN, bIsQuietNaN, bIsSignalingNaN;
1121 flag aIsLargerSignificand;
1122
1123 aIsQuietNaN = floatx80_is_quiet_nan(a, status);
1124 aIsSignalingNaN = floatx80_is_signaling_nan(a, status);
1125 bIsQuietNaN = floatx80_is_quiet_nan(b, status);
1126 bIsSignalingNaN = floatx80_is_signaling_nan(b, status);
1127
1128 if (aIsSignalingNaN | bIsSignalingNaN) {
1129 float_raise(float_flag_invalid, status);
1130 }
1131
1132 if (status->default_nan_mode) {
1133 return floatx80_default_nan(status);
1134 }
1135
1136 if (a.low < b.low) {
1137 aIsLargerSignificand = 0;
1138 } else if (b.low < a.low) {
1139 aIsLargerSignificand = 1;
1140 } else {
1141 aIsLargerSignificand = (a.high < b.high) ? 1 : 0;
1142 }
1143
1144 if (pickNaN(aIsQuietNaN, aIsSignalingNaN, bIsQuietNaN, bIsSignalingNaN,
1145 aIsLargerSignificand)) {
1146 return floatx80_maybe_silence_nan(b, status);
1147 } else {
1148 return floatx80_maybe_silence_nan(a, status);
1149 }
1150}
1151
1152#ifdef NO_SIGNALING_NANS
1153int float128_is_quiet_nan(float128 a_, float_status *status)
1154{
1155 return float128_is_any_nan(a_);
1156}
1157
1158int float128_is_signaling_nan(float128 a_, float_status *status)
1159{
1160 return 0;
1161}
1162#else
1163
1164
1165
1166
1167
1168int float128_is_quiet_nan(float128 a, float_status *status)
1169{
1170 if (status->snan_bit_is_one) {
1171 return (((a.high >> 47) & 0xFFFF) == 0xFFFE)
1172 && (a.low || (a.high & 0x00007FFFFFFFFFFFULL));
1173 } else {
1174 return ((a.high << 1) >= 0xFFFF000000000000ULL)
1175 && (a.low || (a.high & 0x0000FFFFFFFFFFFFULL));
1176 }
1177}
1178
1179
1180
1181
1182
1183
1184int float128_is_signaling_nan(float128 a, float_status *status)
1185{
1186 if (status->snan_bit_is_one) {
1187 return ((a.high << 1) >= 0xFFFF000000000000ULL)
1188 && (a.low || (a.high & 0x0000FFFFFFFFFFFFULL));
1189 } else {
1190 return (((a.high >> 47) & 0xFFFF) == 0xFFFE)
1191 && (a.low || (a.high & LIT64(0x00007FFFFFFFFFFF)));
1192 }
1193}
1194#endif
1195
1196
1197
1198
1199
1200
1201float128 float128_maybe_silence_nan(float128 a, float_status *status)
1202{
1203 if (float128_is_signaling_nan(a, status)) {
1204 if (status->snan_bit_is_one) {
1205 a = float128_default_nan(status);
1206 } else {
1207 a.high |= LIT64(0x0000800000000000);
1208 return a;
1209 }
1210 }
1211 return a;
1212}
1213
1214
1215
1216
1217
1218
1219
1220static commonNaNT float128ToCommonNaN(float128 a, float_status *status)
1221{
1222 commonNaNT z;
1223
1224 if (float128_is_signaling_nan(a, status)) {
1225 float_raise(float_flag_invalid, status);
1226 }
1227 z.sign = a.high >> 63;
1228 shortShift128Left(a.high, a.low, 16, &z.high, &z.low);
1229 return z;
1230}
1231
1232
1233
1234
1235
1236
1237static float128 commonNaNToFloat128(commonNaNT a, float_status *status)
1238{
1239 float128 z;
1240
1241 if (status->default_nan_mode) {
1242 return float128_default_nan(status);
1243 }
1244
1245 shift128Right(a.high, a.low, 16, &z.high, &z.low);
1246 z.high |= (((uint64_t)a.sign) << 63) | LIT64(0x7FFF000000000000);
1247 return z;
1248}
1249
1250
1251
1252
1253
1254
1255
1256static float128 propagateFloat128NaN(float128 a, float128 b,
1257 float_status *status)
1258{
1259 flag aIsQuietNaN, aIsSignalingNaN, bIsQuietNaN, bIsSignalingNaN;
1260 flag aIsLargerSignificand;
1261
1262 aIsQuietNaN = float128_is_quiet_nan(a, status);
1263 aIsSignalingNaN = float128_is_signaling_nan(a, status);
1264 bIsQuietNaN = float128_is_quiet_nan(b, status);
1265 bIsSignalingNaN = float128_is_signaling_nan(b, status);
1266
1267 if (aIsSignalingNaN | bIsSignalingNaN) {
1268 float_raise(float_flag_invalid, status);
1269 }
1270
1271 if (status->default_nan_mode) {
1272 return float128_default_nan(status);
1273 }
1274
1275 if (lt128(a.high << 1, a.low, b.high << 1, b.low)) {
1276 aIsLargerSignificand = 0;
1277 } else if (lt128(b.high << 1, b.low, a.high << 1, a.low)) {
1278 aIsLargerSignificand = 1;
1279 } else {
1280 aIsLargerSignificand = (a.high < b.high) ? 1 : 0;
1281 }
1282
1283 if (pickNaN(aIsQuietNaN, aIsSignalingNaN, bIsQuietNaN, bIsSignalingNaN,
1284 aIsLargerSignificand)) {
1285 return float128_maybe_silence_nan(b, status);
1286 } else {
1287 return float128_maybe_silence_nan(a, status);
1288 }
1289}
1290