[libre-riscv-dev] div/mod algorithm written in python
Luke Kenneth Casson Leighton
lkcl at lkcl.net
Wed Jul 24 09:28:23 BST 2019
jacob what's the setup for RSQRT, i'm getting consistent answers of zero.
changing this from 3 to 2 gives some non-zero answers
with m.Else(): # DivPipeCoreOperation.RSqrtRem
m.d.comb += self.o.compare_lhs.eq(
1 << (self.core_config.fract_width * 3))
--- a/src/ieee754/fpdiv/div0.py
+++ b/src/ieee754/fpdiv/div0.py
@@ -114,6 +114,21 @@ class FPDivStage0Mod(Elaboratable):
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
+ ]
+
On Tue, Jul 23, 2019 at 10:30 PM Luke Kenneth Casson Leighton
<lkcl at lkcl.net> wrote:
>
> ok so i managed to indentify that pass_flags is unary-encoded and is a
> priority unary-encoding. that means that PriorityEncoder can be used
> to turn pass_flags (unary) into next_bits (binary), and that a nmigen
> Array can then be used to select the compare_rhs. yosys knows to use
> a "PMUX" for this.
>
> looks much cleaner code, and the graphviz is a *lot* cleaner. all the
> XORs are gone. by also moving stuff to a new class, Trial, a whooole
> stack of magic constants that were a dog's dinner mess are also gone
> from the top-level, and each "Trial" instance is now way, waaay
> cleaner as well.
>
> l.
More information about the libre-riscv-dev
mailing list