|
21 | 21 |
|
22 | 22 | #include "zend.h" |
23 | 23 |
|
| 24 | +#define ZEND_CPU_EBX_MASK (1<<30) |
24 | 25 | #define ZEND_CPU_EDX_MASK (1<<31) |
25 | 26 |
|
26 | 27 | typedef enum _zend_cpu_feature { |
@@ -55,9 +56,12 @@ typedef enum _zend_cpu_feature { |
55 | 56 | ZEND_CPU_FEATURE_OSXSAVE = (1<<27) , |
56 | 57 | ZEND_CPU_FEATURE_AVX = (1<<28), |
57 | 58 | ZEND_CPU_FEATURE_F16C = (1<<29), |
58 | | - ZEND_CPU_FEATURE_RDRAND = (1<<30), |
| 59 | + /* intentionally don't support = (1<<30) */ |
59 | 60 | /* intentionally don't support = (1<<31) */ |
60 | 61 |
|
| 62 | + /* EBX */ |
| 63 | + ZEND_CPU_FEATURE_AVX2 = (1<<5 | ZEND_CPU_EBX_MASK), |
| 64 | + |
61 | 65 | /* EDX */ |
62 | 66 | ZEND_CPU_FEATURE_FPU = (1<<0 | ZEND_CPU_EDX_MASK), |
63 | 67 | ZEND_CPU_FEATURE_VME = (1<<1 | ZEND_CPU_EDX_MASK), |
@@ -88,47 +92,59 @@ typedef enum _zend_cpu_feature { |
88 | 92 | ZEND_CPU_FEATURE_SSE2 = (1<<26 | ZEND_CPU_EDX_MASK), |
89 | 93 | ZEND_CPU_FEATURE_SS = (1<<27 | ZEND_CPU_EDX_MASK), |
90 | 94 | ZEND_CPU_FEATURE_HT = (1<<28 | ZEND_CPU_EDX_MASK), |
91 | | - ZEND_CPU_FEATURE_TM = (1<<29 | ZEND_CPU_EDX_MASK), |
92 | | - ZEND_CPU_FEATURE_IA64 = (1<<30 | ZEND_CPU_EDX_MASK) |
| 95 | + ZEND_CPU_FEATURE_TM = (1<<29 | ZEND_CPU_EDX_MASK) |
| 96 | + /*intentionally don't support = (1<<30 | ZEND_CPU_EDX_MASK)*/ |
93 | 97 | /*intentionally don't support = (1<<31 | ZEND_CPU_EDX_MASK)*/ |
94 | 98 | } zend_cpu_feature; |
95 | 99 |
|
96 | 100 | void zend_cpu_startup(); |
97 | 101 | ZEND_API int zend_cpu_supports(zend_cpu_feature feature); |
98 | 102 |
|
99 | | -#ifdef PHP_HAVE_BUILTIN_CPU_SUPPORTS |
| 103 | +#if PHP_HAVE_BUILTIN_CPU_SUPPORTS |
100 | 104 | /* NOTE: you should use following inline function in |
101 | 105 | * resolver functions (ifunc), as it could be called |
102 | 106 | * before all PLT symbols are resloved. in other words, |
103 | 107 | * resolver functions should not depends any external |
104 | 108 | * functions */ |
105 | 109 | static zend_always_inline int zend_cpu_support_sse2() { |
| 110 | +#if PHP_HAVE_BUILTIN_CPU_INIT |
106 | 111 | __builtin_cpu_init(); |
| 112 | +#endif |
107 | 113 | return __builtin_cpu_supports("sse2"); |
108 | 114 | } |
109 | 115 |
|
110 | 116 | static zend_always_inline int zend_cpu_support_sse3() { |
| 117 | +#if PHP_HAVE_BUILTIN_CPU_INIT |
111 | 118 | __builtin_cpu_init(); |
| 119 | +#endif |
112 | 120 | return __builtin_cpu_supports("sse3"); |
113 | 121 | } |
114 | 122 |
|
115 | 123 | static zend_always_inline int zend_cpu_support_sse41() { |
| 124 | +#if PHP_HAVE_BUILTIN_CPU_INIT |
116 | 125 | __builtin_cpu_init(); |
| 126 | +#endif |
117 | 127 | return __builtin_cpu_supports("sse4.1"); |
118 | 128 | } |
119 | 129 |
|
120 | 130 | static zend_always_inline int zend_cpu_support_sse42() { |
| 131 | +#if PHP_HAVE_BUILTIN_CPU_INIT |
121 | 132 | __builtin_cpu_init(); |
| 133 | +#endif |
122 | 134 | return __builtin_cpu_supports("sse4.2"); |
123 | 135 | } |
124 | 136 |
|
125 | 137 | static zend_always_inline int zend_cpu_support_avx() { |
| 138 | +#if PHP_HAVE_BUILTIN_CPU_INIT |
126 | 139 | __builtin_cpu_init(); |
| 140 | +#endif |
127 | 141 | return __builtin_cpu_supports("avx"); |
128 | 142 | } |
129 | 143 |
|
130 | 144 | static zend_always_inline int zend_cpu_support_avx2() { |
| 145 | +#if PHP_HAVE_BUILTIN_CPU_INIT |
131 | 146 | __builtin_cpu_init(); |
| 147 | +#endif |
132 | 148 | return __builtin_cpu_supports("avx2"); |
133 | 149 | } |
134 | 150 | #else |
|
0 commit comments