diff --git a/libc/docs/dev/code_style.rst b/libc/docs/dev/code_style.rst --- a/libc/docs/dev/code_style.rst +++ b/libc/docs/dev/code_style.rst @@ -45,18 +45,23 @@ specific operations. e.g., ``LIBC_INLINE``, ``LIBC_NO_LOOP_UNROLL``, ``LIBC_LIKELY``, ``LIBC_INLINE_ASM``. -Inline functions defined in header files +Inline functions and variables defined in header files ======================================== -When defining functions inline in header files, we follow certain rules: +When defining functions and variables inline in header files, we follow certain +rules: #. The functions should not be given file-static linkage. There can be class static methods defined inline however. -#. Instead of using the ``inline`` keyword, they should be tagged with the - ``LIBC_INLINE`` macro defined in ``src/__support/common.h``. For example: +#. Instead of using the ``inline`` keyword, functions should be tagged with the + ``LIBC_INLINE`` macro and variables should be tagged with the + ``LIBC_INLINE_VAR`` macro defined in ``src/__support/macros/attributes.h``. + For example: .. code-block:: c++ + LIBC_INLINE_VAR constexpr bool foo = true; + LIBC_INLINE ReturnType function_defined_inline(ArgType arg) { ... } diff --git a/libc/src/__support/macros/attributes.h b/libc/src/__support/macros/attributes.h --- a/libc/src/__support/macros/attributes.h +++ b/libc/src/__support/macros/attributes.h @@ -20,6 +20,7 @@ #include "properties/architectures.h" #define LIBC_INLINE inline +#define LIBC_INLINE_VAR inline #define LIBC_INLINE_ASM __asm__ __volatile__ #define LIBC_UNUSED __attribute__((unused)) diff --git a/libc/src/string/memory_utils/op_x86.h b/libc/src/string/memory_utils/op_x86.h --- a/libc/src/string/memory_utils/op_x86.h +++ b/libc/src/string/memory_utils/op_x86.h @@ -40,13 +40,12 @@ namespace __llvm_libc::x86 { // A set of constants to check compile time features. -LIBC_INLINE static constexpr bool kSse2 = LLVM_LIBC_IS_DEFINED(__SSE2__); -LIBC_INLINE static constexpr bool kSse41 = LLVM_LIBC_IS_DEFINED(__SSE4_1__); -LIBC_INLINE static constexpr bool kAvx = LLVM_LIBC_IS_DEFINED(__AVX__); -LIBC_INLINE static constexpr bool kAvx2 = LLVM_LIBC_IS_DEFINED(__AVX2__); -LIBC_INLINE static constexpr bool kAvx512F = LLVM_LIBC_IS_DEFINED(__AVX512F__); -LIBC_INLINE static constexpr bool kAvx512BW = - LLVM_LIBC_IS_DEFINED(__AVX512BW__); +LIBC_INLINE_VAR constexpr bool kSse2 = LLVM_LIBC_IS_DEFINED(__SSE2__); +LIBC_INLINE_VAR constexpr bool kSse41 = LLVM_LIBC_IS_DEFINED(__SSE4_1__); +LIBC_INLINE_VAR constexpr bool kAvx = LLVM_LIBC_IS_DEFINED(__AVX__); +LIBC_INLINE_VAR constexpr bool kAvx2 = LLVM_LIBC_IS_DEFINED(__AVX2__); +LIBC_INLINE_VAR constexpr bool kAvx512F = LLVM_LIBC_IS_DEFINED(__AVX512F__); +LIBC_INLINE_VAR constexpr bool kAvx512BW = LLVM_LIBC_IS_DEFINED(__AVX512BW__); /////////////////////////////////////////////////////////////////////////////// // Memcpy repmovsb implementation