1 #include <stdio.h>
2 
3 #if defined(__clang__) && defined(__aarch64__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ <= 4))
4 /* Disable test for clang3.4/aarch64 because it cause the following error:
5    ..../lib/clang/3.4/include/arm_neon.h:65:24: error: 'neon_vector_type' attribute is not
6    supported for this target
7  */
main()8 int main()
9 {
10     return 0;
11 }
12 
13 #else
14 
15 #if defined(__arm__) || defined(__aarch64__)
16 #include <arm_neon.h>
17 #define SP  "sp"
18 #elif defined(__i386__) || defined(__x86_64__)
19 #include <xmmintrin.h>
20 #define SP  "esp"
21 typedef __m128 float32x4_t;
22 #elif defined(__mips__)  // mipsel64- defines __mips__ too
23 #define SP  "sp"
24 typedef float float32x4_t __attribute__ ((__vector_size__ (16)));
25 #else
26 #error unknown arch for type float32x4_t
27 #endif
28 
29 class Vector4
30 {
31   public:
32     inline Vector4(float a, float b, float c, float d);
Vector4()33     inline Vector4() {}
34     inline float32x4_t Set(float a, float b, float c, float d);
35   private:
36     float32x4_t m_floatVector;
37 } __attribute__((aligned(16)));
38 
Vector4(float a,float b,float c,float d)39 inline Vector4::Vector4(float a, float b, float c, float d)
40 {
41     m_floatVector = Set(a, b, c, d);
42 }
43 
Set(float a,float b,float c,float d)44 inline float32x4_t Vector4::Set(float a, float b, float c, float d)
45 {
46     float32x4_t value = { a, b, c, d };
47     return value;
48 }
49 
50 #if 1
initVector4(float a,float b,float c,float d)51 Vector4 initVector4(float a, float b, float c, float d)
52 {
53     return Vector4(a, b, c, d);
54 }
55 #else
initVector4(Vector4 * v,float a,float b,float c,float d)56 void initVector4(Vector4 *v, float a, float b, float c, float d)
57 {
58     v->Set(a, b, c, d);
59 }
60 #endif
61 
62 float f;
63 Vector4 v;
64 
main()65 int main()
66 {
67     register void *sp __asm(SP);
68     printf("sp = %p\n", sp);
69 #if 1
70     v = initVector4(f, f, f, f);
71 #else
72     Vector4 v4;
73     initVector4(&v4, f, f, f, f);
74     v = v4;
75 #endif
76     return 0;
77 }
78 
79 #endif
80