@@ -948,8 +948,6 @@ _Bool __aarch64_have_lse_atomics
948
948
#if defined(__has_include )
949
949
#if __has_include (< sys /auxv .h > )
950
950
#include <sys/auxv.h>
951
- #define HAVE_SYS_AUXV
952
- #endif
953
951
954
952
#if __has_include (< sys /ifunc .h > )
955
953
#include <sys/ifunc.h>
@@ -963,8 +961,6 @@ typedef struct __ifunc_arg_t {
963
961
964
962
#if __has_include (< asm /hwcap .h > )
965
963
#include <asm/hwcap.h>
966
- #define HAVE_SYS_HWCAP
967
- #endif
968
964
969
965
#if defined(__ANDROID__ )
970
966
#include <string.h>
@@ -1001,9 +997,6 @@ typedef struct __ifunc_arg_t {
1001
997
#ifndef HWCAP_SHA2
1002
998
#define HWCAP_SHA2 (1 << 6)
1003
999
#endif
1004
- #ifndef HWCAP_CRC32
1005
- #define HWCAP_CRC32 (1 << 7)
1006
- #endif
1007
1000
#ifndef HWCAP_ATOMICS
1008
1001
#define HWCAP_ATOMICS (1 << 8)
1009
1002
#endif
@@ -1156,7 +1149,6 @@ typedef struct __ifunc_arg_t {
1156
1149
if (__system_property_get("ro.arch", arch) > 0 && \
1157
1150
strncmp(arch, "exynos9810", sizeof("exynos9810") - 1) == 0)
1158
1151
1159
- #if !defined(__APPLE__ )
1160
1152
static void CONSTRUCTOR_ATTRIBUTE init_have_lse_atomics (void ) {
1161
1153
#if defined(__FreeBSD__ )
1162
1154
unsigned long hwcap ;
@@ -1170,7 +1162,7 @@ static void CONSTRUCTOR_ATTRIBUTE init_have_lse_atomics(void) {
1170
1162
zx_status_t status = _zx_system_get_features (ZX_FEATURE_KIND_CPU , & features );
1171
1163
__aarch64_have_lse_atomics =
1172
1164
status == ZX_OK && (features & ZX_ARM64_FEATURE_ISA_ATOMICS ) != 0 ;
1173
- #elif defined( HAVE_SYS_AUXV )
1165
+ #else
1174
1166
unsigned long hwcap = getauxval (AT_HWCAP );
1175
1167
_Bool result = (hwcap & HWCAP_ATOMICS ) != 0 ;
1176
1168
#if defined(__ANDROID__ )
@@ -1188,11 +1180,8 @@ static void CONSTRUCTOR_ATTRIBUTE init_have_lse_atomics(void) {
1188
1180
}
1189
1181
#endif // defined(__ANDROID__)
1190
1182
__aarch64_have_lse_atomics = result ;
1191
- #else
1192
- #error No support for checking for lse atomics on this platfrom yet.
1193
1183
#endif // defined(__FreeBSD__)
1194
1184
}
1195
- #endif // !defined(__APPLE__)
1196
1185
1197
1186
#if !defined(DISABLE_AARCH64_FMV )
1198
1187
// CPUFeatures must correspond to the same AArch64 features in
@@ -1270,76 +1259,6 @@ struct {
1270
1259
// As features grows new fields could be added
1271
1260
} __aarch64_cpu_features __attribute__((visibility ("hidden" ), nocommon ));
1272
1261
1273
- #if defined(__APPLE__ )
1274
- #include <TargetConditionals.h>
1275
- #if TARGET_OS_OSX || TARGET_OS_IPHONE
1276
- #include <dispatch/dispatch.h>
1277
- #include <sys/sysctl.h>
1278
-
1279
- static bool isKnownAndSupported (const char * name ) {
1280
- int32_t val = 0 ;
1281
- size_t size = sizeof (val );
1282
- if (sysctlbyname (name , & val , & size , NULL , 0 ))
1283
- return false;
1284
- return val ;
1285
- }
1286
-
1287
- void __init_cpu_features_resolver (void ) {
1288
- // On Darwin platforms, this may be called concurrently by multiple threads
1289
- // because the resolvers that use it are called lazily at runtime (unlike on
1290
- // ELF platforms, where IFuncs are resolved serially at load time). This
1291
- // function's effect on __aarch64_cpu_features should be idempotent, but even
1292
- // so we need dispatch_once to resolve the race condition. Dispatch is
1293
- // available through libSystem, which we need anyway for the sysctl, so this
1294
- // does not add a new dependency.
1295
-
1296
- static dispatch_once_t onceToken = 0 ;
1297
- dispatch_once (& onceToken , ^{
1298
- // https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics
1299
- static struct {
1300
- const char * sysctl_name ;
1301
- enum CPUFeatures feature ;
1302
- } features [] = {
1303
- {"hw.optional.arm.FEAT_FlagM" , FEAT_FLAGM },
1304
- {"hw.optional.arm.FEAT_FlagM2" , FEAT_FLAGM2 },
1305
- {"hw.optional.arm.FEAT_FHM" , FEAT_FP16FML },
1306
- {"hw.optional.arm.FEAT_DotProd" , FEAT_DOTPROD },
1307
- {"hw.optional.arm.FEAT_RDM" , FEAT_RDM },
1308
- {"hw.optional.arm.FEAT_LSE" , FEAT_LSE },
1309
- {"hw.optional.floatingpoint" , FEAT_FP },
1310
- {"hw.optional.AdvSIMD" , FEAT_SIMD },
1311
- {"hw.optional.armv8_crc32" , FEAT_CRC },
1312
- {"hw.optional.arm.FEAT_SHA1" , FEAT_SHA1 },
1313
- {"hw.optional.arm.FEAT_SHA256" , FEAT_SHA2 },
1314
- {"hw.optional.arm.FEAT_SHA3" , FEAT_SHA3 },
1315
- {"hw.optional.arm.FEAT_AES" , FEAT_AES },
1316
- {"hw.optional.arm.FEAT_PMULL" , FEAT_PMULL },
1317
- {"hw.optional.arm.FEAT_FP16" , FEAT_FP16 },
1318
- {"hw.optional.arm.FEAT_DIT" , FEAT_DIT },
1319
- {"hw.optional.arm.FEAT_DPB" , FEAT_DPB },
1320
- {"hw.optional.arm.FEAT_DPB2" , FEAT_DPB2 },
1321
- {"hw.optional.arm.FEAT_JSCVT" , FEAT_JSCVT },
1322
- {"hw.optional.arm.FEAT_FCMA" , FEAT_FCMA },
1323
- {"hw.optional.arm.FEAT_LRCPC" , FEAT_RCPC },
1324
- {"hw.optional.arm.FEAT_LRCPC2" , FEAT_RCPC2 },
1325
- {"hw.optional.arm.FEAT_FRINTTS" , FEAT_FRINTTS },
1326
- {"hw.optional.arm.FEAT_I8MM" , FEAT_I8MM },
1327
- {"hw.optional.arm.FEAT_BF16" , FEAT_BF16 },
1328
- {"hw.optional.arm.FEAT_SB" , FEAT_SB },
1329
- {"hw.optional.arm.FEAT_SPECRES" , FEAT_PREDRES },
1330
- {"hw.optional.arm.FEAT_SSBS" , FEAT_SSBS2 },
1331
- {"hw.optional.arm.FEAT_BTI" , FEAT_BTI },
1332
- };
1333
-
1334
- for (size_t I = 0 , E = sizeof (features ) / sizeof (features [0 ]); I != E ; ++ I )
1335
- if (isKnownAndSupported (features [I ].sysctl_name ))
1336
- __aarch64_cpu_features .features |= (1ULL << features [I ].feature );
1337
-
1338
- __aarch64_cpu_features .features |= (1ULL << FEAT_INIT );
1339
- });
1340
- }
1341
- #endif // TARGET_OS_OSX || TARGET_OS_IPHONE
1342
- #else // defined(__APPLE__)
1343
1262
static void __init_cpu_features_constructor (unsigned long hwcap ,
1344
1263
const __ifunc_arg_t * arg ) {
1345
1264
#define setCPUFeature (F ) __aarch64_cpu_features.features |= 1ULL << F
@@ -1548,8 +1467,8 @@ void __init_cpu_features_resolver(unsigned long hwcap,
1548
1467
}
1549
1468
1550
1469
void CONSTRUCTOR_ATTRIBUTE __init_cpu_features (void ) {
1551
- unsigned long hwcap = 0 ;
1552
- unsigned long hwcap2 = 0 ;
1470
+ unsigned long hwcap ;
1471
+ unsigned long hwcap2 ;
1553
1472
// CPU features already initialized.
1554
1473
if (__aarch64_cpu_features .features )
1555
1474
return ;
@@ -1559,16 +1478,14 @@ void CONSTRUCTOR_ATTRIBUTE __init_cpu_features(void) {
1559
1478
res |= elf_aux_info (AT_HWCAP2 , & hwcap2 , sizeof hwcap2 );
1560
1479
if (res )
1561
1480
return ;
1562
- #elif defined( HAVE_SYS_AUXV )
1481
+ #else
1563
1482
#if defined(__ANDROID__ )
1564
1483
// Don't set any CPU features,
1565
1484
// detection could be wrong on Exynos 9810.
1566
1485
IF_EXYNOS9810 return ;
1567
1486
#endif // defined(__ANDROID__)
1568
1487
hwcap = getauxval (AT_HWCAP );
1569
1488
hwcap2 = getauxval (AT_HWCAP2 );
1570
- #else
1571
- #error No support for checking hwcap on this platform yet.
1572
1489
#endif // defined(__FreeBSD__)
1573
1490
__ifunc_arg_t arg ;
1574
1491
arg ._size = sizeof (__ifunc_arg_t );
@@ -1580,7 +1497,8 @@ void CONSTRUCTOR_ATTRIBUTE __init_cpu_features(void) {
1580
1497
#undef setCPUFeature
1581
1498
#undef IF_EXYNOS9810
1582
1499
}
1583
- #endif // defined(__APPLE__)
1584
1500
#endif // !defined(DISABLE_AARCH64_FMV)
1585
1501
#endif // defined(__has_include)
1502
+ #endif // __has_include(<sys/auxv.h>)
1503
+ #endif // __has_include(<asm/hwcap.h>)
1586
1504
#endif // defined(__aarch64__)
0 commit comments