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