0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-01-13 16:33:53 +01:00

ircd::simd: Add reduce util suite.

This commit is contained in:
Jason Volk 2020-08-31 11:13:00 -07:00
parent d64d038911
commit c87e444cda
2 changed files with 70 additions and 0 deletions

View file

@ -20,6 +20,7 @@
#include "popcnt.h"
#include "lzcnt.h"
#include "tzcnt.h"
#include "sum.h"
#include "print.h"
namespace ircd

69
include/ircd/simd/sum.h Normal file
View file

@ -0,0 +1,69 @@
// The Construct
//
// Copyright (C) The Construct Developers, Authors & Contributors
// Copyright (C) 2016-2020 Jason Volk <jason@zemos.net>
//
// 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_SUM_H
namespace ircd::simd
{
template<int idx = 0,
class T>
T sum_or(T) noexcept;
template<int idx = 0,
class T>
T sum_and(T) noexcept;
template<int idx = 0,
class T>
T sum_xor(T) noexcept;
}
template<int idx,
class T>
[[using gnu: always_inline, gnu_inline, artificial]]
extern inline T
ircd::simd::sum_and(T a)
noexcept
{
for(size_t i(0); i < lanes<T>(); ++i)
if(i != idx)
a[idx] &= a[i];
return a;
}
template<int idx,
class T>
[[using gnu: always_inline, gnu_inline, artificial]]
extern inline T
ircd::simd::sum_or(T a)
noexcept
{
for(size_t i(0); i < lanes<T>(); ++i)
if(i != idx)
a[idx] |= a[i];
return a;
}
template<int idx,
class T>
[[using gnu: always_inline, gnu_inline, artificial]]
extern inline T
ircd::simd::sum_xor(T a)
noexcept
{
for(size_t i(0); i < lanes<T>(); ++i)
if(i != idx)
a[idx] ^= a[i];
return a;
}