Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions libc/src/__support/endian_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ template <> LIBC_INLINE uint16_t byte_swap<uint16_t>(uint16_t value) {
#if __has_builtin(__builtin_bswap16)
return __builtin_bswap16(value);
#else
return (v << 8) | (v >> 8);
return (value << 8) | (value >> 8);
#endif // __builtin_bswap16
}

template <> LIBC_INLINE uint32_t byte_swap<uint32_t>(uint32_t value) {
#if __has_builtin(__builtin_bswap32)
return __builtin_bswap32(value);
#else
return byte_swap<uint16_t>(static_cast<uint16>(v >> 16)) ||
(static_cast<uint32_t>(byte_swap<uint16_t>(static_cast<uint16_t>(v)))
return byte_swap<uint16_t>(static_cast<uint16_t>(value >> 16)) ||
(static_cast<uint32_t>(
byte_swap<uint16_t>(static_cast<uint16_t>(value)))
<< 16);
#endif // __builtin_bswap64
}
Expand All @@ -53,8 +54,9 @@ template <> LIBC_INLINE uint64_t byte_swap<uint64_t>(uint64_t value) {
#if __has_builtin(__builtin_bswap64)
return __builtin_bswap64(value);
#else
return byte_swap<uint32_t>(static_cast<uint32>(v >> 32)) ||
(static_cast<uint64_t>(byte_swap<uint32_t>(static_cast<uint32_t>(v)))
return byte_swap<uint32_t>(static_cast<uint32_t>(value >> 32)) ||
(static_cast<uint64_t>(
byte_swap<uint32_t>(static_cast<uint32_t>(value)))
<< 32);
#endif // __builtin_bswap64
}
Expand Down
2 changes: 2 additions & 0 deletions libc/src/__support/macros/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
#define __builtin_expect(value, expectation) (value)
#define __builtin_unreachable() __assume(0)

#define __builtin_prefetch(X, Y, Z)

#endif // LIBC_COMPILER_IS_MSVC

#ifdef __clang__
Expand Down
1 change: 1 addition & 0 deletions libc/src/string/memory_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ add_header_library(
libc.src.__support.macros.config
libc.src.__support.macros.optimization
libc.src.__support.macros.properties.architectures
libc.src.__support.macros.properties.compiler
)

add_header_library(
Expand Down
11 changes: 11 additions & 0 deletions libc/src/string/memory_utils/op_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
#include "src/__support/macros/optimization.h"
#include "src/__support/macros/properties/compiler.h"
#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT64
#include "src/string/memory_utils/op_builtin.h"
#include "src/string/memory_utils/utils.h"
Expand All @@ -39,12 +40,22 @@ static_assert((UINTPTR_MAX == 4294967295U) ||
(UINTPTR_MAX == 18446744073709551615UL),
"We currently only support 32- or 64-bit platforms");

#ifdef LIBC_COMPILER_IS_MSVC

namespace LIBC_NAMESPACE_DECL {
using generic_v128 = __m128i;
using generic_v256 = __m256i;
using generic_v512 = __m512i;
} // namespace LIBC_NAMESPACE_DECL

#else
namespace LIBC_NAMESPACE_DECL {
// Compiler types using the vector attributes.
using generic_v128 = uint8_t __attribute__((__vector_size__(16)));
using generic_v256 = uint8_t __attribute__((__vector_size__(32)));
using generic_v512 = uint8_t __attribute__((__vector_size__(64)));
} // namespace LIBC_NAMESPACE_DECL
#endif // LIBC_COMPILER_IS_MSVC

namespace LIBC_NAMESPACE_DECL {
namespace generic {
Expand Down
10 changes: 10 additions & 0 deletions libc/src/string/memory_utils/op_x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
#include "src/__support/macros/properties/architectures.h"
#include "src/__support/macros/properties/compiler.h"

#if defined(LIBC_TARGET_ARCH_IS_X86)

Expand Down Expand Up @@ -57,7 +58,12 @@ LIBC_INLINE_VAR constexpr bool K_AVX512_BW = LLVM_LIBC_IS_DEFINED(__AVX512BW__);
// Memcpy repmovsb implementation
struct Memcpy {
LIBC_INLINE static void repmovsb(void *dst, const void *src, size_t count) {
#ifdef LIBC_COMPILER_IS_MSVC
__movsb(static_cast<unsigned char *>(dst),
static_cast<const unsigned char *>(src), count);
#else
asm volatile("rep movsb" : "+D"(dst), "+S"(src), "+c"(count) : : "memory");
#endif // LIBC_COMPILER_IS_MSVC
}
};

Expand Down Expand Up @@ -138,8 +144,10 @@ LIBC_INLINE MemcmpReturnType cmp_neq<uint64_t>(CPtr p1, CPtr p2,
// When we use these SIMD types in template specialization GCC complains:
// "ignoring attributes on template argument ‘__m128i’ [-Wignored-attributes]"
// Therefore, we disable this warning in this file.
#ifndef LIBC_COMPILER_IS_MSVC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wignored-attributes"
#endif // !LIBC_COMPILER_IS_MSVC

///////////////////////////////////////////////////////////////////////////////
// Specializations for __m128i
Expand Down Expand Up @@ -366,7 +374,9 @@ LIBC_INLINE MemcmpReturnType cmp_neq<__m512i>(CPtr p1, CPtr p2, size_t offset) {
}
#endif // __AVX512BW__

#ifndef LIBC_COMPILER_IS_MSVC
#pragma GCC diagnostic pop
#endif // !LIBC_COMPILER_IS_MSVC

} // namespace generic
} // namespace LIBC_NAMESPACE_DECL
Expand Down
5 changes: 5 additions & 0 deletions libc/src/string/memory_utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
#include "src/__support/macros/properties/architectures.h"
#include "src/__support/macros/properties/compiler.h"

#include <stddef.h> // size_t

Expand Down Expand Up @@ -90,13 +91,17 @@ LIBC_INLINE void memcpy_inline(void *__restrict dst,
// different value of the Size parameter. This doesn't play well with GCC's
// Value Range Analysis that wrongly detects out of bounds accesses. We
// disable these warnings for the purpose of this function.
#ifndef LIBC_COMPILER_IS_MSVC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
#pragma GCC diagnostic ignored "-Wstringop-overread"
#pragma GCC diagnostic ignored "-Wstringop-overflow"
#endif // !LIBC_COMPILER_IS_MSVC
for (size_t i = 0; i < Size; ++i)
static_cast<char *>(dst)[i] = static_cast<const char *>(src)[i];
#ifndef LIBC_COMPILER_IS_MSVC
#pragma GCC diagnostic pop
#endif // !LIBC_COMPILER_IS_MSVC
#endif
}

Expand Down
1 change: 1 addition & 0 deletions libc/test/UnitTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ add_unittest_framework_library(
libc.src.__support.CPP.string_view
libc.src.__support.CPP.type_traits
libc.src.__support.fixed_point.fx_rep
libc.src.__support.macros.properties.compiler
libc.src.__support.macros.properties.types
libc.src.__support.OSUtil.osutil
libc.src.__support.uint128
Expand Down
5 changes: 5 additions & 0 deletions libc/test/UnitTest/LibcTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "src/__support/CPP/string_view.h"
#include "src/__support/CPP/type_traits.h"
#include "src/__support/c_string.h"
#include "src/__support/macros/properties/compiler.h"
#include "test/UnitTest/ExecuteFunction.h"
#include "test/UnitTest/TestLogger.h"

Expand Down Expand Up @@ -260,7 +261,11 @@ constexpr char const *GetPrettyFunctionParamType(char const *str) {
// This function recovers ParamType at compile time by using __PRETTY_FUNCTION__
// It can be customized by using the REGISTER_TYPE_NAME macro below.
template <typename ParamType> static constexpr const char *GetTypeName() {
#ifdef LIBC_COMPILER_IS_MSVC
return GetPrettyFunctionParamType(__FUNCSIG__);
#else
return GetPrettyFunctionParamType(__PRETTY_FUNCTION__);
#endif // LIBC_COMPILER_IS_MSVC
}

template <typename T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ libc_test_library(
"//libc:__support_libc_errno",
"//libc:__support_macros_config",
"//libc:__support_macros_properties_architectures",
"//libc:__support_macros_properties_compiler",
"//libc:__support_macros_properties_types",
"//libc:__support_stringutil",
"//libc:__support_uint128",
Expand Down
Loading