self.o.operation.eq(Const(1)) # XXX SQRT operation
]
+ # RSQRT
+ with m.Elif(self.i.ctx.op == 2):
+ am0 = Signal(len(self.i.a.m)+3, reset_less=True)
+ with m.If(self.i.a.e[0]):
+ m.d.comb += am0.eq(Cat(self.i.a.m, 0)<<(extra-2))
+ m.d.comb += self.o.z.e.eq(-((self.i.a.e+1) >> 1)+1)
+ with m.Else():
+ m.d.comb += am0.eq(Cat(0, self.i.a.m)<<(extra-2))
+ m.d.comb += self.o.z.e.eq((self.i.a.e >> 1)+1)
+
+ m.d.comb += [self.o.z.s.eq(self.i.a.s),
+ self.o.divisor_radicand.eq(am0),
+ self.o.operation.eq(Const(2)) # XXX RSQRT operation
+ ]
+
# these are required and must not be touched
m.d.comb += self.o.oz.eq(self.i.oz)
m.d.comb += self.o.out_do_z.eq(self.i.out_do_z)
--- /dev/null
+""" test of FPDIVMuxInOut
+"""
+
+from ieee754.fpdiv.pipeline import (FPDIVMuxInOut,)
+from ieee754.fpcommon.test.fpmux import runfp
+
+from sfpy import Float64, Float32, Float16
+
+def rsqrt(x):
+ return x.__class__(1.0) / x.sqrt()
+
+def test_pipe_rsqrt_fp16():
+ dut = FPDIVMuxInOut(16, 4)
+ runfp(dut, 16, "test_fprsqrt_pipe_fp16", Float16, rsqrt,
+ single_op=True, opcode=2, n_vals=100)
+
+def test_pipe_rsqrt_fp32():
+ dut = FPDIVMuxInOut(32, 4)
+ runfp(dut, 32, "test_fprsqrt_pipe_fp32", Float32, rsqrt,
+ single_op=True, opcode=2, n_vals=100)
+
+def test_pipe_rsqrt_fp64():
+ dut = FPDIVMuxInOut(64, 4)
+ runfp(dut, 64, "test_fprsqrt_pipe_fp64", Float64, rsqrt,
+ single_op=True, opcode=2, n_vals=100)
+
+if __name__ == '__main__':
+ test_pipe_rsqrt_fp16()
+ test_pipe_rsqrt_fp32()
+ test_pipe_rsqrt_fp64()