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

Side by Side Diff: crosstest/test_cast.cpp

Issue 265703002: Add Om1 lowering with no optimizations (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Merge changed from Karl's committed CL Created 6 years, 7 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
« 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
(Empty)
1 // This aims to test all the conversion bitcode instructions across
2 // all PNaCl primitive data types.
3
4 #include <stdint.h>
5 #include "test_cast.h"
6
7 template <typename FromType, typename ToType>
8 ToType __attribute__((noinline)) cast(FromType a) {
9 return (ToType)a;
10 }
11
12 template <typename FromType, typename ToType>
13 ToType __attribute__((noinline)) castBits(FromType a) {
14 return *(ToType *)&a;
15 }
16
17 // The purpose of the following sets of templates is to force
18 // cast<A,B>() to be instantiated in the resulting bitcode file for
19 // all <A,B>, so that they can be called from the driver.
20 template <typename ToType> class Caster {
21 static ToType f(bool a) { return cast<bool, ToType>(a); }
22 static ToType f(int8_t a) { return cast<int8_t, ToType>(a); }
23 static ToType f(uint8_t a) { return cast<uint8_t, ToType>(a); }
24 static ToType f(int16_t a) { return cast<int16_t, ToType>(a); }
25 static ToType f(uint16_t a) { return cast<uint16_t, ToType>(a); }
26 static ToType f(int32_t a) { return cast<int32_t, ToType>(a); }
27 static ToType f(uint32_t a) { return cast<uint32_t, ToType>(a); }
28 static ToType f(int64_t a) { return cast<int64_t, ToType>(a); }
29 static ToType f(uint64_t a) { return cast<uint64_t, ToType>(a); }
30 static ToType f(float a) { return cast<float, ToType>(a); }
31 static ToType f(double a) { return cast<double, ToType>(a); }
32 };
33
34 // Comment out the definition of Caster<bool> because clang compiles
35 // casts to bool using icmp instead of the desired cast instruction.
36 // The corrected definitions are in test_cast_to_u1.ll.
37
38 // template class Caster<bool>;
39
40 template class Caster<int8_t>;
41 template class Caster<uint8_t>;
42 template class Caster<int16_t>;
43 template class Caster<uint16_t>;
44 template class Caster<int32_t>;
45 template class Caster<uint32_t>;
46 template class Caster<int64_t>;
47 template class Caster<uint64_t>;
48 template class Caster<float>;
49 template class Caster<double>;
50
51 // This function definition forces castBits<A,B>() to be instantiated
52 // in the resulting bitcode file for the 4 relevant <A,B>
53 // combinations, so that they can be called from the driver.
54 double makeBitCasters() {
55 double Result = 0;
56 Result += castBits<uint32_t, float>(0);
57 Result += castBits<uint64_t, double>(0);
58 Result += castBits<float, uint32_t>(0);
59 Result += castBits<double, uint64_t>(0);
60 return Result;
61 }
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