[libc][NFC] Another round of replacement of "inline" with "LIBC_INLINE".
Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D142509
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -164,6 +164,7 @@ add_header_library(
|
||||
multiply_add.h
|
||||
DEPENDS
|
||||
.fma
|
||||
libc.src.__support.common
|
||||
)
|
||||
|
||||
add_header_library(
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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>;
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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...);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 @@ public:
|
||||
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
|
||||
|
||||
@@ -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 @@ public:
|
||||
// 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 @@ public:
|
||||
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 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ public:
|
||||
|
||||
// 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 @@ public:
|
||||
// }
|
||||
|
||||
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;
|
||||
|
||||
@@ -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 @@ public:
|
||||
// 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 @@ public:
|
||||
(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 @@ public:
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 @@ private:
|
||||
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 @@ private:
|
||||
// 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 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ private:
|
||||
// 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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 @@ private:
|
||||
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 @@ private:
|
||||
// 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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user