Home | History | Annotate | Download | only in jni
      1 #include <stdio.h>
      2 
      3 #if defined(__arm__)
      4 #include <arm_neon.h>
      5 #define SP  "sp"
      6 #elif defined(__i386__)
      7 #include <xmmintrin.h>
      8 #define SP  "esp"
      9 typedef __m128 float32x4_t;
     10 #elif defined(__mips__)
     11 #define SP  "sp"
     12 typedef float float32x4_t __attribute__ ((__vector_size__ (16)));
     13 #elif !defined(__le32__)
     14 #error unknown arch for type float32x4_t
     15 #endif
     16 
     17 #ifndef __le32__
     18 class Vector4
     19 {
     20   public:
     21     inline Vector4(float a, float b, float c, float d);
     22     inline Vector4() {}
     23     inline float32x4_t Set(float a, float b, float c, float d);
     24   private:
     25     float32x4_t m_floatVector;
     26 } __attribute__((aligned(16)));
     27 
     28 inline Vector4::Vector4(float a, float b, float c, float d)
     29 {
     30     m_floatVector = Set(a, b, c, d);
     31 }
     32 
     33 inline float32x4_t Vector4::Set(float a, float b, float c, float d)
     34 {
     35     float32x4_t value = { a, b, c, d };
     36     return value;
     37 }
     38 
     39 #if 1
     40 Vector4 initVector4(float a, float b, float c, float d)
     41 {
     42     return Vector4(a, b, c, d);
     43 }
     44 #else
     45 void initVector4(Vector4 *v, float a, float b, float c, float d)
     46 {
     47     v->Set(a, b, c, d);
     48 }
     49 #endif
     50 
     51 float f;
     52 Vector4 v;
     53 
     54 int main()
     55 {
     56     register int sp __asm(SP);
     57     printf("sp = %x\n", sp);
     58 #if 1
     59     v = initVector4(f, f, f, f);
     60 #else
     61     Vector4 v4;
     62     initVector4(&v4, f, f, f, f);
     63     v = v4;
     64 #endif
     65     return 0;
     66 }
     67 
     68 #else // __le32__
     69 
     70 int main()
     71 {
     72     return 0; // Skip this test (Should not assume vector4 type on le32 triple)
     73 }
     74 
     75 #endif
     76