[Libre-soc-dev] SVP64 Vectorised add-carry => big int add

Jacob Lifshay programmerjake at gmail.com
Mon Apr 18 17:23:07 BST 2022


On Mon, Apr 18, 2022, 08:33 lkcl <luke.leighton at gmail.com> wrote:

> On Sun, Apr 17, 2022 at 10:54 AM Jacob Lifshay <programmerjake at gmail.com>
> wrote:
>
> > turns out, after some checking with 4-bit words, afaict the correct
> algorithm for mrsubcarry is:
> > # for big_c - big_a * word_b
> > result <- RC + ~(RA * RB) + CARRY
> > result_high <- HIGH_HALF(result)
> > if CARRY <= 1 then # unsigned comparison
> >     result_high <- result_high + 1
> > end
> > CARRY <- result_high
> > RT <- LOW_HALF(result)
>
> i implemented it here, after finding a suitable c-code implementation
> online (hacker's delight, by hannah suarez) and it didn't work
>
> https://git.libre-soc.org/?p=libreriscv.git;a=commitdiff;h=7af4b874b3ef48c35d13c23d0938ee32c5f67972
>
> any clues as to why?
>

yes...there's 2 problems:
1. sum is uninitialized -- did you even compile with warnings enabled?!
(another UB trap in C, if you had used Rust or basically any good language
it would have not let you compile that).

2. the algorithm I gave requires carry to start at 1
-- just like subfe does (subfe uses RT <- ~RA + RB + CA).
that's because -x == ~x + 1 for all integers x.
I'm trying to have the algorithm be like subfe since that likely gives
simpler hardware, otherwise I'd just have it use the CARRY register as a
borrow value like the original algorithm in that c you added from hackers'
delight

Jacob


More information about the Libre-soc-dev mailing list