fix_word_test.cpp 1.9 KB

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