Skip to content

Commit 39384c0

Browse files
committed
wip
1 parent 9b536f6 commit 39384c0

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

include/Peanut/impl/common.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
// Dependencies headers
3737
#ifdef PEANUT_SIMD
3838
#include <simd/simd.h>
39+
#include <simd/logic.h>
3940
#endif
4041

4142
#if defined(_MSC_VER) && !defined(__llvm__) && !defined(__INTEL_COMPILER)
@@ -46,11 +47,14 @@
4647

4748
#ifdef PEANUT_SIMD
4849
#define ADL_PATTERN(func)\
49-
using simd::func; \
50-
using std::func;
50+
using simd::func;
51+
#define LOGIC_MACRO(signature, simd_impl, scalar_impl) \
52+
signature{simd_impl;}
5153
#else
5254
#define ADL_PATTERN(func)\
5355
using std::func;
56+
#define LOGIC_MACRO(signature, simd_impl, scalar_impl) \
57+
signature{scalar_impl;}
5458
#endif
5559

5660

@@ -61,13 +65,24 @@ namespace Peanut {
6165
using Int = simd_int8;
6266
using Double = simd_double8;
6367
using Bool = simd_int8;
68+
static const Bool True = simd_int8(-1);
69+
static const Bool False = simd_int8(0);
6470
#else
6571
using Float = float;
6672
using Int = int;
6773
using Double = double;
6874
using Bool = bool;
75+
static const Bool True = true;
76+
static const Bool False = false;
6977
#endif
7078

79+
LOGIC_MACRO(Float select(const Bool cond, const Float &a, const Float &b), return simd_select(a, b, cond), return cond ? a : b)
80+
LOGIC_MACRO(Int select(const Bool &cond, const Int &a, const Int &b), return (b & cond) | (a & ~cond), return cond ? a : b)
81+
LOGIC_MACRO(bool any(const Bool &cond), return simd_any(cond), return cond)
82+
LOGIC_MACRO(bool all(const Bool &cond), return simd_all(cond), return cond)
83+
LOGIC_MACRO(bool none(const Bool &cond), return !simd_any(cond), return !cond)
84+
LOGIC_MACRO(Float clamp(const Float &a, const Float &min, const Float &max), return simd_clamp(a, min, max), std::clamp(a, min, max))
85+
7186

7287
/**
7388
* @brief Check if given \p val is zero or not.
@@ -77,7 +92,7 @@ namespace Peanut {
7792
* If \p T is not a floating point type, returns true if \p val is zero, false if not.
7893
*/
7994
template<typename T>
80-
bool is_zero(T val) requires is_arithmetic<T>
95+
Bool is_zero(T val) requires is_arithmetic<T>
8196
#ifdef PEANUT_SIMD
8297
&& (!std::is_same_v<T, simd_float4>)
8398
#endif
@@ -139,3 +154,5 @@ namespace Peanut {
139154
}
140155

141156
}
157+
158+
#undef LOGIC_MACRO

0 commit comments

Comments
 (0)