[Libre-soc-isa] [Bug 1192] dsrd / dsld need "add" option for knuth algorithm d

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Wed Oct 18 16:13:22 BST 2023


https://bugs.libre-soc.org/show_bug.cgi?id=1192

Jacob Lifshay <programmerjake at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |programmerjake at gmail.com

--- Comment #1 from Jacob Lifshay <programmerjake at gmail.com> ---
(In reply to shriya.sharma from comment #0)
> in knuth algorithm d there is a shift-and-add.

actually, not really. this is just a convoluted way (when combined with the
loop computing phi/plo) of writing a bigint multiply-subtract.

I instead used the algorithm in (with #define MADDEDU_SUBFE):
https://git.libre-soc.org/?p=libreriscv.git;a=blob;f=openpower/sv/biginteger/divmnu64.c;h=b4bd10659796f36812e67bc22d2814d176813054;hb=6ecafc9cfa1cf13f25fa851d012b20989d770108#l375

the actual code that I use has no shifts and is (converting extraneous bits
that setup VL and stuff into comments):
# do multiply part
# t = 0
# VL = n
sv.maddedu *product, *vn, qhat, t  # product = vn * qhat
# product[n] = t

# do subtract part
# CA = 1  # no borrow initially
# VL = n + 1
# set REMAP to offset RT and RB by j
sv.subfe *un, *product, *un  # un[j:] -= product

if borrowed:  # there was a borrow, aka. product was too big
    # we need to adjust qhat by one and un[j:] to match
    # qhat -= 1
    # CA = 0  # no carry
    # VL = n
    # set REMAP to offset RT and RA by j
    sv.adde *un, *un, *vn  # un[j:] += vn
    # un[j + n] += CA  # add last digit

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Libre-SOC-ISA mailing list