Skip to content

Commit e1dfd9c

Browse files
authored
Consolidate FCLASS.S (#47)
There is a difference in the signature of fclass_b1-01. When getting 0x80000000 as input, the expected output is 0x00000000, while rv32emu generates 0x00000008. In another test case of the same input, the expected output is 0x00000008.
1 parent 94bb504 commit e1dfd9c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

riscv_private.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ enum {
110110
FMASK_SIGN = 0b10000000000000000000000000000000,
111111
FMASK_EXPN = 0b01111111100000000000000000000000,
112112
FMASK_FRAC = 0b00000000011111111111111111111111,
113+
FMASK_QNAN = 0b00000000010000000000000000000000,
113114
// ....xxxx....xxxx....xxxx....xxxx
114115
FFLAG_MASK = 0b00000000000000000000000000011111,
115116
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

Comments
 (0)