Skip to content

Commit fcfb7ff

Browse files
authored
Merge pull request #2725 from martin-frbg/ccheck_c11
Have c_check probe availability of C11 atomics support and stdatomic.h
2 parents 72ec628 + bbe119e commit fcfb7ff

File tree

10 files changed

+37
-10
lines changed

10 files changed

+37
-10
lines changed

c_check

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,28 @@ if (($architecture eq "x86") || ($architecture eq "x86_64")) {
249249
}
250250
}
251251

252+
$c11_atomics = 0;
253+
if ($data =~ /HAVE_C11/) {
254+
eval "use File::Temp qw(tempfile)";
255+
if ($@){
256+
warn "could not load PERL module File::Temp, so could not check compiler compatibility with C11";
257+
$c11_atomics = 0;
258+
} else {
259+
($fh,$tmpf) = tempfile( SUFFIX => '.c' , UNLINK => 1 );
260+
print $tmpf "#include <stdatomic.h>\nint main(void){}\n";
261+
$args = " -c -o $tmpf.o $tmpf";
262+
my @cmd = ("$compiler_name $flags $args >/dev/null 2>/dev/null");
263+
system(@cmd) == 0;
264+
if ($? != 0) {
265+
$c11_atomics = 0;
266+
} else {
267+
$c11_atomics = 1;
268+
}
269+
unlink("$tmpf.o");
270+
}
271+
}
272+
273+
252274
$data = `$compiler_name $flags -S ctest1.c && grep globl ctest1.s | head -n 1 && rm -f ctest1.s`;
253275

254276
$data =~ /globl\s([_\.]*)(.*)/;
@@ -352,6 +374,8 @@ print CONFFILE "#define __32BIT__\t1\n" if $binformat eq bin32;
352374
print CONFFILE "#define __64BIT__\t1\n" if $binformat eq bin64;
353375
print CONFFILE "#define FUNDERSCORE\t$need_fu\n" if $need_fu ne "";
354376
print CONFFILE "#define HAVE_MSA\t1\n" if $have_msa eq 1;
377+
print CONFFILE "#define HAVE_C11\t1\n" if $c11_atomics eq 1;
378+
355379

356380
if ($os eq "LINUX") {
357381

common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ __declspec(dllimport) int __cdecl omp_in_parallel(void);
681681
__declspec(dllimport) int __cdecl omp_get_num_procs(void);
682682
#endif
683683

684-
#if (__STDC_VERSION__ >= 201112L)
684+
#ifdef HAVE_C11
685685
#if defined(C_GCC) && ( __GNUC__ < 7)
686686
// workaround for GCC bug 65467
687687
#ifndef _Atomic

ctest.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,6 @@ ARCH_ARM
153153
ARCH_ARM64
154154
#endif
155155

156+
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
157+
HAVE_C11
158+
#endif

driver/level3/level3_gemm3m_thread.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
#endif
9292

9393
typedef struct {
94-
#if __STDC_VERSION__ >= 201112L
94+
#ifdef HAVE_C11
9595
_Atomic
9696
#else
9797
volatile

driver/level3/level3_syrk_threaded.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
#endif
6868

6969
typedef struct {
70-
#if __STDC_VERSION__ >= 201112L
70+
#ifdef HAVE_C11
7171
_Atomic
7272
#else
7373
volatile

driver/others/blas_server.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ typedef struct {
141141

142142
} thread_status_t;
143143

144-
#if (__STDC_VERSION__ >= 201112L)
144+
#ifdef HAVE_C11
145145
#define atomic_load_queue(p) __atomic_load_n(p, __ATOMIC_RELAXED)
146146
#define atomic_store_queue(p, v) __atomic_store_n(p, v, __ATOMIC_RELAXED)
147147
#else

driver/others/blas_server_omp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
int blas_server_avail = 0;
5656

5757
static void * blas_thread_buffer[MAX_PARALLEL_NUMBER][MAX_CPU_NUMBER];
58-
#if __STDC_VERSION__ >= 201112L
58+
#ifdef HAVE_C11
5959
static atomic_bool blas_buffer_inuse[MAX_PARALLEL_NUMBER];
6060
#else
6161
static _Bool blas_buffer_inuse[MAX_PARALLEL_NUMBER];
@@ -320,7 +320,7 @@ int exec_blas(BLASLONG num, blas_queue_t *queue){
320320

321321
while(true) {
322322
for(i=0; i < MAX_PARALLEL_NUMBER; i++) {
323-
#if __STDC_VERSION__ >= 201112L
323+
#ifdef HAVE_C11
324324
_Bool inuse = false;
325325
if(atomic_compare_exchange_weak(&blas_buffer_inuse[i], &inuse, true)) {
326326
#else
@@ -345,7 +345,7 @@ int exec_blas(BLASLONG num, blas_queue_t *queue){
345345
exec_threads(&queue[i], buf_index);
346346
}
347347

348-
#if __STDC_VERSION__ >= 201112L
348+
#ifdef HAVE_C11
349349
atomic_store(&blas_buffer_inuse[buf_index], false);
350350
#else
351351
blas_buffer_inuse[buf_index] = false;

driver/others/memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ static BLASULONG base_address = 0UL;
10951095
static BLASULONG base_address = BASE_ADDRESS;
10961096
#endif
10971097

1098-
#if __STDC_VERSION__ >= 201112L
1098+
#ifdef HAVE_C11
10991099
static _Atomic int memory_initialized = 0;
11001100
#else
11011101
static volatile int memory_initialized = 0;

lapack/getrf/getrf_parallel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ double sqrt(double);
6868
#define GETRF_FACTOR 1.00
6969

7070

71-
#if (__STDC_VERSION__ >= 201112L)
71+
#ifdef HAVE_C11
7272
#define atomic_load_long(p) __atomic_load_n(p, __ATOMIC_RELAXED)
7373
#define atomic_store_long(p, v) __atomic_store_n(p, v, __ATOMIC_RELAXED)
7474
#else

lapack/getrf/potrf_parallel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static FLOAT dm1 = -1.;
101101
#endif
102102

103103
typedef struct {
104-
#if __STDC_VERSION__ >= 201112L
104+
#ifdef HAVE_C11
105105
_Atomic
106106
#else
107107
volatile

0 commit comments

Comments
 (0)