v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
simd128.h
Go to the documentation of this file.
1// Copyright 2024 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_COMMON_SIMD128_H_
6#define V8_COMMON_SIMD128_H_
7
8#include <cstdint>
9
10#include "src/base/memory.h"
11#include "src/common/globals.h"
12
13namespace v8::internal {
14
15#define FOREACH_SIMD_TYPE(V) \
16 V(double, float64x2, f64x2, 2) \
17 V(float, float32x4, f32x4, 4) \
18 V(int64_t, int64x2, i64x2, 2) \
19 V(int32_t, int32x4, i32x4, 4) \
20 V(int16_t, int16x8, i16x8, 8) \
21 V(int8_t, int8x16, i8x16, 16)
22
23#define DEFINE_SIMD_TYPE(cType, sType, name, kSize) \
24 struct sType { \
25 cType val[kSize]; \
26 };
28#undef DEFINE_SIMD_TYPE
29
30class alignas(double) Simd128 {
31 public:
32 Simd128() = default;
33
34#define DEFINE_SIMD_TYPE_SPECIFIC_METHODS(cType, sType, name, size) \
35 explicit Simd128(sType val) { \
36 base::WriteUnalignedValue<sType>(reinterpret_cast<Address>(val_), val); \
37 } \
38 sType to_##name() const { \
39 return base::ReadUnalignedValue<sType>(reinterpret_cast<Address>(val_)); \
40 }
42#undef DEFINE_SIMD_TYPE_SPECIFIC_METHODS
43
44 explicit Simd128(uint8_t* bytes) {
45 memcpy(static_cast<void*>(val_), reinterpret_cast<void*>(bytes),
47 }
48
49 bool operator==(const Simd128& other) const noexcept {
50 return memcmp(val_, other.val_, sizeof val_) == 0;
51 }
52
53 const uint8_t* bytes() { return val_; }
54
55 template <typename T>
56 inline T to() const;
57
58 private:
59 uint8_t val_[16] = {0};
60};
61
62#define DECLARE_CAST(cType, sType, name, size) \
63 template <> \
64 inline sType Simd128::to() const { \
65 return to_##name(); \
66 }
68#undef DECLARE_CAST
69
70} // namespace v8::internal
71
72#endif // V8_COMMON_SIMD128_H_
#define DECLARE_CAST(CamelName)
Definition asm-types.h:111
Simd128(uint8_t *bytes)
Definition simd128.h:44
bool operator==(const Simd128 &other) const noexcept
Definition simd128.h:49
const uint8_t * bytes()
Definition simd128.h:53
constexpr int kSimd128Size
Definition globals.h:706
#define FOREACH_SIMD_TYPE(V)
Definition simd128.h:15
#define DEFINE_SIMD_TYPE_SPECIFIC_METHODS(cType, sType, name, size)
Definition simd128.h:34
#define DEFINE_SIMD_TYPE(cType, sType, name, kSize)
Definition simd128.h:23