Repository: valkey-io/valkey
File: src/config.h (C/C++)

Code before:
#endif

/* Check for GCC version >= 4.9 */
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9))
#define HAS_BUILTIN_PREFETCH 1
/* Check for Clang version >= 3.6 */
#elif defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6))
#define HAS_BUILTIN_PREFETCH 1
#else
#define HAS_BUILTIN_PREFETCH 0
#endif

#if HAS_BUILTIN_PREFETCH
#define valkey_prefetch(addr) __builtin_prefetch(addr)
#else
#define valkey_prefetch(addr) ((void)(addr))
#endif

/* Check if we can compile SIMD code */
#if defined(__x86_64__) && ((defined(__GNUC__) && __GNUC__ >= 5) || (defined(__clang__) && __clang_major__ >= 4))
#if defined(__has_attribute) && __has_attribute(target)
#define HAVE_X86_SIMD 1
#endif
#endif

#if HAVE_X86_SIMD
#define ATTRIBUTE_TARGET_AVX2 __attribute__((target("avx2")))
#define ATTRIBUTE_TARGET_AVX512 __attribute__((target("avx512f,avx512bw,avx512vl")))
#else
#define ATTRIBUTE_TARGET_AVX2
#define ATTRIBUTE_TARGET_AVX512
#endif

#endif


Review comment (suggestion):
When I try to compile with `-Wundef` (e.g. `make WARNINGS=-Wundef`) on ARM, I get a warnings about undefined macros. `HAVE_X86_SIMD` here is one of the undefined ones.

```
config.h:286:6: warning: ‘__i386’ is not defined, evaluates to ‘0’ [-Wundef]
  286 | #if (__i386 || __amd64 || __powerpc__) && __GNUC__
      |      ^~~~~~
config.h:286:16: warning: ‘__amd64’ is not defined, evaluates to ‘0’ [-Wundef]
  286 | #if (__i386 || __amd64 || __powerpc__) && __GNUC__
      |                ^~~~~~~
config.h:286:27: warning: ‘__powerpc__’ is not defined, evaluates to ‘0’ [-Wundef]
  286 | #if (__i386 || __amd64 || __powerpc__) && __GNUC__
      |                           ^~~~~~~~~~~
config.h:386:5: warning: ‘HAVE_X86_SIMD’ is not defined, evaluates to ‘0’ [-Wundef]
  386 | #if HAVE_X86_SIMD
      |     ^~~~~~~~~~~~~
```

If you want to change `#if defined` to just `#if`, the macros should always be defined, so add an `#else` clause and define it to 0 here. Ideally, we should fix the other three warnings too so we can enable `-Wundef` by default.

Code after:
#endif

/* Check for GCC version >= 4.9 */
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9))
#define HAS_BUILTIN_PREFETCH 1
/* Check for Clang version >= 3.6 */
#elif defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6))
#define HAS_BUILTIN_PREFETCH 1
#else
#define HAS_BUILTIN_PREFETCH 0
#endif

#if HAS_BUILTIN_PREFETCH
#define valkey_prefetch(addr) __builtin_prefetch(addr)
#else
#define valkey_prefetch(addr) ((void)(addr))
#endif

/* Check if we can compile SIMD code */
#if defined(__x86_64__) && ((defined(__GNUC__) && __GNUC__ >= 5) || (defined(__clang__) && __clang_major__ >= 4)) && defined(__has_attribute) && __has_attribute(target)
#define HAVE_X86_SIMD 1
#else
#define HAVE_X86_SIMD 0
#endif

#if HAVE_X86_SIMD
#define ATTRIBUTE_TARGET_AVX2 __attribute__((target("avx2")))
#define ATTRIBUTE_TARGET_AVX512 __attribute__((target("avx512f,avx512bw,avx512vl")))
#else
#define ATTRIBUTE_TARGET_AVX2
#define ATTRIBUTE_TARGET_AVX512
#endif

#endif