[PATCH] D120327: compiler-rt: Add udivmodei5 to builtins and add bitint library

Matthias Gehre via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 29 01:57:15 PDT 2022


mgehre-amd added inline comments.


================
Comment at: compiler-rt/lib/builtins/int_lib.h:119
+COMPILER_RT_ABI void __udivmodei5(su_int *quo, su_int *rem, const su_int *a,
+                                  const su_int *b, unsigned int words);
+
----------------
programmerjake wrote:
> this should be changed to pass in a buffer big enough for knuth division...
> that is `words * 2 + 1` (the buffer can just be `a` but zero-extended). also `b` needs to be non-const since knuth division needs to modify it.
Maybe it's a stupid question, but does Knuth actually need extra scratch space when it's allowed to modify the inputs?

In APInt::divide, I see four temporary arrays being allocated (U, V, Q, R), each with a size of words (except for U which is words + 1).
But then LHS and RHS are copied in to U and V. And after Knuth's algorithms, Q and R are copied into quo and rem.

Now if we allow to modify the arguments, we don't need to the copies and thus we can directly use the space of `a`, `b`, `quo` and `rem`, can't we?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120327/new/

https://reviews.llvm.org/D120327



More information about the llvm-commits mailing list