[libc-commits] [libc] 494734b - [libc][NFC] Another round of replacement of "inline" with "LIBC_INLINE".

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Tue Jan 24 23:13:32 PST 2023


Author: Siva Chandra Reddy
Date: 2023-01-25T07:13:24Z
New Revision: 494734b06d62b54fdcbd982f96274dede572ba07

URL: https://github.com/llvm/llvm-project/commit/494734b06d62b54fdcbd982f96274dede572ba07
DIFF: https://github.com/llvm/llvm-project/commit/494734b06d62b54fdcbd982f96274dede572ba07.diff

LOG: [libc][NFC] Another round of replacement of "inline" with "LIBC_INLINE".

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D142509

Added: 
    

Modified: 
    libc/src/__support/CMakeLists.txt
    libc/src/__support/FPUtil/CMakeLists.txt
    libc/src/__support/FPUtil/aarch64/sqrt.h
    libc/src/__support/FPUtil/generic/CMakeLists.txt
    libc/src/__support/FPUtil/generic/FMA.h
    libc/src/__support/FPUtil/generic/sqrt.h
    libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h
    libc/src/__support/FPUtil/multiply_add.h
    libc/src/__support/FPUtil/x86_64/PolyEval.h
    libc/src/__support/FPUtil/x86_64/sqrt.h
    libc/src/__support/OSUtil/linux/syscall.h
    libc/src/__support/arg_list.h
    libc/src/__support/char_vector.h
    libc/src/__support/float_to_string.h
    libc/src/__support/integer_to_string.h
    libc/src/__support/integer_utils.h
    libc/src/__support/str_to_float.h
    libc/src/stdio/printf_core/CMakeLists.txt
    libc/src/stdio/printf_core/char_converter.h
    libc/src/stdio/printf_core/converter_utils.h
    libc/src/stdio/printf_core/parser.h
    libc/src/stdio/printf_core/string_converter.h
    libc/src/stdio/scanf_core/parser.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt
index 2526d0cd56dba..85139f123ac2d 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -88,6 +88,7 @@ add_header_library(
     libc.src.__support.CPP.span
     libc.src.__support.CPP.string_view
     libc.src.__support.CPP.type_traits
+    libc.src.__support.common
 )
 
 
@@ -139,6 +140,8 @@ add_header_library(
   arg_list
   HDRS
     arg_list.h
+  DEPENDS
+    libc.src.__support.common
 )
 
 add_header_library(
@@ -153,6 +156,8 @@ add_header_library(
   char_vector
   HDRS
     char_vector.h
+  DEPENDS
+    libc.src.__support.common
 )
 
 add_header_library(
@@ -172,6 +177,7 @@ add_header_library(
     .builtin_wrappers
     .number_pair
     libc.src.__support.CPP.type_traits
+    libc.src.__support.common
 )
 
 add_header_library(

diff  --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt
index 09d90f89ce1d1..401dcaa3c389e 100644
--- a/libc/src/__support/FPUtil/CMakeLists.txt
+++ b/libc/src/__support/FPUtil/CMakeLists.txt
@@ -164,6 +164,7 @@ add_header_library(
     multiply_add.h
   DEPENDS
     .fma
+    libc.src.__support.common
 )
 
 add_header_library(

diff  --git a/libc/src/__support/FPUtil/aarch64/sqrt.h b/libc/src/__support/FPUtil/aarch64/sqrt.h
index 479ebf76b6786..2a8912e65a8af 100644
--- a/libc/src/__support/FPUtil/aarch64/sqrt.h
+++ b/libc/src/__support/FPUtil/aarch64/sqrt.h
@@ -10,6 +10,7 @@
 #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_AARCH64_SQRT_H
 
 #include "src/__support/architectures.h"
+#include "src/__support/common.h"
 
 #if !defined(LLVM_LIBC_ARCH_AARCH64)
 #error "Invalid include"
@@ -20,13 +21,13 @@
 namespace __llvm_libc {
 namespace fputil {
 
-template <> inline float sqrt<float>(float x) {
+template <> LIBC_INLINE float sqrt<float>(float x) {
   float y;
   __asm__ __volatile__("fsqrt %s0, %s1\n\t" : "=w"(y) : "w"(x));
   return y;
 }
 
-template <> inline double sqrt<double>(double x) {
+template <> LIBC_INLINE double sqrt<double>(double x) {
   double y;
   __asm__ __volatile__("fsqrt %d0, %d1\n\t" : "=w"(y) : "w"(x));
   return y;

diff  --git a/libc/src/__support/FPUtil/generic/CMakeLists.txt b/libc/src/__support/FPUtil/generic/CMakeLists.txt
index b449b0e6b982a..ff0a13501b6fb 100644
--- a/libc/src/__support/FPUtil/generic/CMakeLists.txt
+++ b/libc/src/__support/FPUtil/generic/CMakeLists.txt
@@ -10,6 +10,7 @@ add_header_library(
     libc.src.__support.FPUtil.fp_bits
     libc.src.__support.FPUtil.platform_defs
     libc.src.__support.builtin_wrappers
+    libc.src.__support.common
     libc.src.__support.uint128
     libc.include.fenv
 )

diff  --git a/libc/src/__support/FPUtil/generic/FMA.h b/libc/src/__support/FPUtil/generic/FMA.h
index 69868d4e5ba23..f82ff017bd4f9 100644
--- a/libc/src/__support/FPUtil/generic/FMA.h
+++ b/libc/src/__support/FPUtil/generic/FMA.h
@@ -26,7 +26,7 @@ template <typename T> LIBC_INLINE T fma(T x, T y, T z);
 // TODO(lntue): Implement fmaf that is correctly rounded to all rounding modes.
 // The implementation below only is only correct for the default rounding mode,
 // round-to-nearest tie-to-even.
-template <> inline float fma<float>(float x, float y, float z) {
+template <> LIBC_INLINE float fma<float>(float x, float y, float z) {
   // Product is exact.
   double prod = static_cast<double>(x) * static_cast<double>(y);
   double z_d = static_cast<double>(z);
@@ -91,7 +91,7 @@ LIBC_INLINE bool shift_mantissa(int shift_length, UInt128 &mant) {
 
 } // namespace internal
 
-template <> inline double fma<double>(double x, double y, double z) {
+template <> LIBC_INLINE double fma<double>(double x, double y, double z) {
   using FPBits = fputil::FPBits<double>;
   using FloatProp = fputil::FloatProperties<double>;
 

diff  --git a/libc/src/__support/FPUtil/generic/sqrt.h b/libc/src/__support/FPUtil/generic/sqrt.h
index c972c5f40cd59..1464056417d06 100644
--- a/libc/src/__support/FPUtil/generic/sqrt.h
+++ b/libc/src/__support/FPUtil/generic/sqrt.h
@@ -17,6 +17,7 @@
 #include "src/__support/FPUtil/PlatformDefs.h"
 #include "src/__support/UInt128.h"
 #include "src/__support/builtin_wrappers.h"
+#include "src/__support/common.h"
 
 namespace __llvm_libc {
 namespace fputil {
@@ -44,12 +45,12 @@ LIBC_INLINE void normalize(int &exponent,
 
 #ifdef LONG_DOUBLE_IS_DOUBLE
 template <>
-inline void normalize<long double>(int &exponent, uint64_t &mantissa) {
+LIBC_INLINE void normalize<long double>(int &exponent, uint64_t &mantissa) {
   normalize<double>(exponent, mantissa);
 }
 #elif !defined(SPECIAL_X86_LONG_DOUBLE)
 template <>
-inline void normalize<long double>(int &exponent, UInt128 &mantissa) {
+LIBC_INLINE void normalize<long double>(int &exponent, UInt128 &mantissa) {
   const uint64_t hi_bits = static_cast<uint64_t>(mantissa >> 64);
   const int shift = hi_bits
                         ? (unsafe_clz(hi_bits) - 15)

diff  --git a/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h b/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h
index 64fb5e0d8a66c..328b02eec75ff 100644
--- a/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h
+++ b/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h
@@ -14,12 +14,13 @@
 #include "src/__support/FPUtil/PlatformDefs.h"
 #include "src/__support/UInt128.h"
 #include "src/__support/builtin_wrappers.h"
+#include "src/__support/common.h"
 
 namespace __llvm_libc {
 namespace fputil {
 namespace x86 {
 
-inline void normalize(int &exponent, UInt128 &mantissa) {
+LIBC_INLINE void normalize(int &exponent, UInt128 &mantissa) {
   const int shift =
       unsafe_clz(static_cast<uint64_t>(mantissa)) -
       (8 * sizeof(uint64_t) - 1 - MantissaWidth<long double>::VALUE);

diff  --git a/libc/src/__support/FPUtil/multiply_add.h b/libc/src/__support/FPUtil/multiply_add.h
index 384035e76840c..93cca9059297f 100644
--- a/libc/src/__support/FPUtil/multiply_add.h
+++ b/libc/src/__support/FPUtil/multiply_add.h
@@ -34,11 +34,12 @@ template <typename T> LIBC_INLINE T multiply_add(T x, T y, T z) {
 namespace __llvm_libc {
 namespace fputil {
 
-template <> inline float multiply_add<float>(float x, float y, float z) {
+template <> LIBC_INLINE float multiply_add<float>(float x, float y, float z) {
   return fma(x, y, z);
 }
 
-template <> inline double multiply_add<double>(double x, double y, double z) {
+template <>
+LIBC_INLINE double multiply_add<double>(double x, double y, double z) {
   return fma(x, y, z);
 }
 

diff  --git a/libc/src/__support/FPUtil/x86_64/PolyEval.h b/libc/src/__support/FPUtil/x86_64/PolyEval.h
index c59f0ab130e04..d6cd28da83cd4 100644
--- a/libc/src/__support/FPUtil/x86_64/PolyEval.h
+++ b/libc/src/__support/FPUtil/x86_64/PolyEval.h
@@ -10,6 +10,7 @@
 #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_POLYEVAL_H
 
 #include "src/__support/architectures.h"
+#include "src/__support/common.h"
 
 #if !defined(LLVM_LIBC_ARCH_X86_64)
 #error "Invalid include"
@@ -23,7 +24,7 @@ namespace fputil {
 // Cubic polynomials:
 //   polyeval(x, a0, a1, a2, a3) = a3*x^3 + a2*x^2 + a1*x + a0
 template <>
-inline float polyeval(float x, float a0, float a1, float a2, float a3) {
+LIBC_INLINE float polyeval(float x, float a0, float a1, float a2, float a3) {
   __m128 xmm = _mm_set1_ps(x);                 // NOLINT
   __m128 a13 = _mm_set_ps(0.0f, x, a3, a1);    // NOLINT
   __m128 a02 = _mm_set_ps(0.0f, 0.0f, a2, a0); // NOLINT
@@ -34,7 +35,8 @@ inline float polyeval(float x, float a0, float a1, float a2, float a3) {
 }
 
 template <>
-inline double polyeval(double x, double a0, double a1, double a2, double a3) {
+LIBC_INLINE double polyeval(double x, double a0, double a1, double a2,
+                            double a3) {
   __m256d xmm = _mm256_set1_pd(x);               // NOLINT
   __m256d a13 = _mm256_set_pd(0.0, x, a3, a1);   // NOLINT
   __m256d a02 = _mm256_set_pd(0.0, 0.0, a2, a0); // NOLINT
@@ -48,8 +50,8 @@ inline double polyeval(double x, double a0, double a1, double a2, double a3) {
 //   polyeval(x, a0, a1, a2, a3, a4, a5) = a5*x^5 + a4*x^4 + a3*x^3 + a2*x^2 +
 //                                         + a1*x + a0
 template <>
-inline float polyeval(float x, float a0, float a1, float a2, float a3, float a4,
-                      float a5) {
+LIBC_INLINE float polyeval(float x, float a0, float a1, float a2, float a3,
+                           float a4, float a5) {
   __m128 xmm = _mm_set1_ps(x);                 // NOLINT
   __m128 a25 = _mm_set_ps(0.0f, x, a5, a2);    // NOLINT
   __m128 a14 = _mm_set_ps(0.0f, 0.0f, a4, a1); // NOLINT
@@ -63,8 +65,8 @@ inline float polyeval(float x, float a0, float a1, float a2, float a3, float a4,
 }
 
 template <>
-inline double polyeval(double x, double a0, double a1, double a2, double a3,
-                       double a4, double a5) {
+LIBC_INLINE double polyeval(double x, double a0, double a1, double a2,
+                            double a3, double a4, double a5) {
   __m256d xmm = _mm256_set1_pd(x);               // NOLINT
   __m256d a25 = _mm256_set_pd(0.0, x, a5, a2);   // NOLINT
   __m256d a14 = _mm256_set_pd(0.0, 0.0, a4, a1); // NOLINT

diff  --git a/libc/src/__support/FPUtil/x86_64/sqrt.h b/libc/src/__support/FPUtil/x86_64/sqrt.h
index c2ca4b1a1016b..07009d656664b 100644
--- a/libc/src/__support/FPUtil/x86_64/sqrt.h
+++ b/libc/src/__support/FPUtil/x86_64/sqrt.h
@@ -10,6 +10,7 @@
 #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_SQRT_H
 
 #include "src/__support/architectures.h"
+#include "src/__support/common.h"
 
 #if !defined(LLVM_LIBC_ARCH_X86)
 #error "Invalid include"
@@ -20,26 +21,26 @@
 namespace __llvm_libc {
 namespace fputil {
 
-template <> inline float sqrt<float>(float x) {
+template <> LIBC_INLINE float sqrt<float>(float x) {
   float result;
   __asm__ __volatile__("sqrtss %x1, %x0" : "=x"(result) : "x"(x));
   return result;
 }
 
-template <> inline double sqrt<double>(double x) {
+template <> LIBC_INLINE double sqrt<double>(double x) {
   double result;
   __asm__ __volatile__("sqrtsd %x1, %x0" : "=x"(result) : "x"(x));
   return result;
 }
 
 #ifdef LONG_DOUBLE_IS_DOUBLE
-template <> inline long double sqrt<long double>(long double x) {
+template <> LIBC_INLINE long double sqrt<long double>(long double x) {
   long double result;
   __asm__ __volatile__("sqrtsd %x1, %x0" : "=x"(result) : "x"(x));
   return result;
 }
 #else
-template <> inline long double sqrt<long double>(long double x) {
+template <> LIBC_INLINE long double sqrt<long double>(long double x) {
   __asm__ __volatile__("fsqrt" : "+t"(x));
   return x;
 }

diff  --git a/libc/src/__support/OSUtil/linux/syscall.h b/libc/src/__support/OSUtil/linux/syscall.h
index 645145a3044cf..d4defd3ff2852 100644
--- a/libc/src/__support/OSUtil/linux/syscall.h
+++ b/libc/src/__support/OSUtil/linux/syscall.h
@@ -10,6 +10,7 @@
 #define LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_SYSCALL_H
 
 #include "src/__support/architectures.h"
+#include "src/__support/common.h"
 
 #ifdef LLVM_LIBC_ARCH_X86_64
 #include "x86_64/syscall.h"
@@ -22,8 +23,7 @@
 namespace __llvm_libc {
 
 template <typename... Ts>
-__attribute__((always_inline)) inline long syscall_impl(long __number,
-                                                        Ts... ts) {
+LIBC_INLINE long syscall_impl(long __number, Ts... ts) {
   static_assert(sizeof...(Ts) <= 6, "Too many arguments for syscall");
   return syscall_impl(__number, (long)ts...);
 }

diff  --git a/libc/src/__support/arg_list.h b/libc/src/__support/arg_list.h
index 4d82b5e5b2aee..5e79f513ff3e0 100644
--- a/libc/src/__support/arg_list.h
+++ b/libc/src/__support/arg_list.h
@@ -9,6 +9,8 @@
 #ifndef LLVM_LIBC_SRC_SUPPORT_ARG_LIST_H
 #define LLVM_LIBC_SRC_SUPPORT_ARG_LIST_H
 
+#include "src/__support/common.h"
+
 #include <stdarg.h>
 
 namespace __llvm_libc {
@@ -18,16 +20,16 @@ class ArgList {
   va_list vlist;
 
 public:
-  ArgList(va_list vlist) { va_copy(this->vlist, vlist); }
-  ArgList(ArgList &other) { va_copy(this->vlist, other.vlist); }
-  ~ArgList() { va_end(this->vlist); }
+  LIBC_INLINE ArgList(va_list vlist) { va_copy(this->vlist, vlist); }
+  LIBC_INLINE ArgList(ArgList &other) { va_copy(this->vlist, other.vlist); }
+  LIBC_INLINE ~ArgList() { va_end(this->vlist); }
 
-  ArgList &operator=(ArgList &rhs) {
+  LIBC_INLINE ArgList &operator=(ArgList &rhs) {
     va_copy(vlist, rhs.vlist);
     return *this;
   }
 
-  template <class T> T inline next_var() { return va_arg(vlist, T); }
+  template <class T> LIBC_INLINE T next_var() { return va_arg(vlist, T); }
 };
 
 } // namespace internal

diff  --git a/libc/src/__support/char_vector.h b/libc/src/__support/char_vector.h
index 0a9a2d7e4cf14..e60f9fe555fff 100644
--- a/libc/src/__support/char_vector.h
+++ b/libc/src/__support/char_vector.h
@@ -9,6 +9,8 @@
 #ifndef LLVM_LIBC_SRC_SUPPORT_CHARVECTOR_H
 #define LLVM_LIBC_SRC_SUPPORT_CHARVECTOR_H
 
+#include "src/__support/common.h"
+
 #include <stddef.h>
 #include <stdlib.h> // For allocation.
 
@@ -29,13 +31,13 @@ class CharVector {
 
 public:
   CharVector() = default;
-  ~CharVector() {
+  LIBC_INLINE ~CharVector() {
     if (cur_str != local_buffer)
       free(cur_str);
   }
 
   // append returns true on success and false on allocation failure.
-  bool append(char new_char) {
+  LIBC_INLINE bool append(char new_char) {
     // Subtract 1 for index starting at 0 and another for the null terminator.
     if (index >= cur_buff_size - 2) {
       // If the new character would cause the string to be longer than the
@@ -63,12 +65,12 @@ class CharVector {
     return true;
   }
 
-  char *c_str() {
+  LIBC_INLINE char *c_str() {
     cur_str[index] = '\0';
     return cur_str;
   }
 
-  size_t length() { return index; }
+  LIBC_INLINE size_t length() { return index; }
 };
 
 } // namespace __llvm_libc

diff  --git a/libc/src/__support/float_to_string.h b/libc/src/__support/float_to_string.h
index 5fe003f853f35..47b7ae89dcd14 100644
--- a/libc/src/__support/float_to_string.h
+++ b/libc/src/__support/float_to_string.h
@@ -59,7 +59,7 @@ constexpr size_t MID_INT_SIZE = 192;
 namespace internal {
 
 // Returns floor(log_10(2^e)); requires 0 <= e <= 1650.
-constexpr inline uint32_t log10_pow2(const uint32_t e) {
+LIBC_INLINE constexpr uint32_t log10_pow2(const uint32_t e) {
   // The first value this approximation fails for is 2^1651 which is just
   // greater than 10^297. assert(e >= 0); assert(e <= 1650);
   return (e * 78913) >> 18;
@@ -69,14 +69,14 @@ constexpr inline uint32_t log10_pow2(const uint32_t e) {
 // power of 2 was also a power of 10, but since that doesn't exist this is
 // always accurate. This is used to calculate the maximum number of base-10
 // digits a given e-bit number could have.
-constexpr inline uint32_t ceil_log10_pow2(const uint32_t e) {
+LIBC_INLINE constexpr uint32_t ceil_log10_pow2(const uint32_t e) {
   return log10_pow2(e) + 1;
 }
 
 // Returns the maximum number of 9 digit blocks a number described by the given
 // index (which is ceil(exponent/16)) and mantissa width could need.
-constexpr inline uint32_t length_for_num(const uint32_t idx,
-                                         const uint32_t mantissa_width) {
+LIBC_INLINE constexpr uint32_t length_for_num(const uint32_t idx,
+                                              const uint32_t mantissa_width) {
   //+8 to round up when dividing by 9
   return (ceil_log10_pow2(16 * idx) + ceil_log10_pow2(mantissa_width) +
           (BLOCK_SIZE - 1)) /
@@ -90,7 +90,7 @@ constexpr inline uint32_t length_for_num(const uint32_t idx,
 // floor(5^(-9i) * 2^(e + c_1 - 9i) + 1) % (10^9 * 2^c_1)
 
 template <size_t INT_SIZE>
-constexpr inline cpp::UInt<MID_INT_SIZE>
+LIBC_INLINE constexpr cpp::UInt<MID_INT_SIZE>
 get_table_positive(int exponent, size_t i, const size_t constant) {
   // INT_SIZE is the size of int that is used for the internal calculations of
   // this function. It should be large enough to hold 2^(exponent+constant), so
@@ -131,8 +131,8 @@ get_table_positive(int exponent, size_t i, const size_t constant) {
 // calculations.
 // The formula being used looks more like this:
 // floor(10^(9*(-i)) * 2^(c_0 + (-e))) % (10^9 * 2^c_0)
-inline cpp::UInt<MID_INT_SIZE> get_table_negative(int exponent, size_t i,
-                                                  const size_t constant) {
+LIBC_INLINE cpp::UInt<MID_INT_SIZE> get_table_negative(int exponent, size_t i,
+                                                       const size_t constant) {
   constexpr size_t INT_SIZE = 1024;
   int shift_amount = constant - exponent;
   cpp::UInt<INT_SIZE> num(1);
@@ -234,7 +234,7 @@ class FloatToString {
   // constexpr void init_convert();
 
 public:
-  constexpr FloatToString(T init_float) : float_bits(init_float) {
+  LIBC_INLINE constexpr FloatToString(T init_float) : float_bits(init_float) {
     is_negative = float_bits.get_sign();
     exponent = float_bits.get_exponent();
     mantissa = float_bits.get_explicit_mantissa();
@@ -254,13 +254,15 @@ class FloatToString {
     // init_convert();
   }
 
-  constexpr bool is_nan() { return float_bits.is_nan(); }
-  constexpr bool is_inf() { return float_bits.is_inf(); }
-  constexpr bool is_inf_or_nan() { return float_bits.is_inf_or_nan(); }
+  LIBC_INLINE constexpr bool is_nan() { return float_bits.is_nan(); }
+  LIBC_INLINE constexpr bool is_inf() { return float_bits.is_inf(); }
+  LIBC_INLINE constexpr bool is_inf_or_nan() {
+    return float_bits.is_inf_or_nan();
+  }
 
   // get_block returns an integer that represents the digits in the requested
   // block.
-  constexpr BlockInt get_positive_block(int block_index) {
+  LIBC_INLINE constexpr BlockInt get_positive_block(int block_index) {
     if (exponent >= -MANT_WIDTH) {
       // idx is ceil(exponent/16) or 0 if exponent is negative. This is used to
       // find the coarse section of the POW10_SPLIT table that will be used to
@@ -285,7 +287,8 @@ class FloatToString {
       return 0;
     }
   }
-  constexpr BlockInt get_negative_block(int block_index) {
+
+  LIBC_INLINE constexpr BlockInt get_negative_block(int block_index) {
     if (exponent < 0) {
       const int32_t idx = -exponent / 16;
       uint32_t i = block_index;
@@ -312,7 +315,7 @@ class FloatToString {
     }
   }
 
-  constexpr BlockInt get_block(int block_index) {
+  LIBC_INLINE constexpr BlockInt get_block(int block_index) {
     if (block_index >= 0) {
       return get_positive_block(block_index);
     } else {
@@ -320,7 +323,7 @@ class FloatToString {
     }
   }
 
-  constexpr size_t get_positive_blocks() {
+  LIBC_INLINE constexpr size_t get_positive_blocks() {
     if (exponent >= -MANT_WIDTH) {
       const uint32_t idx =
           exponent < 0 ? 0 : static_cast<uint32_t>(exponent + 15) / 16;
@@ -333,14 +336,14 @@ class FloatToString {
 
   // This takes the index of a block after the decimal point (a negative block)
   // and return if it's sure that all of the digits after it are zero.
-  constexpr bool is_lowest_block(size_t block_index) {
+  LIBC_INLINE constexpr bool is_lowest_block(size_t block_index) {
     const int32_t idx = -exponent / 16;
     const uint32_t p = POW10_OFFSET_2[idx] + block_index - MIN_BLOCK_2[idx];
     // If the remaining digits are all 0, then this is the lowest block.
     return p >= POW10_OFFSET_2[idx + 1];
   }
 
-  constexpr size_t zero_blocks_after_point() {
+  LIBC_INLINE constexpr size_t zero_blocks_after_point() {
     return MIN_BLOCK_2[-exponent / 16];
   }
 };
@@ -355,17 +358,18 @@ class FloatToString {
 // }
 
 template <>
-constexpr size_t FloatToString<long double>::zero_blocks_after_point() {
+LIBC_INLINE constexpr size_t
+FloatToString<long double>::zero_blocks_after_point() {
   return 0;
 }
 
 template <>
-constexpr bool FloatToString<long double>::is_lowest_block(size_t) {
+LIBC_INLINE constexpr bool FloatToString<long double>::is_lowest_block(size_t) {
   return false;
 }
 
 template <>
-constexpr BlockInt
+LIBC_INLINE constexpr BlockInt
 FloatToString<long double>::get_positive_block(int block_index) {
   if (exponent >= -MANT_WIDTH) {
     const uint32_t pos_exp = (exponent < 0 ? 0 : exponent);
@@ -401,7 +405,7 @@ FloatToString<long double>::get_positive_block(int block_index) {
 }
 
 template <>
-constexpr BlockInt
+LIBC_INLINE constexpr BlockInt
 FloatToString<long double>::get_negative_block(int block_index) {
   if (exponent < 0) {
     const int32_t idx = -exponent / 16;

diff  --git a/libc/src/__support/integer_to_string.h b/libc/src/__support/integer_to_string.h
index 9d8cddabd59f2..a748575ab0ad5 100644
--- a/libc/src/__support/integer_to_string.h
+++ b/libc/src/__support/integer_to_string.h
@@ -15,6 +15,7 @@
 #include "src/__support/CPP/span.h"
 #include "src/__support/CPP/string_view.h"
 #include "src/__support/CPP/type_traits.h"
+#include "src/__support/common.h"
 
 namespace __llvm_libc {
 
@@ -44,10 +45,10 @@ namespace __llvm_libc {
 //   char b30buf[IntegerToString::bufsize<30, int>(a)];
 //   auto str = IntegerToString::convert<30>(a, b30buf);
 class IntegerToString {
-  static cpp::string_view convert_uintmax(uintmax_t uval,
-                                          cpp::span<char> &buffer,
-                                          bool lowercase,
-                                          const uint8_t conv_base) {
+  LIBC_INLINE static cpp::string_view convert_uintmax(uintmax_t uval,
+                                                      cpp::span<char> &buffer,
+                                                      bool lowercase,
+                                                      const uint8_t conv_base) {
     const char a = lowercase ? 'a' : 'A';
 
     size_t len = 0;
@@ -67,9 +68,10 @@ class IntegerToString {
     return cpp::string_view(buffer.data() + buffer.size() - len, len);
   }
 
-  static cpp::string_view convert_intmax(intmax_t val, cpp::span<char> &buffer,
-                                         bool lowercase,
-                                         const uint8_t conv_base) {
+  LIBC_INLINE static cpp::string_view convert_intmax(intmax_t val,
+                                                     cpp::span<char> &buffer,
+                                                     bool lowercase,
+                                                     const uint8_t conv_base) {
     if (val >= 0)
       return convert_uintmax(uintmax_t(val), buffer, lowercase, conv_base);
     uintmax_t uval = uintmax_t(-val);
@@ -80,7 +82,7 @@ class IntegerToString {
     return cpp::string_view(buffer.data() + buffer.size() - len, len);
   }
 
-  static constexpr inline size_t floor_log_2(size_t num) {
+  LIBC_INLINE static constexpr size_t floor_log_2(size_t num) {
     size_t i = 0;
     for (; num > 1; num /= 2) {
       ++i;
@@ -110,7 +112,8 @@ class IntegerToString {
   // For other bases, we approximate by rounding down to the nearest power of
   // two base, since the space needed is easy to calculate and it won't
   // overestimate by too much.
-  template <uint8_t BASE, typename T> static constexpr size_t bufsize() {
+  template <uint8_t BASE, typename T>
+  LIBC_INLINE static constexpr size_t bufsize() {
     constexpr size_t BITS_PER_DIGIT = floor_log_2(BASE);
     constexpr size_t BUFSIZE_COMMON =
         ((sizeof(T) * 8 + (BITS_PER_DIGIT - 1)) / BITS_PER_DIGIT);
@@ -119,27 +122,27 @@ class IntegerToString {
            (BASE == 10 ? BUFSIZE_BASE10 : BUFSIZE_COMMON);
   }
 
-  template <typename T> static constexpr size_t dec_bufsize() {
+  template <typename T> LIBC_INLINE static constexpr size_t dec_bufsize() {
     return bufsize<10, T>();
   }
 
-  template <typename T> static constexpr size_t hex_bufsize() {
+  template <typename T> LIBC_INLINE static constexpr size_t hex_bufsize() {
     return bufsize<16, T>();
   }
 
-  template <typename T> static constexpr size_t oct_bufsize() {
+  template <typename T> LIBC_INLINE static constexpr size_t oct_bufsize() {
     return bufsize<8, T>();
   }
 
-  template <typename T> static constexpr size_t bin_bufsize() {
+  template <typename T> LIBC_INLINE static constexpr size_t bin_bufsize() {
     return bufsize<2, T>();
   }
 
   template <uint8_t BASE, typename T,
             cpp::enable_if_t<2 <= BASE && BASE <= 36 && cpp::is_integral_v<T>,
                              int> = 0>
-  static cpp::optional<cpp::string_view> convert(T val, cpp::span<char> buffer,
-                                                 bool lowercase = true) {
+  LIBC_INLINE static cpp::optional<cpp::string_view>
+  convert(T val, cpp::span<char> buffer, bool lowercase = true) {
     if (buffer.size() < bufsize<BASE, T>())
       return cpp::optional<cpp::string_view>();
     if (cpp::is_signed_v<T>)
@@ -149,23 +152,26 @@ class IntegerToString {
   }
 
   template <typename T, cpp::enable_if_t<cpp::is_integral_v<T>, int> = 0>
-  static cpp::optional<cpp::string_view> dec(T val, cpp::span<char> buffer) {
+  LIBC_INLINE static cpp::optional<cpp::string_view>
+  dec(T val, cpp::span<char> buffer) {
     return convert<10>(val, buffer);
   }
 
   template <typename T, cpp::enable_if_t<cpp::is_integral_v<T>, int> = 0>
-  static cpp::optional<cpp::string_view> hex(T val, cpp::span<char> buffer,
-                                             bool lowercase = true) {
+  LIBC_INLINE static cpp::optional<cpp::string_view>
+  hex(T val, cpp::span<char> buffer, bool lowercase = true) {
     return convert<16>(val, buffer, lowercase);
   }
 
   template <typename T, cpp::enable_if_t<cpp::is_integral_v<T>, int> = 0>
-  static cpp::optional<cpp::string_view> oct(T val, cpp::span<char> buffer) {
+  LIBC_INLINE static cpp::optional<cpp::string_view>
+  oct(T val, cpp::span<char> buffer) {
     return convert<8>(val, buffer);
   }
 
   template <typename T, cpp::enable_if_t<cpp::is_integral_v<T>, int> = 0>
-  static cpp::optional<cpp::string_view> bin(T val, cpp::span<char> buffer) {
+  LIBC_INLINE static cpp::optional<cpp::string_view>
+  bin(T val, cpp::span<char> buffer) {
     return convert<2>(val, buffer);
   }
 };

diff  --git a/libc/src/__support/integer_utils.h b/libc/src/__support/integer_utils.h
index bad39f9336150..aedcd353436f9 100644
--- a/libc/src/__support/integer_utils.h
+++ b/libc/src/__support/integer_utils.h
@@ -9,7 +9,9 @@
 #ifndef LLVM_LIBC_SRC_SUPPORT_INTEGER_UTILS_H
 #define LLVM_LIBC_SRC_SUPPORT_INTEGER_UTILS_H
 
-#include "CPP/type_traits.h"
+#include "src/__support/CPP/type_traits.h"
+#include "src/__support/common.h"
+
 #include "builtin_wrappers.h"
 #include "number_pair.h"
 
@@ -20,7 +22,7 @@ namespace __llvm_libc {
 template <typename T> NumberPair<T> full_mul(T a, T b);
 
 template <>
-inline NumberPair<uint32_t> full_mul<uint32_t>(uint32_t a, uint32_t b) {
+LIBC_INLINE NumberPair<uint32_t> full_mul<uint32_t>(uint32_t a, uint32_t b) {
   uint64_t prod = uint64_t(a) * uint64_t(b);
   NumberPair<uint32_t> result;
   result.lo = uint32_t(prod);
@@ -29,7 +31,7 @@ inline NumberPair<uint32_t> full_mul<uint32_t>(uint32_t a, uint32_t b) {
 }
 
 template <>
-inline NumberPair<uint64_t> full_mul<uint64_t>(uint64_t a, uint64_t b) {
+LIBC_INLINE NumberPair<uint64_t> full_mul<uint64_t>(uint64_t a, uint64_t b) {
 #ifdef __SIZEOF_INT128__
   __uint128_t prod = __uint128_t(a) * __uint128_t(b);
   NumberPair<uint64_t> result;

diff  --git a/libc/src/__support/str_to_float.h b/libc/src/__support/str_to_float.h
index 55f41c1db29ce..cdc3c3c073192 100644
--- a/libc/src/__support/str_to_float.h
+++ b/libc/src/__support/str_to_float.h
@@ -76,7 +76,8 @@ template <class T> LIBC_INLINE void set_implicit_bit(fputil::FPBits<T> &) {
 
 #if defined(SPECIAL_X86_LONG_DOUBLE)
 template <>
-inline void set_implicit_bit<long double>(fputil::FPBits<long double> &result) {
+LIBC_INLINE void
+set_implicit_bit<long double>(fputil::FPBits<long double> &result) {
   result.set_implicit_bit(result.get_unbiased_exponent() != 0);
 }
 #endif
@@ -190,7 +191,7 @@ eisel_lemire(typename fputil::FPBits<T>::UIntType mantissa, int32_t exp10,
 
 #if !defined(LONG_DOUBLE_IS_DOUBLE)
 template <>
-inline bool eisel_lemire<long double>(
+LIBC_INLINE bool eisel_lemire<long double>(
     typename fputil::FPBits<long double>::UIntType mantissa, int32_t exp10,
     typename fputil::FPBits<long double>::UIntType *outputMantissa,
     uint32_t *outputExp2) {

diff  --git a/libc/src/stdio/printf_core/CMakeLists.txt b/libc/src/stdio/printf_core/CMakeLists.txt
index 518f9d7b50959..c908b9198903b 100644
--- a/libc/src/stdio/printf_core/CMakeLists.txt
+++ b/libc/src/stdio/printf_core/CMakeLists.txt
@@ -22,6 +22,7 @@ add_object_library(
     libc.src.__support.CPP.bit
     libc.src.__support.CPP.string_view
     libc.src.__support.CPP.type_traits
+    libc.src.__support.common
 )
 
 add_object_library(

diff  --git a/libc/src/stdio/printf_core/char_converter.h b/libc/src/stdio/printf_core/char_converter.h
index cd4724fd7695b..23a85eb572883 100644
--- a/libc/src/stdio/printf_core/char_converter.h
+++ b/libc/src/stdio/printf_core/char_converter.h
@@ -10,6 +10,7 @@
 #define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_CHAR_CONVERTER_H
 
 #include "src/__support/CPP/string_view.h"
+#include "src/__support/common.h"
 #include "src/stdio/printf_core/converter_utils.h"
 #include "src/stdio/printf_core/core_structs.h"
 #include "src/stdio/printf_core/writer.h"
@@ -17,7 +18,7 @@
 namespace __llvm_libc {
 namespace printf_core {
 
-int inline convert_char(Writer *writer, const FormatSection &to_conv) {
+LIBC_INLINE int convert_char(Writer *writer, const FormatSection &to_conv) {
   char c = to_conv.conv_val_raw;
 
   constexpr int string_len = 1;

diff  --git a/libc/src/stdio/printf_core/converter_utils.h b/libc/src/stdio/printf_core/converter_utils.h
index 4d2c84700ad37..54948a2a5f1fd 100644
--- a/libc/src/stdio/printf_core/converter_utils.h
+++ b/libc/src/stdio/printf_core/converter_utils.h
@@ -10,6 +10,7 @@
 #define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_CONVERTER_UTILS_H
 
 #include "src/__support/CPP/limits.h"
+#include "src/__support/common.h"
 #include "src/stdio/printf_core/core_structs.h"
 
 #include <inttypes.h>
@@ -18,7 +19,7 @@
 namespace __llvm_libc {
 namespace printf_core {
 
-inline uintmax_t apply_length_modifier(uintmax_t num, LengthModifier lm) {
+LIBC_INLINE uintmax_t apply_length_modifier(uintmax_t num, LengthModifier lm) {
   switch (lm) {
   case LengthModifier::none:
     return num & cpp::numeric_limits<unsigned int>::max();

diff  --git a/libc/src/stdio/printf_core/parser.h b/libc/src/stdio/printf_core/parser.h
index 7829914a78aeb..107876784cd58 100644
--- a/libc/src/stdio/printf_core/parser.h
+++ b/libc/src/stdio/printf_core/parser.h
@@ -11,6 +11,7 @@
 
 #include "src/__support/CPP/type_traits.h"
 #include "src/__support/arg_list.h"
+#include "src/__support/common.h"
 #include "src/stdio/printf_core/core_structs.h"
 #include "src/stdio/printf_core/printf_config.h"
 
@@ -39,7 +40,7 @@ class Parser {
   struct TypeDesc {
     uint8_t size;
     PrimaryType primary_type;
-    constexpr bool operator==(const TypeDesc &other) const {
+    LIBC_INLINE constexpr bool operator==(const TypeDesc &other) const {
       return (size == other.size) && (primary_type == other.primary_type);
     }
   };
@@ -60,10 +61,10 @@ class Parser {
 
 public:
 #ifndef LLVM_LIBC_PRINTF_DISABLE_INDEX_MODE
-  Parser(const char *__restrict new_str, internal::ArgList &args)
+  LIBC_INLINE Parser(const char *__restrict new_str, internal::ArgList &args)
       : str(new_str), args_cur(args), args_start(args) {}
 #else
-  Parser(const char *__restrict new_str, internal::ArgList &args)
+  LIBC_INLINE Parser(const char *__restrict new_str, internal::ArgList &args)
       : str(new_str), args_cur(args) {}
 #endif // LLVM_LIBC_PRINTF_DISABLE_INDEX_MODE
 
@@ -87,7 +88,7 @@ class Parser {
   LengthModifier parse_length_modifier(size_t *local_pos);
 
   // get_next_arg_value gets the next value from the arg list as type T.
-  template <class T> T inline get_next_arg_value() {
+  template <class T> LIBC_INLINE T get_next_arg_value() {
     return args_cur.next_var<T>();
   }
 
@@ -104,7 +105,7 @@ class Parser {
   // local_pos.
   size_t parse_index(size_t *local_pos);
 
-  template <typename T> static constexpr TypeDesc get_type_desc() {
+  template <typename T> LIBC_INLINE static constexpr TypeDesc get_type_desc() {
     if constexpr (cpp::is_same_v<T, void>) {
       return TypeDesc{0, PrimaryType::Integer};
     } else {
@@ -117,7 +118,7 @@ class Parser {
     }
   }
 
-  void inline set_type_desc(size_t index, TypeDesc value) {
+  LIBC_INLINE void set_type_desc(size_t index, TypeDesc value) {
     if (index != 0 && index <= DESC_ARR_LEN)
       desc_arr[index - 1] = value;
   }
@@ -125,7 +126,7 @@ class Parser {
   // get_arg_value gets the value from the arg list at index (starting at 1).
   // This may require parsing the format string. An index of 0 is interpreted as
   // the next value.
-  template <class T> T inline get_arg_value(size_t index) {
+  template <class T> LIBC_INLINE T get_arg_value(size_t index) {
     if (!(index == 0 || index == args_index))
       args_to_index(index);
 

diff  --git a/libc/src/stdio/printf_core/string_converter.h b/libc/src/stdio/printf_core/string_converter.h
index e10ecd6f9f55d..59e98e20c526a 100644
--- a/libc/src/stdio/printf_core/string_converter.h
+++ b/libc/src/stdio/printf_core/string_converter.h
@@ -10,6 +10,7 @@
 #define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_STRING_CONVERTER_H
 
 #include "src/__support/CPP/string_view.h"
+#include "src/__support/common.h"
 #include "src/stdio/printf_core/converter_utils.h"
 #include "src/stdio/printf_core/core_structs.h"
 #include "src/stdio/printf_core/writer.h"
@@ -19,7 +20,7 @@
 namespace __llvm_libc {
 namespace printf_core {
 
-int inline convert_string(Writer *writer, const FormatSection &to_conv) {
+LIBC_INLINE int convert_string(Writer *writer, const FormatSection &to_conv) {
   size_t string_len = 0;
 
   for (char *cur_str = reinterpret_cast<char *>(to_conv.conv_val_ptr);

diff  --git a/libc/src/stdio/scanf_core/parser.h b/libc/src/stdio/scanf_core/parser.h
index ced841f1d6ca1..a4139d33401ee 100644
--- a/libc/src/stdio/scanf_core/parser.h
+++ b/libc/src/stdio/scanf_core/parser.h
@@ -10,6 +10,7 @@
 #define LLVM_LIBC_SRC_STDIO_SCANF_CORE_PARSER_H
 
 #include "src/__support/arg_list.h"
+#include "src/__support/common.h"
 #include "src/stdio/scanf_core/core_structs.h"
 #include "src/stdio/scanf_core/scanf_config.h"
 
@@ -34,10 +35,10 @@ class Parser {
 
 public:
 #ifndef LLVM_LIBC_SCANF_DISABLE_INDEX_MODE
-  Parser(const char *__restrict new_str, internal::ArgList &args)
+  LIBC_INLINE Parser(const char *__restrict new_str, internal::ArgList &args)
       : str(new_str), args_cur(args), args_start(args) {}
 #else
-  Parser(const char *__restrict new_str, internal::ArgList &args)
+  LIBC_INLINE Parser(const char *__restrict new_str, internal::ArgList &args)
       : str(new_str), args_cur(args) {}
 #endif // LLVM_LIBC_SCANF_DISABLE_INDEX_MODE
 
@@ -55,7 +56,7 @@ class Parser {
   LengthModifier parse_length_modifier(size_t *local_pos);
 
   // get_next_arg_value gets the next value from the arg list as type T.
-  template <class T> T inline get_next_arg_value() {
+  template <class T> LIBC_INLINE T get_next_arg_value() {
     return args_cur.next_var<T>();
   }
 
@@ -75,7 +76,7 @@ class Parser {
   // get_arg_value gets the value from the arg list at index (starting at 1).
   // This may require parsing the format string. An index of 0 is interpreted as
   // the next value.
-  template <class T> T inline get_arg_value(size_t index) {
+  template <class T> LIBC_INLINE T get_arg_value(size_t index) {
     if (!(index == 0 || index == args_index))
       args_to_index(index);
 


        


More information about the libc-commits mailing list