From d267ed57314a8bfa7efaf46e444c593f9d45bbc6 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 17 Jan 2025 12:35:12 -0500 Subject: build: Feature-detect #pragma nounroll support --- build/has/pragma-nounroll.c | 10 ++++++++++ build/header.mk | 1 + src/bfs.h | 4 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 build/has/pragma-nounroll.c diff --git a/build/has/pragma-nounroll.c b/build/has/pragma-nounroll.c new file mode 100644 index 0000000..2bdae14 --- /dev/null +++ b/build/has/pragma-nounroll.c @@ -0,0 +1,10 @@ +// Copyright © Tavian Barnes +// SPDX-License-Identifier: 0BSD + +/// -Werror + +int main(void) { +#pragma nounroll + for (int i = 0; i < 100; ++i); + return 0; +} diff --git a/build/header.mk b/build/header.mk index 919a2a2..6a63221 100644 --- a/build/header.mk +++ b/build/header.mk @@ -36,6 +36,7 @@ HEADERS := \ gen/has/getprogname.h \ gen/has/io-uring-max-workers.h \ gen/has/pipe2.h \ + gen/has/pragma-nounroll.h \ gen/has/posix-getdents.h \ gen/has/posix-spawn-addfchdir-np.h \ gen/has/posix-spawn-addfchdir.h \ diff --git a/src/bfs.h b/src/bfs.h index 6c930ad..32dbbae 100644 --- a/src/bfs.h +++ b/src/bfs.h @@ -221,9 +221,9 @@ extern const char bfs_ldlibs[]; /** * Optimization hint to not unroll a loop. */ -#if __clang__ +#if BFS_HAS_PRAGMA_NOUNROLL # define _nounroll _Pragma("nounroll") -#elif __GNUC__ +#elif __GNUC__ && !__clang__ # define _nounroll _Pragma("GCC unroll 0") #else # define _nounroll -- cgit v1.2.3