1 # IEEE Floating Point Conversion
2 # Copyright (C) 2019 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
4 from nmigen
import Module
, Signal
, Cat
6 from nmutil
.pipemodbase
import PipeModBase
7 from ieee754
.fpcommon
.basedata
import FPBaseData
8 from ieee754
.fpcommon
.packdata
import FPPackData
11 class FSGNJPipeMod(PipeModBase
):
12 """ FP Sign injection - replaces operand A's sign bit with one
13 generated from operand B
15 self.ctx.i.op & 0x3 == 0x0 : Copy sign bit from operand B
16 self.ctx.i.op & 0x3 == 0x1 : Copy inverted sign bit from operand B
17 self.ctx.i.op & 0x3 == 0x2 : Sign bit is A's sign XOR B's sign
19 def __init__(self
, in_pspec
):
20 self
.in_pspec
= in_pspec
21 super().__init
__(in_pspec
, "fsgnj")
24 return FPBaseData(self
.in_pspec
)
27 return FPPackData(self
.in_pspec
)
29 def elaborate(self
, platform
):
32 width
= self
.pspec
.width
39 opcode
= self
.i
.ctx
.op
43 with m
.Switch(opcode
):
45 comb
+= sign
.eq(b
[-1])
47 comb
+= sign
.eq(~b
[-1])
49 comb
+= sign
.eq(a
[-1] ^ b
[-1])
51 comb
+= sign
.eq(b
[-1])
53 comb
+= z1
.eq(Cat(a
[0:width
-1], sign
))
55 # copy the context (muxid, operator)
56 comb
+= self
.o
.ctx
.eq(self
.i
.ctx
)