srsRAN_4G icon indicating copy to clipboard operation
srsRAN_4G copied to clipboard

Compilation error on gcc - macro definition __OPTIMIZE__

Open kistlin opened this issue 9 months ago • 1 comments
trafficstars

When compiling with default flags, I get

/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/include/avx512bwintrin.h:202:17: error: #if with no expression
  202 | #if __OPTIMIZE__
      |                 ^

GCC manual Section 3.7.2 Common Predefined Macros

__OPTIMIZE__

__OPTIMIZE_SIZE__

__NO_INLINE__

These macros describe the compilation mode. __OPTIMIZE__ is defined in all optimizing compilations. __OPTIMIZE_SIZE__ is defined if the compiler is optimizing for size, not speed. __NO_INLINE__ is defined if no functions will be inlined into their callers (when not optimizing, or when inlining has been specifically disabled by -fno-inline).

These macros cause certain GNU header files to provide optimized definitions, using macros or inline functions, of system library functions. You should not use these macros in any way unless you make sure that programs will execute with the same effect whether or not they are defined. If they are defined, their value is 1.

(see https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues/20#note_244143.)

No matter if #define __OPTIMIZE__ should work as well, #define __OPTIMIZE__ 1 makes it work.

diff --git a/lib/include/srsran/phy/utils/simd.h b/lib/include/srsran/phy/utils/simd.h
index 80e450a0a..8b11db109 100644
--- a/lib/include/srsran/phy/utils/simd.h
+++ b/lib/include/srsran/phy/utils/simd.h
@@ -24,7 +24,7 @@
 
 #ifdef LV_HAVE_SSE /* AVX, AVX2, FMA, AVX512  are in this group */
 #ifndef __OPTIMIZE__
-#define __OPTIMIZE__
+#define __OPTIMIZE__ 1
 #endif
 #include <immintrin.h>
 #endif /* LV_HAVE_SSE */

kistlin avatar Feb 09 '25 04:02 kistlin

Note the define of OPTIMIZE was workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96174 which has been fixed since GCC 9.4.0 and 10.2.0 and 11+.

pinskia avatar Feb 10 '25 05:02 pinskia