math-emu: fix floating-point to integer overflow detection
[sfrench/cifs-2.6.git] / include / math-emu / op-common.h
index 70fe5e989ace4a78800e4e39ef52c9495dc7b7ad..6bdf8c61d221f7267914974958f96f2cc2156460 100644 (file)
@@ -743,12 +743,17 @@ do {                                                                      \
          }                                                                     \
        else                                                                    \
          {                                                                     \
+           int _lz0, _lz1;                                                     \
            if (X##_e <= -_FP_WORKBITS - 1)                                     \
              _FP_FRAC_SET_##wc(X, _FP_MINFRAC_##wc);                           \
            else                                                                \
              _FP_FRAC_SRS_##wc(X, _FP_FRACBITS_##fs - 1 - X##_e,               \
                                _FP_WFRACBITS_##fs);                            \
+           _FP_FRAC_CLZ_##wc(_lz0, X);                                         \
            _FP_ROUND(wc, X);                                                   \
+           _FP_FRAC_CLZ_##wc(_lz1, X);                                         \
+           if (_lz1 < _lz0)                                                    \
+             X##_e++; /* For overflow detection.  */                           \
            _FP_FRAC_SRL_##wc(X, _FP_WORKBITS);                                 \
            _FP_FRAC_ASSEMBLE_##wc(r, X, rsize);                                \
          }                                                                     \