hstk
hstk

Reputation: 169

How to init neon data type correctly in big endian

I have following code, it can compile in gcc without warning. But in clang, have following warning

warning: vector initializers are not compatible with NEON intrinsics in big endian mode [-Wnonportable-vector-initialization]
unalignedvec a = {11, 13};
note: consider using vld1q_s32() to initialize a vector from memory, or vcombine_s32(vcreate_s32(), vcreate_s32()) to initialize from integer constants
#include <arm_neon.h>

   extern int memcmp (const void *s1, const void *s2, __SIZE_TYPE__ n);
   extern void abort (void);

   typedef __attribute__((aligned (4))) int32x4_t unalignedvec;

   unalignedvec a = {11, 13};
   unalignedvec b = {17, 19};

   void
   foo (int r0, unalignedvec r2, int s0, unalignedvec s8)
   {
     if (r0 != 2 || s0 != 6
         || memcmp ( (void *) &r2, (void *) &a, 16)
         || memcmp ( (void *) &s8, (void *) &b, 16))
       abort ();
   }

   int
   main (int argc, char **argv)
   {
     foo (2, a, 6, b);
     return 0;
   }

So, I try use vld1q_s32 like

#include <arm_neon.h>

extern int memcmp (const void *s1, const void *s2, __SIZE_TYPE__ n);
extern void abort (void);

int arr1[] = {11, 13, 0, 0};
int arr2[] = {17, 19, 0, 0};

void
foo (int r0, int32x4_t r2, int s0, int32x4_t s8)
{
  if (r0 != 2 || s0 != 6
      || memcmp ( (void *) &r2, (void *) &arr1, 16)
      || memcmp ( (void *) &s8, (void *) &arr2, 16))
    abort ();
}

int
main (int argc, char **argv)
{
  int32x4_t a = vld1q_s32(arr1);
  int32x4_t b = vld1q_s32(arr2);
  foo (2, a, 6, b);
  return 0;
}

But it fail because of the byte endian(in function foo, the data of r2 and a is reversed)

Upvotes: 1

Views: 70

Answers (0)

Related Questions