0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 18:18:56 +02:00

ircd::simd: Categorical interface renaming for stream related.

This commit is contained in:
Jason Volk 2020-10-10 00:07:06 -07:00
parent de0650d3f7
commit c49e546be5
6 changed files with 96 additions and 113 deletions

View file

@ -40,7 +40,7 @@ noexcept
{
const u64x2 res
{
stream<block_t>(in, max, [&val, &closure]
for_each<block_t>(in, max, [&val, &closure]
(const auto block, const auto mask)
{
closure(val, block, mask);

View file

@ -9,58 +9,58 @@
// full license for this software is available in the LICENSE file.
#pragma once
#define HAVE_IRCD_SIMD_ISTREAM_H
#define HAVE_IRCD_SIMD_FOR_EACH_H
namespace ircd::simd
{
template<class block_t>
using istream_fixed_proto = void (block_t, block_t mask);
using for_each_fixed_proto = void (block_t, block_t mask);
template<class block_t>
using istream_variable_proto = u64x2 (block_t, block_t mask);
using for_each_variable_proto = u64x2 (block_t, block_t mask);
template<class block_t,
class lambda>
using istream_is_fixed_stride = std::is_same
using for_each_is_fixed_stride = std::is_same
<
std::invoke_result_t<lambda, block_t, block_t>, void
>;
template<class block_t,
class lambda>
using istream_is_variable_stride = std::is_same
using for_each_is_variable_stride = std::is_same
<
std::invoke_result_t<lambda, block_t, block_t>, u64x2
>;
template<class block_t,
class lambda>
using istream_fixed_stride = std::enable_if
using for_each_fixed_stride = std::enable_if
<
istream_is_fixed_stride<block_t, lambda>::value, u64x2
for_each_is_fixed_stride<block_t, lambda>::value, u64x2
>;
template<class block_t,
class lambda>
using istream_variable_stride = std::enable_if
using for_each_variable_stride = std::enable_if
<
istream_is_variable_stride<block_t, lambda>::value, u64x2
for_each_is_variable_stride<block_t, lambda>::value, u64x2
>;
template<class block_t,
class lambda>
typename istream_fixed_stride<block_t, lambda>::type
stream(const block_t *, const u64x2, lambda&&) noexcept;
typename for_each_fixed_stride<block_t, lambda>::type
for_each(const block_t *, const u64x2, lambda&&) noexcept;
template<class block_t,
class lambda>
typename istream_fixed_stride<block_t, lambda>::type
stream(const char *, const u64x2, lambda&&) noexcept;
typename for_each_fixed_stride<block_t, lambda>::type
for_each(const char *, const u64x2, lambda&&) noexcept;
template<class block_t,
class lambda>
typename istream_variable_stride<block_t, lambda>::type
stream(const char *, const u64x2, lambda&&) noexcept;
typename for_each_variable_stride<block_t, lambda>::type
for_each(const char *, const u64x2, lambda&&) noexcept;
}
/// Streaming consumer
@ -90,10 +90,10 @@ namespace ircd::simd
///
template<class block_t,
class lambda>
inline typename ircd::simd::istream_variable_stride<block_t, lambda>::type
ircd::simd::stream(const char *const __restrict__ in,
const u64x2 max,
lambda&& closure)
inline typename ircd::simd::for_each_variable_stride<block_t, lambda>::type
ircd::simd::for_each(const char *const __restrict__ in,
const u64x2 max,
lambda&& closure)
noexcept
{
using block_t_u = unaligned<block_t>;
@ -172,10 +172,10 @@ noexcept
///
template<class block_t,
class lambda>
inline typename ircd::simd::istream_fixed_stride<block_t, lambda>::type
ircd::simd::stream(const char *const __restrict__ in,
const u64x2 max,
lambda&& closure)
inline typename ircd::simd::for_each_fixed_stride<block_t, lambda>::type
ircd::simd::for_each(const char *const __restrict__ in,
const u64x2 max,
lambda&& closure)
noexcept
{
using block_t_u = unaligned<block_t>;
@ -246,10 +246,10 @@ noexcept
////
template<class block_t,
class lambda>
inline typename ircd::simd::istream_fixed_stride<block_t, lambda>::type
ircd::simd::stream(const block_t *const __restrict__ in,
const u64x2 max,
lambda&& closure)
inline typename ircd::simd::for_each_fixed_stride<block_t, lambda>::type
ircd::simd::for_each(const block_t *const __restrict__ in,
const u64x2 max,
lambda&& closure)
noexcept
{
u64x2 count

View file

@ -9,58 +9,58 @@
// full license for this software is available in the LICENSE file.
#pragma once
#define HAVE_IRCD_SIMD_OSTREAM_H
#define HAVE_IRCD_SIMD_GENERATE_H
namespace ircd::simd
{
template<class block_t>
using ostream_fixed_proto = void (block_t &, block_t &mask);
using generate_fixed_proto = void (block_t &);
template<class block_t>
using ostream_variable_proto = u64x2 (block_t &, block_t &mask);
using generate_variable_proto = u64x2 (block_t &);
template<class block_t,
class lambda>
using ostream_is_fixed_stride = std::is_same
using generate_is_fixed_stride = std::is_same
<
std::invoke_result_t<lambda, block_t &, block_t &>, void
std::invoke_result_t<lambda, block_t &>, void
>;
template<class block_t,
class lambda>
using ostream_is_variable_stride = std::is_same
using generate_is_variable_stride = std::is_same
<
std::invoke_result_t<lambda, block_t &, block_t &>, u64x2
std::invoke_result_t<lambda, block_t &>, u64x2
>;
template<class block_t,
class lambda>
using ostream_fixed_stride = std::enable_if
using generate_fixed_stride = std::enable_if
<
ostream_is_fixed_stride<block_t, lambda>::value, u64x2
generate_is_fixed_stride<block_t, lambda>::value, u64x2
>;
template<class block_t,
class lambda>
using ostream_variable_stride = std::enable_if
using generate_variable_stride = std::enable_if
<
ostream_is_variable_stride<block_t, lambda>::value, u64x2
generate_is_variable_stride<block_t, lambda>::value, u64x2
>;
template<class block_t,
class lambda>
typename ostream_fixed_stride<block_t, lambda>::type
stream(block_t *, const u64x2, lambda&&) noexcept;
typename generate_fixed_stride<block_t, lambda>::type
generate(block_t *, const u64x2, lambda&&) noexcept;
template<class block_t,
class lambda>
typename ostream_fixed_stride<block_t, lambda>::type
stream(char *, const u64x2, lambda&&) noexcept;
typename generate_fixed_stride<block_t, lambda>::type
generate(char *, const u64x2, lambda&&) noexcept;
template<class block_t,
class lambda>
typename ostream_variable_stride<block_t, lambda>::type
stream(char *, const u64x2, lambda&&) noexcept;
typename generate_variable_stride<block_t, lambda>::type
generate(char *, const u64x2, lambda&&) noexcept;
}
/// Streaming generator
@ -73,9 +73,7 @@ namespace ircd::simd
///
/// * variable-stride: progress for each iteration of the loop across the
/// output and buffer is not fixed; the transform function may advance the
/// pointer one to sizeof(block_t) bytes each iteration. Due to these
/// characteristics, unaligned bytes may be redundantly loaded and non-temporal
/// features are not used to optimize the operation.
/// pointer one to sizeof(block_t) bytes each iteration.
///
/// u64x2 counter lanes = { output_length, available_to_user }; The argument
/// `max` gives the buffer size in that format. The return value is the
@ -90,10 +88,10 @@ namespace ircd::simd
///
template<class block_t,
class lambda>
inline typename ircd::simd::ostream_variable_stride<block_t, lambda>::type
ircd::simd::stream(char *const __restrict__ out,
const u64x2 max,
lambda&& closure)
inline typename ircd::simd::generate_variable_stride<block_t, lambda>::type
ircd::simd::generate(char *const __restrict__ out,
const u64x2 max,
lambda&& closure)
noexcept
{
using block_t_u = unaligned<block_t>;
@ -113,11 +111,6 @@ noexcept
// primary broadband loop
while(produce[0] && count[0] + sizeof(block_t) <= max[0])
{
auto mask
{
~block_t{0}
};
const auto di
{
reinterpret_cast<block_t_u *>(out + count[0])
@ -128,16 +121,16 @@ noexcept
*di
);
produce = closure(block, mask);
produce = closure(block);
count += produce;
}
// trailing narrowband loop
while(produce[0] && count[0] < max[0])
{
block_t block {0}, mask {0};
produce = closure(block, mask);
for(size_t i(0); count[0] + i < max[0] && i < sizeof(block_t) && mask[i]; ++i)
block_t block {0};
produce = closure(block);
for(size_t i(0); count[0] + i < max[0] && i < sizeof(block_t); ++i)
out[count[0] + i] = block[i];
count += produce;
@ -169,10 +162,10 @@ noexcept
///
template<class block_t,
class lambda>
inline typename ircd::simd::ostream_fixed_stride<block_t, lambda>::type
ircd::simd::stream(char *const __restrict__ out,
const u64x2 max,
lambda&& closure)
inline typename ircd::simd::generate_fixed_stride<block_t, lambda>::type
ircd::simd::generate(char *const __restrict__ out,
const u64x2 max,
lambda&& closure)
noexcept
{
using block_t_u = unaligned<block_t>;
@ -201,12 +194,7 @@ noexcept
*di
);
auto mask
{
~block_t{0}
};
closure(block, mask);
closure(block);
count += produce;
}
@ -214,11 +202,11 @@ noexcept
assert(count[0] + sizeof(block_t) > max[0]);
if(likely(count[0] < max[0]))
{
block_t block {0}, mask {0};
closure(block, mask);
block_t block;
closure(block);
size_t i(0);
for(; count[0] + i < max[0] && mask[i]; ++i)
for(; count[0] + i < max[0]; ++i)
out[count[0] + i] = block[i];
count += u64x2
@ -241,10 +229,10 @@ noexcept
////
template<class block_t,
class lambda>
inline typename ircd::simd::ostream_fixed_stride<block_t, lambda>::type
ircd::simd::stream(block_t *const __restrict__ out,
const u64x2 max,
lambda&& closure)
inline typename ircd::simd::generate_fixed_stride<block_t, lambda>::type
ircd::simd::generate(block_t *const __restrict__ out,
const u64x2 max,
lambda&& closure)
noexcept
{
u64x2 count
@ -271,12 +259,7 @@ noexcept
*di
);
auto mask
{
~block_t{0}
};
closure(block, mask);
closure(block);
count += produce;
}

View file

@ -32,9 +32,9 @@
#include "lateral.h"
#include "any.h"
#include "all.h"
#include "istream.h"
#include "iostream.h"
#include "ostream.h"
#include "for_each.h"
#include "transform.h"
#include "generate.h"
#include "accumulate.h"
#include "print.h"

View file

@ -9,53 +9,53 @@
// full license for this software is available in the LICENSE file.
#pragma once
#define HAVE_IRCD_SIMD_IOSTREAM_H
#define HAVE_IRCD_SIMD_TRANSFORM_H
namespace ircd::simd
{
template<class block_t>
using iostream_fixed_proto = void (block_t &, block_t mask);
using transform_fixed_proto = void (block_t &, block_t mask);
template<class block_t>
using iostream_variable_proto = u64x2 (block_t &, block_t mask);
using transform_variable_proto = u64x2 (block_t &, block_t mask);
template<class block_t,
class lambda>
using iostream_is_fixed_stride = std::is_same
using transform_is_fixed_stride = std::is_same
<
std::invoke_result_t<lambda, block_t &, block_t>, void
>;
template<class block_t,
class lambda>
using iostream_is_variable_stride = std::is_same
using transform_is_variable_stride = std::is_same
<
std::invoke_result_t<lambda, block_t &, block_t>, u64x2
>;
template<class block_t,
class lambda>
using iostream_fixed_stride = std::enable_if
using transform_fixed_stride = std::enable_if
<
iostream_is_fixed_stride<block_t, lambda>::value, u64x2
transform_is_fixed_stride<block_t, lambda>::value, u64x2
>;
template<class block_t,
class lambda>
using iostream_variable_stride = std::enable_if
using transform_variable_stride = std::enable_if
<
iostream_is_variable_stride<block_t, lambda>::value, u64x2
transform_is_variable_stride<block_t, lambda>::value, u64x2
>;
template<class block_t,
class lambda>
typename iostream_fixed_stride<block_t, lambda>::type
stream(char *, const char *, const u64x2, lambda&&) noexcept;
typename transform_fixed_stride<block_t, lambda>::type
transform(char *, const char *, const u64x2, lambda&&) noexcept;
template<class block_t,
class lambda>
typename iostream_variable_stride<block_t, lambda>::type
stream(char *, const char *, const u64x2, lambda&&) noexcept;
typename transform_variable_stride<block_t, lambda>::type
transform(char *, const char *, const u64x2, lambda&&) noexcept;
}
/// Streaming transform
@ -82,11 +82,11 @@ namespace ircd::simd
///
template<class block_t,
class lambda>
inline typename ircd::simd::iostream_variable_stride<block_t, lambda>::type
ircd::simd::stream(char *const __restrict__ out,
const char *const __restrict__ in,
const u64x2 max,
lambda&& closure)
inline typename ircd::simd::transform_variable_stride<block_t, lambda>::type
ircd::simd::transform(char *const __restrict__ out,
const char *const __restrict__ in,
const u64x2 max,
lambda&& closure)
noexcept
{
using block_t_u = unaligned<block_t>;
@ -178,11 +178,11 @@ noexcept
///
template<class block_t,
class lambda>
inline typename ircd::simd::iostream_fixed_stride<block_t, lambda>::type
ircd::simd::stream(char *const __restrict__ out,
const char *const __restrict__ in,
const u64x2 max,
lambda&& closure)
inline typename ircd::simd::transform_fixed_stride<block_t, lambda>::type
ircd::simd::transform(char *const __restrict__ out,
const char *const __restrict__ in,
const u64x2 max,
lambda&& closure)
noexcept
{
using block_t_u = unaligned<block_t>;

View file

@ -529,7 +529,7 @@ const
const auto count
{
simd::stream<block_t>(start + 1, max, each_block)
simd::for_each<block_t>(start + 1, max, each_block)
};
const bool ok
@ -3456,7 +3456,7 @@ noexcept
const auto consumed
{
simd::stream<block_t>(ircd::data(buf), ircd::data(input), max, string_stringify)
simd::transform<block_t>(ircd::data(buf), ircd::data(input), max, string_stringify)
};
return consumed[0]; // output pos (bytes written)
@ -3701,7 +3701,7 @@ noexcept
const auto count
{
simd::stream<block_t>(ircd::data(input), max, string_serialized)
simd::for_each<block_t>(ircd::data(input), max, string_serialized)
};
return count[0];