Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 37 additions & 19 deletions stdlib/public/runtime/KnownMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,16 @@ namespace pointer_types {
}

namespace {
template<typename T>
constexpr size_t getAlignment() { return alignof(T); }
template <typename T>
struct BuiltinType {
static constexpr const size_t Alignment = alignof(T);
};

#define SET_FIXED_ALIGNMENT(Type, Align) \
template<> constexpr size_t getAlignment<Type>() { return Align; }
#define SET_FIXED_ALIGNMENT(Type, Align) \
template <> \
struct BuiltinType<Type> { \
static constexpr const size_t Alignment = Align; \
};

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

#undef SET_FIXED_ALIGNMENT

template<typename T, unsigned N>
struct SwiftVecT {
typedef T type __attribute__((ext_vector_type(N)));
template <typename T, unsigned N>
struct SIMDVector {
using Type = T __attribute__((__ext_vector_type__(N)));
};

template<typename T, unsigned N>
using SwiftVec = typename SwiftVecT<T, N>::type;
template <>
struct SIMDVector<float, 3> {
using Type = float __attribute__((__ext_vector_type__(4)));
};

template <>
struct SIMDVector<double, 3> {
using Type = double __attribute__((__ext_vector_type__(4)));
};

template <typename T, unsigned N>
using SIMDVectorType = typename SIMDVector<T, N>::Type;
}

#define BUILTIN_TYPE(Symbol, Name) \
const ValueWitnessTable swift::VALUE_WITNESS_SYM(Symbol) = \
ValueWitnessTableForBox<NativeBox<ctypes::Symbol, \
getAlignment<ctypes::Symbol>()>>::table;
#define BUILTIN_TYPE(Symbol, Name) \
const ValueWitnessTable swift::VALUE_WITNESS_SYM(Symbol) = \
ValueWitnessTableForBox<NativeBox<ctypes::Symbol, \
BuiltinType<ctypes::Symbol>::Alignment>>::table;

#define BUILTIN_POINTER_TYPE(Symbol, Name) \
const ExtraInhabitantsValueWitnessTable swift::VALUE_WITNESS_SYM(Symbol) = \
const ExtraInhabitantsValueWitnessTable swift::VALUE_WITNESS_SYM(Symbol) = \
ValueWitnessTableForBox<pointer_types::Symbol>::table;
#define BUILTIN_VECTOR_TYPE(ElementSymbol, _, Width) \
const ValueWitnessTable \
swift::VALUE_WITNESS_SYM(VECTOR_BUILTIN_SYMBOL_NAME(ElementSymbol,Width)) = \
ValueWitnessTableForBox<NativeBox<SwiftVec<ctypes::ElementSymbol, \
Width>>>::table;

#define BUILTIN_VECTOR_TYPE(ElementSymbol, _, Width) \
const ValueWitnessTable \
swift::VALUE_WITNESS_SYM(VECTOR_BUILTIN_SYMBOL_NAME(ElementSymbol,Width)) = \
ValueWitnessTableForBox<NativeBox<SIMDVectorType<ctypes::ElementSymbol, \
Width>>>::table;

#include "swift/Runtime/BuiltinTypes.def"

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