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

Jacob Lifshay programmerjake at gmail.com
Mon Apr 18 17:44:05 BST 2022


On Mon, Apr 18, 2022, 09:23 Jacob Lifshay <programmerjake at gmail.com> wrote:

> On Mon, Apr 18, 2022, 08:33 lkcl <luke.leighton at gmail.com> wrote:
>
>> 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).
>

another problem i spotted, borrow out in k is used, the algorithm i gave
has carry out instead, the code needs to be adjusted here:
https://git.libre-soc.org/?p=libreriscv.git;a=blob;f=openpower/sv/bitmanip/divmnu64.c;h=02bef0bb5061cf86f0c88b36f6e92fa63fcad5b4;hb=7af4b874b3ef48c35d13c23d0938ee32c5f67972#l128

basically you need to replace the assignment to un[i + n] after the loop
with instead running the loop one more iteration, but with 0 instead of
vn[i] (since that'd be an out-of-bounds read).

Jacob

>


More information about the Libre-soc-dev mailing list