@@ -131,6 +131,9 @@ dnl Check with:
131
131
dnl 1. No compiler/linker flags.
132
132
dnl 2. CFLAGS += -mcx16
133
133
dnl 3. LIBS += -latomic
134
+ dnl 4. Finally, if it links ok with any of #1, #2, or #3, actually try
135
+ dnl to run the test code (if we're not cross-compiling) and verify
136
+ dnl that it actually gives us the correct result.
134
137
dnl
135
138
dnl Note that we unfortunately can't use AC SEARCH_LIBS because its
136
139
dnl check incorrectly fails (because these functions are special compiler
@@ -150,7 +153,10 @@ dnl $3: action if any of 1, 2, or 3 succeeds
150
153
dnl #4: action if all of 1, 2, and 3 fail
151
154
dnl
152
155
AC_DEFUN ( [ OPAL_ASM_CHECK_ATOMIC_FUNC] ,[
153
- OPAL_VAR_SCOPE_PUSH([ opal_asm_check_func_happy opal_asm_check_func_FLAGS_save] )
156
+ OPAL_VAR_SCOPE_PUSH([ opal_asm_check_func_happy opal_asm_check_func_CFLAGS_save opal_asm_check_func_LIBS_save] )
157
+
158
+ opal_asm_check_func_CFLAGS_save=$CFLAGS
159
+ opal_asm_check_func_LIBS_save=$LIBS
154
160
155
161
dnl Check with no compiler/linker flags
156
162
AC_MSG_CHECKING ( [ for $1 ] )
@@ -163,29 +169,45 @@ AC_DEFUN([OPAL_ASM_CHECK_ATOMIC_FUNC],[
163
169
dnl If that didn't work, try again with CFLAGS+=mcx16
164
170
AS_IF ( [ test $opal_asm_check_func_happy -eq 0] ,
165
171
[ AC_MSG_CHECKING ( [ for $1 with -mcx16] )
166
- opal_asm_check_func_FLAGS_save=$CFLAGS
167
172
CFLAGS="$CFLAGS -mcx16"
168
173
AC_LINK_IFELSE ( [ $2 ] ,
169
174
[ opal_asm_check_func_happy=1
170
175
AC_MSG_RESULT ( [ yes] ) ] ,
171
176
[ opal_asm_check_func_happy=0
172
- CFLAGS=$opal_asm_check_func_FLAGS_save
177
+ CFLAGS=$opal_asm_check_func_CFLAGS_save
173
178
AC_MSG_RESULT ( [ no] ) ] )
174
179
] )
175
180
176
181
dnl If that didn't work, try again with LIBS+=-latomic
177
182
AS_IF ( [ test $opal_asm_check_func_happy -eq 0] ,
178
183
[ AC_MSG_CHECKING ( [ for $1 with -latomic] )
179
- opal_asm_check_func_FLAGS_save=$LIBS
180
184
LIBS="$LIBS -latomic"
181
185
AC_LINK_IFELSE ( [ $2 ] ,
182
186
[ opal_asm_check_func_happy=1
183
187
AC_MSG_RESULT ( [ yes] ) ] ,
184
188
[ opal_asm_check_func_happy=0
185
- LIBS=$opal_asm_check_func_FLAGS_save
189
+ LIBS=$opal_asm_check_func_LIBS_save
186
190
AC_MSG_RESULT ( [ no] ) ] )
187
191
] )
188
192
193
+ dnl If we have it, try it and make sure it gives a correct result.
194
+ dnl As of Aug 2018, we know that it links but does *not* work on clang
195
+ dnl 6 on ARM64.
196
+ AS_IF ( [ test $opal_asm_check_func_happy -eq 1] ,
197
+ [ AC_MSG_CHECKING ( [ if $1 gives correct results] )
198
+ AC_RUN_IFELSE ( [ $2 ] ,
199
+ [ AC_MSG_RESULT ( [ yes] ) ] ,
200
+ [ opal_asm_check_func_happy=0
201
+ AC_MSG_RESULT ( [ no] ) ] ,
202
+ [ AC_MSG_RESULT ( [ cannot test -- assume yes (cross compiling)] ) ] )
203
+ ] )
204
+
205
+ dnl If we were unsuccessful, restore CFLAGS/LIBS
206
+ AS_IF ( [ test $opal_asm_check_func_happy -eq 0] ,
207
+ [ CFLAGS=$opal_asm_check_func_CFLAGS_save
208
+ LIBS=$opal_asm_check_func_LIBS_save] )
209
+
210
+ dnl Run the user actions
189
211
AS_IF ( [ test $opal_asm_check_func_happy -eq 1] , [ $3 ] , [ $4 ] )
190
212
191
213
OPAL_VAR_SCOPE_POP
@@ -204,17 +226,6 @@ AC_DEFUN([OPAL_CHECK_SYNC_BUILTIN_CSWAP_INT128], [
204
226
[ sync_bool_compare_and_swap_128_result=1] ,
205
227
[ sync_bool_compare_and_swap_128_result=0] )
206
228
207
- # If we have it, try it, and make sure it works. As of Aug 2018, we
208
- # know that it links but does *not* work on clang 6 on ARM64.
209
- AS_IF ( [ test $sync_bool_compare_and_swap_128_result -eq 1] ,
210
- [ AC_MSG_CHECKING ( [ if __sync_bool_compare_and_swap works] )
211
- AC_RUN_IFELSE ( [ AC_LANG_SOURCE ( OPAL_SYNC_BOOL_COMPARE_AND_SWAP_TEST_SOURCE ) ] ,
212
- [ AC_MSG_RESULT ( [ yes] ) ] ,
213
- [ sync_bool_compare_and_swap_128_result=0
214
- AC_MSG_RESULT ( [ no] ) ] ,
215
- [ AC_MSG_RESULT ( [ cannot test -- assume yes (cross compiling)] ) ] )
216
- ] )
217
-
218
229
AC_DEFINE_UNQUOTED ( [ OPAL_HAVE_SYNC_BUILTIN_CSWAP_INT128] ,
219
230
[ $sync_bool_compare_and_swap_128_result] ,
220
231
[ Whether the __sync builtin atomic compare and swap supports 128-bit values] )
@@ -267,17 +278,6 @@ AC_DEFUN([OPAL_CHECK_GCC_BUILTIN_CSWAP_INT128], [
267
278
[ atomic_compare_exchange_n_128_result=1] ,
268
279
[ atomic_compare_exchange_n_128_result=0] )
269
280
270
- # If we have it, try it, and make sure it works. As of Aug 2018, we
271
- # know that it does *not* work on clang 6 on ARM64.
272
- AS_IF ( [ test $atomic_compare_exchange_n_128_result -eq 1] ,
273
- [ AC_MSG_CHECKING ( [ if __atomic_compare_exchange_n works] )
274
- AC_RUN_IFELSE ( [ AC_LANG_SOURCE ( OPAL_ATOMIC_COMPARE_EXCHANGE_N_TEST_SOURCE ) ] ,
275
- [ AC_MSG_RESULT ( [ yes] ) ] ,
276
- [ atomic_compare_exchange_n_128_result=0
277
- AC_MSG_RESULT ( [ no] ) ] ,
278
- [ AC_MSG_RESULT ( [ cannot test -- assume yes (cross compiling)] ) ] )
279
- ] )
280
-
281
281
# If we have it and it works, check to make sure it is always lock
282
282
# free.
283
283
AS_IF ( [ test $atomic_compare_exchange_n_128_result -eq 1] ,
0 commit comments