Skip to content

Commit ff20f2b

Browse files
committed
runtime: adjust known metadata for SIMD vector types
Rather than use a function, use a templated structure with a constant expression to metaprogram the alignment of the type. NFC. Adjust the templating for the SIMD vector types. Use the reserved spelling for the clang extension, and rename the types. NFC. The meat of this change is the explicit template specialization for the float 3 vector and double 3 vector. Since they are going to be emitted as float 4 vector underneath everything, we can simply treat them the same. This has a benefit of allowing us to share the same specialization of the witness tables. Additionally, it works around a bug in clang where we cannot correctly decorate the extended type with Microsoft's ABI (which is a separate issue). Since this saves some bytes, this is still beneficial.
1 parent 6b68303 commit ff20f2b

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

stdlib/public/runtime/KnownMetadata.cpp

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,16 @@ namespace pointer_types {
104104
}
105105

106106
namespace {
107-
template<typename T>
108-
constexpr size_t getAlignment() { return alignof(T); }
107+
template <typename T>
108+
struct BuiltinType {
109+
static constexpr const size_t Alignment = alignof(T);
110+
};
109111

110-
#define SET_FIXED_ALIGNMENT(Type, Align) \
111-
template<> constexpr size_t getAlignment<Type>() { return Align; }
112+
#define SET_FIXED_ALIGNMENT(Type, Align) \
113+
template <> \
114+
struct BuiltinType<Type> { \
115+
static constexpr const size_t Alignment = Align; \
116+
};
112117

113118
SET_FIXED_ALIGNMENT(uint8_t, 1)
114119
SET_FIXED_ALIGNMENT(uint16_t, 2)
@@ -120,27 +125,40 @@ template<> constexpr size_t getAlignment<Type>() { return Align; }
120125

121126
#undef SET_FIXED_ALIGNMENT
122127

123-
template<typename T, unsigned N>
124-
struct SwiftVecT {
125-
typedef T type __attribute__((ext_vector_type(N)));
128+
template <typename T, unsigned N>
129+
struct SIMDVector {
130+
using Type = T __attribute__((__ext_vector_type__(N)));
126131
};
127132

128-
template<typename T, unsigned N>
129-
using SwiftVec = typename SwiftVecT<T, N>::type;
133+
template <>
134+
struct SIMDVector<float, 3> {
135+
using Type = float __attribute__((__ext_vector_type__(4)));
136+
};
137+
138+
template <>
139+
struct SIMDVector<double, 3> {
140+
using Type = double __attribute__((__ext_vector_type__(4)));
141+
};
142+
143+
template <typename T, unsigned N>
144+
using SIMDVectorType = typename SIMDVector<T, N>::Type;
130145
}
131146

132-
#define BUILTIN_TYPE(Symbol, Name) \
133-
const ValueWitnessTable swift::VALUE_WITNESS_SYM(Symbol) = \
134-
ValueWitnessTableForBox<NativeBox<ctypes::Symbol, \
135-
getAlignment<ctypes::Symbol>()>>::table;
147+
#define BUILTIN_TYPE(Symbol, Name) \
148+
const ValueWitnessTable swift::VALUE_WITNESS_SYM(Symbol) = \
149+
ValueWitnessTableForBox<NativeBox<ctypes::Symbol, \
150+
BuiltinType<ctypes::Symbol>::Alignment>>::table;
151+
136152
#define BUILTIN_POINTER_TYPE(Symbol, Name) \
137-
const ExtraInhabitantsValueWitnessTable swift::VALUE_WITNESS_SYM(Symbol) = \
153+
const ExtraInhabitantsValueWitnessTable swift::VALUE_WITNESS_SYM(Symbol) = \
138154
ValueWitnessTableForBox<pointer_types::Symbol>::table;
139-
#define BUILTIN_VECTOR_TYPE(ElementSymbol, _, Width) \
140-
const ValueWitnessTable \
141-
swift::VALUE_WITNESS_SYM(VECTOR_BUILTIN_SYMBOL_NAME(ElementSymbol,Width)) = \
142-
ValueWitnessTableForBox<NativeBox<SwiftVec<ctypes::ElementSymbol, \
143-
Width>>>::table;
155+
156+
#define BUILTIN_VECTOR_TYPE(ElementSymbol, _, Width) \
157+
const ValueWitnessTable \
158+
swift::VALUE_WITNESS_SYM(VECTOR_BUILTIN_SYMBOL_NAME(ElementSymbol,Width)) = \
159+
ValueWitnessTableForBox<NativeBox<SIMDVectorType<ctypes::ElementSymbol, \
160+
Width>>>::table;
161+
144162
#include "swift/Runtime/BuiltinTypes.def"
145163

146164
/// The value-witness table for pointer-aligned unmanaged pointer types.

0 commit comments

Comments
 (0)