mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 07:23:53 +01:00
ircd::simd: Add lower()/upper() templates for splitting.
This commit is contained in:
parent
7557040542
commit
0d586d6d0c
4 changed files with 136 additions and 0 deletions
44
include/ircd/simd/lower.h
Normal file
44
include/ircd/simd/lower.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
// 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_LOWER_H
|
||||
|
||||
namespace ircd::simd
|
||||
{
|
||||
template<class R,
|
||||
class T>
|
||||
R lower(const T) noexcept;
|
||||
}
|
||||
|
||||
template<class R,
|
||||
class T>
|
||||
inline R
|
||||
ircd::simd::lower(const T a)
|
||||
noexcept
|
||||
{
|
||||
static_assert
|
||||
(
|
||||
sizeof(R) * 2 == sizeof(T),
|
||||
"Types must have equal size."
|
||||
);
|
||||
|
||||
static_assert
|
||||
(
|
||||
lanes<R>() * 2 == lanes<T>(),
|
||||
"T must have twice as many lanes as R"
|
||||
);
|
||||
|
||||
R ret;
|
||||
for(size_t i(0); i < lanes<R>(); ++i)
|
||||
ret[i] = a[i];
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -16,6 +16,9 @@
|
|||
#include "traits.h"
|
||||
#include "lane_cast.h"
|
||||
#include "broad_cast.h"
|
||||
#include "split.h"
|
||||
#include "lower.h"
|
||||
#include "upper.h"
|
||||
#include "shift.h"
|
||||
#include "popcnt.h"
|
||||
#include "lzcnt.h"
|
||||
|
|
45
include/ircd/simd/split.h
Normal file
45
include/ircd/simd/split.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
// 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_SPLIT_H
|
||||
|
||||
namespace ircd::simd
|
||||
{
|
||||
template<class R,
|
||||
class T>
|
||||
std::array<R, 2> split(const T) noexcept;
|
||||
}
|
||||
|
||||
template<class R,
|
||||
class T>
|
||||
inline std::array<R, 2>
|
||||
ircd::simd::split(const T a)
|
||||
noexcept
|
||||
{
|
||||
static_assert
|
||||
(
|
||||
sizeof(R) * 2 == sizeof(T),
|
||||
"Types must have equal size."
|
||||
);
|
||||
|
||||
static_assert
|
||||
(
|
||||
lanes<R>() * 2 == lanes<T>(),
|
||||
"T must have twice as many lanes as R"
|
||||
);
|
||||
|
||||
std::array<R, 2> ret;
|
||||
for(size_t i(0); i < lanes<R>(); ++i)
|
||||
ret[0][i] = a[i],
|
||||
ret[1][i] = a[lanes<R>() + i];
|
||||
|
||||
return ret;
|
||||
}
|
44
include/ircd/simd/upper.h
Normal file
44
include/ircd/simd/upper.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
// 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_UPPER_H
|
||||
|
||||
namespace ircd::simd
|
||||
{
|
||||
template<class R,
|
||||
class T>
|
||||
R upper(const T) noexcept;
|
||||
}
|
||||
|
||||
template<class R,
|
||||
class T>
|
||||
inline R
|
||||
ircd::simd::upper(const T a)
|
||||
noexcept
|
||||
{
|
||||
static_assert
|
||||
(
|
||||
sizeof(R) * 2 == sizeof(T),
|
||||
"Types must have equal size."
|
||||
);
|
||||
|
||||
static_assert
|
||||
(
|
||||
lanes<R>() * 2 == lanes<T>(),
|
||||
"T must have twice as many lanes as R"
|
||||
);
|
||||
|
||||
R ret;
|
||||
for(size_t i(0); i < lanes<R>(); ++i)
|
||||
ret[i] = a[lanes<R>() + i];
|
||||
|
||||
return ret;
|
||||
}
|
Loading…
Reference in a new issue