# special cases
with m.If(a1.is_nan):
- m.d.comb += self.o.z.eq((1<<mz)-1) # NaN overflow
+ with m.If(signed):
+ m.d.comb += self.o.z.eq((1<<(mz-1))-1) # signed NaN overflow
+ with m.Else():
+ m.d.comb += self.o.z.eq((1<<mz)-1) # NaN overflow
with m.Elif(a1.exp_n127):
m.d.comb += self.o.z.eq(0)
m.submodules.norm_exp = msr
m.d.comb += [msr.m_in.eq(mantissa),
msr.e_in.eq(a1.e),
- msr.ediff.eq(Mux(signed, mz-1, mz)-a1.e)
+ msr.ediff.eq(Mux(signed, mz, mz)-a1.e)
]
of = Overflow()
m.d.comb += of.m0.eq(msr.m_out[3])
# XXX TODO: check if this overflows the mantissa
+ mround = Signal(mlen, reset_less=True)
with m.If(of.roundz):
- m.d.comb += self.o.z.eq(msr.m_out[3:]+1)
+ m.d.comb += mround.eq(msr.m_out[3:]+1)
+ with m.Else():
+ m.d.comb += mround.eq(msr.m_out[3:])
+
+ with m.If(signed & a1.s):
+ m.d.comb += self.o.z.eq(-mround)
with m.Else():
- m.d.comb += self.o.z.eq(msr.m_out[3:])
+ m.d.comb += self.o.z.eq(mround)
# copy the context (muxid, operator)
#m.d.comb += self.o.oz.eq(self.o.z.v)
def fcvt_f16_ui16(x):
return sfpy.float.f16_to_ui32(x) & 0xffff
+def fcvt_f16_i16(x):
+ x = sfpy.float.f16_to_i32(x)
+ if x >= 0x7fff:
+ return 0x7fff
+ if x <= -0x8000:
+ return 0x8000
+ return x & 0xffff
+
+def fcvt_f32_i32(x):
+ return sfpy.float.f32_to_i32(x) & 0xffffffff
+
+
######################
# signed int to fp
######################
runfp(dut, 32, "test_fcvt_int_pipe_i32_f32", to_int32, fcvt_i32_f32, True,
n_vals=100, opcode=0x1)
+def test_int_pipe_f32_i32():
+ dut = FPCVTF2IntMuxInOut(32, 32, 4, op_wid=1)
+ runfp(dut, 32, "test_fcvt_f2int_pipe_f32_i32", Float32, fcvt_f32_i32,
+ True, n_vals=100, opcode=0x1)
+
+def test_int_pipe_f16_i16():
+ dut = FPCVTF2IntMuxInOut(16, 16, 4, op_wid=1)
+ runfp(dut, 16, "test_fcvt_f2int_pipe_f16_i16", Float16, fcvt_f16_i16,
+ True, n_vals=100, opcode=0x1)
+
######################
# fp to unsigned int
######################
if __name__ == '__main__':
for i in range(200):
+ test_int_pipe_f16_i16()
+ test_int_pipe_f32_i32()
+ continue
test_int_pipe_f64_ui64()
test_int_pipe_f32_ui32()
test_int_pipe_f16_ui16()