GCC Code Coverage Report


Directory: ./
File: openvdb_ax/openvdb_ax/test/backend/TestCodecs.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 189 190 99.5%
Functions: 9 9 100.0%
Branches: 571 1106 51.6%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #include "util.h"
5
6 #include <openvdb_ax/codegen/Types.h>
7 #include <openvdb_ax/codegen/Codecs.h>
8
9 #include <openvdb/points/AttributeArray.h> // for native codec types
10
11 #include <cppunit/extensions/HelperMacros.h>
12
13 #include <limits>
14
15 using namespace openvdb;
16 using namespace openvdb::ax;
17 using namespace openvdb::ax::codegen;
18 using namespace openvdb::points;
19 using HalfTy = openvdb::math::half;
20
21 struct UFxpt8 { static const bool OneByte = true; using type = FixedPointCodec<OneByte, UnitRange>; };
22 struct UFxpt16 { static const bool OneByte = false; using type = FixedPointCodec<OneByte, UnitRange>; };
23 struct PRFxpt8 { static const bool OneByte = true; using type = FixedPointCodec<OneByte, PositionRange>; };
24 struct PRFxpt16 { static const bool OneByte = false; using type = FixedPointCodec<OneByte, PositionRange>; };
25
26
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
6 class TestCodecs : public CppUnit::TestCase
27 {
28 public:
29
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
4 CPPUNIT_TEST_SUITE(TestCodecs);
30
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
6 CPPUNIT_TEST(testRegisteredCodecs);
31
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
6 CPPUNIT_TEST(testTruncateCodec);
32
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
6 CPPUNIT_TEST(testFxptCodec<UFxpt8>);
33
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
6 CPPUNIT_TEST(testFxptCodec<UFxpt16>);
34
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
6 CPPUNIT_TEST(testFxptCodec<PRFxpt8>);
35
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
6 CPPUNIT_TEST(testFxptCodec<PRFxpt16>);
36
4/8
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
4 CPPUNIT_TEST_SUITE_END();
37
38 void testRegisteredCodecs();
39 void testTruncateCodec();
40 template <typename FxptCodecT>
41 void testFxptCodec();
42 };
43
44 CPPUNIT_TEST_SUITE_REGISTRATION(TestCodecs);
45
46 inline const Codec*
47 5 getCodecByCodecName(const std::string& name)
48 {
49 std::vector<const Codec*> codecs;
50 5 const auto& map = getCodecTypeMap();
51
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 for (const auto& typemap : map) {
52
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 2 times.
17 for (const auto& nameToCodec : typemap.second) {
53
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 10 times.
15 if (nameToCodec.first == name) {
54 5 return nameToCodec.second;
55 }
56 }
57 }
58 return nullptr;
59 }
60
61 1 void TestCodecs::testRegisteredCodecs()
62 {
63 // For each codec, verify the way its been setup. Really this should be
64 // enforced as part of the API but the majority of the setup code is internal.
65
66 2 llvm::LLVMContext C;
67
68 // Get all unique registered codecs
69 std::set<const Codec*> codecs;
70
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const auto& map = getCodecTypeMap();
71
72
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for (const auto& typemap : map) {
73
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2 times.
10 for (const auto& nameToCodec : typemap.second) {
74
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 codecs.insert(nameToCodec.second);
75 }
76 }
77
78 // currently only 5 codecs are registered by default
79
4/8
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
1 CPPUNIT_ASSERT_EQUAL(codecs.size(), size_t(5));
80
81 // for each codec, check:
82 // make sure the codecs flags are unique
83 // make sure the encoder/decoder functions have unique signatures
84
85 std::set<uint32_t> flags;
86
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
6 for (const Codec* codec : codecs) {
87
7/14
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 5 times.
✗ Branch 14 not taken.
✓ Branch 17 taken 5 times.
✗ Branch 18 not taken.
✓ Branch 25 taken 5 times.
✗ Branch 26 not taken.
10 CPPUNIT_ASSERT(!flags.count(codec->flag()));
88
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 flags.insert(codec->flag());
89 }
90
91 //
92
93
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
6 for (const Codec* codec : codecs) {
94 const codegen::FunctionGroup* encoder = codec->encoder();
95 const codegen::FunctionGroup* decoder = codec->decoder();
96
6/12
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 5 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 5 times.
✗ Branch 17 not taken.
5 CPPUNIT_ASSERT(encoder);
97
6/12
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 5 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 5 times.
✗ Branch 17 not taken.
5 CPPUNIT_ASSERT(decoder);
98
6/12
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 5 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 5 times.
✗ Branch 17 not taken.
5 CPPUNIT_ASSERT(!encoder->list().empty());
99
6/12
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 5 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 5 times.
✗ Branch 17 not taken.
5 CPPUNIT_ASSERT(!decoder->list().empty());
100
101 std::set<std::vector<llvm::Type*>> decoderSignatures, encoderSignatures;
102
103
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 5 times.
21 for (const auto& F : decoder->list()) {
104 // check the function takes 2 arguments (in/out)
105 // @note This could change in the future e.g. a value is returned
106
5/10
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 16 times.
✗ Branch 11 not taken.
✓ Branch 16 taken 16 times.
✗ Branch 17 not taken.
16 CPPUNIT_ASSERT_EQUAL(F->size(), size_t(2)); // input/output
107 std::vector<llvm::Type*> types;
108
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 llvm::Type* ret = F->types(types, C);
109 // currently expect codecs to ret void
110
4/8
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 16 times.
✗ Branch 11 not taken.
32 CPPUNIT_ASSERT_EQUAL(ret, codegen::LLVMType<void>::get(C));
111 // signature should be unqiue
112
7/14
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 16 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 16 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 16 times.
✗ Branch 17 not taken.
✓ Branch 24 taken 16 times.
✗ Branch 25 not taken.
32 CPPUNIT_ASSERT(!decoderSignatures.count(types));
113 decoderSignatures.insert(types);
114 }
115
116
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 5 times.
21 for (const auto& F : encoder->list()) {
117 // check the function takes 2 arguments (in/out)
118 // @note This could change in the future e.g. a value is returned
119
5/10
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 16 times.
✗ Branch 11 not taken.
✓ Branch 16 taken 16 times.
✗ Branch 17 not taken.
16 CPPUNIT_ASSERT_EQUAL(F->size(), size_t(2)); // input/output
120 std::vector<llvm::Type*> types;
121
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 llvm::Type* ret = F->types(types, C);
122 // currently expect codecs to ret void
123
4/8
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 16 times.
✗ Branch 11 not taken.
32 CPPUNIT_ASSERT_EQUAL(ret, codegen::LLVMType<void>::get(C));
124 // signature should be unqiue
125
7/14
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 16 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 16 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 16 times.
✗ Branch 17 not taken.
✓ Branch 24 taken 16 times.
✗ Branch 25 not taken.
32 CPPUNIT_ASSERT(!encoderSignatures.count(types));
126 encoderSignatures.insert(types);
127 }
128
129
6/12
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 5 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 5 times.
✗ Branch 17 not taken.
5 CPPUNIT_ASSERT(!encoderSignatures.empty());
130
6/12
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 5 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 5 times.
✗ Branch 17 not taken.
5 CPPUNIT_ASSERT(!decoderSignatures.empty());
131
5/10
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 16 taken 5 times.
✗ Branch 17 not taken.
5 CPPUNIT_ASSERT_EQUAL(decoderSignatures.size(), encoderSignatures.size());
132
133 // check signatures have unique input/output types
134 // @note This is necessary so that the IR knows what type to expect for a given input
135
136
2/4
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
10 std::vector<std::vector<llvm::Type*>> copy(decoderSignatures.size());
137
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 std::copy(decoderSignatures.begin(), decoderSignatures.end(), copy.begin());
138
139
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 5 times.
13 for (size_t i = 0; i < copy.size(); ++i) {
140
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 const auto types = copy.back();
141 8 const llvm::Type* first = types[0];
142
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 const llvm::Type* second = types[1];
143 copy.pop_back();
144
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 8 times.
34 for (const auto& remaining : copy) {
145
6/12
✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 26 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 26 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 26 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 26 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 26 times.
✗ Branch 17 not taken.
26 CPPUNIT_ASSERT(first != remaining[0]);
146
6/12
✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 26 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 26 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 26 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 26 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 26 times.
✗ Branch 17 not taken.
26 CPPUNIT_ASSERT(second != remaining[1]);
147 }
148 }
149
150 // check signatures have unique input/output types
151 // @note This is necessary so that the IR knows what type to expect for a given input
152
153
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 copy.resize(decoderSignatures.size());
154
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 std::copy(encoderSignatures.begin(), encoderSignatures.end(), copy.begin());
155
156
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 5 times.
13 for (size_t i = 0; i < copy.size(); ++i) {
157
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 const auto types = copy.back();
158 8 const llvm::Type* first = types[0];
159
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 const llvm::Type* second = types[1];
160 copy.pop_back();
161
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 8 times.
34 for (const auto& remaining : copy) {
162
6/12
✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 26 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 26 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 26 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 26 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 26 times.
✗ Branch 17 not taken.
26 CPPUNIT_ASSERT(first != remaining[0]);
163
6/12
✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 26 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 26 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 26 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 26 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 26 times.
✗ Branch 17 not taken.
26 CPPUNIT_ASSERT(second != remaining[1]);
164 }
165 }
166
167 // Check that every decoder has a matching encoder signature
168
169
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 5 times.
21 for (const auto& types : decoderSignatures) {
170
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 std::vector<llvm::Type*> rev = types;
171 16 std::reverse(rev.begin(), rev.end());
172
7/14
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 16 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 16 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 16 times.
✗ Branch 17 not taken.
✓ Branch 23 taken 16 times.
✗ Branch 24 not taken.
32 CPPUNIT_ASSERT(encoderSignatures.find(rev) != encoderSignatures.end());
173 }
174 }
175 1 }
176
177 1 void TestCodecs::testTruncateCodec()
178 {
179
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
2 unittest_util::LLVMState state;
180 llvm::LLVMContext& C = state.context();
181 llvm::Module& M = state.module();
182
183 const Codec* const codec =
184
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 getCodecByCodecName(TruncateCodec::name());
185
7/14
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 24 taken 1 times.
✗ Branch 25 not taken.
1 CPPUNIT_ASSERT(codec);
186
187
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 llvm::Type* floatty = codegen::LLVMType<float>::get(C);
188
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 llvm::Type* vfloatty = codegen::LLVMType<math::Vec3<float>>::get(C);
189
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 llvm::Type* halfty = codegen::LLVMType<HalfTy>::get(C);
190 1 llvm::Type* vhalfty = codegen::LLVMType<math::Vec3<HalfTy>>::get(C);
191
192
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
1 CPPUNIT_ASSERT_EQUAL(halfty, codec->decodedToEncoded(ast::tokens::CoreType::FLOAT, C));
193
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
1 CPPUNIT_ASSERT_EQUAL(vhalfty, codec->decodedToEncoded(ast::tokens::CoreType::VEC3F, C));
194
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
1 CPPUNIT_ASSERT_EQUAL(floatty, codec->encodedToDecoded(halfty));
195
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
1 CPPUNIT_ASSERT_EQUAL(vfloatty, codec->encodedToDecoded(vhalfty));
196
197 // JIT the codec and test the IR
198
199 const codegen::FunctionGroup* encoder = codec->encoder();
200 const codegen::FunctionGroup* decoder = codec->decoder();
201
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
1 CPPUNIT_ASSERT(encoder);
202
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
1 CPPUNIT_ASSERT(decoder);
203
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
1 CPPUNIT_ASSERT(!encoder->list().empty());
204
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
1 CPPUNIT_ASSERT(!decoder->list().empty());
205
206
8/14
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 8 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 8 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 8 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 8 times.
✗ Branch 19 not taken.
9 for (auto& F : encoder->list()) CPPUNIT_ASSERT(F->create(M));
207
8/14
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 8 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 8 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 8 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 8 times.
✗ Branch 19 not taken.
9 for (auto& F : decoder->list()) CPPUNIT_ASSERT(F->create(M));
208
209
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 auto EE = state.EE();
210
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
1 CPPUNIT_ASSERT(EE);
211
212 // test truncate encoders
213
214 using FloatToHalf = void(HalfTy*, float*);
215 using VFloatToHalf = void(math::Vec3<HalfTy>*, math::Vec3<float>*);
216
217 const std::vector<float> floatInputs {
218 1.0f, 0.0f, -1.0f,
219 0.5f, 0.13454f, -0.98781f,
220 1.0431e-6f, 1.0431e+6f, std::numeric_limits<float>::max(),
221 313.33f, std::numeric_limits<float>::min(), std::numeric_limits<float>::lowest()
222
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1 };
223
224 const std::vector<math::Vec3<float>> vfloatInputs {
225 math::Vec3<float>(floatInputs.data() + 0),
226 math::Vec3<float>(floatInputs.data() + 3),
227 math::Vec3<float>(floatInputs.data() + 6),
228 math::Vec3<float>(floatInputs.data() + 9)
229
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1 };
230
231 {
232
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 const int64_t address = EE->getFunctionAddress(encoder->list()[0]->symbol());
233
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
1 CPPUNIT_ASSERT(address);
234 1 const auto truncEncodeFloatToHalf = reinterpret_cast<std::add_pointer<FloatToHalf>::type>(address);
235
236 HalfTy result1, result2;
237
238
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1 times.
13 for (float input : floatInputs)
239 {
240 12 const float tmp = input;
241
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 truncEncodeFloatToHalf(&result1, &input);
242
5/10
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 12 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 12 times.
✗ Branch 11 not taken.
✓ Branch 16 taken 12 times.
✗ Branch 17 not taken.
12 CPPUNIT_ASSERT_EQUAL(input, tmp); // doesn't change
243 TruncateCodec::encode<HalfTy, float>(input, result2);
244
4/8
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 12 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 12 times.
✗ Branch 11 not taken.
12 CPPUNIT_ASSERT_EQUAL(result2, result1);
245 }
246 }
247
248 {
249
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 const int64_t address = EE->getFunctionAddress(encoder->list()[5]->symbol());
250
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
1 CPPUNIT_ASSERT(address);
251 1 const auto truncEncodeVecFloatToHalf = reinterpret_cast<std::add_pointer<VFloatToHalf>::type>(address);
252
253 math::Vec3<HalfTy> result1, result2;
254
255
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (math::Vec3<float> input : vfloatInputs)
256 {
257 4 const math::Vec3<float> tmp(input);
258
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 truncEncodeVecFloatToHalf(&result1, &input);
259
5/10
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
4 CPPUNIT_ASSERT_EQUAL(input, tmp); // doesn't change
260 TruncateCodec::encode<math::Vec3<HalfTy>, math::Vec3<float>>(input, result2);
261
4/8
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
4 CPPUNIT_ASSERT_EQUAL(result2, result1);
262 }
263 }
264
265 // test truncate decoders
266
267 using HalfToFloat = void(float*, HalfTy*);
268 using VHalfToFloat = void(math::Vec3<float>*, math::Vec3<HalfTy>*);
269
270 const std::vector<HalfTy> halfInputs {
271 1.0f, 0.0f, -1.0f,
272 0.5f, 0.13454f, -0.98781f,
273 1.0431e-6f, 1.0431e+6f, std::numeric_limits<HalfTy>::max(),
274 313.33f, std::numeric_limits<HalfTy>::min(), std::numeric_limits<HalfTy>::lowest()
275
3/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
2 };
276
277 const std::vector<math::Vec3<HalfTy>> vhalfInputs {
278 math::Vec3<HalfTy>(halfInputs.data() + 0),
279 math::Vec3<HalfTy>(halfInputs.data() + 3),
280 math::Vec3<HalfTy>(halfInputs.data() + 6),
281 math::Vec3<HalfTy>(halfInputs.data() + 9)
282
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1 };
283
284 {
285
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 const int64_t address = EE->getFunctionAddress(decoder->list()[0]->symbol());
286
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
1 CPPUNIT_ASSERT(address);
287 1 const auto truncDecodeHalfToFloat = reinterpret_cast<std::add_pointer<HalfToFloat>::type>(address);
288
289 float result1, result2;
290
291
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1 times.
13 for (HalfTy input : halfInputs)
292 {
293 12 const HalfTy tmp = input;
294
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 truncDecodeHalfToFloat(&result1, &input);
295
5/10
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 12 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 12 times.
✗ Branch 11 not taken.
✓ Branch 16 taken 12 times.
✗ Branch 17 not taken.
12 CPPUNIT_ASSERT_EQUAL(input, tmp); // doesn't change
296 TruncateCodec::encode<float, HalfTy>(input, result2);
297
4/8
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 12 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 12 times.
✗ Branch 11 not taken.
12 CPPUNIT_ASSERT_EQUAL(result2, result1);
298 }
299 }
300
301 {
302
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 const int64_t address = EE->getFunctionAddress(decoder->list()[5]->symbol());
303
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
1 CPPUNIT_ASSERT(address);
304 1 const auto truncDecodeVecHalfToFloat = reinterpret_cast<std::add_pointer<VHalfToFloat>::type>(address);
305
306 math::Vec3<float> result1, result2;
307
308
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (math::Vec3<HalfTy> input : vhalfInputs)
309 {
310 4 const math::Vec3<HalfTy> tmp(input);
311
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 truncDecodeVecHalfToFloat(&result1, &input);
312
4/8
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
4 CPPUNIT_ASSERT_EQUAL(input, tmp); // doesn't change
313 TruncateCodec::encode<math::Vec3<float>, math::Vec3<HalfTy>>(input, result2);
314
4/8
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
4 CPPUNIT_ASSERT_EQUAL(result2, result1);
315 }
316 }
317 1 }
318
319 template <typename FxptCodecT>
320 8 void TestCodecs::testFxptCodec()
321 {
322 static const bool OneByte = FxptCodecT::OneByte;
323 using IntT = typename std::conditional<OneByte, uint8_t, uint16_t>::type;
324 using FixedPointCodecType = typename FxptCodecT::type;
325
326
3/6
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
16 unittest_util::LLVMState state;
327 llvm::LLVMContext& C = state.context();
328 llvm::Module& M = state.module();
329
330
3/6
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
8 const Codec* const codec = getCodecByCodecName(FixedPointCodecType::name());
331
7/14
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
✓ Branch 24 taken 4 times.
✗ Branch 25 not taken.
8 CPPUNIT_ASSERT(codec);
332
333
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
8 llvm::Type* uintty = OneByte ? codegen::LLVMType<uint8_t>::get(C) : codegen::LLVMType<uint16_t>::get(C);
334
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
8 llvm::Type* vuintty = OneByte ? codegen::LLVMType<math::Vec3<uint8_t>>::get(C) : codegen::LLVMType<math::Vec3<uint16_t>>::get(C);
335
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
8 llvm::Type* floatty = codegen::LLVMType<float>::get(C);
336 8 llvm::Type* vfloatty = codegen::LLVMType<math::Vec3<float>>::get(C);
337
338
7/14
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 4 times.
✗ Branch 20 not taken.
8 CPPUNIT_ASSERT(nullptr == codec->decodedToEncoded(ast::tokens::CoreType::INT32, C));
339
7/14
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 4 times.
✗ Branch 20 not taken.
8 CPPUNIT_ASSERT(nullptr == codec->decodedToEncoded(ast::tokens::CoreType::VEC2F, C));
340
7/14
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 4 times.
✗ Branch 20 not taken.
8 CPPUNIT_ASSERT(nullptr == codec->decodedToEncoded(ast::tokens::CoreType::STRING, C));
341
5/10
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
8 CPPUNIT_ASSERT_EQUAL(uintty, codec->decodedToEncoded(ast::tokens::CoreType::FLOAT, C));
342
5/10
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
8 CPPUNIT_ASSERT_EQUAL(vuintty, codec->decodedToEncoded(ast::tokens::CoreType::VEC3F, C));
343
5/10
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
8 CPPUNIT_ASSERT_EQUAL(floatty, codec->encodedToDecoded(uintty));
344
6/12
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 19 taken 4 times.
✗ Branch 20 not taken.
8 CPPUNIT_ASSERT_EQUAL(vfloatty, codec->encodedToDecoded(vuintty));
345
346 // JIT the codec and test the IR
347
348 const codegen::FunctionGroup* encoder = codec->encoder();
349 const codegen::FunctionGroup* decoder = codec->decoder();
350
6/12
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
8 CPPUNIT_ASSERT(encoder);
351
6/12
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
8 CPPUNIT_ASSERT(decoder);
352
6/12
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
8 CPPUNIT_ASSERT(!encoder->list().empty());
353
6/12
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
8 CPPUNIT_ASSERT(!decoder->list().empty());
354
4/8
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
8 CPPUNIT_ASSERT_EQUAL(encoder->list().size(), size_t(2));
355
4/8
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
8 CPPUNIT_ASSERT_EQUAL(decoder->list().size(), size_t(2));
356
357
8/14
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 8 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 8 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 8 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 8 times.
✗ Branch 19 not taken.
24 for (auto& F : encoder->list()) CPPUNIT_ASSERT(F->create(M));
358
8/14
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 8 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 8 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 8 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 8 times.
✗ Branch 19 not taken.
24 for (auto& F : decoder->list()) CPPUNIT_ASSERT(F->create(M));
359
360
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
8 auto EE = state.EE();
361
6/12
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
8 CPPUNIT_ASSERT(EE);
362
363 // test truncate encoders
364
365 using FloatToFxpt = void(IntT*, float*);
366 using VFloatToFxpt = void(math::Vec3<IntT>*, math::Vec3<float>*);
367
368
2/6
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
8 const std::vector<float> floatInputs {
369 1.0f, 0.0f, -1.0f,
370 0.5f, 0.20024414435034715f, -0.98781f,
371 1e-3f, 0.2f, 0.6f,
372 0.8f, 1.5f, -1.5f,
373 100.0f, std::numeric_limits<float>::lowest(), -100.0f
374 };
375
376
2/6
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
8 const std::vector<math::Vec3<float>> vfloatInputs {
377 math::Vec3<float>(floatInputs.data() + 0),
378 math::Vec3<float>(floatInputs.data() + 3),
379 math::Vec3<float>(floatInputs.data() + 6),
380 math::Vec3<float>(floatInputs.data() + 9),
381 math::Vec3<float>(floatInputs.data() + 12)
382 };
383
384 {
385
2/4
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
8 const int64_t address = EE->getFunctionAddress(encoder->list()[0]->symbol());
386
6/12
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
8 CPPUNIT_ASSERT(address);
387 8 const auto fxptEncodeFloat = reinterpret_cast<typename std::add_pointer<FloatToFxpt>::type>(address);
388
389 IntT result1, result2;
390
391
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 4 times.
128 for (float input : floatInputs)
392 {
393 120 const float tmp = input;
394
1/2
✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
120 fxptEncodeFloat(&result1, &input);
395
6/10
✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 60 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 60 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 60 times.
✗ Branch 11 not taken.
✓ Branch 15 taken 40 times.
✓ Branch 16 taken 20 times.
120 CPPUNIT_ASSERT_EQUAL(input, tmp); // doesn't change
396 FixedPointCodecType::template encode<IntT, float>(input, result2);
397
4/8
✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 60 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 60 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 60 times.
✗ Branch 11 not taken.
120 CPPUNIT_ASSERT_EQUAL(result2, result1);
398 }
399 }
400
401 {
402
2/4
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
8 const int64_t address = EE->getFunctionAddress(encoder->list()[1]->symbol());
403
6/12
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
8 CPPUNIT_ASSERT(address);
404 8 const auto fxptEncodeVFloat = reinterpret_cast<typename std::add_pointer<VFloatToFxpt>::type>(address);
405
406 math::Vec3<IntT> result1, result2;
407
408
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 4 times.
48 for (math::Vec3<float> input : vfloatInputs)
409 {
410 40 const math::Vec3<float> tmp(input);
411
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 fxptEncodeVFloat(&result1, &input);
412
4/8
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 20 times.
✗ Branch 11 not taken.
40 CPPUNIT_ASSERT_EQUAL(input, tmp); // doesn't change
413 20 FixedPointCodecType::template encode<math::Vec3<IntT>, math::Vec3<float>>(input, result2);
414
4/8
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 20 times.
✗ Branch 11 not taken.
40 CPPUNIT_ASSERT_EQUAL(result2, result1);
415 }
416 }
417
418 // test truncate decoders
419
420 using FxptToFloat = void(float*, IntT*);
421 using VFxptToFloat = void(math::Vec3<float>*, math::Vec3<IntT>*);
422
423
1/4
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
8 std::vector<IntT> uintInputs = {
424 0, 1, 2,
425 100, 200, 212,
426 10, 215, 94,
427 54, std::numeric_limits<IntT>::max(), 199
428 };
429
430
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
4 if (OneByte) uintInputs.insert(uintInputs.end(), { IntT(13132), IntT(31334), IntT(60000) });
431
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
4 else uintInputs.insert(uintInputs.end(), { 111, 222, 18 });
432
433
2/6
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
8 const std::vector<math::Vec3<IntT>> vuintInputs {
434 math::Vec3<IntT>(uintInputs.data() + 0),
435 math::Vec3<IntT>(uintInputs.data() + 3),
436 math::Vec3<IntT>(uintInputs.data() + 6),
437 math::Vec3<IntT>(uintInputs.data() + 9),
438 math::Vec3<IntT>(uintInputs.data() + 12)
439 };
440
441 {
442
2/4
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
8 const int64_t address = EE->getFunctionAddress(decoder->list()[0]->symbol());
443
6/12
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
8 CPPUNIT_ASSERT(address);
444 8 const auto fxptDecodeUint8 = reinterpret_cast<typename std::add_pointer<FxptToFloat>::type>(address);
445
446 float result1, result2;
447
448
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 4 times.
128 for (IntT input : uintInputs)
449 {
450 120 const IntT tmp = input;
451
1/2
✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
120 fxptDecodeUint8(&result1, &input);
452
5/10
✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 60 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 60 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 60 times.
✗ Branch 11 not taken.
✓ Branch 16 taken 60 times.
✗ Branch 17 not taken.
120 CPPUNIT_ASSERT_EQUAL(input, tmp); // doesn't change
453 FixedPointCodecType::template decode<IntT, float>(input, result2);
454
4/8
✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 60 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 60 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 60 times.
✗ Branch 11 not taken.
120 CPPUNIT_ASSERT_EQUAL(result2, result1);
455 }
456 }
457
458 {
459
2/4
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
8 const int64_t address = EE->getFunctionAddress(decoder->list()[1]->symbol());
460
6/12
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
8 CPPUNIT_ASSERT(address);
461 8 const auto fxptDecodeVuint8 = reinterpret_cast<typename std::add_pointer<VFxptToFloat>::type>(address);
462
463 math::Vec3<float> result1, result2;
464
465
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 4 times.
48 for (math::Vec3<IntT> input : vuintInputs)
466 {
467 40 const math::Vec3<IntT> tmp(input);
468
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 fxptDecodeVuint8(&result1, &input);
469
4/8
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 20 times.
✗ Branch 11 not taken.
40 CPPUNIT_ASSERT_EQUAL(input, tmp); // doesn't change
470 40 FixedPointCodecType::template decode<math::Vec3<IntT>, math::Vec3<float>>(input, result2);
471
4/8
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 20 times.
✗ Branch 11 not taken.
40 CPPUNIT_ASSERT_EQUAL(result2, result1);
472 }
473 }
474 8 }
475