mirror of
https://github.com/matrix-construct/construct
synced 2024-12-27 07:54:05 +01:00
ircd::simd: Split lane_cast into header.
This commit is contained in:
parent
7254d3c945
commit
86aa96fa91
2 changed files with 42 additions and 23 deletions
40
include/ircd/simd/lane_cast.h
Normal file
40
include/ircd/simd/lane_cast.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
// 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_LANE_CAST_H
|
||||
|
||||
namespace ircd::simd
|
||||
{
|
||||
template<class R,
|
||||
class T>
|
||||
R lane_cast(const T &);
|
||||
}
|
||||
|
||||
/// Convert each lane from a smaller type to a larger type
|
||||
template<class R,
|
||||
class T>
|
||||
inline R
|
||||
ircd::simd::lane_cast(const T &in)
|
||||
{
|
||||
static_assert
|
||||
(
|
||||
lanes<R>() == lanes<T>(), "Types must have matching number of lanes."
|
||||
);
|
||||
|
||||
if constexpr(__has_builtin(__builtin_convertvector))
|
||||
return __builtin_convertvector(in, R);
|
||||
|
||||
R ret;
|
||||
for(size_t i(0); i < lanes<R>(); ++i)
|
||||
ret[i] = in[i];
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include "type.h"
|
||||
#include "traits.h"
|
||||
#include "lane_cast.h"
|
||||
#include "print.h"
|
||||
|
||||
namespace ircd::simd
|
||||
|
@ -24,35 +25,13 @@ namespace ircd::simd
|
|||
template<int bits> u128x1 shr(const u128x1 &a) noexcept;
|
||||
template<int bits> u256x1 shl(const u256x1 &a) noexcept;
|
||||
template<int bits> u256x1 shr(const u256x1 &a) noexcept;
|
||||
|
||||
template<class R, class T> R lane_cast(const T &);
|
||||
}
|
||||
|
||||
namespace ircd
|
||||
{
|
||||
using simd::shl;
|
||||
using simd::shr;
|
||||
}
|
||||
|
||||
/// Convert each lane from a smaller type to a larger type
|
||||
template<class R,
|
||||
class T>
|
||||
inline R
|
||||
ircd::simd::lane_cast(const T &in)
|
||||
{
|
||||
static_assert
|
||||
(
|
||||
lanes<R>() == lanes<T>(), "Types must have matching number of lanes."
|
||||
);
|
||||
|
||||
if constexpr(__has_builtin(__builtin_convertvector))
|
||||
return __builtin_convertvector(in, R);
|
||||
|
||||
R ret;
|
||||
for(size_t i(0); i < lanes<R>(); ++i)
|
||||
ret[i] = in[i];
|
||||
|
||||
return ret;
|
||||
using simd::lane_cast;
|
||||
}
|
||||
|
||||
#ifdef HAVE_X86INTRIN_H
|
||||
|
|
Loading…
Reference in a new issue