mirror of
https://github.com/intel/llvm.git
synced 2026-01-14 03:50:17 +08:00
[libc][NFC] Replace "inline" keyword with "LIBC_INLINE".
This is the first of patches doing similar cleanup. A section in the code style doc has been added explaining where and how LIBC_INLINE is to be used. Reviewed By: jeffbailey, lntue Differential Revision: https://reviews.llvm.org/D142434
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
The libc code style
|
||||
===================
|
||||
|
||||
Naming style
|
||||
============
|
||||
|
||||
For the large part, the libc project follows the general `coding standards of
|
||||
the LLVM project <https://llvm.org/docs/CodingStandards.html>`_. The libc
|
||||
project differs from that standard with respect to the naming style. The
|
||||
@@ -17,6 +20,27 @@ differences are as follows:
|
||||
#. **Function and methods** - They use the ``snake_case`` style like the
|
||||
non-const variables.
|
||||
#. **Internal type names** - These are types which are interal to the libc
|
||||
implementation. They use the `CaptilizedCamelCase` style.
|
||||
implementation. They use the ``CaptilizedCamelCase`` style.
|
||||
#. **Public names** - These are the names as prescribed by the standards and
|
||||
will follow the style as prescribed by the standards.
|
||||
|
||||
Inline functions defined in header files
|
||||
========================================
|
||||
|
||||
When defining functions inline in header files, we follow certain rules:
|
||||
|
||||
#. The functions should not be given file-static linkage. There can be class
|
||||
static methods defined inline however.
|
||||
#. Instead of using the ``inline`` keyword, they should be tagged with the
|
||||
``LIBC_INLINE`` macro defined in ``src/__support/common.h``. For example:
|
||||
|
||||
.. code-block:: c++
|
||||
|
||||
LIBC_INLINE ReturnType function_defined_inline(ArgType arg) {
|
||||
...
|
||||
}
|
||||
|
||||
#. The ``LIBC_INLINE`` tag should also be added to functions which have
|
||||
definitions that are implicitly inline. Examples of such functions are
|
||||
class methods (static and non-static) defined inline and ``constexpr``
|
||||
functions.
|
||||
|
||||
@@ -51,6 +51,8 @@ add_header_library(
|
||||
string_view
|
||||
HDRS
|
||||
string_view.h
|
||||
DEPENDS
|
||||
libc.src.__support.common
|
||||
)
|
||||
|
||||
add_header_library(
|
||||
@@ -101,4 +103,5 @@ add_object_library(
|
||||
new.h
|
||||
DEPENDS
|
||||
libc.include.stdlib
|
||||
libc.src.__support.common
|
||||
)
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_NEW_H
|
||||
#define LLVM_LIBC_SRC_SUPPORT_CPP_NEW_H
|
||||
|
||||
#include "src/__support/common.h"
|
||||
|
||||
#include <stddef.h> // For size_t
|
||||
#include <stdlib.h> // For malloc, free etc.
|
||||
|
||||
@@ -34,14 +36,14 @@ public:
|
||||
AllocChecker() = default;
|
||||
operator bool() const { return success; }
|
||||
|
||||
static void *alloc(size_t s, AllocChecker &ac) {
|
||||
LIBC_INLINE static void *alloc(size_t s, AllocChecker &ac) {
|
||||
void *mem = ::malloc(s);
|
||||
ac = (mem != nullptr);
|
||||
return mem;
|
||||
}
|
||||
|
||||
static void *aligned_alloc(size_t s, std::align_val_t align,
|
||||
AllocChecker &ac) {
|
||||
LIBC_INLINE static void *aligned_alloc(size_t s, std::align_val_t align,
|
||||
AllocChecker &ac) {
|
||||
void *mem = ::aligned_alloc(static_cast<size_t>(align), s);
|
||||
ac = (mem != nullptr);
|
||||
return mem;
|
||||
@@ -50,27 +52,28 @@ public:
|
||||
|
||||
} // namespace __llvm_libc
|
||||
|
||||
inline void *operator new(size_t size, __llvm_libc::AllocChecker &ac) noexcept {
|
||||
LIBC_INLINE void *operator new(size_t size,
|
||||
__llvm_libc::AllocChecker &ac) noexcept {
|
||||
return __llvm_libc::AllocChecker::alloc(size, ac);
|
||||
}
|
||||
|
||||
inline void *operator new(size_t size, std::align_val_t align,
|
||||
__llvm_libc::AllocChecker &ac) noexcept {
|
||||
LIBC_INLINE void *operator new(size_t size, std::align_val_t align,
|
||||
__llvm_libc::AllocChecker &ac) noexcept {
|
||||
return __llvm_libc::AllocChecker::aligned_alloc(size, align, ac);
|
||||
}
|
||||
|
||||
inline void *operator new[](size_t size,
|
||||
__llvm_libc::AllocChecker &ac) noexcept {
|
||||
LIBC_INLINE void *operator new[](size_t size,
|
||||
__llvm_libc::AllocChecker &ac) noexcept {
|
||||
return __llvm_libc::AllocChecker::alloc(size, ac);
|
||||
}
|
||||
|
||||
inline void *operator new[](size_t size, std::align_val_t align,
|
||||
__llvm_libc::AllocChecker &ac) noexcept {
|
||||
LIBC_INLINE void *operator new[](size_t size, std::align_val_t align,
|
||||
__llvm_libc::AllocChecker &ac) noexcept {
|
||||
return __llvm_libc::AllocChecker::aligned_alloc(size, align, ac);
|
||||
}
|
||||
|
||||
// The ideal situation would be to define the various flavors of operator delete
|
||||
// inline like we do with operator new above. However, since we need operator
|
||||
// inlinelike we do with operator new above. However, since we need operator
|
||||
// delete prototypes to match those specified by the C++ standard, we cannot
|
||||
// define them inline as the C++ standard does not allow inline definitions of
|
||||
// replacement operator delete implementations. Note also that we assign a
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_STRINGVIEW_H
|
||||
#define LLVM_LIBC_SRC_SUPPORT_CPP_STRINGVIEW_H
|
||||
|
||||
#include "src/__support/common.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace __llvm_libc {
|
||||
@@ -26,20 +28,21 @@ private:
|
||||
|
||||
static size_t min(size_t A, size_t B) { return A <= B ? A : B; }
|
||||
|
||||
static int compareMemory(const char *Lhs, const char *Rhs, size_t Length) {
|
||||
LIBC_INLINE static int compareMemory(const char *Lhs, const char *Rhs,
|
||||
size_t Length) {
|
||||
for (size_t I = 0; I < Length; ++I)
|
||||
if (int Diff = (int)Lhs[I] - (int)Rhs[I])
|
||||
return Diff;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static constexpr size_t length(const char *Str) {
|
||||
LIBC_INLINE static constexpr size_t length(const char *Str) {
|
||||
for (const char *End = Str;; ++End)
|
||||
if (*End == '\0')
|
||||
return End - Str;
|
||||
}
|
||||
|
||||
bool equals(string_view Other) const {
|
||||
LIBC_INLINE bool equals(string_view Other) const {
|
||||
return (Len == Other.Len &&
|
||||
compareMemory(Data, Other.Data, Other.Len) == 0);
|
||||
}
|
||||
@@ -59,39 +62,43 @@ public:
|
||||
// size_type.
|
||||
inline static constexpr size_t npos = -1;
|
||||
|
||||
constexpr string_view() : Data(nullptr), Len(0) {}
|
||||
LIBC_INLINE constexpr string_view() : Data(nullptr), Len(0) {}
|
||||
|
||||
// Assumes Str is a null-terminated string. The length of the string does
|
||||
// not include the terminating null character.
|
||||
// Preconditions: [Str, Str + length(Str)) is a valid range.
|
||||
constexpr string_view(const char *Str) : Data(Str), Len(length(Str)) {}
|
||||
LIBC_INLINE constexpr string_view(const char *Str)
|
||||
: Data(Str), Len(length(Str)) {}
|
||||
|
||||
// Preconditions: [Str, Str + N) is a valid range.
|
||||
constexpr string_view(const char *Str, size_t N) : Data(Str), Len(N) {}
|
||||
LIBC_INLINE constexpr string_view(const char *Str, size_t N)
|
||||
: Data(Str), Len(N) {}
|
||||
|
||||
constexpr const char *data() const { return Data; }
|
||||
LIBC_INLINE constexpr const char *data() const { return Data; }
|
||||
|
||||
// Returns the size of the string_view.
|
||||
constexpr size_t size() const { return Len; }
|
||||
LIBC_INLINE constexpr size_t size() const { return Len; }
|
||||
|
||||
// Returns whether the string_view is empty.
|
||||
constexpr bool empty() const { return Len == 0; }
|
||||
LIBC_INLINE constexpr bool empty() const { return Len == 0; }
|
||||
|
||||
// Returns an iterator to the first character of the view.
|
||||
const char *begin() const { return Data; }
|
||||
LIBC_INLINE const char *begin() const { return Data; }
|
||||
|
||||
// Returns an iterator to the character following the last character of the
|
||||
// view.
|
||||
const char *end() const { return Data + Len; }
|
||||
LIBC_INLINE const char *end() const { return Data + Len; }
|
||||
|
||||
// Returns a const reference to the character at specified location pos.
|
||||
// No bounds checking is performed: the behavior is undefined if pos >=
|
||||
// size().
|
||||
constexpr const char &operator[](size_t Index) const { return Data[Index]; }
|
||||
LIBC_INLINE constexpr const char &operator[](size_t Index) const {
|
||||
return Data[Index];
|
||||
}
|
||||
|
||||
/// compare - Compare two strings; the result is -1, 0, or 1 if this string
|
||||
/// is lexicographically less than, equal to, or greater than the \p Other.
|
||||
int compare(string_view Other) const {
|
||||
LIBC_INLINE int compare(string_view Other) const {
|
||||
// Check the prefix for a mismatch.
|
||||
if (int Res = compareMemory(Data, Other.Data, min(Len, Other.Len)))
|
||||
return Res < 0 ? -1 : 1;
|
||||
@@ -101,48 +108,52 @@ public:
|
||||
return Len < Other.Len ? -1 : 1;
|
||||
}
|
||||
|
||||
inline bool operator==(string_view Other) const { return equals(Other); }
|
||||
inline bool operator!=(string_view Other) const { return !(*this == Other); }
|
||||
inline bool operator<(string_view Other) const {
|
||||
LIBC_INLINE bool operator==(string_view Other) const { return equals(Other); }
|
||||
LIBC_INLINE bool operator!=(string_view Other) const {
|
||||
return !(*this == Other);
|
||||
}
|
||||
LIBC_INLINE bool operator<(string_view Other) const {
|
||||
return compare(Other) == -1;
|
||||
}
|
||||
inline bool operator<=(string_view Other) const {
|
||||
LIBC_INLINE bool operator<=(string_view Other) const {
|
||||
return compare(Other) != 1;
|
||||
}
|
||||
inline bool operator>(string_view Other) const { return compare(Other) == 1; }
|
||||
inline bool operator>=(string_view Other) const {
|
||||
LIBC_INLINE bool operator>(string_view Other) const {
|
||||
return compare(Other) == 1;
|
||||
}
|
||||
LIBC_INLINE bool operator>=(string_view Other) const {
|
||||
return compare(Other) != -1;
|
||||
}
|
||||
|
||||
// Moves the start of the view forward by n characters.
|
||||
// The behavior is undefined if n > size().
|
||||
void remove_prefix(size_t N) {
|
||||
LIBC_INLINE void remove_prefix(size_t N) {
|
||||
Len -= N;
|
||||
Data += N;
|
||||
}
|
||||
|
||||
// Moves the end of the view back by n characters.
|
||||
// The behavior is undefined if n > size().
|
||||
void remove_suffix(size_t N) { Len -= N; }
|
||||
LIBC_INLINE void remove_suffix(size_t N) { Len -= N; }
|
||||
|
||||
// Check if this string starts with the given Prefix.
|
||||
bool starts_with(string_view Prefix) const {
|
||||
LIBC_INLINE bool starts_with(string_view Prefix) const {
|
||||
return Len >= Prefix.Len &&
|
||||
compareMemory(Data, Prefix.Data, Prefix.Len) == 0;
|
||||
}
|
||||
|
||||
// Check if this string starts with the given Prefix.
|
||||
bool starts_with(const char Prefix) const {
|
||||
LIBC_INLINE bool starts_with(const char Prefix) const {
|
||||
return !empty() && front() == Prefix;
|
||||
}
|
||||
|
||||
// Check if this string ends with the given Prefix.
|
||||
bool ends_with(const char Suffix) const {
|
||||
LIBC_INLINE bool ends_with(const char Suffix) const {
|
||||
return !empty() && back() == Suffix;
|
||||
}
|
||||
|
||||
// Check if this string ends with the given Suffix.
|
||||
bool ends_with(string_view Suffix) const {
|
||||
LIBC_INLINE bool ends_with(string_view Suffix) const {
|
||||
return Len >= Suffix.Len &&
|
||||
compareMemory(end() - Suffix.Len, Suffix.Data, Suffix.Len) == 0;
|
||||
}
|
||||
@@ -156,19 +167,19 @@ public:
|
||||
// N The number of characters to included in the substring. If N exceeds the
|
||||
// number of characters remaining in the string, the string suffix (starting
|
||||
// with Start) will be returned.
|
||||
string_view substr(size_t Start, size_t N = npos) const {
|
||||
LIBC_INLINE string_view substr(size_t Start, size_t N = npos) const {
|
||||
Start = min(Start, Len);
|
||||
return string_view(Data + Start, min(N, Len - Start));
|
||||
}
|
||||
|
||||
// front - Get the first character in the string.
|
||||
char front() const { return Data[0]; }
|
||||
LIBC_INLINE char front() const { return Data[0]; }
|
||||
|
||||
// back - Get the last character in the string.
|
||||
char back() const { return Data[Len - 1]; }
|
||||
LIBC_INLINE char back() const { return Data[Len - 1]; }
|
||||
|
||||
// Finds the first occurence of c in this view, starting at position From.
|
||||
size_t find_first_of(const char c, size_t From = 0) const {
|
||||
LIBC_INLINE size_t find_first_of(const char c, size_t From = 0) const {
|
||||
for (size_t Pos = From; Pos < size(); ++Pos)
|
||||
if ((*this)[Pos] == c)
|
||||
return Pos;
|
||||
@@ -176,7 +187,7 @@ public:
|
||||
}
|
||||
|
||||
// Finds the last occurence of c in this view, ending at position End.
|
||||
size_t find_last_of(const char c, size_t End = npos) const {
|
||||
LIBC_INLINE size_t find_last_of(const char c, size_t End = npos) const {
|
||||
End = End >= size() ? size() : End + 1;
|
||||
for (; End > 0; --End)
|
||||
if ((*this)[End - 1] == c)
|
||||
|
||||
@@ -59,6 +59,7 @@ add_header_library(
|
||||
DEPENDS
|
||||
.fp_bits
|
||||
libc.src.__support.CPP.type_traits
|
||||
libc.src.__support.common
|
||||
)
|
||||
|
||||
add_header_library(
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "FPBits.h"
|
||||
|
||||
#include "src/__support/CPP/type_traits.h"
|
||||
#include "src/__support/common.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -44,7 +45,7 @@ template <typename T> struct NormalFloat {
|
||||
|
||||
bool sign;
|
||||
|
||||
NormalFloat(int32_t e, UIntType m, bool s)
|
||||
LIBC_INLINE NormalFloat(int32_t e, UIntType m, bool s)
|
||||
: exponent(e), mantissa(m), sign(s) {
|
||||
if (mantissa >= ONE)
|
||||
return;
|
||||
@@ -54,14 +55,14 @@ template <typename T> struct NormalFloat {
|
||||
exponent -= normalization_shift;
|
||||
}
|
||||
|
||||
explicit NormalFloat(T x) { init_from_bits(FPBits<T>(x)); }
|
||||
LIBC_INLINE explicit NormalFloat(T x) { init_from_bits(FPBits<T>(x)); }
|
||||
|
||||
explicit NormalFloat(FPBits<T> bits) { init_from_bits(bits); }
|
||||
LIBC_INLINE explicit NormalFloat(FPBits<T> bits) { init_from_bits(bits); }
|
||||
|
||||
// Compares this normalized number with another normalized number.
|
||||
// Returns -1 is this number is less than |other|, 0 if this number is equal
|
||||
// to |other|, and 1 if this number is greater than |other|.
|
||||
int cmp(const NormalFloat<T> &other) const {
|
||||
LIBC_INLINE int cmp(const NormalFloat<T> &other) const {
|
||||
if (sign != other.sign)
|
||||
return sign ? -1 : 1;
|
||||
|
||||
@@ -82,13 +83,13 @@ template <typename T> struct NormalFloat {
|
||||
// Returns a new normalized floating point number which is equal in value
|
||||
// to this number multiplied by 2^e. That is:
|
||||
// new = this * 2^e
|
||||
NormalFloat<T> mul2(int e) const {
|
||||
LIBC_INLINE NormalFloat<T> mul2(int e) const {
|
||||
NormalFloat<T> result = *this;
|
||||
result.exponent += e;
|
||||
return result;
|
||||
}
|
||||
|
||||
operator T() const {
|
||||
LIBC_INLINE operator T() const {
|
||||
int biased_exponent = exponent + FPBits<T>::EXPONENT_BIAS;
|
||||
// Max exponent is of the form 0xFF...E. That is why -2 and not -1.
|
||||
constexpr int MAX_EXPONENT_VALUE = (1 << ExponentWidth<T>::VALUE) - 2;
|
||||
@@ -138,7 +139,7 @@ template <typename T> struct NormalFloat {
|
||||
}
|
||||
|
||||
private:
|
||||
void init_from_bits(FPBits<T> bits) {
|
||||
LIBC_INLINE void init_from_bits(FPBits<T> bits) {
|
||||
sign = bits.get_sign();
|
||||
|
||||
if (bits.is_inf_or_nan() || bits.is_zero()) {
|
||||
@@ -160,7 +161,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
unsigned evaluate_normalization_shift(UIntType m) {
|
||||
LIBC_INLINE unsigned evaluate_normalization_shift(UIntType m) {
|
||||
unsigned shift = 0;
|
||||
for (; (ONE & m) == 0 && (shift < MantissaWidth<T>::VALUE);
|
||||
m <<= 1, ++shift)
|
||||
@@ -171,7 +172,8 @@ private:
|
||||
|
||||
#ifdef SPECIAL_X86_LONG_DOUBLE
|
||||
template <>
|
||||
inline void NormalFloat<long double>::init_from_bits(FPBits<long double> bits) {
|
||||
LIBC_INLINE void
|
||||
NormalFloat<long double>::init_from_bits(FPBits<long double> bits) {
|
||||
sign = bits.get_sign();
|
||||
|
||||
if (bits.is_inf_or_nan() || bits.is_zero()) {
|
||||
@@ -205,7 +207,7 @@ inline void NormalFloat<long double>::init_from_bits(FPBits<long double> bits) {
|
||||
}
|
||||
}
|
||||
|
||||
template <> inline NormalFloat<long double>::operator long double() const {
|
||||
template <> LIBC_INLINE NormalFloat<long double>::operator long double() const {
|
||||
int biased_exponent = exponent + FPBits<long double>::EXPONENT_BIAS;
|
||||
// Max exponent is of the form 0xFF...E. That is why -2 and not -1.
|
||||
constexpr int MAX_EXPONENT_VALUE =
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#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 {
|
||||
@@ -17,7 +18,7 @@ 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;
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
@@ -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"
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
@@ -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};
|
||||
@@ -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};
|
||||
@@ -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};
|
||||
@@ -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};
|
||||
@@ -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};
|
||||
@@ -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;
|
||||
@@ -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};
|
||||
@@ -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};
|
||||
@@ -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};
|
||||
@@ -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};
|
||||
@@ -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};
|
||||
|
||||
@@ -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 {
|
||||
@@ -37,49 +39,49 @@ 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;
|
||||
}
|
||||
@@ -87,48 +89,49 @@ Endian<__ORDER_LITTLE_ENDIAN__>::to_little_endian<uint64_t>(uint64_t 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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -491,9 +492,9 @@ public:
|
||||
};
|
||||
|
||||
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();
|
||||
@@ -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();
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
|
||||
@@ -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"
|
||||
@@ -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.
|
||||
|
||||
@@ -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"
|
||||
@@ -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';
|
||||
|
||||
@@ -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"
|
||||
@@ -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') {
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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"
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
|
||||
@@ -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>
|
||||
@@ -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,
|
||||
|
||||
@@ -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(
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user