Skip to content

Commit b54a067

Browse files
Merge #1304: build: Rename arm to arm32 and check if it's really supported
c6bb29b build: Rename `64bit` to `x86_64` (Hennadii Stepanov) 0324645 autotools: Add `SECP_ARM32_ASM_CHECK` macro (Hennadii Stepanov) ed4ba23 cmake: Add `check_arm32_assembly` function (Hennadii Stepanov) e5cf4bf build: Rename `arm` to `arm32` (Hennadii Stepanov) Pull request description: Closes #1034. Solves one item in #1235. ACKs for top commit: real-or-random: ACK c6bb29b tested on x86_64 but not on ARM Tree-SHA512: c3615a18cfa30bb2cc53be18c09ccab08fc800b84444d8c6b333347b4db039a3981da61e7da5086dd9f4472838d7c031d554be9ddc7c435ba906852bba593982
2 parents 3353d3c + c6bb29b commit b54a067

8 files changed

+72
-28
lines changed

.cirrus.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ task:
176176
CTIMETESTS: no
177177
matrix:
178178
- env: {}
179-
- env: {EXPERIMENTAL: yes, ASM: arm}
179+
- env: {EXPERIMENTAL: yes, ASM: arm32}
180180
<< : *MERGE_BASE
181181
test_script:
182182
- ./ci/cirrus.sh

CMakeLists.txt

+15-9
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,22 @@ if(SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY)
102102
endif()
103103
mark_as_advanced(FORCE SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY)
104104

105-
set(SECP256K1_ASM "AUTO" CACHE STRING "Assembly optimizations to use: \"AUTO\", \"OFF\", \"x86_64\" or \"arm\" (experimental). [default=AUTO]")
106-
set_property(CACHE SECP256K1_ASM PROPERTY STRINGS "AUTO" "OFF" "x86_64" "arm")
105+
set(SECP256K1_ASM "AUTO" CACHE STRING "Assembly optimizations to use: \"AUTO\", \"OFF\", \"x86_64\" or \"arm32\" (experimental). [default=AUTO]")
106+
set_property(CACHE SECP256K1_ASM PROPERTY STRINGS "AUTO" "OFF" "x86_64" "arm32")
107107
check_string_option_value(SECP256K1_ASM)
108-
if(SECP256K1_ASM STREQUAL "arm")
108+
if(SECP256K1_ASM STREQUAL "arm32")
109109
enable_language(ASM)
110-
add_compile_definitions(USE_EXTERNAL_ASM=1)
110+
include(CheckArm32Assembly)
111+
check_arm32_assembly()
112+
if(HAVE_ARM32_ASM)
113+
add_compile_definitions(USE_EXTERNAL_ASM=1)
114+
else()
115+
message(FATAL_ERROR "ARM32 assembly optimization requested but not available.")
116+
endif()
111117
elseif(SECP256K1_ASM)
112-
include(Check64bitAssembly)
113-
check_64bit_assembly()
114-
if(HAS_64BIT_ASM)
118+
include(CheckX86_64Assembly)
119+
check_x86_64_assembly()
120+
if(HAVE_X86_64_ASM)
115121
set(SECP256K1_ASM "x86_64")
116122
add_compile_definitions(USE_ASM_X86_64=1)
117123
elseif(SECP256K1_ASM STREQUAL "AUTO")
@@ -123,8 +129,8 @@ endif()
123129

124130
option(SECP256K1_EXPERIMENTAL "Allow experimental configuration options." OFF)
125131
if(NOT SECP256K1_EXPERIMENTAL)
126-
if(SECP256K1_ASM STREQUAL "arm")
127-
message(FATAL_ERROR "ARM assembly optimization is experimental. Use -DSECP256K1_EXPERIMENTAL=ON to allow.")
132+
if(SECP256K1_ASM STREQUAL "arm32")
133+
message(FATAL_ERROR "ARM32 assembly optimization is experimental. Use -DSECP256K1_EXPERIMENTAL=ON to allow.")
128134
endif()
129135
endif()
130136

build-aux/m4/bitcoin_secp.m4

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
dnl escape "$0x" below using the m4 quadrigaph @S|@, and escape it again with a \ for the shell.
2-
AC_DEFUN([SECP_64BIT_ASM_CHECK],[
2+
AC_DEFUN([SECP_X86_64_ASM_CHECK],[
33
AC_MSG_CHECKING(for x86_64 assembly availability)
44
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
55
#include <stdint.h>]],[[
66
uint64_t a = 11, tmp;
77
__asm__ __volatile__("movq \@S|@0x100000000,%1; mulq %%rsi" : "+a"(a) : "S"(tmp) : "cc", "%rdx");
8-
]])],[has_64bit_asm=yes],[has_64bit_asm=no])
9-
AC_MSG_RESULT([$has_64bit_asm])
8+
]])], [has_x86_64_asm=yes], [has_x86_64_asm=no])
9+
AC_MSG_RESULT([$has_x86_64_asm])
10+
])
11+
12+
AC_DEFUN([SECP_ARM32_ASM_CHECK], [
13+
AC_MSG_CHECKING(for ARM32 assembly availability)
14+
SECP_ARM32_ASM_CHECK_CFLAGS_saved_CFLAGS="$CFLAGS"
15+
CFLAGS="-x assembler"
16+
AC_LINK_IFELSE([AC_LANG_SOURCE([[
17+
.syntax unified
18+
.eabi_attribute 24, 1
19+
.eabi_attribute 25, 1
20+
.text
21+
.global main
22+
main:
23+
ldr r0, =0x002A
24+
mov r7, #1
25+
swi 0
26+
]])], [has_arm32_asm=yes], [has_arm32_asm=no])
27+
AC_MSG_RESULT([$has_arm32_asm])
28+
CFLAGS="$SECP_ARM32_ASM_CHECK_CFLAGS_saved_CFLAGS"
1029
])
1130

1231
AC_DEFUN([SECP_VALGRIND_CHECK],[

cmake/CheckArm32Assembly.cmake

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function(check_arm32_assembly)
2+
try_compile(HAVE_ARM32_ASM
3+
${CMAKE_BINARY_DIR}/check_arm32_assembly
4+
SOURCES ${CMAKE_SOURCE_DIR}/cmake/source_arm32.s
5+
)
6+
endfunction()
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include(CheckCSourceCompiles)
22

3-
function(check_64bit_assembly)
3+
function(check_x86_64_assembly)
44
check_c_source_compiles("
55
#include <stdint.h>
66
@@ -9,6 +9,6 @@ function(check_64bit_assembly)
99
uint64_t a = 11, tmp;
1010
__asm__ __volatile__(\"movq $0x100000000,%1; mulq %%rsi\" : \"+a\"(a) : \"S\"(tmp) : \"cc\", \"%rdx\");
1111
}
12-
" HAS_64BIT_ASM)
13-
set(HAS_64BIT_ASM ${HAS_64BIT_ASM} PARENT_SCOPE)
12+
" HAVE_X86_64_ASM)
13+
set(HAVE_X86_64_ASM ${HAVE_X86_64_ASM} PARENT_SCOPE)
1414
endfunction()

cmake/source_arm32.s

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.syntax unified
2+
.eabi_attribute 24, 1
3+
.eabi_attribute 25, 1
4+
.text
5+
.global main
6+
main:
7+
ldr r0, =0x002A
8+
mov r7, #1
9+
swi 0

configure.ac

+15-11
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ AC_ARG_ENABLE(external_default_callbacks,
197197
# * and auto (the default).
198198
AC_ARG_WITH([test-override-wide-multiply], [] ,[set_widemul=$withval], [set_widemul=auto])
199199

200-
AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|arm|no|auto],
201-
[assembly optimizations to use (experimental: arm) [default=auto]])],[req_asm=$withval], [req_asm=auto])
200+
AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|arm32|no|auto],
201+
[assembly optimizations to use (experimental: arm32) [default=auto]])],[req_asm=$withval], [req_asm=auto])
202202

203203
AC_ARG_WITH([ecmult-window], [AS_HELP_STRING([--with-ecmult-window=SIZE|auto],
204204
[window size for ecmult precomputation for verification, specified as integer in range [2..24].]
@@ -263,8 +263,8 @@ else
263263
fi
264264

265265
if test x"$req_asm" = x"auto"; then
266-
SECP_64BIT_ASM_CHECK
267-
if test x"$has_64bit_asm" = x"yes"; then
266+
SECP_X86_64_ASM_CHECK
267+
if test x"$has_x86_64_asm" = x"yes"; then
268268
set_asm=x86_64
269269
fi
270270
if test x"$set_asm" = x; then
@@ -274,12 +274,16 @@ else
274274
set_asm=$req_asm
275275
case $set_asm in
276276
x86_64)
277-
SECP_64BIT_ASM_CHECK
278-
if test x"$has_64bit_asm" != x"yes"; then
277+
SECP_X86_64_ASM_CHECK
278+
if test x"$has_x86_64_asm" != x"yes"; then
279279
AC_MSG_ERROR([x86_64 assembly optimization requested but not available])
280280
fi
281281
;;
282-
arm)
282+
arm32)
283+
SECP_ARM32_ASM_CHECK
284+
if test x"$has_arm32_asm" != x"yes"; then
285+
AC_MSG_ERROR([ARM32 assembly optimization requested but not available])
286+
fi
283287
;;
284288
no)
285289
;;
@@ -296,7 +300,7 @@ case $set_asm in
296300
x86_64)
297301
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_ASM_X86_64=1"
298302
;;
299-
arm)
303+
arm32)
300304
enable_external_asm=yes
301305
;;
302306
no)
@@ -413,8 +417,8 @@ if test x"$enable_experimental" = x"yes"; then
413417
AC_MSG_NOTICE([Experimental features do not have stable APIs or properties, and may not be safe for production use.])
414418
AC_MSG_NOTICE([******])
415419
else
416-
if test x"$set_asm" = x"arm"; then
417-
AC_MSG_ERROR([ARM assembly optimization is experimental. Use --enable-experimental to allow.])
420+
if test x"$set_asm" = x"arm32"; then
421+
AC_MSG_ERROR([ARM32 assembly optimization is experimental. Use --enable-experimental to allow.])
418422
fi
419423
fi
420424

@@ -436,7 +440,7 @@ AM_CONDITIONAL([ENABLE_MODULE_RECOVERY], [test x"$enable_module_recovery" = x"ye
436440
AM_CONDITIONAL([ENABLE_MODULE_EXTRAKEYS], [test x"$enable_module_extrakeys" = x"yes"])
437441
AM_CONDITIONAL([ENABLE_MODULE_SCHNORRSIG], [test x"$enable_module_schnorrsig" = x"yes"])
438442
AM_CONDITIONAL([USE_EXTERNAL_ASM], [test x"$enable_external_asm" = x"yes"])
439-
AM_CONDITIONAL([USE_ASM_ARM], [test x"$set_asm" = x"arm"])
443+
AM_CONDITIONAL([USE_ASM_ARM], [test x"$set_asm" = x"arm32"])
440444
AM_CONDITIONAL([BUILD_WINDOWS], [test "$build_windows" = "yes"])
441445
AC_SUBST(LIB_VERSION_CURRENT, _LIB_VERSION_CURRENT)
442446
AC_SUBST(LIB_VERSION_REVISION, _LIB_VERSION_REVISION)

src/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ add_library(secp256k1_precomputed OBJECT EXCLUDE_FROM_ALL
1111
add_library(secp256k1 secp256k1.c $<TARGET_OBJECTS:secp256k1_precomputed>)
1212

1313
add_library(secp256k1_asm INTERFACE)
14-
if(SECP256K1_ASM STREQUAL "arm")
14+
if(SECP256K1_ASM STREQUAL "arm32")
1515
add_library(secp256k1_asm_arm OBJECT EXCLUDE_FROM_ALL)
1616
target_sources(secp256k1_asm_arm PUBLIC
1717
asm/field_10x26_arm.s

0 commit comments

Comments
 (0)