summaryrefslogtreecommitdiffhomepage
path: root/serialize/packbits-write.cpp
blob: 7dab800a6615c72e3a248fbfb433dc7e552e8350 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "packbits-write.hpp"

namespace floormat {

namespace {

using namespace floormat::Pack_impl;

using u32 = uint32_t;
using u16 = uint16_t;
using u8 = uint8_t;
template<size_t N> using f32 = output_field<u32, N>;
template<size_t N> using f16 = output_field<u16, N>;
template<size_t N> using f8 = output_field<u8, N>;

static_assert(write_(std::tuple<output_field<u32, 13>>{4242}, output<u32, 32, 32>{0}, std::index_sequence<0>{}) == 4242u);

static_assert(write_(
    std::tuple{f8<3>{7}, f8<2>{3}, f8<1>{1}},
    output<u8, 8, 6>{0},
    std::make_index_sequence<3>{}
) == (1 << 6) - 1);

static_assert(write_(
    std::tuple{f32<2>{0b10}, f32<3>{0b011}, f32<3>{0b001}},
    output<u32, 32, 32>{0},
    make_reverse_index_sequence<3>{}) == 0b000101110);

static_assert(pack_write(std::tuple{f32<2>{0b10}, f32<3>{0b011}, f32<3>{0b01}}) == 0b00101110);
//static_assert(pack_write(std::tuple{f32<2>{0b10}, f32<3>{0b1011}, f32<3>{0b001}}) == 0b000101110);
static_assert(pack_write(std::tuple{f8<2>{0b10}, f8<3>{0b011}, f8<3>{0b01}}) == 0b00101110);
//static_assert(pack_write(std::tuple{f8<2>{0b10}, f8<3>{0b011}, f8<4>{0b01}}) == 0b00101110);
//static_assert(pack_write(std::tuple{}) == 0);
static_assert(pack_write(std::tuple{f8<1>{0b1}, f8<3>{0b101}, f8<2>{0b10}}) == 0b101011);

#if 0 // check disassembly
u32 foo1(u32 a, u32 b, u32 c);
u32 foo1(u32 a, u32 b, u32 c)
{
    return pack_write(std::tuple{f32<2>{a}, f32<3>{b}, f32<3>{c}});
}
#endif

} // namespace

#if 0
[[maybe_unused]] uint8_t test1(uint8_t a, uint8_t b, uint8_t c)
{
    return pack_write(std::tuple{f8<2>{a}, f8<3>{b}, f8<3>{c}});
}
#endif

} // namespace floormat