@@ -109,6 +109,7 @@ enum {
109109 FMASK_SIGN = 0b10000000000000000000000000000000 ,
110110 FMASK_EXPN = 0b01111111100000000000000000000000 ,
111111 FMASK_FRAC = 0b00000000011111111111111111111111 ,
112+ FMASK_QNAN = 0b00000000010000000000000000000000 ,
112113 // ....xxxx....xxxx....xxxx....xxxx
113114 FFLAG_MASK = 0b00000000000000000000000000011111 ,
114115 FFLAG_INVALID_OP = 0b00000000000000000000000000010000 ,
@@ -312,7 +313,7 @@ static inline uint32_t calc_fclass(uint32_t f) {
312313 /* 0x001 rs1 is -INF */
313314 out |= (f == 0xff800000 ) ? 0x001 : 0 ;
314315 /* 0x002 rs1 is negative normal */
315- out |= (expn && expn < 0x78000000 && sign ) ? 0x002 : 0 ;
316+ out |= (expn && ( expn != FMASK_EXPN ) && sign ) ? 0x002 : 0 ;
316317 /* 0x004 rs1 is negative subnormal */
317318 out |= (!expn && frac && sign ) ? 0x004 : 0 ;
318319 /* 0x008 rs1 is -0 */
@@ -322,13 +323,13 @@ static inline uint32_t calc_fclass(uint32_t f) {
322323 /* 0x020 rs1 is positive subnormal */
323324 out |= (!expn && frac && !sign ) ? 0x020 : 0 ;
324325 /* 0x040 rs1 is positive normal */
325- out |= (expn && expn < 0x78000000 && !sign ) ? 0x040 : 0 ;
326+ out |= (expn && ( expn != FMASK_EXPN ) && !sign ) ? 0x040 : 0 ;
326327 /* 0x080 rs1 is +INF */
327- out |= (f == 0x7f800000 ) ? 0x080 : 0 ;
328+ out |= (expn == FMASK_EXPN && ! frac && ! sign ) ? 0x080 : 0 ;
328329 /* 0x100 rs1 is a signaling NaN */
329- out |= (expn == FMASK_EXPN && ( frac <= 0x7ff ) && frac ) ? 0x100 : 0 ;
330+ out |= (expn == FMASK_EXPN && frac && !( frac & FMASK_QNAN ) ) ? 0x100 : 0 ;
330331 /* 0x200 rs1 is a quiet NaN */
331- out |= (expn == FMASK_EXPN && (frac >= 0x800 )) ? 0x200 : 0 ;
332+ out |= (expn == FMASK_EXPN && (frac & FMASK_QNAN )) ? 0x200 : 0 ;
332333
333334 return out ;
334335}
0 commit comments