662181912ff3d2738857cc3d6d8821228619521a
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
):
37 opcode
= self
.i
.ctx
.op
41 with m
.Switch(opcode
):
43 comb
+= sign
.eq(b
[31])
45 comb
+= sign
.eq(~b
[31])
47 comb
+= sign
.eq(a
[31] ^ b
[31])
49 comb
+= z1
.eq(Cat(a
[0:31], sign
))
51 # copy the context (muxid, operator)
52 comb
+= self
.o
.ctx
.eq(self
.i
.ctx
)