9 changes: 5 additions & 4 deletions libc/src/__support/FPUtil/double_double.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
#define LLVM_LIBC_SRC_SUPPORT_FPUTIL_DOUBLEDOUBLE_H

#include "multiply_add.h"
#include "src/__support/common.h"
#include "src/__support/number_pair.h"

namespace __llvm_libc::fputil {

using DoubleDouble = __llvm_libc::NumberPair<double>;

// Assumption: |a| >= |b|
constexpr inline DoubleDouble exact_add(double a, double b) {
LIBC_INLINE constexpr DoubleDouble exact_add(double a, double b) {
DoubleDouble r{0.0, 0.0};
r.hi = a + b;
double t = r.hi - a;
Expand All @@ -26,21 +27,21 @@ constexpr inline DoubleDouble exact_add(double a, double b) {
}

// Assumption: |a.hi| >= |b.hi|
constexpr inline DoubleDouble add(DoubleDouble a, DoubleDouble b) {
LIBC_INLINE constexpr DoubleDouble add(DoubleDouble a, DoubleDouble b) {
DoubleDouble r = exact_add(a.hi, b.hi);
double lo = a.lo + b.lo;
return exact_add(r.hi, r.lo + lo);
}

// Assumption: |a.hi| >= |b|
constexpr inline DoubleDouble add(DoubleDouble a, double b) {
LIBC_INLINE constexpr DoubleDouble add(DoubleDouble a, double b) {
DoubleDouble r = exact_add(a.hi, b);
return exact_add(r.hi, r.lo + a.lo);
}

// TODO(lntue): add a correct multiplication when FMA instructions are not
// available.
inline DoubleDouble exact_mult(double a, double b) {
LIBC_INLINE DoubleDouble exact_mult(double a, double b) {
DoubleDouble r{0.0, 0.0};
r.hi = a * b;
r.lo = fputil::multiply_add(a, b, -r.hi);
Expand Down
26 changes: 10 additions & 16 deletions libc/src/__support/OSUtil/linux/aarch64/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,52 +44,46 @@

namespace __llvm_libc {

__attribute__((always_inline)) inline long syscall_impl(long number) {
LIBC_INLINE long syscall_impl(long number) {
REGISTER_DECL_0;
SYSCALL_INSTR(REGISTER_CONSTRAINT_0);
return x0;
}

__attribute__((always_inline)) inline long syscall_impl(long number,
long arg1) {
LIBC_INLINE long syscall_impl(long number, long arg1) {
REGISTER_DECL_1;
SYSCALL_INSTR(REGISTER_CONSTRAINT_1);
return x0;
}

__attribute__((always_inline)) inline long syscall_impl(long number, long arg1,
long arg2) {
LIBC_INLINE long syscall_impl(long number, long arg1, long arg2) {
REGISTER_DECL_2;
SYSCALL_INSTR(REGISTER_CONSTRAINT_2);
return x0;
}

__attribute__((always_inline)) inline long syscall_impl(long number, long arg1,
long arg2, long arg3) {
LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3) {
REGISTER_DECL_3;
SYSCALL_INSTR(REGISTER_CONSTRAINT_3);
return x0;
}

__attribute__((always_inline)) inline long
syscall_impl(long number, long arg1, long arg2, long arg3, long arg4) {
LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3,
long arg4) {
REGISTER_DECL_4;
SYSCALL_INSTR(REGISTER_CONSTRAINT_4);
return x0;
}

__attribute__((always_inline)) inline long syscall_impl(long number, long arg1,
long arg2, long arg3,
long arg4, long arg5) {
LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3,
long arg4, long arg5) {
REGISTER_DECL_5;
SYSCALL_INSTR(REGISTER_CONSTRAINT_5);
return x0;
}

__attribute__((always_inline)) inline long syscall_impl(long number, long arg1,
long arg2, long arg3,
long arg4, long arg5,
long arg6) {
LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3,
long arg4, long arg5, long arg6) {
REGISTER_DECL_6;
SYSCALL_INSTR(REGISTER_CONSTRAINT_6);
return x0;
Expand Down
26 changes: 10 additions & 16 deletions libc/src/__support/OSUtil/linux/arm/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,52 +50,46 @@

namespace __llvm_libc {

__attribute__((always_inline)) inline long syscall_impl(long number) {
LIBC_INLINE long syscall_impl(long number) {
REGISTER_DECL_0;
SYSCALL_INSTR(REGISTER_CONSTRAINT_0);
return r0;
}

__attribute__((always_inline)) inline long syscall_impl(long number,
long arg1) {
LIBC_INLINE long syscall_impl(long number, long arg1) {
REGISTER_DECL_1;
SYSCALL_INSTR(REGISTER_CONSTRAINT_1);
return r0;
}

__attribute__((always_inline)) inline long syscall_impl(long number, long arg1,
long arg2) {
LIBC_INLINE long syscall_impl(long number, long arg1, long arg2) {
REGISTER_DECL_2;
SYSCALL_INSTR(REGISTER_CONSTRAINT_2);
return r0;
}

__attribute__((always_inline)) inline long syscall_impl(long number, long arg1,
long arg2, long arg3) {
LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3) {
REGISTER_DECL_3;
SYSCALL_INSTR(REGISTER_CONSTRAINT_3);
return r0;
}

__attribute__((always_inline)) inline long
syscall_impl(long number, long arg1, long arg2, long arg3, long arg4) {
LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3,
long arg4) {
REGISTER_DECL_4;
SYSCALL_INSTR(REGISTER_CONSTRAINT_4);
return r0;
}

__attribute__((always_inline)) inline long syscall_impl(long number, long arg1,
long arg2, long arg3,
long arg4, long arg5) {
LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3,
long arg4, long arg5) {
REGISTER_DECL_5;
SYSCALL_INSTR(REGISTER_CONSTRAINT_5);
return r0;
}

__attribute__((always_inline)) inline long syscall_impl(long number, long arg1,
long arg2, long arg3,
long arg4, long arg5,
long arg6) {
LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3,
long arg4, long arg5, long arg6) {
REGISTER_DECL_6;
SYSCALL_INSTR(REGISTER_CONSTRAINT_6);
return r0;
Expand Down
28 changes: 12 additions & 16 deletions libc/src/__support/OSUtil/linux/x86_64/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace __llvm_libc {

__attribute__((always_inline)) inline long syscall_impl(long __number) {
LIBC_INLINE long syscall_impl(long __number) {
long retcode;
LIBC_INLINE_ASM("syscall"
: "=a"(retcode)
Expand All @@ -24,8 +24,7 @@ __attribute__((always_inline)) inline long syscall_impl(long __number) {
return retcode;
}

__attribute__((always_inline)) inline long syscall_impl(long __number,
long __arg1) {
LIBC_INLINE long syscall_impl(long __number, long __arg1) {
long retcode;
LIBC_INLINE_ASM("syscall"
: "=a"(retcode)
Expand All @@ -34,8 +33,7 @@ __attribute__((always_inline)) inline long syscall_impl(long __number,
return retcode;
}

__attribute__((always_inline)) inline long
syscall_impl(long __number, long __arg1, long __arg2) {
LIBC_INLINE long syscall_impl(long __number, long __arg1, long __arg2) {
long retcode;
LIBC_INLINE_ASM("syscall"
: "=a"(retcode)
Expand All @@ -44,8 +42,8 @@ syscall_impl(long __number, long __arg1, long __arg2) {
return retcode;
}

__attribute__((always_inline)) inline long
syscall_impl(long __number, long __arg1, long __arg2, long __arg3) {
LIBC_INLINE long syscall_impl(long __number, long __arg1, long __arg2,
long __arg3) {
long retcode;
LIBC_INLINE_ASM("syscall"
: "=a"(retcode)
Expand All @@ -54,9 +52,8 @@ syscall_impl(long __number, long __arg1, long __arg2, long __arg3) {
return retcode;
}

__attribute__((always_inline)) inline long
syscall_impl(long __number, long __arg1, long __arg2, long __arg3,
long __arg4) {
LIBC_INLINE long syscall_impl(long __number, long __arg1, long __arg2,
long __arg3, long __arg4) {
long retcode;
register long r10 __asm__("r10") = __arg4;
LIBC_INLINE_ASM("syscall"
Expand All @@ -67,9 +64,8 @@ syscall_impl(long __number, long __arg1, long __arg2, long __arg3,
return retcode;
}

__attribute__((always_inline)) inline long
syscall_impl(long __number, long __arg1, long __arg2, long __arg3, long __arg4,
long __arg5) {
LIBC_INLINE long syscall_impl(long __number, long __arg1, long __arg2,
long __arg3, long __arg4, long __arg5) {
long retcode;
register long r10 __asm__("r10") = __arg4;
register long r8 __asm__("r8") = __arg5;
Expand All @@ -81,9 +77,9 @@ syscall_impl(long __number, long __arg1, long __arg2, long __arg3, long __arg4,
return retcode;
}

__attribute__((always_inline)) inline long
syscall_impl(long __number, long __arg1, long __arg2, long __arg3, long __arg4,
long __arg5, long __arg6) {
LIBC_INLINE long syscall_impl(long __number, long __arg1, long __arg2,
long __arg3, long __arg4, long __arg5,
long __arg6) {
long retcode;
register long r10 __asm__("r10") = __arg4;
register long r8 __asm__("r8") = __arg5;
Expand Down
38 changes: 20 additions & 18 deletions libc/src/__support/builtin_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,26 @@ template <typename T> LIBC_INLINE int correct_zero(T val, int bits) {
}

template <typename T> LIBC_INLINE int clz(T val);
template <> inline int clz<unsigned int>(unsigned int val) {
template <> LIBC_INLINE int clz<unsigned int>(unsigned int val) {
return __builtin_clz(val);
}
template <> inline int clz<unsigned long int>(unsigned long int val) {
template <> LIBC_INLINE int clz<unsigned long int>(unsigned long int val) {
return __builtin_clzl(val);
}
template <> inline int clz<unsigned long long int>(unsigned long long int val) {
template <>
LIBC_INLINE int clz<unsigned long long int>(unsigned long long int val) {
return __builtin_clzll(val);
}

template <typename T> LIBC_INLINE int ctz(T val);
template <> inline int ctz<unsigned int>(unsigned int val) {
template <> LIBC_INLINE int ctz<unsigned int>(unsigned int val) {
return __builtin_ctz(val);
}
template <> inline int ctz<unsigned long int>(unsigned long int val) {
template <> LIBC_INLINE int ctz<unsigned long int>(unsigned long int val) {
return __builtin_ctzl(val);
}
template <> inline int ctz<unsigned long long int>(unsigned long long int val) {
template <>
LIBC_INLINE int ctz<unsigned long long int>(unsigned long long int val) {
return __builtin_ctzll(val);
}
} // namespace __internal
Expand All @@ -73,7 +75,7 @@ template <typename T> LIBC_INLINE int unsafe_clz(T val) {
DEFINE_NAMED_PAIR_TEMPLATE(SumCarry, sum, carry);

template <typename T>
inline constexpr cpp::enable_if_t<
LIBC_INLINE constexpr cpp::enable_if_t<
cpp::is_integral_v<T> && cpp::is_unsigned_v<T>, SumCarry<T>>
add_with_carry(T a, T b, T carry_in) {
T tmp = a + carry_in;
Expand All @@ -86,7 +88,7 @@ add_with_carry(T a, T b, T carry_in) {
// https://clang.llvm.org/docs/LanguageExtensions.html#multiprecision-arithmetic-builtins

template <>
inline SumCarry<unsigned char>
LIBC_INLINE SumCarry<unsigned char>
add_with_carry<unsigned char>(unsigned char a, unsigned char b,
unsigned char carry_in) {
SumCarry<unsigned char> result{0, 0};
Expand All @@ -95,7 +97,7 @@ add_with_carry<unsigned char>(unsigned char a, unsigned char b,
}

template <>
inline SumCarry<unsigned short>
LIBC_INLINE SumCarry<unsigned short>
add_with_carry<unsigned short>(unsigned short a, unsigned short b,
unsigned short carry_in) {
SumCarry<unsigned short> result{0, 0};
Expand All @@ -104,7 +106,7 @@ add_with_carry<unsigned short>(unsigned short a, unsigned short b,
}

template <>
inline SumCarry<unsigned int>
LIBC_INLINE SumCarry<unsigned int>
add_with_carry<unsigned int>(unsigned int a, unsigned int b,
unsigned int carry_in) {
SumCarry<unsigned int> result{0, 0};
Expand All @@ -113,7 +115,7 @@ add_with_carry<unsigned int>(unsigned int a, unsigned int b,
}

template <>
inline SumCarry<unsigned long>
LIBC_INLINE SumCarry<unsigned long>
add_with_carry<unsigned long>(unsigned long a, unsigned long b,
unsigned long carry_in) {
SumCarry<unsigned long> result{0, 0};
Expand All @@ -122,7 +124,7 @@ add_with_carry<unsigned long>(unsigned long a, unsigned long b,
}

template <>
inline SumCarry<unsigned long long>
LIBC_INLINE SumCarry<unsigned long long>
add_with_carry<unsigned long long>(unsigned long long a, unsigned long long b,
unsigned long long carry_in) {
SumCarry<unsigned long long> result{0, 0};
Expand All @@ -136,7 +138,7 @@ add_with_carry<unsigned long long>(unsigned long long a, unsigned long long b,
DEFINE_NAMED_PAIR_TEMPLATE(DiffBorrow, diff, borrow);

template <typename T>
inline constexpr cpp::enable_if_t<
LIBC_INLINE constexpr cpp::enable_if_t<
cpp::is_integral_v<T> && cpp::is_unsigned_v<T>, DiffBorrow<T>>
sub_with_borrow(T a, T b, T borrow_in) {
T tmp = a - b;
Expand All @@ -149,7 +151,7 @@ sub_with_borrow(T a, T b, T borrow_in) {
// https://clang.llvm.org/docs/LanguageExtensions.html#multiprecision-arithmetic-builtins

template <>
inline DiffBorrow<unsigned char>
LIBC_INLINE DiffBorrow<unsigned char>
sub_with_borrow<unsigned char>(unsigned char a, unsigned char b,
unsigned char borrow_in) {
DiffBorrow<unsigned char> result{0, 0};
Expand All @@ -158,7 +160,7 @@ sub_with_borrow<unsigned char>(unsigned char a, unsigned char b,
}

template <>
inline DiffBorrow<unsigned short>
LIBC_INLINE DiffBorrow<unsigned short>
sub_with_borrow<unsigned short>(unsigned short a, unsigned short b,
unsigned short borrow_in) {
DiffBorrow<unsigned short> result{0, 0};
Expand All @@ -167,7 +169,7 @@ sub_with_borrow<unsigned short>(unsigned short a, unsigned short b,
}

template <>
inline DiffBorrow<unsigned int>
LIBC_INLINE DiffBorrow<unsigned int>
sub_with_borrow<unsigned int>(unsigned int a, unsigned int b,
unsigned int borrow_in) {
DiffBorrow<unsigned int> result{0, 0};
Expand All @@ -176,7 +178,7 @@ sub_with_borrow<unsigned int>(unsigned int a, unsigned int b,
}

template <>
inline DiffBorrow<unsigned long>
LIBC_INLINE DiffBorrow<unsigned long>
sub_with_borrow<unsigned long>(unsigned long a, unsigned long b,
unsigned long borrow_in) {
DiffBorrow<unsigned long> result{0, 0};
Expand All @@ -185,7 +187,7 @@ sub_with_borrow<unsigned long>(unsigned long a, unsigned long b,
}

template <>
inline DiffBorrow<unsigned long long>
LIBC_INLINE DiffBorrow<unsigned long long>
sub_with_borrow<unsigned long long>(unsigned long long a, unsigned long long b,
unsigned long long borrow_in) {
DiffBorrow<unsigned long long> result{0, 0};
Expand Down
35 changes: 19 additions & 16 deletions libc/src/__support/endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef LLVM_LIBC_SRC_SUPPORT_ENDIAN_H
#define LLVM_LIBC_SRC_SUPPORT_ENDIAN_H

#include "common.h"

#include <stdint.h>

namespace __llvm_libc {
Expand Down Expand Up @@ -37,98 +39,99 @@ template <unsigned ORDER> struct Endian {
// Little Endian specializations
template <>
template <>
inline uint8_t
LIBC_INLINE uint8_t
Endian<__ORDER_LITTLE_ENDIAN__>::to_big_endian<uint8_t>(uint8_t v) {
return v;
}
template <>
template <>
inline uint8_t
LIBC_INLINE uint8_t
Endian<__ORDER_LITTLE_ENDIAN__>::to_little_endian<uint8_t>(uint8_t v) {
return v;
}
template <>
template <>
inline uint16_t
LIBC_INLINE uint16_t
Endian<__ORDER_LITTLE_ENDIAN__>::to_big_endian<uint16_t>(uint16_t v) {
return __builtin_bswap16(v);
}
template <>
template <>
inline uint16_t
LIBC_INLINE uint16_t
Endian<__ORDER_LITTLE_ENDIAN__>::to_little_endian<uint16_t>(uint16_t v) {
return v;
}
template <>
template <>
inline uint32_t
LIBC_INLINE uint32_t
Endian<__ORDER_LITTLE_ENDIAN__>::to_big_endian<uint32_t>(uint32_t v) {
return __builtin_bswap32(v);
}
template <>
template <>
inline uint32_t
LIBC_INLINE uint32_t
Endian<__ORDER_LITTLE_ENDIAN__>::to_little_endian<uint32_t>(uint32_t v) {
return v;
}
template <>
template <>
inline uint64_t
LIBC_INLINE uint64_t
Endian<__ORDER_LITTLE_ENDIAN__>::to_big_endian<uint64_t>(uint64_t v) {
return __builtin_bswap64(v);
}
template <>
template <>
inline uint64_t
LIBC_INLINE uint64_t
Endian<__ORDER_LITTLE_ENDIAN__>::to_little_endian<uint64_t>(uint64_t v) {
return v;
}

// Big Endian specializations
template <>
template <>
inline uint8_t Endian<__ORDER_BIG_ENDIAN__>::to_big_endian<uint8_t>(uint8_t v) {
LIBC_INLINE uint8_t
Endian<__ORDER_BIG_ENDIAN__>::to_big_endian<uint8_t>(uint8_t v) {
return v;
}
template <>
template <>
inline uint8_t
LIBC_INLINE uint8_t
Endian<__ORDER_BIG_ENDIAN__>::to_little_endian<uint8_t>(uint8_t v) {
return v;
}
template <>
template <>
inline uint16_t
LIBC_INLINE uint16_t
Endian<__ORDER_BIG_ENDIAN__>::to_big_endian<uint16_t>(uint16_t v) {
return v;
}
template <>
template <>
inline uint16_t
LIBC_INLINE uint16_t
Endian<__ORDER_BIG_ENDIAN__>::to_little_endian<uint16_t>(uint16_t v) {
return __builtin_bswap16(v);
}
template <>
template <>
inline uint32_t
LIBC_INLINE uint32_t
Endian<__ORDER_BIG_ENDIAN__>::to_big_endian<uint32_t>(uint32_t v) {
return v;
}
template <>
template <>
inline uint32_t
LIBC_INLINE uint32_t
Endian<__ORDER_BIG_ENDIAN__>::to_little_endian<uint32_t>(uint32_t v) {
return __builtin_bswap32(v);
}
template <>
template <>
inline uint64_t
LIBC_INLINE uint64_t
Endian<__ORDER_BIG_ENDIAN__>::to_big_endian<uint64_t>(uint64_t v) {
return v;
}
template <>
template <>
inline uint64_t
LIBC_INLINE uint64_t
Endian<__ORDER_BIG_ENDIAN__>::to_little_endian<uint64_t>(uint64_t v) {
return __builtin_bswap64(v);
}
Expand Down
1 change: 1 addition & 0 deletions libc/src/stdio/printf_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ add_object_library(
libc.src.__support.CPP.string_view
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.common
libc.src.__support.uint
libc.src.__support.uint128
libc.src.__support.integer_to_string
Expand Down
23 changes: 13 additions & 10 deletions libc/src/stdio/printf_core/float_dec_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "src/__support/FPUtil/FloatProperties.h"
#include "src/__support/UInt.h"
#include "src/__support/UInt128.h"
#include "src/__support/common.h"
#include "src/__support/float_to_string.h"
#include "src/__support/integer_to_string.h"
#include "src/stdio/printf_core/converter_utils.h"
Expand All @@ -31,8 +32,8 @@ namespace printf_core {
using MantissaInt = fputil::FPBits<long double>::UIntType;

// Returns true if value is divisible by 2^p.
constexpr inline bool multiple_of_power_of_2(const uint64_t value,
const uint32_t p) {
LIBC_INLINE constexpr bool multiple_of_power_of_2(const uint64_t value,
const uint32_t p) {
return (value & ((uint64_t(1) << p) - 1)) == 0;
}

Expand Down Expand Up @@ -491,9 +492,9 @@ class FloatWriter {
};

template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
int inline convert_float_decimal_typed(Writer *writer,
const FormatSection &to_conv,
fputil::FPBits<T> float_bits) {
LIBC_INLINE int convert_float_decimal_typed(Writer *writer,
const FormatSection &to_conv,
fputil::FPBits<T> float_bits) {
// signed because later we use -MANT_WIDTH
constexpr int32_t MANT_WIDTH = fputil::MantissaWidth<T>::VALUE;
bool is_negative = float_bits.get_sign();
Expand Down Expand Up @@ -634,9 +635,9 @@ int inline convert_float_decimal_typed(Writer *writer,
}

template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
int inline convert_float_dec_exp_typed(Writer *writer,
const FormatSection &to_conv,
fputil::FPBits<T> float_bits) {
LIBC_INLINE int convert_float_dec_exp_typed(Writer *writer,
const FormatSection &to_conv,
fputil::FPBits<T> float_bits) {
// signed because later we use -MANT_WIDTH
constexpr int32_t MANT_WIDTH = fputil::MantissaWidth<T>::VALUE;
bool is_negative = float_bits.get_sign();
Expand Down Expand Up @@ -793,7 +794,8 @@ int inline convert_float_dec_exp_typed(Writer *writer,
return WRITE_OK;
}

int inline convert_float_decimal(Writer *writer, const FormatSection &to_conv) {
LIBC_INLINE int convert_float_decimal(Writer *writer,
const FormatSection &to_conv) {
if (to_conv.length_modifier == LengthModifier::L) {
fputil::FPBits<long double>::UIntType float_raw = to_conv.conv_val_raw;
fputil::FPBits<long double> float_bits(float_raw);
Expand All @@ -812,7 +814,8 @@ int inline convert_float_decimal(Writer *writer, const FormatSection &to_conv) {
return convert_inf_nan(writer, to_conv);
}

int inline convert_float_dec_exp(Writer *writer, const FormatSection &to_conv) {
LIBC_INLINE int convert_float_dec_exp(Writer *writer,
const FormatSection &to_conv) {
if (to_conv.length_modifier == LengthModifier::L) {
fputil::FPBits<long double>::UIntType float_raw = to_conv.conv_val_raw;
fputil::FPBits<long double> float_bits(float_raw);
Expand Down
4 changes: 3 additions & 1 deletion libc/src/stdio/printf_core/float_hex_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "src/__support/CPP/string_view.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.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/float_inf_nan_converter.h"
Expand All @@ -25,7 +26,8 @@ namespace printf_core {

using MantissaInt = fputil::FPBits<long double>::UIntType;

int inline convert_float_hex_exp(Writer *writer, const FormatSection &to_conv) {
LIBC_INLINE int convert_float_hex_exp(Writer *writer,
const FormatSection &to_conv) {
// All of the letters will be defined relative to variable a, which will be
// the appropriate case based on the name of the conversion.
// Since the name of the conversion is also 'a', we can just use it directly.
Expand Down
3 changes: 2 additions & 1 deletion libc/src/stdio/printf_core/float_inf_nan_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_FLOAT_INF_NAN_CONVERTER_H

#include "src/__support/FPUtil/FPBits.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"
Expand All @@ -22,7 +23,7 @@ namespace printf_core {

using MantissaInt = fputil::FPBits<long double>::UIntType;

int inline convert_inf_nan(Writer *writer, const FormatSection &to_conv) {
LIBC_INLINE int convert_inf_nan(Writer *writer, const FormatSection &to_conv) {
// All of the letters will be defined relative to variable a, which will be
// the appropriate case based on the case of the conversion.
const char a = (to_conv.conv_name & 32) | 'A';
Expand Down
12 changes: 6 additions & 6 deletions libc/src/stdio/printf_core/int_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "src/__support/CPP/span.h"
#include "src/__support/CPP/string_view.h"
#include "src/__support/common.h"
#include "src/__support/integer_to_string.h"
#include "src/stdio/printf_core/converter_utils.h"
#include "src/stdio/printf_core/core_structs.h"
Expand All @@ -24,12 +25,11 @@ namespace printf_core {

// These functions only work on characters that are already known to be in the
// alphabet. Their behavior is undefined otherwise.
constexpr char inline to_lower(char a) { return a | 32; }
constexpr bool inline is_lower(char a) { return (a & 32) > 0; }
LIBC_INLINE constexpr char to_lower(char a) { return a | 32; }
LIBC_INLINE constexpr bool is_lower(char a) { return (a & 32) > 0; }

cpp::optional<cpp::string_view> inline num_to_strview(uintmax_t num,
cpp::span<char> bufref,
char conv_name) {
LIBC_INLINE cpp::optional<cpp::string_view>
num_to_strview(uintmax_t num, cpp::span<char> bufref, char conv_name) {
if (to_lower(conv_name) == 'x') {
return IntegerToString::hex(num, bufref, is_lower(conv_name));
} else if (conv_name == 'o') {
Expand All @@ -39,7 +39,7 @@ cpp::optional<cpp::string_view> inline num_to_strview(uintmax_t num,
}
}

int inline convert_int(Writer *writer, const FormatSection &to_conv) {
LIBC_INLINE int convert_int(Writer *writer, const FormatSection &to_conv) {
static constexpr size_t BITS_IN_BYTE = 8;
static constexpr size_t BITS_IN_NUM = sizeof(uintmax_t) * BITS_IN_BYTE;

Expand Down
3 changes: 2 additions & 1 deletion libc/src/stdio/printf_core/ptr_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_PTR_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/int_converter.h"
Expand All @@ -18,7 +19,7 @@
namespace __llvm_libc {
namespace printf_core {

int inline convert_pointer(Writer *writer, const FormatSection &to_conv) {
LIBC_INLINE int convert_pointer(Writer *writer, const FormatSection &to_conv) {
if (to_conv.conv_val_ptr == (void *)(nullptr)) {
RET_IF_RESULT_NEGATIVE(writer->write("(nullptr)"));
} else {
Expand Down
1 change: 1 addition & 0 deletions libc/src/sys/stat/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ add_header_library(
libc.include.sys_stat
libc.include.sys_syscall
libc.src.__support.OSUtil.osutil
libc.src.__support.common
libc.src.errno.errno
)

Expand Down
5 changes: 3 additions & 2 deletions libc/src/sys/stat/linux/kernel_statx.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLVM_LIBC_SRC_SYS_STAT_LINUX_STATX_H

#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"

#include <errno.h>
#include <stdint.h>
Expand Down Expand Up @@ -69,8 +70,8 @@ constexpr unsigned int STATX_BASIC_STATS_MASK = 0x7FF;

namespace __llvm_libc {

inline int statx(int dirfd, const char *__restrict path, int flags,
struct stat *__restrict statbuf) {
LIBC_INLINE int statx(int dirfd, const char *__restrict path, int flags,
struct stat *__restrict statbuf) {
// We make a statx syscall and copy out the result into the |statbuf|.
::statx_buf xbuf;
long ret = __llvm_libc::syscall_impl(SYS_statx, dirfd, path, flags,
Expand Down
6 changes: 5 additions & 1 deletion utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ libc_support_library(
libc_support_library(
name = "__support_cpp_string_view",
hdrs = ["src/__support/CPP/string_view.h"],
deps = [":libc_root"],
deps = [
":__support_common",
":libc_root",
],
)

libc_support_library(
Expand Down Expand Up @@ -393,6 +396,7 @@ libc_support_library(
name = "__support_fputil_normal_float",
hdrs = ["src/__support/FPUtil/NormalFloat.h"],
deps = [
":__support_common",
":__support_cpp_type_traits",
":__support_fputil_fp_bits",
":libc_root",
Expand Down