From 2a1f24b817829f4e0a9fd9d1256fc9b72af9e328 Mon Sep 17 00:00:00 2001 From: ouyangxiangzhen Date: Sun, 4 Jan 2026 14:13:05 +0800 Subject: [PATCH] compiler: Add PRAGMA and unroll_loop. This commit added PRAGMA and unroll_loop to support compiler loop-unrolling. Signed-off-by: ouyangxiangzhen --- include/nuttx/compiler.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h index 1dd51c86b8b..65cbce4e8d0 100644 --- a/include/nuttx/compiler.h +++ b/include/nuttx/compiler.h @@ -175,6 +175,14 @@ # define offsetof(a, b) __builtin_offsetof(a, b) # define return_address(x) __builtin_return_address(x) +# define PRAGMA(x) _Pragma(#x) + +# if defined(__clang__) +# define unroll_loop(n) PRAGMA(clang loop unroll_count(n)) +# else +# define unroll_loop(n) PRAGMA(GCC unroll n) +# endif + /* Attributes * * GCC supports weak symbols which can be used to reduce code size because @@ -814,6 +822,9 @@ # define offsetof(a, b) ((size_t)(&(((a *)(0))->b))) # define return_address(x) 0 +# define PRAGMA(x) +# define unroll_loop(n) + # define no_builtin(n) /* Warning about usage of deprecated features. */ @@ -979,6 +990,9 @@ # define offsetof(a, b) ((size_t)(&(((a *)(0))->b))) # define return_address(x) 0 +# define PRAGMA(x) +# define unroll_loop(n) + # define no_builtin(n) /* Warning about usage of deprecated features. */ @@ -1073,6 +1087,9 @@ # define offsetof(a, b) ((size_t)(&(((a *)(0))->b))) # define return_address(x) 0 +# define PRAGMA(x) +# define unroll_loop(n) + # define no_builtin(n) /* Warning about usage of deprecated features. */ @@ -1175,6 +1192,9 @@ # define offsetof(a, b) ((size_t)(&(((a *)(0))->b))) # define return_address(x) 0 +# define PRAGMA(x) +# define unroll_loop(n) + # define no_builtin(n) /* Warning about usage of deprecated features. */ @@ -1276,6 +1296,9 @@ # define offsetof(a, b) ((size_t)(&(((a *)(0))->b))) # define return_address(x) 0 +# define PRAGMA(x) +# define unroll_loop(n) + # define no_builtin(n) /* Warning about usage of deprecated features. */ @@ -1368,6 +1391,9 @@ # define offsetof(a, b) ((size_t)(&(((a *)(0))->b))) # define return_address(x) 0 +# define PRAGMA(x) +# define unroll_loop(n) + # define no_builtin(n) /* Warning about usage of deprecated features. */