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

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, 2 months 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
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 #ifdef MIPS32
32 template <typename FromType, typename ToType>
33 ToType __attribute__((noinline)) cast(int i, FromType a) {
34 (void) i;
35 return (ToType)a;
36 }
37
38 template <typename FromType, typename ToType>
39 ToType __attribute__((noinline)) castBits(int i, FromType a) {
40 (void) i;
41 return *(ToType *)&a;
42 }
43 #endif
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
61 #ifdef MIPS32
62 static ToType f(int i, myint8_t a) { return cast<myint8_t, ToType>(i, a); }
63 static ToType f(int i, uint8_t a) { return cast<uint8_t, ToType>(i, a); }
64 static ToType f(int i, int16_t a) { return cast<int16_t, ToType>(i, a); }
65 static ToType f(int i, uint16_t a) { return cast<uint16_t, ToType>(i, a); }
66 static ToType f(int i, int32_t a) { return cast<int32_t, ToType>(i, a); }
67 static ToType f(int i, uint32_t a) { return cast<uint32_t, ToType>(i, a); }
68 static ToType f(int i, int64 a) { return cast<int64, ToType>(i, a); }
69 static ToType f(int i, uint64 a) { return cast<uint64, ToType>(i, a); }
70 static ToType f(int i, float a) { return cast<float, ToType>(i, a); }
71 static ToType f(int i, double a) { return cast<double, ToType>(i, a); }
72 #endif
46 }; 73 };
47 74
48 // Comment out the definition of Caster<bool> because clang compiles 75 // Comment out the definition of Caster<bool> because clang compiles
49 // casts to bool using icmp instead of the desired cast instruction. 76 // casts to bool using icmp instead of the desired cast instruction.
50 // The corrected definitions are in test_cast_to_u1.ll. 77 // The corrected definitions are in test_cast_to_u1.ll.
51 78
52 // template class Caster<bool>; 79 // template class Caster<bool>;
53 80
54 template class Caster<myint8_t>; 81 template class Caster<myint8_t>;
55 template class Caster<uint8_t>; 82 template class Caster<uint8_t>;
56 template class Caster<int16_t>; 83 template class Caster<int16_t>;
57 template class Caster<uint16_t>; 84 template class Caster<uint16_t>;
58 template class Caster<int32_t>; 85 template class Caster<int32_t>;
59 template class Caster<uint32_t>; 86 template class Caster<uint32_t>;
60 template class Caster<int64>; 87 template class Caster<int64>;
61 template class Caster<uint64>; 88 template class Caster<uint64>;
62 template class Caster<float>; 89 template class Caster<float>;
63 template class Caster<double>; 90 template class Caster<double>;
64 91
65 // This function definition forces castBits<A,B>() to be instantiated 92 // This function definition forces castBits<A,B>() to be instantiated
66 // in the resulting bitcode file for the 4 relevant <A,B> 93 // in the resulting bitcode file for the 4 relevant <A,B>
67 // combinations, so that they can be called from the driver. 94 // combinations, so that they can be called from the driver.
68 double makeBitCasters() { 95 double makeBitCasters() {
69 double Result = 0; 96 double Result = 0;
70 Result += castBits<uint32_t, float>(0); 97 Result += castBits<uint32_t, float>(0);
71 Result += castBits<uint64, double>(0); 98 Result += castBits<uint64, double>(0);
72 Result += castBits<float, uint32_t>(0); 99 Result += castBits<float, uint32_t>(0);
73 Result += castBits<double, uint64>(0); 100 Result += castBits<double, uint64>(0);
101 #ifdef MIPS32
102 Result += castBits<uint32_t, float>(1, 0);
103 Result += castBits<uint64, double>(1, 0);
104 Result += castBits<float, uint32_t>(1, 0);
105 Result += castBits<double, uint64>(1, 0);
106 #endif
74 return Result; 107 return Result;
75 } 108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698