Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1111)

Side by Side Diff: crosstest/test_cast.cpp

Issue 2432373002: [SubZero] Fix f64 to/from i64 moves (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Addressed review comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « crosstest/test_cast.h ('k') | crosstest/test_cast_main.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/crosstest/test_cast.cpp - Cast operator tests --------------===// 1 //===- subzero/crosstest/test_cast.cpp - Cast operator tests --------------===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // Implementation for crosstesting cast operations. 10 // Implementation for crosstesting cast operations.
(...skipping 10 matching lines...) Expand all
21 template <typename FromType, typename ToType> 21 template <typename FromType, typename ToType>
22 ToType __attribute__((noinline)) cast(FromType a) { 22 ToType __attribute__((noinline)) cast(FromType a) {
23 return (ToType)a; 23 return (ToType)a;
24 } 24 }
25 25
26 template <typename FromType, typename ToType> 26 template <typename FromType, typename ToType>
27 ToType __attribute__((noinline)) castBits(FromType a) { 27 ToType __attribute__((noinline)) castBits(FromType a) {
28 return *(ToType *)&a; 28 return *(ToType *)&a;
29 } 29 }
30 30
31 template <typename FromType, typename ToType>
32 ToType __attribute__((noinline)) cast(int i, FromType a, int j) {
33 (void) i;
34 (void) j;
35 return (ToType)a;
36 }
37
38 template <typename FromType, typename ToType>
39 ToType __attribute__((noinline)) castBits(int i, FromType a, int j) {
40 (void) i;
41 (void) j;
42 return *(ToType *)&a;
43 }
44
31 // The purpose of the following sets of templates is to force 45 // The purpose of the following sets of templates is to force
32 // cast<A,B>() to be instantiated in the resulting bitcode file for 46 // cast<A,B>() to be instantiated in the resulting bitcode file for
33 // all <A,B>, so that they can be called from the driver. 47 // all <A,B>, so that they can be called from the driver.
34 template <typename ToType> class Caster { 48 template <typename ToType> class Caster {
35 static ToType f(bool a) { return cast<bool, ToType>(a); } 49 static ToType f(bool a) { return cast<bool, ToType>(a); }
36 static ToType f(myint8_t a) { return cast<myint8_t, ToType>(a); } 50 static ToType f(myint8_t a) { return cast<myint8_t, ToType>(a); }
37 static ToType f(uint8_t a) { return cast<uint8_t, ToType>(a); } 51 static ToType f(uint8_t a) { return cast<uint8_t, ToType>(a); }
38 static ToType f(int16_t a) { return cast<int16_t, ToType>(a); } 52 static ToType f(int16_t a) { return cast<int16_t, ToType>(a); }
39 static ToType f(uint16_t a) { return cast<uint16_t, ToType>(a); } 53 static ToType f(uint16_t a) { return cast<uint16_t, ToType>(a); }
40 static ToType f(int32_t a) { return cast<int32_t, ToType>(a); } 54 static ToType f(int32_t a) { return cast<int32_t, ToType>(a); }
41 static ToType f(uint32_t a) { return cast<uint32_t, ToType>(a); } 55 static ToType f(uint32_t a) { return cast<uint32_t, ToType>(a); }
42 static ToType f(int64 a) { return cast<int64, ToType>(a); } 56 static ToType f(int64 a) { return cast<int64, ToType>(a); }
43 static ToType f(uint64 a) { return cast<uint64, ToType>(a); } 57 static ToType f(uint64 a) { return cast<uint64, ToType>(a); }
44 static ToType f(float a) { return cast<float, ToType>(a); } 58 static ToType f(float a) { return cast<float, ToType>(a); }
45 static ToType f(double a) { return cast<double, ToType>(a); } 59 static ToType f(double a) { return cast<double, ToType>(a); }
60 static ToType f(int i, bool a) { return cast<bool, ToType>(i, a, i); }
61 static ToType f(int i, myint8_t a) { return cast<myint8_t, ToType>(i, a, i); }
62 static ToType f(int i, uint8_t a) { return cast<uint8_t, ToType>(i, a, i); }
63 static ToType f(int i, int16_t a) { return cast<int16_t, ToType>(i, a, i); }
64 static ToType f(int i, uint16_t a) { return cast<uint16_t, ToType>(i, a, i); }
65 static ToType f(int i, int32_t a) { return cast<int32_t, ToType>(i, a, i); }
66 static ToType f(int i, uint32_t a) { return cast<uint32_t, ToType>(i, a, i); }
67 static ToType f(int i, int64 a) { return cast<int64, ToType>(i, a, i); }
68 static ToType f(int i, uint64 a) { return cast<uint64, ToType>(i, a, i); }
69 static ToType f(int i, float a) { return cast<float, ToType>(i, a, i); }
70 static ToType f(int i, double a) { return cast<double, ToType>(i, a, i); }
46 }; 71 };
47 72
48 // Comment out the definition of Caster<bool> because clang compiles 73 // Comment out the definition of Caster<bool> because clang compiles
49 // casts to bool using icmp instead of the desired cast instruction. 74 // casts to bool using icmp instead of the desired cast instruction.
50 // The corrected definitions are in test_cast_to_u1.ll. 75 // The corrected definitions are in test_cast_to_u1.ll.
51 76
52 // template class Caster<bool>; 77 // template class Caster<bool>;
53 78
54 template class Caster<myint8_t>; 79 template class Caster<myint8_t>;
55 template class Caster<uint8_t>; 80 template class Caster<uint8_t>;
56 template class Caster<int16_t>; 81 template class Caster<int16_t>;
57 template class Caster<uint16_t>; 82 template class Caster<uint16_t>;
58 template class Caster<int32_t>; 83 template class Caster<int32_t>;
59 template class Caster<uint32_t>; 84 template class Caster<uint32_t>;
60 template class Caster<int64>; 85 template class Caster<int64>;
61 template class Caster<uint64>; 86 template class Caster<uint64>;
62 template class Caster<float>; 87 template class Caster<float>;
63 template class Caster<double>; 88 template class Caster<double>;
64 89
65 // This function definition forces castBits<A,B>() to be instantiated 90 // This function definition forces castBits<A,B>() to be instantiated
66 // in the resulting bitcode file for the 4 relevant <A,B> 91 // in the resulting bitcode file for the 4 relevant <A,B>
67 // combinations, so that they can be called from the driver. 92 // combinations, so that they can be called from the driver.
68 double makeBitCasters() { 93 double makeBitCasters() {
69 double Result = 0; 94 double Result = 0;
70 Result += castBits<uint32_t, float>(0); 95 Result += castBits<uint32_t, float>(0);
71 Result += castBits<uint64, double>(0); 96 Result += castBits<uint64, double>(0);
72 Result += castBits<float, uint32_t>(0); 97 Result += castBits<float, uint32_t>(0);
73 Result += castBits<double, uint64>(0); 98 Result += castBits<double, uint64>(0);
99 Result += castBits<uint32_t, float>(1, 0, 2);
100 Result += castBits<uint64, double>(1, 0, 2);
101 Result += castBits<float, uint32_t>(1, 0, 2);
102 Result += castBits<double, uint64>(1, 0, 2);
74 return Result; 103 return Result;
75 } 104 }
OLDNEW
« no previous file with comments | « crosstest/test_cast.h ('k') | crosstest/test_cast_main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698