| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
#pragma once |
| 27 |
|
| 28 |
#include <iostream> |
| 29 |
#include "cpuid.h" |
| 30 |
#include <smmintrin.h> |
| 31 |
|
| 32 |
typedef uintptr_t UINT_PTR; |
| 33 |
#define __fastcall |
| 34 |
#define __noop |
| 35 |
|
| 36 |
#ifdef __try |
| 37 |
#undef __try |
| 38 |
#endif |
| 39 |
#define __try try |
| 40 |
|
| 41 |
#ifdef __except |
| 42 |
#undef __except |
| 43 |
#endif |
| 44 |
|
| 45 |
#define EXCEPTION_EXECUTE_HANDLER std::exception const& e |
| 46 |
|
| 47 |
#define __except(e) catch(e) |
| 48 |
|
| 49 |
#ifndef __EXCEPTIONS |
| 50 |
|
| 51 |
#define NO_EXCEPTION_HANDLING 1 |
| 52 |
#endif |
| 53 |
|
| 54 |
#if NO_EXCEPTION_HANDLING || ANDROID |
| 55 |
#define try if (true) |
| 56 |
|
| 57 |
#ifndef catch |
| 58 |
#define catch(x) if (false) |
| 59 |
#endif |
| 60 |
|
| 61 |
#define throw(...) |
| 62 |
#endif |
| 63 |
|
| 64 |
#define CM_CPU_FASTCOPY_THRESHOLD 1024 |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
inline void Prefetch( const void* ptr ) |
| 74 |
{ |
| 75 |
__asm__("prefetchnta 0(%0)"::"r"(ptr)); |
| 76 |
} |
| 77 |
|
| 78 |
inline bool TestSSE4_1( void ) |
| 79 |
{ |
| 80 |
bool success = true; |
| 81 |
|
| 82 |
#ifndef NO_EXCEPTION_HANDLING |
| 83 |
__try |
| 84 |
{ |
| 85 |
#endif |
| 86 |
|
| 87 |
if ( sizeof(void *) == 4) |
| 88 |
{ |
| 89 |
__asm__ __volatile__ (".byte 0x66"); |
| 90 |
__asm__ __volatile__ (".byte 0x0f"); |
| 91 |
__asm__ __volatile__ (".byte 0x38"); |
| 92 |
__asm__ __volatile__ (".byte 0x17"); |
| 93 |
__asm__ __volatile__ (".byte 0xc1"); |
| 94 |
} |
| 95 |
else |
| 96 |
{ |
| 97 |
success = true; |
| 98 |
} |
| 99 |
|
| 100 |
#ifndef NO_EXCEPTION_HANDLING |
| 101 |
} |
| 102 |
__except( EXCEPTION_EXECUTE_HANDLER ) |
| 103 |
{ |
| 104 |
success = false; |
| 105 |
} |
| 106 |
#endif |
| 107 |
return success; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
inline void GetCPUID(int cpuInfo[4], int infoType) |
| 122 |
{ |
| 123 |
#ifndef NO_EXCEPTION_HANDLING |
| 124 |
__try |
| 125 |
{ |
| 126 |
#endif |
| 127 |
|
| 128 |
__get_cpuid(infoType, (unsigned int*)cpuInfo, (unsigned int*)cpuInfo + 1, (unsigned int*)cpuInfo + 2, (unsigned int*)cpuInfo + 3); |
| 129 |
|
| 130 |
#ifndef NO_EXCEPTION_HANDLING |
| 131 |
} |
| 132 |
__except( EXCEPTION_EXECUTE_HANDLER ) |
| 133 |
{ |
| 134 |
|
| 135 |
return; |
| 136 |
} |
| 137 |
#endif |
| 138 |
} |
| 139 |
|
| 140 |
void CmFastMemCopyFromWC( void* dst, const void* src, const size_t bytes, CPU_INSTRUCTION_LEVEL cpuInstructionLevel ); |