On Fri, May 06, 2022 at 02:09:21PM +0000, Matthias Gehre via Gcc wrote: > /// \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);
> Sizes certainly should be with size_t, not unsigned type. Agreed > Rather than uint32_t, wouldn't using the word size (64-bit for lp64, 32-bit for ilp32) be better? Is there a portable way to specify this in C? (size_t, uintptr_t?) And is the word size clearly defined for each target? (I'm not a backend expert). > And I really don't like the N + 1 stuff you're proposing, at least for > _BigInts that would be represented as an array of those word etc. elements > from least to most significant (or vice versa? That really needs to be > specified too), if they are same precision having to copy one of them just > to get the extra scratch is bad. Yes, that's a trade-off. Knuth algorithm is generally a good choice, but not having the extra scratch space would introduce more branches into it. Also, the proposed __udivmodei5 is allowed to overwrite the inputs, so you might need to copy them anyways. I actually didn't have this N + 1 initially, but then I got a comment on the compiler-rt review, and added it subsequently. Personally, I don't mind either way.