libdpf/include/dpf/prg_dummy.hpp

108 lines
3 KiB
C++
Raw Normal View History

/// @file dpf/prg_dummy.hpp
/// @brief Identity PRG. `eval` returns the seed and ignores the lane.
/// @details Used where a PRG-shaped type is required and the block must stay
/// equal to the seed. The batched entry points write that seed into
/// every output lane.
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @copyright Copyright (c) 2019-2024 Ryan Henry and [others](@ref authors)
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref license) for details.
#ifndef LIBDPF_INCLUDE_DPF_PRG_DUMMY_HPP__
#define LIBDPF_INCLUDE_DPF_PRG_DUMMY_HPP__
#include <array>
#include <algorithm>
#include <cstddef>
#include "hedley/hedley.h"
#include "portable-snippets/exact-int/exact-int.h"
#include "dpf/utils.hpp"
namespace dpf
{
namespace prg
{
struct dummy final
{
using block_type = simde__m128i;
HEDLEY_NO_THROW
HEDLEY_ALWAYS_INLINE
HEDLEY_CONST
static block_type eval(block_type seed, psnip_uint32_t) noexcept
{
return seed;
}
HEDLEY_NO_THROW
HEDLEY_ALWAYS_INLINE
HEDLEY_CONST
static auto eval01(block_type seed) noexcept
{
HEDLEY_PRAGMA(GCC diagnostic push)
HEDLEY_PRAGMA(GCC diagnostic ignored "-Wignored-attributes")
return std::array<block_type, 2>{seed, seed};
HEDLEY_PRAGMA(GCC diagnostic pop)
}
HEDLEY_NO_THROW
HEDLEY_ALWAYS_INLINE
static void eval(block_type seed, block_type * HEDLEY_RESTRICT output,
psnip_uint32_t count_, psnip_uint32_t = 0) noexcept
{
std::fill_n(output, count_, seed);
}
HEDLEY_NO_THROW
HEDLEY_ALWAYS_INLINE
HEDLEY_NON_NULL(1, 2, 3)
static void eval01_x4(const block_type * HEDLEY_RESTRICT seeds,
block_type * HEDLEY_RESTRICT left,
block_type * HEDLEY_RESTRICT right) noexcept
{
for (std::size_t i = 0; i < 4; ++i)
{
left[i] = right[i] = seeds[i];
}
}
HEDLEY_NO_THROW
HEDLEY_ALWAYS_INLINE
HEDLEY_NON_NULL(1, 2)
static void eval_x4(const block_type * HEDLEY_RESTRICT seeds,
block_type * HEDLEY_RESTRICT output, psnip_uint32_t = 0) noexcept
{
std::copy_n(seeds, 4, output);
}
HEDLEY_NO_THROW
HEDLEY_ALWAYS_INLINE
HEDLEY_NON_NULL(1, 2)
static void eval_x8(const block_type * HEDLEY_RESTRICT seeds,
block_type * HEDLEY_RESTRICT output, psnip_uint32_t = 0) noexcept
{
std::copy_n(seeds, 8, output);
}
/// @brief Raw-bit subtractive share of `T` for party `Party` (see `prg.hpp`).
/// @tparam T value type
/// @tparam Party party index, `0` or `1`
/// @param seed the PRG seed
/// @param pos the 0-based index
/// @return Raw-bit subtractive share of `T` for party `Party` (see `prg.hpp`)
/// @see `prg.hpp`
template <typename T, std::size_t Party>
HEDLEY_NO_THROW
static auto expand(block_type seed, psnip_uint32_t pos = 0) noexcept;
}; // struct dummy
} // namespace prg
} // namespace dpf
#endif // LIBDPF_INCLUDE_DPF_PRG_DUMMY_HPP__