Warning: This file is not a C or C++ file. It does not have highlighting.
| 1 | //===-- RISC-V implementation of memory function building blocks ----------===// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file provides x86 specific building blocks to compose memory functions. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | #ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_OP_RISCV_H |
| 13 | #define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_OP_RISCV_H |
| 14 | |
| 15 | #include "src/__support/macros/attributes.h" // LIBC_INLINE |
| 16 | #include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL |
| 17 | #include "src/__support/macros/properties/architectures.h" |
| 18 | |
| 19 | #if defined(LIBC_TARGET_ARCH_IS_ANY_RISCV) |
| 20 | |
| 21 | #include "src/__support/common.h" |
| 22 | #include "src/string/memory_utils/op_generic.h" |
| 23 | |
| 24 | namespace LIBC_NAMESPACE_DECL { |
| 25 | namespace generic { |
| 26 | |
| 27 | /////////////////////////////////////////////////////////////////////////////// |
| 28 | // Specializations for uint16_t |
| 29 | template <> struct cmp_is_expensive<uint16_t> : public cpp::false_type {}; |
| 30 | template <> LIBC_INLINE bool eq<uint16_t>(CPtr p1, CPtr p2, size_t offset) { |
| 31 | return load<uint16_t>(p1, offset) == load<uint16_t>(p2, offset); |
| 32 | } |
| 33 | template <> |
| 34 | LIBC_INLINE uint32_t neq<uint16_t>(CPtr p1, CPtr p2, size_t offset) { |
| 35 | return load<uint16_t>(p1, offset) ^ load<uint16_t>(p2, offset); |
| 36 | } |
| 37 | template <> |
| 38 | LIBC_INLINE MemcmpReturnType cmp<uint16_t>(CPtr p1, CPtr p2, size_t offset) { |
| 39 | return static_cast<int32_t>(load_be<uint16_t>(p1, offset)) - |
| 40 | static_cast<int32_t>(load_be<uint16_t>(p2, offset)); |
| 41 | } |
| 42 | template <> |
| 43 | LIBC_INLINE MemcmpReturnType cmp_neq<uint16_t>(CPtr p1, CPtr p2, size_t offset); |
| 44 | |
| 45 | /////////////////////////////////////////////////////////////////////////////// |
| 46 | // Specializations for uint32_t |
| 47 | template <> struct cmp_is_expensive<uint32_t> : public cpp::false_type {}; |
| 48 | template <> LIBC_INLINE bool eq<uint32_t>(CPtr p1, CPtr p2, size_t offset) { |
| 49 | return load<uint32_t>(p1, offset) == load<uint32_t>(p2, offset); |
| 50 | } |
| 51 | template <> |
| 52 | LIBC_INLINE uint32_t neq<uint32_t>(CPtr p1, CPtr p2, size_t offset) { |
| 53 | return load<uint32_t>(p1, offset) ^ load<uint32_t>(p2, offset); |
| 54 | } |
| 55 | template <> |
| 56 | LIBC_INLINE MemcmpReturnType cmp<uint32_t>(CPtr p1, CPtr p2, size_t offset) { |
| 57 | const auto a = load_be<uint32_t>(p1, offset); |
| 58 | const auto b = load_be<uint32_t>(p2, offset); |
| 59 | return cmp_uint32_t(a, b); |
| 60 | } |
| 61 | template <> |
| 62 | LIBC_INLINE MemcmpReturnType cmp_neq<uint32_t>(CPtr p1, CPtr p2, size_t offset); |
| 63 | |
| 64 | /////////////////////////////////////////////////////////////////////////////// |
| 65 | // Specializations for uint64_t |
| 66 | template <> struct cmp_is_expensive<uint64_t> : public cpp::true_type {}; |
| 67 | template <> LIBC_INLINE bool eq<uint64_t>(CPtr p1, CPtr p2, size_t offset) { |
| 68 | return load<uint64_t>(p1, offset) == load<uint64_t>(p2, offset); |
| 69 | } |
| 70 | template <> |
| 71 | LIBC_INLINE uint32_t neq<uint64_t>(CPtr p1, CPtr p2, size_t offset) { |
| 72 | return !eq<uint64_t>(p1, p2, offset); |
| 73 | } |
| 74 | template <> |
| 75 | LIBC_INLINE MemcmpReturnType cmp<uint64_t>(CPtr p1, CPtr p2, size_t offset); |
| 76 | template <> |
| 77 | LIBC_INLINE MemcmpReturnType cmp_neq<uint64_t>(CPtr p1, CPtr p2, |
| 78 | size_t offset) { |
| 79 | const auto a = load_be<uint64_t>(p1, offset); |
| 80 | const auto b = load_be<uint64_t>(p2, offset); |
| 81 | return cmp_neq_uint64_t(a, b); |
| 82 | } |
| 83 | |
| 84 | } // namespace generic |
| 85 | } // namespace LIBC_NAMESPACE_DECL |
| 86 | |
| 87 | #endif // LIBC_TARGET_ARCH_IS_ANY_RISCV |
| 88 | #endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_OP_RISCV_H |
| 89 |
Warning: This file is not a C or C++ file. It does not have highlighting.
