1*67fe3bd3SGuillaume Chatelet //===-- Elementary operations to compose memory primitives ----------------===// 2*67fe3bd3SGuillaume Chatelet // 3*67fe3bd3SGuillaume Chatelet // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*67fe3bd3SGuillaume Chatelet // See https://llvm.org/LICENSE.txt for license information. 5*67fe3bd3SGuillaume Chatelet // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*67fe3bd3SGuillaume Chatelet // 7*67fe3bd3SGuillaume Chatelet //===----------------------------------------------------------------------===// 8*67fe3bd3SGuillaume Chatelet // 9*67fe3bd3SGuillaume Chatelet // This file defines the concept of a Backend. 10*67fe3bd3SGuillaume Chatelet // It constitutes the lowest level of the framework and is akin to instruction 11*67fe3bd3SGuillaume Chatelet // selection. It defines how to implement aligned/unaligned, 12*67fe3bd3SGuillaume Chatelet // temporal/non-temporal native loads and stores for a particular architecture 13*67fe3bd3SGuillaume Chatelet // as well as efficient ways to fill and compare types. 14*67fe3bd3SGuillaume Chatelet //===----------------------------------------------------------------------===// 15*67fe3bd3SGuillaume Chatelet 16*67fe3bd3SGuillaume Chatelet #ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_BACKENDS_H 17*67fe3bd3SGuillaume Chatelet #define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_BACKENDS_H 18*67fe3bd3SGuillaume Chatelet 19*67fe3bd3SGuillaume Chatelet #include "src/string/memory_utils/address.h" // Temporality, Aligned 20*67fe3bd3SGuillaume Chatelet #include "src/string/memory_utils/sized_op.h" // SizedOp 21*67fe3bd3SGuillaume Chatelet #include <stddef.h> // size_t 22*67fe3bd3SGuillaume Chatelet #include <stdint.h> // uint##_t 23*67fe3bd3SGuillaume Chatelet 24*67fe3bd3SGuillaume Chatelet namespace __llvm_libc { 25*67fe3bd3SGuillaume Chatelet 26*67fe3bd3SGuillaume Chatelet // Backends must implement the following interface. 27*67fe3bd3SGuillaume Chatelet struct NoBackend { 28*67fe3bd3SGuillaume Chatelet static constexpr bool IS_BACKEND_TYPE = true; 29*67fe3bd3SGuillaume Chatelet 30*67fe3bd3SGuillaume Chatelet // Loads a T from `src` honoring Temporality and Alignment. 31*67fe3bd3SGuillaume Chatelet template <typename T, Temporality, Aligned> static T load(const T *src); 32*67fe3bd3SGuillaume Chatelet 33*67fe3bd3SGuillaume Chatelet // Stores a T to `dst` honoring Temporality and Alignment. 34*67fe3bd3SGuillaume Chatelet template <typename T, Temporality, Aligned> 35*67fe3bd3SGuillaume Chatelet static void store(T *dst, T value); 36*67fe3bd3SGuillaume Chatelet 37*67fe3bd3SGuillaume Chatelet // Returns a T filled with `value` bytes. 38*67fe3bd3SGuillaume Chatelet template <typename T> static T splat(ubyte value); 39*67fe3bd3SGuillaume Chatelet 40*67fe3bd3SGuillaume Chatelet // Returns zero iff v1 == v2. 41*67fe3bd3SGuillaume Chatelet template <typename T> static uint64_t notEquals(T v1, T v2); 42*67fe3bd3SGuillaume Chatelet 43*67fe3bd3SGuillaume Chatelet // Returns zero iff v1 == v2, a negative number if v1 < v2 and a positive 44*67fe3bd3SGuillaume Chatelet // number otherwise. 45*67fe3bd3SGuillaume Chatelet template <typename T> static int32_t threeWayCmp(T v1, T v2); 46*67fe3bd3SGuillaume Chatelet 47*67fe3bd3SGuillaume Chatelet // Returns the type to use to consume Size bytes. 48*67fe3bd3SGuillaume Chatelet // If no type handles Size bytes at once 49*67fe3bd3SGuillaume Chatelet template <size_t Size> using getNextType = void; 50*67fe3bd3SGuillaume Chatelet }; 51*67fe3bd3SGuillaume Chatelet 52*67fe3bd3SGuillaume Chatelet } // namespace __llvm_libc 53*67fe3bd3SGuillaume Chatelet 54*67fe3bd3SGuillaume Chatelet // We inline all backend implementations here to simplify the build system. 55*67fe3bd3SGuillaume Chatelet // Each file need to be guarded with the appropriate LLVM_LIBC_ARCH_XXX ifdef. 56*67fe3bd3SGuillaume Chatelet #include "src/string/memory_utils/backend_aarch64.h" 57*67fe3bd3SGuillaume Chatelet #include "src/string/memory_utils/backend_scalar.h" 58*67fe3bd3SGuillaume Chatelet #include "src/string/memory_utils/backend_x86.h" 59*67fe3bd3SGuillaume Chatelet 60*67fe3bd3SGuillaume Chatelet #endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_BACKENDS_H 61