Re: [PATCH v2 1/3] lib: extract 32bit mul/div helpers from nios2 into GENERIC_LIB
From: Simon Schuster
Date: Fri Nov 06 2026 - 08:08:16 EST
Hello Vineet,
On Tue, Nov 03, 2026 at 08:23:23PM -0800, Vineet Gupta wrote:
> > +/*
> > + * Software 32-bit multiply for cores built without the hardware multiplier.
> > + */
> > +s32 notrace __mulsi3(s32 a, s32 b);
> > +s32 notrace __divsi3(s32 a, s32 b);
> > +s32 notrace __udivsi3(s32 a, s32 b);
> > +s32 notrace __modsi3(s32 a, s32 b);
> > +s32 notrace __umodsi3(s32 a, s32 b);
>
> Shouldn't the 'u' prefixed functions have unsigned int args, result.
> It seems libgcc/?divmod.c doesn't but ARC does have nint_t for those which
> is unsigned.
> Nios it seems was removed from gcc?
As David has correctly pointed out, nios2 was dropped from gcc with
release line 14.y being the last one to contain it.
So at least for nios2, it seems like it has always been the case that
__udivsi3/__umodsi3 were declared as taking and returning SItypes:
https://github.com/gcc-mirror/gcc/blob/releases/gcc-14/libgcc/config/nios2/lib2-divmod.c#L106
Given that both implementations continue to pass it through to a very
similarly looking udivmodsi4 as u32, I would assume that this has partly
relied on 'why should the compiler do any strange upcasts here, it will
just pass through the registers and be done with it and this is
implementation-defined-good-enough', so I would not mind rolling a v3
with u32s for __umodsi3 and __udivsi3. Are these the only two symbols
you are concerned about, and would these signatures work for you?
u32 notrace __udivsi3(u32 a, u32 b);
u32 notrace __umodsi3(u32 a, u32 b);
Best regards
Simon