From 112151249b25bfd0233f50172a3cc9dd9acf72a5 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 6 Oct 2020 17:42:06 -0700 Subject: [PATCH] ircd::simd: Use template as basis for unaligned wrapper; simplify suite. ircd::simd: Rename unaligned header. --- include/ircd/simd/simd.h | 2 +- include/ircd/simd/type.unaligned.h | 111 ----------------------------- include/ircd/simd/unaligned.h | 93 ++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 112 deletions(-) delete mode 100644 include/ircd/simd/type.unaligned.h create mode 100644 include/ircd/simd/unaligned.h diff --git a/include/ircd/simd/simd.h b/include/ircd/simd/simd.h index 084c1359e..0c02b47a5 100644 --- a/include/ircd/simd/simd.h +++ b/include/ircd/simd/simd.h @@ -12,7 +12,7 @@ #define HAVE_IRCD_SIMD_H #include "type.h" -#include "type.unaligned.h" +#include "unaligned.h" #include "traits.h" #include "lane_cast.h" #include "broad_cast.h" diff --git a/include/ircd/simd/type.unaligned.h b/include/ircd/simd/type.unaligned.h deleted file mode 100644 index 3079360a7..000000000 --- a/include/ircd/simd/type.unaligned.h +++ /dev/null @@ -1,111 +0,0 @@ -// The Construct -// -// Copyright (C) The Construct Developers, Authors & Contributors -// Copyright (C) 2016-2020 Jason Volk -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice is present in all copies. The -// full license for this software is available in the LICENSE file. - -#pragma once -#define HAVE_IRCD_SIMD_TYPE_UNALIGNED_H - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wpsabi" -#pragma GCC diagnostic ignored "-Wpacked" - -/// Unaligned type wrapper macro -#define IRCD_SIMD_TYPEDEF_UNALIGNED(TYPE, NAME) \ -struct \ -__attribute__((packed)) \ -__attribute__((aligned(1))) \ -__attribute__((visibility("internal"))) \ -NAME \ -{ \ - using value_type = TYPE; \ - \ - TYPE val; \ - \ - operator TYPE() const { return val; } \ - \ - template NAME &operator=(T&& t) \ - { \ - val = std::forward(t); \ - return *this; \ - } \ -} - -// -// unsigned -// - -namespace ircd::simd -{ - IRCD_SIMD_TYPEDEF_UNALIGNED(m512i, u512x1_u); - IRCD_SIMD_TYPEDEF_UNALIGNED(m256i, u256x1_u); - IRCD_SIMD_TYPEDEF_UNALIGNED(m128i, u128x1_u); -} - -namespace ircd -{ - using simd::u512x1_u; - using simd::u256x1_u; - using simd::u128x1_u; -} - -// -// signed -// - -namespace ircd::simd -{ - IRCD_SIMD_TYPEDEF_UNALIGNED(m512i, i512x1_u); - IRCD_SIMD_TYPEDEF_UNALIGNED(m256i, i256x1_u); - IRCD_SIMD_TYPEDEF_UNALIGNED(m128i, i128x1_u); -} - -namespace ircd -{ - using simd::i512x1_u; - using simd::i256x1_u; - using simd::i128x1_u; -} - -// -// single precision -// - -namespace ircd::simd -{ - IRCD_SIMD_TYPEDEF_UNALIGNED(m512f, f512x1_u); - IRCD_SIMD_TYPEDEF_UNALIGNED(m256f, f256x1_u); - IRCD_SIMD_TYPEDEF_UNALIGNED(m128f, f128x1_u); -} - -namespace ircd -{ - using simd::f512x1_u; - using simd::f256x1_u; - using simd::f128x1_u; -} - -// -// double precision -// - -namespace ircd::simd -{ - IRCD_SIMD_TYPEDEF_UNALIGNED(m512d, d512x1_u); - IRCD_SIMD_TYPEDEF_UNALIGNED(m256d, d256x1_u); - IRCD_SIMD_TYPEDEF_UNALIGNED(m128d, d128x1_u); -} - -namespace ircd -{ - using simd::d512x1_u; - using simd::d256x1_u; - using simd::d128x1_u; -} - -#pragma GCC diagnostic pop diff --git a/include/ircd/simd/unaligned.h b/include/ircd/simd/unaligned.h new file mode 100644 index 000000000..dde38538c --- /dev/null +++ b/include/ircd/simd/unaligned.h @@ -0,0 +1,93 @@ +// The Construct +// +// Copyright (C) The Construct Developers, Authors & Contributors +// Copyright (C) 2016-2020 Jason Volk +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice is present in all copies. The +// full license for this software is available in the LICENSE file. + +#pragma once +#define HAVE_IRCD_SIMD_TYPE_UNALIGNED_H + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpsabi" +#pragma GCC diagnostic ignored "-Wpacked" + +namespace ircd::simd +{ + template struct unaligned; +} + +/// Unaligned wrapper template class. +/// T = inner aligned type +template +struct +__attribute__((packed)) +__attribute__((aligned(1))) +__attribute__((visibility("internal"))) +ircd::simd::unaligned +{ + using value_type = T; + + T val; + + operator T() const + { + return val; + } + + template + unaligned(U&& val) + :val(std::forward(val)) + {} +}; + +/// Unaligned type wrapper macro. We use this macro to define several common +/// instantiations of unaligned. +/// +#define IRCD_SIMD_TYPEDEF_UNALIGNED(TYPE, NAME) \ +namespace ircd \ +{ \ + namespace simd \ + { \ + using NAME = unaligned; \ + } \ + \ + using simd::NAME; \ +} + +// +// unsigned +// + +IRCD_SIMD_TYPEDEF_UNALIGNED(m512i, u512x1_u); +IRCD_SIMD_TYPEDEF_UNALIGNED(m256i, u256x1_u); +IRCD_SIMD_TYPEDEF_UNALIGNED(m128i, u128x1_u); + +// +// signed +// + +IRCD_SIMD_TYPEDEF_UNALIGNED(m512i, i512x1_u); +IRCD_SIMD_TYPEDEF_UNALIGNED(m256i, i256x1_u); +IRCD_SIMD_TYPEDEF_UNALIGNED(m128i, i128x1_u); + +// +// single precision +// + +IRCD_SIMD_TYPEDEF_UNALIGNED(m512f, f512x1_u); +IRCD_SIMD_TYPEDEF_UNALIGNED(m256f, f256x1_u); +IRCD_SIMD_TYPEDEF_UNALIGNED(m128f, f128x1_u); + +// +// double precision +// + +IRCD_SIMD_TYPEDEF_UNALIGNED(m512d, d512x1_u); +IRCD_SIMD_TYPEDEF_UNALIGNED(m256d, d256x1_u); +IRCD_SIMD_TYPEDEF_UNALIGNED(m128d, d128x1_u); + +#pragma GCC diagnostic pop