On Wed, 24 May 2023, Richard Biener via Gcc-patches wrote:

> I’d have to check the ISAs what they actually do here - it of course depends
> on RTL semantics as well but as you say those are not strictly defined here
> either.

Plus, we can add the following executable test to the testsuite:

#include <stdint.h>

#define CHECK(TYPE, WIDTH, OP, COUNT, INVERT)         \
{                                                     \
typedef TYPE vec __attribute__((vector_size(WIDTH))); \
                                                      \
        static volatile vec zero;                     \
        vec tmp = (zero-2) OP (COUNT);                \
        vec ref = INVERT zero;                        \
        if (__builtin_memcmp(&tmp, &ref, sizeof tmp)) \
                __builtin_abort();                    \
}

int main(void)
{
        CHECK( uint8_t, 16, <<, 8,  )
        CHECK( uint8_t, 16, <<, 31, )
        CHECK( uint8_t, 16, >>, 8,  )
        CHECK( uint8_t, 16, >>, 31, )
        CHECK(  int8_t, 16, <<, 8,  )
        CHECK(  int8_t, 16, <<, 31, )
        CHECK(  int8_t, 16, >>, 8,  ~)
        CHECK(  int8_t, 16, >>, 31, ~)
        CHECK(uint16_t, 16, <<, 16, )
        CHECK(uint16_t, 16, <<, 31, )
        CHECK(uint16_t, 16, >>, 16, )
        CHECK(uint16_t, 16, >>, 31, )
        CHECK( int16_t, 16, <<, 16, )
        CHECK( int16_t, 16, <<, 31, )
        CHECK( int16_t, 16, >>, 16, ~)
        CHECK( int16_t, 16, >>, 31, ~)
        // Per-lane-variable shifts:
        CHECK( uint8_t, 16, <<, zero+8,  )
        CHECK( uint8_t, 16, <<, zero+31, )
        CHECK( uint8_t, 16, >>, zero+8,  )
        CHECK( uint8_t, 16, >>, zero+31, )
        CHECK(  int8_t, 16, <<, zero+8,  )
        CHECK(  int8_t, 16, <<, zero+31, )
        CHECK(  int8_t, 16, >>, zero+8,  ~)
        CHECK(  int8_t, 16, >>, zero+31, ~)
        CHECK(uint16_t, 16, <<, zero+16, )
        CHECK(uint16_t, 16, <<, zero+31, )
        CHECK(uint16_t, 16, >>, zero+16, )
        CHECK(uint16_t, 16, >>, zero+31, )
        CHECK( int16_t, 16, <<, zero+16, )
        CHECK( int16_t, 16, <<, zero+31, )
        CHECK( int16_t, 16, >>, zero+16, ~)
        CHECK( int16_t, 16, >>, zero+31, ~)

        // Repeat for WIDTH=32 and WIDTH=64
}

Alexander

Reply via email to