E.V.E
v2023.02.15
 
Loading...
Searching...
No Matches

◆ bit_ternary

auto eve::bit_ternary = functor<bit_ternary_t>
inlineconstexpr

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto bit_ternary(integral_constant k, auto u, auto v, auto w) noexcept; // 1
// Lanes masking
constexpr auto bit_xor[conditional_expr auto c](/*any of the above overloads*/) noexcept; // 2
constexpr auto bit_xor[logical_value auto m](/*any of the above overloads*/) noexcept; // 2
}
Specifies that a type is a Conditional Expression.
Definition conditional.hpp:28
The concept logical_value<T> is satisfied if and only if T satisfies eve::value and the element type ...
Definition value.hpp:132
constexpr auto bit_xor
strict_tuple_callable object computing the bitwise XOR of its arguments.
Definition bit_xor.hpp:86
constexpr auto bit_ternary
strict_elementwise_callable object implementing ternary logic.
Definition bit_ternary.hpp:106
EVE Main Namespace.
Definition abi.hpp:18

Parameters

  • k: integral constant whose bits are the result of a lookup table for the ternary operation. The consteval function mfb (make from bits) can be used to generate this constant from its bits (see below).
  • u, v, w, : first argument.
  • c: Conditional expression masking the operation.
  • m: Logical value masking the operation.

Return value

  1. Bitwise ternary logict provides the capability to implement any three-operand binary function; the specific ternary function is specified by value of k. For each bit in each integer, the corresponding bit from a, b, and c are used according to ik, and the result is output.
  2. The operation is performed conditionnaly. Note that the element type of the output is always the one of a and if any parameter is simd, its number of lanes is the number of lanes of the output
  3. The operation is performed conditionnaly.

The following table is the pattern of a truth table: if op is a ternary bit operator the result column is the desired bit output when calling op pn the x, y and z bit values.

x y z result
0 0 0 a
0 0 1 b
0 1 0 c
0 1 1 d
1 0 0 e
1 0 1 f
1 1 0 g
1 1 1 h

A programmer as only to supply the result column, i.e. defines values of bits a through h in a single 8-bit value

k = .(a << 7) + (b << 6) + (c << 5) + (d << 4) + (e << 3) + (f << 2) + (g << 1) + h

(the consteval function eve::truth_table can be used to do that operation: see the example)

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 3u, 5u, 4u, 3u, 2u, 1u, 0u};
eve::wide wu2{6u, 5u, 4u, 3u, 2u, 1u, 0u, ~0u};
std::integral_constant<std::uint8_t, 0xff> iff;
std::integral_constant<std::uint8_t, 0x80> i80;
std::integral_constant<std::uint8_t, 0xac> iac;
std::cout << std::hex << std::endl;
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "<- wu2 = " << wu2 << "\n";
std::cout << "<- iff = " << std::bitset<8>(iff) << std::endl;
std::cout << "<- i80 = " << std::bitset<8>(i80) << std::endl;
std::cout << "<- iac = " << std::bitset<8>(iac) << std::endl;
std::cout << "-> bit_ternary(eve::truth_table<1,1,1,1,1,1,1,1>(), wu0, wu1, wu2) = " << (eve::bit_ternary(eve::truth_table<1,1,1,1,1,1,1,1>(), wu0, wu1, wu2)) << "\n";
std::cout << "-> bit_ternary(iff, wu0, wu1, wu2) = " << (eve::bit_ternary(iff, wu0, wu1, wu2)) << "\n";
std::cout << "-> bit_ternary(eve::truth_table<1,0,0,0,0,0,0,0>(), wu0, wu1, wu2) = " << (eve::bit_ternary(eve::truth_table<1,0,0,0,0,0,0,0>(), wu0, wu1, wu2)) << "\n";
std::cout << "-> bit_ternary(i80, wu0, wu1, wu2) = " << (eve::bit_ternary(i80, wu0, wu1, wu2)) << "\n";
std::cout << "-> bit_ternary(eve::truth_table<1,0,1,0,1,1,0,0>(), wu0, wu1, wu2))= " << (eve::bit_ternary(eve::truth_table<1,0,1,0,1,1,0,0>(), wu0, wu1, wu2)) << "\n";
std::cout << "-> bit_ternary(iac, wu0, wu1, wu2) = " << (eve::bit_ternary(iac, wu0, wu1, wu2)) << "\n";
}
Wrapper for SIMD registers.
Definition wide.hpp:70