89 lines · c
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-exception6//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_H13#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_OP_RISCV_H14 15#include "src/__support/macros/attributes.h" // LIBC_INLINE16#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL17#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 24namespace LIBC_NAMESPACE_DECL {25namespace generic {26 27///////////////////////////////////////////////////////////////////////////////28// Specializations for uint16_t29template <> struct cmp_is_expensive<uint16_t> : public cpp::false_type {};30template <> 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}33template <>34LIBC_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}37template <>38LIBC_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}42template <>43LIBC_INLINE MemcmpReturnType cmp_neq<uint16_t>(CPtr p1, CPtr p2, size_t offset);44 45///////////////////////////////////////////////////////////////////////////////46// Specializations for uint32_t47template <> struct cmp_is_expensive<uint32_t> : public cpp::false_type {};48template <> 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}51template <>52LIBC_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}55template <>56LIBC_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}61template <>62LIBC_INLINE MemcmpReturnType cmp_neq<uint32_t>(CPtr p1, CPtr p2, size_t offset);63 64///////////////////////////////////////////////////////////////////////////////65// Specializations for uint64_t66template <> struct cmp_is_expensive<uint64_t> : public cpp::true_type {};67template <> 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}70template <>71LIBC_INLINE uint32_t neq<uint64_t>(CPtr p1, CPtr p2, size_t offset) {72 return !eq<uint64_t>(p1, p2, offset);73}74template <>75LIBC_INLINE MemcmpReturnType cmp<uint64_t>(CPtr p1, CPtr p2, size_t offset);76template <>77LIBC_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 generic85} // namespace LIBC_NAMESPACE_DECL86 87#endif // LIBC_TARGET_ARCH_IS_ANY_RISCV88#endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_OP_RISCV_H89