]> git.saurik.com Git - apple/javascriptcore.git/blob - dfg/DFGArithMode.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / dfg / DFGArithMode.h
1 /*
2 * Copyright (C) 2014 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #ifndef DFGArithMode_h
27 #define DFGArithMode_h
28
29 #if ENABLE(DFG_JIT)
30
31 namespace JSC { namespace DFG {
32
33 // Arith::Mode describes the mode of an arithmetic operation that speculates integer.
34 // Note that not all modes are valid for all operations.
35 namespace Arith {
36 enum Mode {
37 NotSet, // Arithmetic mode is either not relevant because we're using doubles anyway or we are at a phase in compilation where we don't know what we're doing, yet. Should never see this after FixupPhase except for nodes that take doubles as inputs already.
38 Unchecked, // Don't check anything and just do the direct hardware operation.
39 CheckOverflow, // Check for overflow but don't bother with negative zero.
40 CheckOverflowAndNegativeZero, // Check for both overflow and negative zero.
41 DoOverflow // Up-convert to the smallest type that soundly represents all possible results after input type speculation.
42 };
43
44 // Define the type of operation the rounding operation will perform.
45 enum class RoundingMode {
46 Int32, // The round operation produces a integer and -0 is considered as 0.
47 Int32WithNegativeZeroCheck, // The round operation produces a integer and checks for -0.
48 Double // The round operation produce a double. The result can be -0, NaN or (+/-)Infinity.
49 };
50
51 } // namespace Arith
52
53 inline bool doesOverflow(Arith::Mode mode)
54 {
55 switch (mode) {
56 case Arith::NotSet:
57 ASSERT_NOT_REACHED();
58 #if ASSERT_DISABLED
59 FALLTHROUGH;
60 #endif
61 case Arith::Unchecked:
62 case Arith::CheckOverflow:
63 case Arith::CheckOverflowAndNegativeZero:
64 return false;
65 case Arith::DoOverflow:
66 return true;
67 }
68 ASSERT_NOT_REACHED();
69 return true;
70 }
71
72 // It's only valid to call this once you've determined that you don't need to *do*
73 // overflow. For most nodes, that's implicit.
74 inline bool shouldCheckOverflow(Arith::Mode mode)
75 {
76 switch (mode) {
77 case Arith::NotSet:
78 case Arith::DoOverflow:
79 ASSERT_NOT_REACHED();
80 return true;
81 case Arith::Unchecked:
82 return false;
83 case Arith::CheckOverflow:
84 case Arith::CheckOverflowAndNegativeZero:
85 return true;
86 }
87 ASSERT_NOT_REACHED();
88 return true;
89 }
90
91 inline bool shouldCheckNegativeZero(Arith::Mode mode)
92 {
93 switch (mode) {
94 case Arith::NotSet:
95 case Arith::DoOverflow:
96 ASSERT_NOT_REACHED();
97 return true;
98 case Arith::Unchecked:
99 case Arith::CheckOverflow:
100 return false;
101 case Arith::CheckOverflowAndNegativeZero:
102 return true;
103 }
104 ASSERT_NOT_REACHED();
105 return true;
106 }
107
108 inline bool subsumes(Arith::Mode earlier, Arith::Mode later)
109 {
110 switch (earlier) {
111 case Arith::CheckOverflow:
112 switch (later) {
113 case Arith::Unchecked:
114 case Arith::CheckOverflow:
115 return true;
116 default:
117 return false;
118 }
119 case Arith::CheckOverflowAndNegativeZero:
120 switch (later) {
121 case Arith::Unchecked:
122 case Arith::CheckOverflow:
123 case Arith::CheckOverflowAndNegativeZero:
124 return true;
125 default:
126 return false;
127 }
128 default:
129 return earlier == later;
130 }
131 }
132
133 inline bool producesInteger(Arith::RoundingMode mode)
134 {
135 return mode == Arith::RoundingMode::Int32WithNegativeZeroCheck || mode == Arith::RoundingMode::Int32;
136 }
137
138 inline bool shouldCheckNegativeZero(Arith::RoundingMode mode)
139 {
140 return mode == Arith::RoundingMode::Int32WithNegativeZeroCheck;
141 }
142
143 } } // namespace JSC::DFG
144
145 namespace WTF {
146
147 class PrintStream;
148 void printInternal(PrintStream&, JSC::DFG::Arith::Mode);
149
150 } // namespace WTF
151
152 #endif // ENABLE(DFG_JIT)
153
154 #endif // DFGArithMode_h
155