mirror of
https://github.com/matrix-construct/construct
synced 2025-02-18 01:30:12 +01:00
ircd::simd: Add pack convenience template funcro.
This commit is contained in:
parent
6723539997
commit
880f089169
2 changed files with 50 additions and 0 deletions
49
include/ircd/simd/pack.h
Normal file
49
include/ircd/simd/pack.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
// Matrix Construct
|
||||
//
|
||||
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
||||
// Copyright (C) 2016-2021 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_PACK_H
|
||||
|
||||
// Pack values left overwriting unmasked lanes.
|
||||
namespace ircd::simd
|
||||
{
|
||||
template<class T,
|
||||
class U>
|
||||
T pack(const T vals, const U mask) noexcept;
|
||||
}
|
||||
|
||||
/// Left-pack values to eliminate unmasked lanes.
|
||||
/// TODO: WIP
|
||||
template<class T,
|
||||
class U>
|
||||
inline T
|
||||
ircd::simd::pack(const T val,
|
||||
const U mask)
|
||||
noexcept
|
||||
{
|
||||
static_assert
|
||||
(
|
||||
lanes<T>() == lanes<U>()
|
||||
);
|
||||
|
||||
static_assert
|
||||
(
|
||||
std::is_integral<lane_type<U>>()
|
||||
);
|
||||
|
||||
U idx{0}, add(mask & 1);
|
||||
for(uint i(0); i < lanes<U>(); ++i)
|
||||
{
|
||||
add = shl<sizeof_lane<U>() * 8L>(add);
|
||||
idx += add;
|
||||
}
|
||||
|
||||
return shuf(val, idx);
|
||||
}
|
|
@ -37,6 +37,7 @@
|
|||
#include "any.h"
|
||||
#include "all.h"
|
||||
#include "shuf.h"
|
||||
#include "pack.h"
|
||||
#include "stream.h"
|
||||
#include "for_each.h"
|
||||
#include "transform.h"
|
||||
|
|
Loading…
Add table
Reference in a new issue