bit_stream.cpp 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  1. // Copyright (c) 2017 Google Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include <limits>
  15. #include <sstream>
  16. #include <string>
  17. #include <utility>
  18. #include <vector>
  19. #include "gmock/gmock.h"
  20. #include "source/comp/bit_stream.h"
  21. namespace spvtools {
  22. namespace comp {
  23. namespace {
  24. // Converts |buffer| to a stream of '0' and '1'.
  25. template <typename T>
  26. std::string BufferToStream(const std::vector<T>& buffer) {
  27. std::stringstream ss;
  28. for (auto it = buffer.begin(); it != buffer.end(); ++it) {
  29. std::string str = std::bitset<sizeof(T) * 8>(*it).to_string();
  30. // Strings generated by std::bitset::to_string are read right to left.
  31. // Reversing to left to right.
  32. std::reverse(str.begin(), str.end());
  33. ss << str;
  34. }
  35. return ss.str();
  36. }
  37. // Converts a left-to-right input string of '0' and '1' to a buffer of |T|
  38. // words.
  39. template <typename T>
  40. std::vector<T> StreamToBuffer(std::string str) {
  41. // The input string is left-to-right, the input argument of std::bitset needs
  42. // to right-to-left. Instead of reversing tokens, reverse the entire string
  43. // and iterate tokens from end to begin.
  44. std::reverse(str.begin(), str.end());
  45. const int word_size = static_cast<int>(sizeof(T) * 8);
  46. const int str_length = static_cast<int>(str.length());
  47. std::vector<T> buffer;
  48. buffer.reserve(NumBitsToNumWords<sizeof(T)>(str.length()));
  49. for (int index = str_length - word_size; index >= 0; index -= word_size) {
  50. buffer.push_back(static_cast<T>(
  51. std::bitset<sizeof(T) * 8>(str, index, word_size).to_ullong()));
  52. }
  53. const size_t suffix_length = str.length() % word_size;
  54. if (suffix_length != 0) {
  55. buffer.push_back(static_cast<T>(
  56. std::bitset<sizeof(T) * 8>(str, 0, suffix_length).to_ullong()));
  57. }
  58. return buffer;
  59. }
  60. // Adds '0' chars at the end of the string until the size is a multiple of N.
  61. template <size_t N>
  62. std::string PadToWord(std::string&& str) {
  63. const size_t tail_length = str.size() % N;
  64. if (tail_length != 0) str += std::string(N - tail_length, '0');
  65. return std::move(str);
  66. }
  67. // Adds '0' chars at the end of the string until the size is a multiple of N.
  68. template <size_t N>
  69. std::string PadToWord(const std::string& str) {
  70. return PadToWord<N>(std::string(str));
  71. }
  72. // Converts a left-to-right stream of bits to std::bitset.
  73. template <size_t N>
  74. std::bitset<N> StreamToBitset(std::string str) {
  75. std::reverse(str.begin(), str.end());
  76. return std::bitset<N>(str);
  77. }
  78. // Converts a left-to-right stream of bits to uint64.
  79. uint64_t StreamToBits(std::string str) {
  80. std::reverse(str.begin(), str.end());
  81. return std::bitset<64>(str).to_ullong();
  82. }
  83. // A simple and inefficient implementatition of BitWriterInterface,
  84. // using std::stringstream. Intended for tests only.
  85. class BitWriterStringStream : public BitWriterInterface {
  86. public:
  87. void WriteBits(uint64_t bits, size_t num_bits) override {
  88. assert(num_bits <= 64);
  89. ss_ << BitsToStream(bits, num_bits);
  90. }
  91. size_t GetNumBits() const override { return ss_.str().size(); }
  92. std::vector<uint8_t> GetDataCopy() const override {
  93. return StreamToBuffer<uint8_t>(ss_.str());
  94. }
  95. std::string GetStreamRaw() const { return ss_.str(); }
  96. private:
  97. std::stringstream ss_;
  98. };
  99. // A simple and inefficient implementatition of BitReaderInterface.
  100. // Intended for tests only.
  101. class BitReaderFromString : public BitReaderInterface {
  102. public:
  103. explicit BitReaderFromString(std::string&& str)
  104. : str_(std::move(str)), pos_(0) {}
  105. explicit BitReaderFromString(const std::vector<uint64_t>& buffer)
  106. : str_(BufferToStream(buffer)), pos_(0) {}
  107. explicit BitReaderFromString(const std::vector<uint8_t>& buffer)
  108. : str_(PadToWord<64>(BufferToStream(buffer))), pos_(0) {}
  109. size_t ReadBits(uint64_t* bits, size_t num_bits) override {
  110. if (ReachedEnd()) return 0;
  111. std::string sub = str_.substr(pos_, num_bits);
  112. *bits = StreamToBits(sub);
  113. pos_ += sub.length();
  114. return sub.length();
  115. }
  116. size_t GetNumReadBits() const override { return pos_; }
  117. bool ReachedEnd() const override { return pos_ >= str_.length(); }
  118. private:
  119. std::string str_;
  120. size_t pos_;
  121. };
  122. TEST(NumBitsToNumWords, Word8) {
  123. EXPECT_EQ(0u, NumBitsToNumWords<8>(0));
  124. EXPECT_EQ(1u, NumBitsToNumWords<8>(1));
  125. EXPECT_EQ(1u, NumBitsToNumWords<8>(7));
  126. EXPECT_EQ(1u, NumBitsToNumWords<8>(8));
  127. EXPECT_EQ(2u, NumBitsToNumWords<8>(9));
  128. EXPECT_EQ(2u, NumBitsToNumWords<8>(16));
  129. EXPECT_EQ(3u, NumBitsToNumWords<8>(17));
  130. EXPECT_EQ(3u, NumBitsToNumWords<8>(23));
  131. EXPECT_EQ(3u, NumBitsToNumWords<8>(24));
  132. EXPECT_EQ(4u, NumBitsToNumWords<8>(25));
  133. }
  134. TEST(NumBitsToNumWords, Word64) {
  135. EXPECT_EQ(0u, NumBitsToNumWords<64>(0));
  136. EXPECT_EQ(1u, NumBitsToNumWords<64>(1));
  137. EXPECT_EQ(1u, NumBitsToNumWords<64>(64));
  138. EXPECT_EQ(2u, NumBitsToNumWords<64>(65));
  139. EXPECT_EQ(2u, NumBitsToNumWords<64>(128));
  140. EXPECT_EQ(3u, NumBitsToNumWords<64>(129));
  141. }
  142. TEST(ZigZagCoding, Encode0) {
  143. EXPECT_EQ(0u, EncodeZigZag(0, 0));
  144. EXPECT_EQ(1u, EncodeZigZag(-1, 0));
  145. EXPECT_EQ(2u, EncodeZigZag(1, 0));
  146. EXPECT_EQ(3u, EncodeZigZag(-2, 0));
  147. EXPECT_EQ(std::numeric_limits<uint64_t>::max() - 1,
  148. EncodeZigZag(std::numeric_limits<int64_t>::max(), 0));
  149. EXPECT_EQ(std::numeric_limits<uint64_t>::max(),
  150. EncodeZigZag(std::numeric_limits<int64_t>::min(), 0));
  151. }
  152. TEST(ZigZagCoding, Decode0) {
  153. EXPECT_EQ(0, DecodeZigZag(0, 0));
  154. EXPECT_EQ(-1, DecodeZigZag(1, 0));
  155. EXPECT_EQ(1, DecodeZigZag(2, 0));
  156. EXPECT_EQ(-2, DecodeZigZag(3, 0));
  157. EXPECT_EQ(std::numeric_limits<int64_t>::min(),
  158. DecodeZigZag(std::numeric_limits<uint64_t>::max(), 0));
  159. EXPECT_EQ(std::numeric_limits<int64_t>::max(),
  160. DecodeZigZag(std::numeric_limits<uint64_t>::max() - 1, 0));
  161. }
  162. TEST(ZigZagCoding, Encode1) {
  163. EXPECT_EQ(0u, EncodeZigZag(0, 1));
  164. EXPECT_EQ(1u, EncodeZigZag(1, 1));
  165. EXPECT_EQ(2u, EncodeZigZag(-1, 1));
  166. EXPECT_EQ(3u, EncodeZigZag(-2, 1));
  167. EXPECT_EQ(4u, EncodeZigZag(2, 1));
  168. EXPECT_EQ(5u, EncodeZigZag(3, 1));
  169. EXPECT_EQ(6u, EncodeZigZag(-3, 1));
  170. EXPECT_EQ(7u, EncodeZigZag(-4, 1));
  171. EXPECT_EQ(std::numeric_limits<uint64_t>::max() - 2,
  172. EncodeZigZag(std::numeric_limits<int64_t>::max(), 1));
  173. EXPECT_EQ(std::numeric_limits<uint64_t>::max() - 1,
  174. EncodeZigZag(std::numeric_limits<int64_t>::min() + 1, 1));
  175. EXPECT_EQ(std::numeric_limits<uint64_t>::max(),
  176. EncodeZigZag(std::numeric_limits<int64_t>::min(), 1));
  177. }
  178. TEST(ZigZagCoding, Decode1) {
  179. EXPECT_EQ(0, DecodeZigZag(0, 1));
  180. EXPECT_EQ(1, DecodeZigZag(1, 1));
  181. EXPECT_EQ(-1, DecodeZigZag(2, 1));
  182. EXPECT_EQ(-2, DecodeZigZag(3, 1));
  183. EXPECT_EQ(2, DecodeZigZag(4, 1));
  184. EXPECT_EQ(3, DecodeZigZag(5, 1));
  185. EXPECT_EQ(-3, DecodeZigZag(6, 1));
  186. EXPECT_EQ(-4, DecodeZigZag(7, 1));
  187. EXPECT_EQ(std::numeric_limits<int64_t>::min(),
  188. DecodeZigZag(std::numeric_limits<uint64_t>::max(), 1));
  189. EXPECT_EQ(std::numeric_limits<int64_t>::min() + 1,
  190. DecodeZigZag(std::numeric_limits<uint64_t>::max() - 1, 1));
  191. EXPECT_EQ(std::numeric_limits<int64_t>::max(),
  192. DecodeZigZag(std::numeric_limits<uint64_t>::max() - 2, 1));
  193. }
  194. TEST(ZigZagCoding, Encode2) {
  195. EXPECT_EQ(0u, EncodeZigZag(0, 2));
  196. EXPECT_EQ(1u, EncodeZigZag(1, 2));
  197. EXPECT_EQ(2u, EncodeZigZag(2, 2));
  198. EXPECT_EQ(3u, EncodeZigZag(3, 2));
  199. EXPECT_EQ(4u, EncodeZigZag(-1, 2));
  200. EXPECT_EQ(5u, EncodeZigZag(-2, 2));
  201. EXPECT_EQ(6u, EncodeZigZag(-3, 2));
  202. EXPECT_EQ(7u, EncodeZigZag(-4, 2));
  203. EXPECT_EQ(8u, EncodeZigZag(4, 2));
  204. EXPECT_EQ(9u, EncodeZigZag(5, 2));
  205. EXPECT_EQ(10u, EncodeZigZag(6, 2));
  206. EXPECT_EQ(11u, EncodeZigZag(7, 2));
  207. EXPECT_EQ(12u, EncodeZigZag(-5, 2));
  208. EXPECT_EQ(13u, EncodeZigZag(-6, 2));
  209. EXPECT_EQ(14u, EncodeZigZag(-7, 2));
  210. EXPECT_EQ(15u, EncodeZigZag(-8, 2));
  211. EXPECT_EQ(std::numeric_limits<uint64_t>::max() - 4,
  212. EncodeZigZag(std::numeric_limits<int64_t>::max(), 2));
  213. EXPECT_EQ(std::numeric_limits<uint64_t>::max() - 3,
  214. EncodeZigZag(std::numeric_limits<int64_t>::min() + 3, 2));
  215. EXPECT_EQ(std::numeric_limits<uint64_t>::max() - 2,
  216. EncodeZigZag(std::numeric_limits<int64_t>::min() + 2, 2));
  217. EXPECT_EQ(std::numeric_limits<uint64_t>::max() - 1,
  218. EncodeZigZag(std::numeric_limits<int64_t>::min() + 1, 2));
  219. EXPECT_EQ(std::numeric_limits<uint64_t>::max(),
  220. EncodeZigZag(std::numeric_limits<int64_t>::min(), 2));
  221. }
  222. TEST(ZigZagCoding, Decode2) {
  223. EXPECT_EQ(0, DecodeZigZag(0, 2));
  224. EXPECT_EQ(1, DecodeZigZag(1, 2));
  225. EXPECT_EQ(2, DecodeZigZag(2, 2));
  226. EXPECT_EQ(3, DecodeZigZag(3, 2));
  227. EXPECT_EQ(-1, DecodeZigZag(4, 2));
  228. EXPECT_EQ(-2, DecodeZigZag(5, 2));
  229. EXPECT_EQ(-3, DecodeZigZag(6, 2));
  230. EXPECT_EQ(-4, DecodeZigZag(7, 2));
  231. EXPECT_EQ(4, DecodeZigZag(8, 2));
  232. EXPECT_EQ(5, DecodeZigZag(9, 2));
  233. EXPECT_EQ(6, DecodeZigZag(10, 2));
  234. EXPECT_EQ(7, DecodeZigZag(11, 2));
  235. EXPECT_EQ(-5, DecodeZigZag(12, 2));
  236. EXPECT_EQ(-6, DecodeZigZag(13, 2));
  237. EXPECT_EQ(-7, DecodeZigZag(14, 2));
  238. EXPECT_EQ(-8, DecodeZigZag(15, 2));
  239. EXPECT_EQ(std::numeric_limits<int64_t>::min(),
  240. DecodeZigZag(std::numeric_limits<uint64_t>::max(), 2));
  241. EXPECT_EQ(std::numeric_limits<int64_t>::min() + 1,
  242. DecodeZigZag(std::numeric_limits<uint64_t>::max() - 1, 2));
  243. EXPECT_EQ(std::numeric_limits<int64_t>::min() + 2,
  244. DecodeZigZag(std::numeric_limits<uint64_t>::max() - 2, 2));
  245. EXPECT_EQ(std::numeric_limits<int64_t>::min() + 3,
  246. DecodeZigZag(std::numeric_limits<uint64_t>::max() - 3, 2));
  247. EXPECT_EQ(std::numeric_limits<int64_t>::max(),
  248. DecodeZigZag(std::numeric_limits<uint64_t>::max() - 4, 2));
  249. }
  250. TEST(ZigZagCoding, Encode63) {
  251. EXPECT_EQ(0u, EncodeZigZag(0, 63));
  252. for (int64_t i = 0; i < 0xFFFFFFFF; i += 1234567) {
  253. const int64_t positive_val = GetLowerBits(i * i * i + i * i, 63) | 1UL;
  254. ASSERT_EQ(static_cast<uint64_t>(positive_val),
  255. EncodeZigZag(positive_val, 63));
  256. ASSERT_EQ((1ULL << 63) - 1 + positive_val, EncodeZigZag(-positive_val, 63));
  257. }
  258. EXPECT_EQ((1ULL << 63) - 1,
  259. EncodeZigZag(std::numeric_limits<int64_t>::max(), 63));
  260. EXPECT_EQ(std::numeric_limits<uint64_t>::max() - 1,
  261. EncodeZigZag(std::numeric_limits<int64_t>::min() + 1, 63));
  262. EXPECT_EQ(std::numeric_limits<uint64_t>::max(),
  263. EncodeZigZag(std::numeric_limits<int64_t>::min(), 63));
  264. }
  265. TEST(BufToStream, UInt8_Empty) {
  266. const std::string expected_bits = "";
  267. std::vector<uint8_t> buffer = StreamToBuffer<uint8_t>(expected_bits);
  268. EXPECT_TRUE(buffer.empty());
  269. const std::string result_bits = BufferToStream(buffer);
  270. EXPECT_EQ(expected_bits, result_bits);
  271. }
  272. TEST(BufToStream, UInt8_OneWord) {
  273. const std::string expected_bits = "00101100";
  274. std::vector<uint8_t> buffer = StreamToBuffer<uint8_t>(expected_bits);
  275. EXPECT_EQ(std::vector<uint8_t>({static_cast<uint8_t>(
  276. StreamToBitset<8>(expected_bits).to_ulong())}),
  277. buffer);
  278. const std::string result_bits = BufferToStream(buffer);
  279. EXPECT_EQ(expected_bits, result_bits);
  280. }
  281. TEST(BufToStream, UInt8_MultipleWords) {
  282. const std::string expected_bits =
  283. "00100010"
  284. "01101010"
  285. "01111101"
  286. "00100010";
  287. std::vector<uint8_t> buffer = StreamToBuffer<uint8_t>(expected_bits);
  288. EXPECT_EQ(std::vector<uint8_t>({
  289. static_cast<uint8_t>(StreamToBitset<8>("00100010").to_ulong()),
  290. static_cast<uint8_t>(StreamToBitset<8>("01101010").to_ulong()),
  291. static_cast<uint8_t>(StreamToBitset<8>("01111101").to_ulong()),
  292. static_cast<uint8_t>(StreamToBitset<8>("00100010").to_ulong()),
  293. }),
  294. buffer);
  295. const std::string result_bits = BufferToStream(buffer);
  296. EXPECT_EQ(expected_bits, result_bits);
  297. }
  298. TEST(BufToStream, UInt64_Empty) {
  299. const std::string expected_bits = "";
  300. std::vector<uint64_t> buffer = StreamToBuffer<uint64_t>(expected_bits);
  301. EXPECT_TRUE(buffer.empty());
  302. const std::string result_bits = BufferToStream(buffer);
  303. EXPECT_EQ(expected_bits, result_bits);
  304. }
  305. TEST(BufToStream, UInt64_OneWord) {
  306. const std::string expected_bits =
  307. "0001000111101110011001101010101000100010110011000100010010001000";
  308. std::vector<uint64_t> buffer = StreamToBuffer<uint64_t>(expected_bits);
  309. ASSERT_EQ(1u, buffer.size());
  310. EXPECT_EQ(0x1122334455667788u, buffer[0]);
  311. const std::string result_bits = BufferToStream(buffer);
  312. EXPECT_EQ(expected_bits, result_bits);
  313. }
  314. TEST(BufToStream, UInt64_Unaligned) {
  315. const std::string expected_bits =
  316. "0010001001101010011111010010001001001010000111110010010010010101"
  317. "0010001001101010011111111111111111111111";
  318. std::vector<uint64_t> buffer = StreamToBuffer<uint64_t>(expected_bits);
  319. EXPECT_EQ(std::vector<uint64_t>({
  320. StreamToBits(expected_bits.substr(0, 64)),
  321. StreamToBits(expected_bits.substr(64, 64)),
  322. }),
  323. buffer);
  324. const std::string result_bits = BufferToStream(buffer);
  325. EXPECT_EQ(PadToWord<64>(expected_bits), result_bits);
  326. }
  327. TEST(BufToStream, UInt64_MultipleWords) {
  328. const std::string expected_bits =
  329. "0010001001101010011111010010001001001010000111110010010010010101"
  330. "0010001001101010011111111111111111111111000111110010010010010111"
  331. "0000000000000000000000000000000000000000000000000010010011111111";
  332. std::vector<uint64_t> buffer = StreamToBuffer<uint64_t>(expected_bits);
  333. EXPECT_EQ(std::vector<uint64_t>({
  334. StreamToBits(expected_bits.substr(0, 64)),
  335. StreamToBits(expected_bits.substr(64, 64)),
  336. StreamToBits(expected_bits.substr(128, 64)),
  337. }),
  338. buffer);
  339. const std::string result_bits = BufferToStream(buffer);
  340. EXPECT_EQ(expected_bits, result_bits);
  341. }
  342. TEST(PadToWord, Test) {
  343. EXPECT_EQ("10100000", PadToWord<8>("101"));
  344. EXPECT_EQ(
  345. "10100000"
  346. "00000000",
  347. PadToWord<16>("101"));
  348. EXPECT_EQ(
  349. "10100000"
  350. "00000000"
  351. "00000000"
  352. "00000000",
  353. PadToWord<32>("101"));
  354. EXPECT_EQ(
  355. "10100000"
  356. "00000000"
  357. "00000000"
  358. "00000000"
  359. "00000000"
  360. "00000000"
  361. "00000000"
  362. "00000000",
  363. PadToWord<64>("101"));
  364. }
  365. TEST(BitWriterStringStream, Empty) {
  366. BitWriterStringStream writer;
  367. EXPECT_EQ(0u, writer.GetNumBits());
  368. EXPECT_EQ(0u, writer.GetDataSizeBytes());
  369. EXPECT_EQ("", writer.GetStreamRaw());
  370. }
  371. TEST(BitWriterStringStream, WriteBits) {
  372. BitWriterStringStream writer;
  373. const uint64_t bits1 = 0x1 | 0x2 | 0x10;
  374. writer.WriteBits(bits1, 5);
  375. EXPECT_EQ(5u, writer.GetNumBits());
  376. EXPECT_EQ(1u, writer.GetDataSizeBytes());
  377. EXPECT_EQ("11001", writer.GetStreamRaw());
  378. }
  379. TEST(BitWriterStringStream, WriteUnencodedU8) {
  380. BitWriterStringStream writer;
  381. const uint8_t bits = 127;
  382. writer.WriteUnencoded(bits);
  383. EXPECT_EQ(8u, writer.GetNumBits());
  384. EXPECT_EQ("11111110", writer.GetStreamRaw());
  385. }
  386. TEST(BitWriterStringStream, WriteUnencodedS64) {
  387. BitWriterStringStream writer;
  388. const int64_t bits = std::numeric_limits<int64_t>::min() + 7;
  389. writer.WriteUnencoded(bits);
  390. EXPECT_EQ(64u, writer.GetNumBits());
  391. EXPECT_EQ("1110000000000000000000000000000000000000000000000000000000000001",
  392. writer.GetStreamRaw());
  393. }
  394. TEST(BitWriterStringStream, WriteMultiple) {
  395. BitWriterStringStream writer;
  396. std::string expected_result;
  397. const uint64_t b2_val = 0x4 | 0x2 | 0x40;
  398. const std::string bits2 = BitsToStream(b2_val, 8);
  399. writer.WriteBits(b2_val, 8);
  400. const uint64_t val = 0x1 | 0x2 | 0x10;
  401. const std::string bits3 = BitsToStream(val, 8);
  402. writer.WriteBits(val, 8);
  403. const std::string expected = bits2 + bits3;
  404. EXPECT_EQ(expected.length(), writer.GetNumBits());
  405. EXPECT_EQ(2u, writer.GetDataSizeBytes());
  406. EXPECT_EQ(expected, writer.GetStreamRaw());
  407. EXPECT_EQ(PadToWord<8>(expected), BufferToStream(writer.GetDataCopy()));
  408. }
  409. TEST(BitWriterWord64, Empty) {
  410. BitWriterWord64 writer;
  411. EXPECT_EQ(0u, writer.GetNumBits());
  412. EXPECT_EQ(0u, writer.GetDataSizeBytes());
  413. }
  414. TEST(BitWriterWord64, WriteBits) {
  415. BitWriterWord64 writer;
  416. const uint64_t bits1 = 0x1 | 0x2 | 0x10;
  417. writer.WriteBits(bits1, 5);
  418. writer.WriteBits(bits1, 5);
  419. writer.WriteBits(bits1, 5);
  420. EXPECT_EQ(15u, writer.GetNumBits());
  421. EXPECT_EQ(2u, writer.GetDataSizeBytes());
  422. }
  423. TEST(BitWriterWord64, WriteZeroBits) {
  424. BitWriterWord64 writer;
  425. writer.WriteBits(0, 0);
  426. writer.WriteBits(1, 0);
  427. EXPECT_EQ(0u, writer.GetNumBits());
  428. writer.WriteBits(1, 1);
  429. writer.WriteBits(0, 0);
  430. writer.WriteBits(0, 63);
  431. EXPECT_EQ(64u, writer.GetNumBits());
  432. writer.WriteBits(0, 0);
  433. writer.WriteBits(7, 3);
  434. writer.WriteBits(0, 0);
  435. }
  436. TEST(BitWriterWord64, ComparisonTestWriteLotsOfBits) {
  437. BitWriterStringStream writer1;
  438. BitWriterWord64 writer2(16384);
  439. for (uint64_t i = 0; i < 65000; i += 25) {
  440. writer1.WriteBits(i, 16);
  441. writer2.WriteBits(i, 16);
  442. ASSERT_EQ(writer1.GetNumBits(), writer2.GetNumBits());
  443. }
  444. }
  445. TEST(GetLowerBits, Test) {
  446. EXPECT_EQ(0u, GetLowerBits<uint8_t>(255, 0));
  447. EXPECT_EQ(1u, GetLowerBits<uint8_t>(255, 1));
  448. EXPECT_EQ(3u, GetLowerBits<uint8_t>(255, 2));
  449. EXPECT_EQ(7u, GetLowerBits<uint8_t>(255, 3));
  450. EXPECT_EQ(15u, GetLowerBits<uint8_t>(255, 4));
  451. EXPECT_EQ(31u, GetLowerBits<uint8_t>(255, 5));
  452. EXPECT_EQ(63u, GetLowerBits<uint8_t>(255, 6));
  453. EXPECT_EQ(127u, GetLowerBits<uint8_t>(255, 7));
  454. EXPECT_EQ(255u, GetLowerBits<uint8_t>(255, 8));
  455. EXPECT_EQ(0xFFu, GetLowerBits<uint32_t>(0xFFFFFFFF, 8));
  456. EXPECT_EQ(0xFFFFu, GetLowerBits<uint32_t>(0xFFFFFFFF, 16));
  457. EXPECT_EQ(0xFFFFFFu, GetLowerBits<uint32_t>(0xFFFFFFFF, 24));
  458. EXPECT_EQ(0xFFFFFFu, GetLowerBits<uint64_t>(0xFFFFFFFFFFFF, 24));
  459. EXPECT_EQ(0xFFFFFFFFFFFFFFFFu,
  460. GetLowerBits<uint64_t>(0xFFFFFFFFFFFFFFFFu, 64));
  461. EXPECT_EQ(StreamToBits("1010001110"),
  462. GetLowerBits<uint64_t>(StreamToBits("1010001110111101111111"), 10));
  463. }
  464. TEST(BitReaderFromString, FromU8) {
  465. std::vector<uint8_t> buffer = {
  466. 0xAA,
  467. 0xBB,
  468. 0xCC,
  469. 0xDD,
  470. };
  471. const std::string total_stream =
  472. "01010101"
  473. "11011101"
  474. "00110011"
  475. "10111011";
  476. BitReaderFromString reader(buffer);
  477. uint64_t bits = 0;
  478. EXPECT_EQ(2u, reader.ReadBits(&bits, 2));
  479. EXPECT_EQ(PadToWord<64>("01"), BitsToStream(bits));
  480. EXPECT_EQ(20u, reader.ReadBits(&bits, 20));
  481. EXPECT_EQ(PadToWord<64>("01010111011101001100"), BitsToStream(bits));
  482. EXPECT_EQ(20u, reader.ReadBits(&bits, 20));
  483. EXPECT_EQ(PadToWord<64>("11101110110000000000"), BitsToStream(bits));
  484. EXPECT_EQ(22u, reader.ReadBits(&bits, 30));
  485. EXPECT_EQ(PadToWord<64>("0000000000000000000000"), BitsToStream(bits));
  486. EXPECT_TRUE(reader.ReachedEnd());
  487. }
  488. TEST(BitReaderFromString, FromU64) {
  489. std::vector<uint64_t> buffer = {
  490. 0xAAAAAAAAAAAAAAAA,
  491. 0xBBBBBBBBBBBBBBBB,
  492. 0xCCCCCCCCCCCCCCCC,
  493. 0xDDDDDDDDDDDDDDDD,
  494. };
  495. const std::string total_stream =
  496. "0101010101010101010101010101010101010101010101010101010101010101"
  497. "1101110111011101110111011101110111011101110111011101110111011101"
  498. "0011001100110011001100110011001100110011001100110011001100110011"
  499. "1011101110111011101110111011101110111011101110111011101110111011";
  500. BitReaderFromString reader(buffer);
  501. uint64_t bits = 0;
  502. size_t pos = 0;
  503. size_t to_read = 5;
  504. while (reader.ReadBits(&bits, to_read) > 0) {
  505. EXPECT_EQ(BitsToStream(bits),
  506. PadToWord<64>(total_stream.substr(pos, to_read)));
  507. pos += to_read;
  508. to_read = (to_read + 35) % 64 + 1;
  509. }
  510. EXPECT_TRUE(reader.ReachedEnd());
  511. }
  512. TEST(BitReaderWord64, ReadBitsSingleByte) {
  513. BitReaderWord64 reader(std::vector<uint8_t>({uint8_t(0xF0)}));
  514. EXPECT_FALSE(reader.ReachedEnd());
  515. uint64_t bits = 0;
  516. EXPECT_EQ(1u, reader.ReadBits(&bits, 1));
  517. EXPECT_EQ(0u, bits);
  518. EXPECT_EQ(2u, reader.ReadBits(&bits, 2));
  519. EXPECT_EQ(0u, bits);
  520. EXPECT_EQ(2u, reader.ReadBits(&bits, 2));
  521. EXPECT_EQ(2u, bits);
  522. EXPECT_EQ(2u, reader.ReadBits(&bits, 2));
  523. EXPECT_EQ(3u, bits);
  524. EXPECT_FALSE(reader.OnlyZeroesLeft());
  525. EXPECT_FALSE(reader.ReachedEnd());
  526. EXPECT_EQ(2u, reader.ReadBits(&bits, 2));
  527. EXPECT_EQ(1u, bits);
  528. EXPECT_TRUE(reader.OnlyZeroesLeft());
  529. EXPECT_FALSE(reader.ReachedEnd());
  530. EXPECT_EQ(55u, reader.ReadBits(&bits, 64));
  531. EXPECT_EQ(0u, bits);
  532. EXPECT_TRUE(reader.ReachedEnd());
  533. }
  534. TEST(BitReaderWord64, ReadBitsTwoWords) {
  535. std::vector<uint64_t> buffer = {0x0000000000000001, 0x0000000000FFFFFF};
  536. BitReaderWord64 reader(std::move(buffer));
  537. uint64_t bits = 0;
  538. EXPECT_EQ(1u, reader.ReadBits(&bits, 1));
  539. EXPECT_EQ(1u, bits);
  540. EXPECT_EQ(62u, reader.ReadBits(&bits, 62));
  541. EXPECT_EQ(0u, bits);
  542. EXPECT_EQ(2u, reader.ReadBits(&bits, 2));
  543. EXPECT_EQ(2u, bits);
  544. EXPECT_EQ(3u, reader.ReadBits(&bits, 3));
  545. EXPECT_EQ(7u, bits);
  546. EXPECT_FALSE(reader.OnlyZeroesLeft());
  547. EXPECT_EQ(32u, reader.ReadBits(&bits, 32));
  548. EXPECT_EQ(0xFFFFFu, bits);
  549. EXPECT_TRUE(reader.OnlyZeroesLeft());
  550. EXPECT_FALSE(reader.ReachedEnd());
  551. EXPECT_EQ(28u, reader.ReadBits(&bits, 32));
  552. EXPECT_EQ(0u, bits);
  553. EXPECT_TRUE(reader.ReachedEnd());
  554. }
  555. TEST(BitReaderFromString, ReadUnencodedU8) {
  556. BitReaderFromString reader("11111110");
  557. uint8_t val = 0;
  558. ASSERT_TRUE(reader.ReadUnencoded(&val));
  559. EXPECT_EQ(8u, reader.GetNumReadBits());
  560. EXPECT_EQ(127, val);
  561. }
  562. TEST(BitReaderFromString, ReadUnencodedU16Fail) {
  563. BitReaderFromString reader("11111110");
  564. uint16_t val = 0;
  565. ASSERT_FALSE(reader.ReadUnencoded(&val));
  566. }
  567. TEST(BitReaderFromString, ReadUnencodedS64) {
  568. BitReaderFromString reader(
  569. "1110000000000000000000000000000000000000000000000000000000000001");
  570. int64_t val = 0;
  571. ASSERT_TRUE(reader.ReadUnencoded(&val));
  572. EXPECT_EQ(64u, reader.GetNumReadBits());
  573. EXPECT_EQ(std::numeric_limits<int64_t>::min() + 7, val);
  574. }
  575. TEST(BitReaderWord64, FromU8) {
  576. std::vector<uint8_t> buffer = {
  577. 0xAA,
  578. 0xBB,
  579. 0xCC,
  580. 0xDD,
  581. };
  582. BitReaderWord64 reader(std::move(buffer));
  583. uint64_t bits = 0;
  584. EXPECT_EQ(2u, reader.ReadBits(&bits, 2));
  585. EXPECT_EQ(PadToWord<64>("01"), BitsToStream(bits));
  586. EXPECT_EQ(20u, reader.ReadBits(&bits, 20));
  587. EXPECT_EQ(PadToWord<64>("01010111011101001100"), BitsToStream(bits));
  588. EXPECT_EQ(20u, reader.ReadBits(&bits, 20));
  589. EXPECT_EQ(PadToWord<64>("11101110110000000000"), BitsToStream(bits));
  590. EXPECT_EQ(22u, reader.ReadBits(&bits, 30));
  591. EXPECT_EQ(PadToWord<64>("0000000000000000000000"), BitsToStream(bits));
  592. EXPECT_TRUE(reader.ReachedEnd());
  593. }
  594. TEST(BitReaderWord64, FromU64) {
  595. std::vector<uint64_t> buffer = {
  596. 0xAAAAAAAAAAAAAAAA,
  597. 0xBBBBBBBBBBBBBBBB,
  598. 0xCCCCCCCCCCCCCCCC,
  599. 0xDDDDDDDDDDDDDDDD,
  600. };
  601. const std::string total_stream =
  602. "0101010101010101010101010101010101010101010101010101010101010101"
  603. "1101110111011101110111011101110111011101110111011101110111011101"
  604. "0011001100110011001100110011001100110011001100110011001100110011"
  605. "1011101110111011101110111011101110111011101110111011101110111011";
  606. BitReaderWord64 reader(std::move(buffer));
  607. uint64_t bits = 0;
  608. size_t pos = 0;
  609. size_t to_read = 5;
  610. while (reader.ReadBits(&bits, to_read) > 0) {
  611. EXPECT_EQ(BitsToStream(bits),
  612. PadToWord<64>(total_stream.substr(pos, to_read)));
  613. pos += to_read;
  614. to_read = (to_read + 35) % 64 + 1;
  615. }
  616. EXPECT_TRUE(reader.ReachedEnd());
  617. }
  618. TEST(BitReaderWord64, ComparisonLotsOfU8) {
  619. std::vector<uint8_t> buffer;
  620. for (uint32_t i = 0; i < 10003; ++i) {
  621. buffer.push_back(static_cast<uint8_t>(i % 255));
  622. }
  623. BitReaderFromString reader1(buffer);
  624. BitReaderWord64 reader2(std::move(buffer));
  625. uint64_t bits1 = 0, bits2 = 0;
  626. size_t to_read = 5;
  627. while (reader1.ReadBits(&bits1, to_read) > 0) {
  628. reader2.ReadBits(&bits2, to_read);
  629. EXPECT_EQ(bits1, bits2);
  630. to_read = (to_read + 35) % 64 + 1;
  631. }
  632. EXPECT_EQ(0u, reader2.ReadBits(&bits2, 1));
  633. }
  634. TEST(BitReaderWord64, ComparisonLotsOfU64) {
  635. std::vector<uint64_t> buffer;
  636. for (uint64_t i = 0; i < 1000; ++i) {
  637. buffer.push_back(i);
  638. }
  639. BitReaderFromString reader1(buffer);
  640. BitReaderWord64 reader2(std::move(buffer));
  641. uint64_t bits1 = 0, bits2 = 0;
  642. size_t to_read = 5;
  643. while (reader1.ReadBits(&bits1, to_read) > 0) {
  644. reader2.ReadBits(&bits2, to_read);
  645. EXPECT_EQ(bits1, bits2);
  646. to_read = (to_read + 35) % 64 + 1;
  647. }
  648. EXPECT_EQ(0u, reader2.ReadBits(&bits2, 1));
  649. }
  650. TEST(ReadWriteWord64, ReadWriteLotsOfBits) {
  651. BitWriterWord64 writer(16384);
  652. for (uint64_t i = 0; i < 65000; i += 25) {
  653. const uint64_t num_bits = i % 64 + 1;
  654. const uint64_t bits = i >> (64 - num_bits);
  655. writer.WriteBits(bits, size_t(num_bits));
  656. }
  657. BitReaderWord64 reader(writer.GetDataCopy());
  658. for (uint64_t i = 0; i < 65000; i += 25) {
  659. const uint64_t num_bits = i % 64 + 1;
  660. const uint64_t expected_bits = i >> (64 - num_bits);
  661. uint64_t bits = 0;
  662. reader.ReadBits(&bits, size_t(num_bits));
  663. EXPECT_EQ(expected_bits, bits);
  664. }
  665. EXPECT_TRUE(reader.OnlyZeroesLeft());
  666. }
  667. TEST(VariableWidthWrite, Write0U) {
  668. BitWriterStringStream writer;
  669. writer.WriteVariableWidthU64(0, 2);
  670. EXPECT_EQ("000", writer.GetStreamRaw());
  671. writer.WriteVariableWidthU32(0, 2);
  672. EXPECT_EQ(
  673. "000"
  674. "000",
  675. writer.GetStreamRaw());
  676. writer.WriteVariableWidthU16(0, 2);
  677. EXPECT_EQ(
  678. "000"
  679. "000"
  680. "000",
  681. writer.GetStreamRaw());
  682. }
  683. TEST(VariableWidthWrite, WriteSmallUnsigned) {
  684. BitWriterStringStream writer;
  685. writer.WriteVariableWidthU64(1, 2);
  686. EXPECT_EQ("100", writer.GetStreamRaw());
  687. writer.WriteVariableWidthU32(2, 2);
  688. EXPECT_EQ(
  689. "100"
  690. "010",
  691. writer.GetStreamRaw());
  692. writer.WriteVariableWidthU16(3, 2);
  693. EXPECT_EQ(
  694. "100"
  695. "010"
  696. "110",
  697. writer.GetStreamRaw());
  698. }
  699. TEST(VariableWidthWrite, WriteSmallSigned) {
  700. BitWriterStringStream writer;
  701. writer.WriteVariableWidthS64(1, 2, 0);
  702. EXPECT_EQ("010", writer.GetStreamRaw());
  703. writer.WriteVariableWidthS64(-1, 2, 0);
  704. EXPECT_EQ(
  705. "010"
  706. "100",
  707. writer.GetStreamRaw());
  708. }
  709. TEST(VariableWidthWrite, U64Val127ChunkLength7) {
  710. BitWriterStringStream writer;
  711. writer.WriteVariableWidthU64(127, 7);
  712. EXPECT_EQ(
  713. "1111111"
  714. "0",
  715. writer.GetStreamRaw());
  716. }
  717. TEST(VariableWidthWrite, U32Val255ChunkLength7) {
  718. BitWriterStringStream writer;
  719. writer.WriteVariableWidthU32(255, 7);
  720. EXPECT_EQ(
  721. "1111111"
  722. "1"
  723. "1000000"
  724. "0",
  725. writer.GetStreamRaw());
  726. }
  727. TEST(VariableWidthWrite, U16Val2ChunkLength4) {
  728. BitWriterStringStream writer;
  729. writer.WriteVariableWidthU16(2, 4);
  730. EXPECT_EQ(
  731. "0100"
  732. "0",
  733. writer.GetStreamRaw());
  734. }
  735. TEST(VariableWidthWrite, U64ValAAAAChunkLength2) {
  736. BitWriterStringStream writer;
  737. writer.WriteVariableWidthU64(0xAAAA, 2);
  738. EXPECT_EQ(
  739. "01"
  740. "1"
  741. "01"
  742. "1"
  743. "01"
  744. "1"
  745. "01"
  746. "1"
  747. "01"
  748. "1"
  749. "01"
  750. "1"
  751. "01"
  752. "1"
  753. "01"
  754. "0",
  755. writer.GetStreamRaw());
  756. }
  757. TEST(VariableWidthRead, U64Val127ChunkLength7) {
  758. BitReaderFromString reader(
  759. "1111111"
  760. "0");
  761. uint64_t val = 0;
  762. ASSERT_TRUE(reader.ReadVariableWidthU64(&val, 7));
  763. EXPECT_EQ(127u, val);
  764. }
  765. TEST(VariableWidthRead, U32Val255ChunkLength7) {
  766. BitReaderFromString reader(
  767. "1111111"
  768. "1"
  769. "1000000"
  770. "0");
  771. uint32_t val = 0;
  772. ASSERT_TRUE(reader.ReadVariableWidthU32(&val, 7));
  773. EXPECT_EQ(255u, val);
  774. }
  775. TEST(VariableWidthRead, U16Val2ChunkLength4) {
  776. BitReaderFromString reader(
  777. "0100"
  778. "0");
  779. uint16_t val = 0;
  780. ASSERT_TRUE(reader.ReadVariableWidthU16(&val, 4));
  781. EXPECT_EQ(2u, val);
  782. }
  783. TEST(VariableWidthRead, U64ValAAAAChunkLength2) {
  784. BitReaderFromString reader(
  785. "01"
  786. "1"
  787. "01"
  788. "1"
  789. "01"
  790. "1"
  791. "01"
  792. "1"
  793. "01"
  794. "1"
  795. "01"
  796. "1"
  797. "01"
  798. "1"
  799. "01"
  800. "0");
  801. uint64_t val = 0;
  802. ASSERT_TRUE(reader.ReadVariableWidthU64(&val, 2));
  803. EXPECT_EQ(0xAAAAu, val);
  804. }
  805. TEST(VariableWidthRead, FailTooShort) {
  806. BitReaderFromString reader("00000001100000");
  807. uint64_t val = 0;
  808. ASSERT_FALSE(reader.ReadVariableWidthU64(&val, 7));
  809. }
  810. TEST(VariableWidthWriteRead, SingleWriteReadU64) {
  811. for (uint64_t i = 0; i < 1000000; i += 1234) {
  812. const uint64_t val = i * i * i;
  813. const size_t chunk_length = size_t(i % 16 + 1);
  814. BitWriterWord64 writer;
  815. writer.WriteVariableWidthU64(val, chunk_length);
  816. BitReaderWord64 reader(writer.GetDataCopy());
  817. uint64_t read_val = 0;
  818. ASSERT_TRUE(reader.ReadVariableWidthU64(&read_val, chunk_length));
  819. ASSERT_EQ(val, read_val) << "Chunk length " << chunk_length;
  820. }
  821. }
  822. TEST(VariableWidthWriteRead, SingleWriteReadS64) {
  823. for (int64_t i = 0; i < 1000000; i += 4321) {
  824. const int64_t val = i * i * (i % 2 ? -i : i);
  825. const size_t chunk_length = size_t(i % 16 + 1);
  826. const size_t zigzag_exponent = size_t(i % 13);
  827. BitWriterWord64 writer;
  828. writer.WriteVariableWidthS64(val, chunk_length, zigzag_exponent);
  829. BitReaderWord64 reader(writer.GetDataCopy());
  830. int64_t read_val = 0;
  831. ASSERT_TRUE(
  832. reader.ReadVariableWidthS64(&read_val, chunk_length, zigzag_exponent));
  833. ASSERT_EQ(val, read_val) << "Chunk length " << chunk_length;
  834. }
  835. }
  836. TEST(VariableWidthWriteRead, SingleWriteReadU32) {
  837. for (uint32_t i = 0; i < 100000; i += 123) {
  838. const uint32_t val = i * i;
  839. const size_t chunk_length = i % 16 + 1;
  840. BitWriterWord64 writer;
  841. writer.WriteVariableWidthU32(val, chunk_length);
  842. BitReaderWord64 reader(writer.GetDataCopy());
  843. uint32_t read_val = 0;
  844. ASSERT_TRUE(reader.ReadVariableWidthU32(&read_val, chunk_length));
  845. ASSERT_EQ(val, read_val) << "Chunk length " << chunk_length;
  846. }
  847. }
  848. TEST(VariableWidthWriteRead, SingleWriteReadU16) {
  849. for (int i = 0; i < 65536; i += 123) {
  850. const uint16_t val = static_cast<int16_t>(i);
  851. const size_t chunk_length = val % 10 + 1;
  852. BitWriterWord64 writer;
  853. writer.WriteVariableWidthU16(val, chunk_length);
  854. BitReaderWord64 reader(writer.GetDataCopy());
  855. uint16_t read_val = 0;
  856. ASSERT_TRUE(reader.ReadVariableWidthU16(&read_val, chunk_length));
  857. ASSERT_EQ(val, read_val) << "Chunk length " << chunk_length;
  858. }
  859. }
  860. TEST(VariableWidthWriteRead, SmallNumbersChunkLength4) {
  861. const std::vector<uint64_t> expected_values = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  862. BitWriterWord64 writer;
  863. for (uint64_t val : expected_values) {
  864. writer.WriteVariableWidthU64(val, 4);
  865. }
  866. EXPECT_EQ(50u, writer.GetNumBits());
  867. std::vector<uint64_t> actual_values;
  868. BitReaderWord64 reader(writer.GetDataCopy());
  869. while (!reader.OnlyZeroesLeft()) {
  870. uint64_t val = 0;
  871. ASSERT_TRUE(reader.ReadVariableWidthU64(&val, 4));
  872. actual_values.push_back(val);
  873. }
  874. EXPECT_EQ(expected_values, actual_values);
  875. }
  876. TEST(VariableWidthWriteRead, VariedNumbersChunkLength8) {
  877. const std::vector<uint64_t> expected_values = {1000, 0, 255, 4294967296};
  878. const size_t kExpectedNumBits = 9 * (2 + 1 + 1 + 5);
  879. BitWriterWord64 writer;
  880. for (uint64_t val : expected_values) {
  881. writer.WriteVariableWidthU64(val, 8);
  882. }
  883. EXPECT_EQ(kExpectedNumBits, writer.GetNumBits());
  884. std::vector<uint64_t> actual_values;
  885. BitReaderWord64 reader(writer.GetDataCopy());
  886. while (!reader.OnlyZeroesLeft()) {
  887. uint64_t val = 0;
  888. ASSERT_TRUE(reader.ReadVariableWidthU64(&val, 8));
  889. actual_values.push_back(val);
  890. }
  891. EXPECT_EQ(expected_values, actual_values);
  892. }
  893. } // namespace
  894. } // namespace comp
  895. } // namespace spvtools