SuperDex Physics C++ API
Loading...
Searching...
No Matches
simd_specializations_inl.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include "../debug.h"
20#include "../simd.h" // for Intelisense
21
22namespace superdex {
23
24/***********************************************************************************************
25 Constrains a templated scalar parameter U to types convertible to scalar type S, but
26 explicitly not bool. Rejecting bool prevents silent promotion of comparison results into
27 broadcast values (e.g., `Simd<float> v = (a == b)` would otherwise broadcast 0.0f or 1.0f
28 instead of producing a mask).
29*/
30#define MOCHI_REQUIRES_NON_BOOL_SCALAR(U, S) \
31 MOCHI_CONCEPT((std::is_convertible_v<U, S> && !std::is_same_v<U, bool>))
32
33/***********************************************************************************************
34 Boilerplate code shared by all Simd<T, N> specializations
35*/
36#define MOCHI_NATIVE_SIMD_IMPL_BOILERPLATE(T, N, NativeT) \
37 NativeT raw; \
38 static constexpr int kSize = N; \
39 static constexpr bool kIsSupported = true; \
40 static constexpr bool kIsComposite = false; \
41 static constexpr bool kIsEmulated = false; \
42 using NativeType = NativeT; \
43 using Scalar = T; \
44 MOCHI_FORCE_INLINE Simd() = default; \
45 MOCHI_FORCE_INLINE ~Simd() = default; \
46 MOCHI_FORCE_INLINE Simd(Simd const& rhs) = default; \
47 MOCHI_FORCE_INLINE Simd(Simd&& rhs) = default; \
48 MOCHI_FORCE_INLINE Simd(NativeType rhs) : raw(rhs) {}; \
49 MOCHI_FORCE_INLINE static constexpr size_t size() { \
50 return kSize; \
51 } \
52 MOCHI_FORCE_INLINE Simd& operator=(Simd const& rhs) = default; \
53 MOCHI_FORCE_INLINE Simd& operator=(Simd&& rhs) = default; \
54 template <class U, MOCHI_REQUIRES_NON_BOOL_SCALAR(U, Scalar)> \
55 MOCHI_FORCE_INLINE Simd& operator=(U rhs) { \
56 raw = Simd{rhs}.raw; \
57 return *this; \
58 } \
59 [[nodiscard]] MOCHI_FORCE_INLINE Scalar operator[](int i) const { \
60 return Get(*this, i); /* return by value */ \
61 }
62
63} // namespace superdex
64
65/**
66 Architecture dependent Simd specializations
67*/
68#if MOCHI_USE_SIMD
69#if MOCHI_ARCH_ARM
70#include "arm/arm_simd_inl.h"
71#elif MOCHI_ARCH_X64
72#include "x64/x64_simd_inl.h"
73#else
74#error No supported SIMD architecture was detected. MOCHI_USE_SIMD should be zero.
75#endif
76// Partial specialization supporting Simd<T, N> for larger values of N
77#include "simd_composite_inl.h"
78#else
79// Use scalar fallback when !MOCHI_USE_SIMD
81#endif