public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* [RFC] Adding division/modulo on arbitrary precision integers to libgcc
@ 2022-05-06 14:09 Matthias Gehre
  2022-05-06 14:36 ` Joseph Myers
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Matthias Gehre @ 2022-05-06 14:09 UTC (permalink / raw)
  To: gcc

Hello!

We would like to add support for division/modulo on large arbitrary precision integers to libgcc/compiler-rt
as required by C23's _BitInt type [0].

From what I know, gcc doesn't yet support C23 _BitInt, but we would still
like to ensure that libgcc and compiler-rt can stay compatible in the future.

We created a prototype in compiler-rt [1], which uses the following declarations:

/// Computes the unsigned division of a / b for two large integers
/// composed of n significant words.
/// Writes the quotient to quo and the remainder to rem.
///
/// \param quo The quotient represented by n words. Must be non-null.
/// \param rem The remainder represented by n words. Must be non-null.
/// \param a The dividend represented by n + 1 words. Must be non-null.
/// \param b The divisor represented by n words. Must be non-null.

/// \note The word order is in host endianness.
/// \note Might modify a and b.
/// \note The storage of 'a' needs to hold n + 1 elements because some
///       implementations need extra scratch space in the most significant word.
///       The value of that word is ignored.
void __udivmodei5(uint32_t *quo, uint32_t *rem, uint32_t *a,
                                  uint32_t *b, unsigned n);

/// Computes the signed division of a / b.
/// See __udivmodei5 for details.
void __divmodei5(uint32_t *quo, uint32_t *rem, uint32_t *a, uint32_t *b,
                                 unsigned n);

The current prototype requires the compiler backend to first promote large integers to a multiple of 32 bits.
The extra word of storage in argument `a` is required to allow implementations to use Knuth's
algorithm efficiently.

We are not fixed on the current function prototypes, and would like
to take your feedback.
E.g. is the naming of the functions in line with the scheme used by libgcc?

Best wishes,
Matthias

CC'ing Martin Liska as recommended by MaskRay on the PR

[0] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2763.pdf
[1] https://reviews.llvm.org/D120327#change-mseSeWmhjTZf

 
Dr. Matthias Gehre 
SMTS Software Development Engineer |  AMD
Adaptive Computing Tools 
---------------------------------------------------------------------------------------------------------------------------------- 
2485 Augustine Drive, Santa Clara, CA 95054 
Facebook |  Twitter |  amd.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-05-06 18:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-06 14:09 [RFC] Adding division/modulo on arbitrary precision integers to libgcc Matthias Gehre
2022-05-06 14:36 ` Joseph Myers
2022-05-06 15:57   ` AW: " Matthias Gehre
2022-05-06 16:02     ` Joseph Myers
2022-05-06 14:47 ` Jakub Jelinek
2022-05-06 15:23   ` Joseph Myers
2022-05-06 15:42   ` AW: " Matthias Gehre
2022-05-06 16:39     ` Jonathan Lennox
2022-05-06 18:05 ` Segher Boessenkool

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).