• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2015-2016 The Khronos Group 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 
15 #include "test/unit_spirv.h"
16 
17 namespace spvtools {
18 namespace {
19 
TEST(FixWord,Default)20 TEST(FixWord, Default) {
21   spv_endianness_t endian;
22   if (I32_ENDIAN_HOST == I32_ENDIAN_LITTLE) {
23     endian = SPV_ENDIANNESS_LITTLE;
24   } else {
25     endian = SPV_ENDIANNESS_BIG;
26   }
27   uint32_t word = 0x53780921;
28   ASSERT_EQ(word, spvFixWord(word, endian));
29 }
30 
TEST(FixWord,Reorder)31 TEST(FixWord, Reorder) {
32   spv_endianness_t endian;
33   if (I32_ENDIAN_HOST == I32_ENDIAN_LITTLE) {
34     endian = SPV_ENDIANNESS_BIG;
35   } else {
36     endian = SPV_ENDIANNESS_LITTLE;
37   }
38   uint32_t word = 0x53780921;
39   uint32_t result = 0x21097853;
40   ASSERT_EQ(result, spvFixWord(word, endian));
41 }
42 
TEST(FixDoubleWord,Default)43 TEST(FixDoubleWord, Default) {
44   spv_endianness_t endian =
45       (I32_ENDIAN_HOST == I32_ENDIAN_LITTLE ? SPV_ENDIANNESS_LITTLE
46                                             : SPV_ENDIANNESS_BIG);
47   uint32_t low = 0x53780921;
48   uint32_t high = 0xdeadbeef;
49   uint64_t result = 0xdeadbeef53780921;
50   ASSERT_EQ(result, spvFixDoubleWord(low, high, endian));
51 }
52 
TEST(FixDoubleWord,Reorder)53 TEST(FixDoubleWord, Reorder) {
54   spv_endianness_t endian =
55       (I32_ENDIAN_HOST == I32_ENDIAN_LITTLE ? SPV_ENDIANNESS_BIG
56                                             : SPV_ENDIANNESS_LITTLE);
57   uint32_t low = 0x53780921;
58   uint32_t high = 0xdeadbeef;
59   uint64_t result = 0xefbeadde21097853;
60   ASSERT_EQ(result, spvFixDoubleWord(low, high, endian));
61 }
62 
63 }  // namespace
64 }  // namespace spvtools
65