1/* Copyright (C) 2011-2017 Povilas Kanapickas <povilas@radix.lt>
2
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at
5 http://www.boost.org/LICENSE_1_0.txt)
6*/
7
8#ifndef LIBSIMDPP_SIMD_CORE_EXTRACT_BITS_H
9#define LIBSIMDPP_SIMD_CORE_EXTRACT_BITS_H
10
11#ifndef LIBSIMDPP_SIMD_H
12 #error "This file must be included through simd.h"
13#endif
14
15#include <simdpp/types.h>
16#include <simdpp/detail/insn/extract_bits.h>
17
18namespace simdpp {
19namespace SIMDPP_ARCH_NAMESPACE {
20
21/** Extracts a bit from each byte of each element of a vector containing 8-bit
22 elements.
23
24 This operation is only sensible if each byte within the vector is either
25 0x00 or 0xff.
26
27 @code
28 r = ((a[0] & 0x??) ? 0x01 : 0) |
29 ((a[1] & 0x??) ? 0x02 : 0) |
30 ...
31 ((a[15] & 0x??) ? 0x80 : 0)
32 @endcode
33*/
34SIMDPP_INL uint16_t extract_bits_any(const uint8<16>& a)
35{
36 return detail::insn::i_extract_bits_any(a);
37}
38SIMDPP_INL uint32_t extract_bits_any(const uint8<32>& a)
39{
40 return detail::insn::i_extract_bits_any(a);
41}
42
43/** Extracts specific bit from each byte of each element of a int8x16 vector.
44
45 @code
46 r = (a[0] & 0x80 >> 7) | (a[1] & 0x80 >> 6) | ... | (a[15] & 0x80 << 8)
47 @endcode
48*/
49template<unsigned id> SIMDPP_INL
50uint16_t extract_bits(const uint8<16>& a)
51{
52 static_assert(id < 8, "index out of bounds");
53 return detail::insn::i_extract_bits<id>(a);
54}
55template<unsigned id> SIMDPP_INL
56uint32_t extract_bits(const uint8<32>& a)
57{
58 static_assert(id < 8, "index out of bounds");
59 return detail::insn::i_extract_bits<id>(a);
60}
61
62} // namespace SIMDPP_ARCH_NAMESPACE
63} // namespace simdpp
64
65#endif
66
67
68