Skip to content

Commit 782019f

Browse files
committed
Refactor CRC32 check
This refactors the CRC32 API check on ARM to its own utility module/file and enables CRC32 API also for Windows when processor is ARM64.
1 parent 63544ae commit 782019f

File tree

2 files changed

+78
-29
lines changed

2 files changed

+78
-29
lines changed

cmake/ext/standard/CMakeLists.txt

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ endif()
284284
# Configuration checks.
285285
################################################################################
286286

287+
# Check for ARM CRC32 API.
288+
include(cmake/CheckArmCrc32.cmake)
289+
287290
# Check for missing fclose declaration.
288291
include(cmake/CheckFclose.cmake)
289292

@@ -293,35 +296,6 @@ include(cmake/CheckFnmatch.cmake)
293296
# Check strptime().
294297
include(cmake/CheckStrptime.cmake)
295298

296-
# Check for aarch64 CRC32 API.
297-
message(CHECK_START "Checking for aarch64 CRC32 API availability")
298-
cmake_push_check_state(RESET)
299-
set(CMAKE_REQUIRED_QUIET TRUE)
300-
check_source_compiles(C [[
301-
#include <arm_acle.h>
302-
#if defined(__GNUC__)
303-
# if !defined(__clang__)
304-
# pragma GCC push_options
305-
# pragma GCC target ("+nothing+crc")
306-
# elif defined(__APPLE__)
307-
# pragma clang attribute push(__attribute__((target("crc"))), apply_to=function)
308-
# else
309-
# pragma clang attribute push(__attribute__((target("+nothing+crc"))), apply_to=function)
310-
# endif
311-
#endif
312-
int main(void)
313-
{
314-
__crc32d(0, 0);
315-
return 0;
316-
}
317-
]] HAVE_AARCH64_CRC32)
318-
cmake_pop_check_state()
319-
if(HAVE_AARCH64_CRC32)
320-
message(CHECK_PASS "yes")
321-
else()
322-
message(CHECK_FAIL "no")
323-
endif()
324-
325299
# Check if there is a support means of creating a new process and defining which
326300
# handles it receives.
327301
message(CHECK_START "Checking if OS can spawn processes with inherited handles")
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#[=============================================================================[
2+
Check whether CRC32 API is supported on ARM architecture.
3+
4+
Result variables:
5+
6+
* HAVE_AARCH64_CRC32
7+
#]=============================================================================]
8+
9+
if(DEFINED PHP_EXT_STANDARD_HAS_ARM_CRC32)
10+
set(HAVE_AARCH64_CRC32 FALSE)
11+
12+
if(PHP_EXT_STANDARD_HAS_ARM_CRC32)
13+
set(HAVE_AARCH64_CRC32 TRUE)
14+
endif()
15+
16+
return()
17+
endif()
18+
19+
include(CheckSourceCompiles)
20+
include(CMakePushCheckState)
21+
22+
include_guard(GLOBAL)
23+
24+
function(_php_ext_standard_check_arm_crc32 result)
25+
message(CHECK_START "Checking for ARM CRC32 API availability")
26+
27+
set(${result} FALSE)
28+
29+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
30+
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64")
31+
set(${result} TRUE)
32+
endif()
33+
34+
set(
35+
PHP_EXT_STANDARD_HAS_ARM_CRC32
36+
${${result}}
37+
CACHE INTERNAL
38+
"Whether ARM has CRC32."
39+
)
40+
endif()
41+
42+
cmake_push_check_state(RESET)
43+
set(CMAKE_REQUIRED_QUIET TRUE)
44+
45+
check_source_compiles(C [[
46+
#include <arm_acle.h>
47+
#ifdef __GNUC__
48+
# ifndef __clang__
49+
# pragma GCC push_options
50+
# pragma GCC target ("+nothing+crc")
51+
# elif defined(__APPLE__)
52+
# pragma clang attribute push(__attribute__((target("crc"))), apply_to=function)
53+
# else
54+
# pragma clang attribute push(__attribute__((target("+nothing+crc"))), apply_to=function)
55+
# endif
56+
#endif
57+
int main(void)
58+
{
59+
__crc32d(0, 0);
60+
return 0;
61+
}
62+
]] PHP_EXT_STANDARD_HAS_ARM_CRC32)
63+
cmake_pop_check_state()
64+
65+
if(PHP_EXT_STANDARD_HAS_ARM_CRC32)
66+
message(CHECK_PASS "yes")
67+
set(${result} TRUE)
68+
else()
69+
message(CHECK_FAIL "no")
70+
endif()
71+
72+
return(PROPAGATE ${result})
73+
endfunction()
74+
75+
_php_ext_standard_check_arm_crc32(HAVE_AARCH64_CRC32)

0 commit comments

Comments
 (0)