Skip to content

Commit 48d6c64

Browse files
committed
math-emu: Add support for reporting exact invalid exception
Some architectures (like powerpc) provide status information on the exact type of invalid exception. This is pretty straight forward as we already report invalid exceptions via FP_SET_EXCEPTION. We add new flags (FP_EX_INVALID_*) the architecture code can define if it wants the exact invalid exception reported. We had to split out the INF/INF and 0/0 cases for divide to allow reporting the two invalid forms properly. Signed-off-by: Kumar Gala <[email protected]> Acked-by: David S. Miller <[email protected]>
1 parent 40d3057 commit 48d6c64

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

include/math-emu/op-common.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ do { \
7373
X##_c = FP_CLS_NAN; \
7474
/* Check for signaling NaN */ \
7575
if (!(_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs)) \
76-
FP_SET_EXCEPTION(FP_EX_INVALID); \
76+
FP_SET_EXCEPTION(FP_EX_INVALID | FP_EX_INVALID_SNAN); \
7777
} \
7878
break; \
7979
} \
@@ -324,7 +324,7 @@ do { \
324324
_FP_FRAC_SET_##wc(R, _FP_NANFRAC_##fs); \
325325
R##_s = _FP_NANSIGN_##fs; \
326326
R##_c = FP_CLS_NAN; \
327-
FP_SET_EXCEPTION(FP_EX_INVALID); \
327+
FP_SET_EXCEPTION(FP_EX_INVALID | FP_EX_INVALID_ISI); \
328328
break; \
329329
} \
330330
/* FALLTHRU */ \
@@ -431,7 +431,7 @@ do { \
431431
R##_s = _FP_NANSIGN_##fs; \
432432
R##_c = FP_CLS_NAN; \
433433
_FP_FRAC_SET_##wc(R, _FP_NANFRAC_##fs); \
434-
FP_SET_EXCEPTION(FP_EX_INVALID); \
434+
FP_SET_EXCEPTION(FP_EX_INVALID | FP_EX_INVALID_IMZ);\
435435
break; \
436436
\
437437
default: \
@@ -490,11 +490,15 @@ do { \
490490
break; \
491491
\
492492
case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_INF): \
493+
R##_s = _FP_NANSIGN_##fs; \
494+
R##_c = FP_CLS_NAN; \
495+
_FP_FRAC_SET_##wc(R, _FP_NANFRAC_##fs); \
496+
FP_SET_EXCEPTION(FP_EX_INVALID | FP_EX_INVALID_IDI);\
493497
case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_ZERO): \
494498
R##_s = _FP_NANSIGN_##fs; \
495499
R##_c = FP_CLS_NAN; \
496500
_FP_FRAC_SET_##wc(R, _FP_NANFRAC_##fs); \
497-
FP_SET_EXCEPTION(FP_EX_INVALID); \
501+
FP_SET_EXCEPTION(FP_EX_INVALID | FP_EX_INVALID_ZDZ);\
498502
break; \
499503
\
500504
default: \

include/math-emu/soft-fp.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,25 @@
5151
#ifndef FP_EX_INVALID
5252
#define FP_EX_INVALID 0
5353
#endif
54+
#ifndef FP_EX_INVALID_SNAN
55+
#define FP_EX_INVALID_SNAN 0
56+
#endif
57+
/* inf - inf */
58+
#ifndef FP_EX_INVALID_ISI
59+
#define FP_EX_INVALID_ISI 0
60+
#endif
61+
/* inf / inf */
62+
#ifndef FP_EX_INVALID_IDI
63+
#define FP_EX_INVALID_IDI 0
64+
#endif
65+
/* 0 / 0 */
66+
#ifndef FP_EX_INVALID_ZDZ
67+
#define FP_EX_INVALID_ZDZ 0
68+
#endif
69+
/* inf * 0 */
70+
#ifndef FP_EX_INVALID_IMZ
71+
#define FP_EX_INVALID_IMZ 0
72+
#endif
5473
#ifndef FP_EX_OVERFLOW
5574
#define FP_EX_OVERFLOW 0
5675
#endif

0 commit comments

Comments
 (0)