| 1 |
#include<simdconfig.h> |
| 2 |
#include<simdfuncs.h> |
| 3 |
|
| 4 |
#include<stdint.h> |
| 5 |
|
| 6 |
#ifdef _MSC_VER |
| 7 |
#include<intrin.h> |
| 8 |
int mmx_available(void) { |
| 9 |
return 1; |
| 10 |
} |
| 11 |
/* Contrary to MSDN documentation, MMX intrinsics |
| 12 |
* just plain don't work. |
| 13 |
*/ |
| 14 |
void increment_mmx(float arr[4]) { |
| 15 |
arr[0]++; |
| 16 |
arr[1]++; |
| 17 |
arr[2]++; |
| 18 |
arr[3]++; |
| 19 |
} |
| 20 |
#elif defined(__MINGW32__) |
| 21 |
int mmx_available(void) { |
| 22 |
return 1; |
| 23 |
} |
| 24 |
/* MinGW does not seem to ship with MMX or it is broken. |
| 25 |
*/ |
| 26 |
void increment_mmx(float arr[4]) { |
| 27 |
arr[0]++; |
| 28 |
arr[1]++; |
| 29 |
arr[2]++; |
| 30 |
arr[3]++; |
| 31 |
} |
| 32 |
#else |
| 33 |
#include<mmintrin.h> |
| 34 |
#include<cpuid.h> |
| 35 |
|
| 36 |
#if defined(__APPLE__) |
| 37 |
int mmx_available(void) { return 1; } |
| 38 |
#else |
| 39 |
int mmx_available(void) { |
| 40 |
return __builtin_cpu_supports("mmx"); |
| 41 |
} |
| 42 |
#endif |
| 43 |
void increment_mmx(float arr[4]) { |
| 44 |
/* Super ugly but we know that values in arr are always small |
| 45 |
* enough to fit in int16; |
| 46 |
*/ |
| 47 |
int i; |
| 48 |
/* This is unused due to below comment about GCC 8. |
| 49 |
__m64 packed = _mm_set_pi16(arr[3], arr[2], arr[1], arr[0]); |
| 50 |
__m64 incr = _mm_set1_pi16(1); |
| 51 |
__m64 result = _mm_add_pi16(packed, incr); |
| 52 |
int64_t unpacker = (int64_t)(result); |
| 53 |
*/ |
| 54 |
/* The above should be |
| 55 |
* int64_t unpacker = _m_to_int64(result); |
| 56 |
* but it does not exist on 32 bit platforms for some reason. |
| 57 |
*/ |
| 58 |
_mm_empty(); |
| 59 |
for(i=0; i<4; i++) { |
| 60 |
/* This fails on GCC 8 when optimizations are enabled. |
| 61 |
* Disable it. Patches welcome to fix this. |
| 62 |
arr[i] = (float)(unpacker & ((1<<16)-1)); |
| 63 |
unpacker >>= 16; |
| 64 |
*/ |
| 65 |
arr[i] += 1.0f; |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
#endif |