diff --git a/include/ircd/simd/mask.h b/include/ircd/simd/mask.h new file mode 100644 index 000000000..a5b25dcb1 --- /dev/null +++ b/include/ircd/simd/mask.h @@ -0,0 +1,39 @@ +// 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_MASK_H + +namespace ircd::simd +{ + template T popmask(const T) noexcept; + template T boolmask(const T) noexcept; +} + +/// Convenience template. Extends a bool value where the lsb is 1 or 0 into a +/// mask value like the result of vector comparisons. +template +inline T +ircd::simd::boolmask(const T a) +noexcept +{ + return ~(popmask(a) - 1); +} + +/// Convenience template. Vector compare instructions yield 0xff on equal; +/// sometimes one might need an actual value of 1 for accumulators or maybe +/// some bool-type reason... +template +inline T +ircd::simd::popmask(const T a) +noexcept +{ + return a & 1; +} diff --git a/include/ircd/simd/popcnt.h b/include/ircd/simd/popcnt.h index 25f99e2d1..e36df75df 100644 --- a/include/ircd/simd/popcnt.h +++ b/include/ircd/simd/popcnt.h @@ -13,8 +13,6 @@ namespace ircd::simd { - template T popmask(const T) noexcept; - template T boolmask(const T) noexcept; template uint popcnt(const T) noexcept; } @@ -36,26 +34,3 @@ noexcept return ret; } - -/// Convenience template. Extends a bool value where the lsb is 1 or 0 into a -/// mask value like the result of vector comparisons. -template -[[gnu::always_inline]] -inline T -ircd::simd::boolmask(const T a) -noexcept -{ - return ~(popmask(a) - 1); -} - -/// Convenience template. Vector compare instructions yield 0xff on equal; -/// sometimes one might need an actual value of 1 for accumulators or maybe -/// some bool-type reason... -template -[[gnu::always_inline]] -inline T -ircd::simd::popmask(const T a) -noexcept -{ - return a & 1; -} diff --git a/include/ircd/simd/simd.h b/include/ircd/simd/simd.h index b3b6ec790..c76b90690 100644 --- a/include/ircd/simd/simd.h +++ b/include/ircd/simd/simd.h @@ -19,6 +19,7 @@ #include "split.h" #include "lower.h" #include "upper.h" +#include "mask.h" #include "gather.h" #include "shl.h" #include "shr.h"