1 #include <stdio.h>
2
3 #if defined(__arm__) || defined(__aarch64__)
4 #include <arm_neon.h>
5 #define SP "sp"
6 #elif defined(__i386__) || defined(__x86_64__)
7 #include <xmmintrin.h>
8 #define SP "esp"
9 typedef __m128 float32x4_t;
10 #elif defined(__mips__) // mipsel64- defines __mips__ too
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);
Vector4()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
Vector4(float a,float b,float c,float d)28 inline Vector4::Vector4(float a, float b, float c, float d)
29 {
30 m_floatVector = Set(a, b, c, d);
31 }
32
Set(float a,float b,float c,float d)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
initVector4(float a,float b,float c,float d)40 Vector4 initVector4(float a, float b, float c, float d)
41 {
42 return Vector4(a, b, c, d);
43 }
44 #else
initVector4(Vector4 * v,float a,float b,float c,float d)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
main()54 int main()
55 {
56 register void *sp __asm(SP);
57 printf("sp = %p\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
main()70 int main()
71 {
72 return 0; // Skip this test (Should not assume vector4 type on le32 triple)
73 }
74
75 #endif
76