On Tue, Aug 05, 2025 at 12:22:17PM GMT, Jakub Jelinek wrote:
> On Sat, Aug 02, 2025 at 05:14:23PM +0800, Yang Yujie wrote:
> > A widening cast from a signed _BitInt operand to an unsigned _BitInt
> > type involves filling the extra limb(s) with sign extension.
> > On a target that wants _BitInts extended in memory, if this unsigned
> > type has a partial limb, the unused part of it should be zeroed.
> > 
> > e.g. Assuming limb_mode == E_DImode, at the end of
> > 
> >   void
> >   test (unsigned _BitInt(519) *t, _BitInt(512) x)
> >   {
> >     *t = -x;
> >   }
> > 
> > the most significant limb of *t should be masked with 0x7f.
> > 
> > This patch also fixes gcc.dg/torture/bitint-16.c, which aborts at -O2
> > when the extension on load is optimized away.
> > 
> > gcc/ChangeLog:
> > 
> >     * gimple-lower-bitint.cc (bitint_large_huge::lower_mergeable_stmt):
> >     zero-extend the partial limb of any unsigned _BitInt LHS assigned
> 
> ChangeLog entry should start with capital letter, so Zero-extend
> > new file mode 100644
> > index 00000000000..b106dd36ef1
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.dg/torture/bitint-83.c
> > @@ -0,0 +1,52 @@
> > +/* Derived from a test in gcc.dg/torture/bitint-16.c */
> > +/* { dg-do run { target bitint } } */
> > +/* { dg-options "-std=c23 -pedantic-errors" } */
> > +/* { dg-skip-if "" { ! run_expensive_tests }  { "*" } { "-O0" "-O2" } } */
> > +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */
> > +
> > +#include "../bitintext.h"
> > +
> > +#define BASIC_TESTS \
> > +  TEST(8)      \
> > +  TEST(16)     \
> > +  TEST(32)     \
> 
> The above 3 are certainly ok always, C23 requires that BITINT_MAXWIDTH
> is at least ULLONG_WIDTH and ULLONG_WIDTH has minimum 64.
> 
> > +  TEST(64)     \
> > +  TEST(128)
> 
> The above aren't, 64 + 7 is more than 64 and 128 + 7 even more.
> > +
> > +#if __BITINT_MAXWIDTH__ >= 512
> 
> You're using _BitInt(N + 7), so this should
> be #if __BITINT_MAXWIDTH__ >= 519
> 
> > +#define __ALL_TESTS__ \
> 
> Why __ around the macro name?  Just use ALL_TESTS
> 
> > +  BASIC_TESTS            \
> > +  TEST(256)              \
> > +  TEST(512)
> > +#elif __BITINT_MAXWIDTH__ >= 256
> 
> I wouldn't bother with >= 256 (256 + 7) case, perhaps there will be targets
> with only <= 64 or <= 128 support (though hopefully not), others should
> have maximum around 64K.  Just I want to make sure the tests are compilable
> also with other compilers etc. and clearly state their needs.
> 
> So, I'd go with
> #if __BITINT_MAXWIDTH__ >= 519
> #define ALL_TESTS \
>   BASIC_TESTS         \
>   TEST(64)            \
>   TEST(128)           \
>   TEST(256)           \
>   TEST(512)
> #else
> #define ALL_TESTS BASIC_TESTS
> #endif
> 
>       Jakub

Ok. clearly I need to double-check these. :)

Reply via email to