2 * Copyright (C) 2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef DFGArithMode_h
27 #define DFGArithMode_h
31 namespace JSC { namespace DFG {
33 // Arith::Mode describes the mode of an arithmetic operation that speculates integer.
34 // Note that not all modes are valid for all operations.
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.
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.
53 inline bool doesOverflow(Arith::Mode mode)
61 case Arith::Unchecked:
62 case Arith::CheckOverflow:
63 case Arith::CheckOverflowAndNegativeZero:
65 case Arith::DoOverflow:
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)
78 case Arith::DoOverflow:
81 case Arith::Unchecked:
83 case Arith::CheckOverflow:
84 case Arith::CheckOverflowAndNegativeZero:
91 inline bool shouldCheckNegativeZero(Arith::Mode mode)
95 case Arith::DoOverflow:
98 case Arith::Unchecked:
99 case Arith::CheckOverflow:
101 case Arith::CheckOverflowAndNegativeZero:
104 ASSERT_NOT_REACHED();
108 inline bool subsumes(Arith::Mode earlier, Arith::Mode later)
111 case Arith::CheckOverflow:
113 case Arith::Unchecked:
114 case Arith::CheckOverflow:
119 case Arith::CheckOverflowAndNegativeZero:
121 case Arith::Unchecked:
122 case Arith::CheckOverflow:
123 case Arith::CheckOverflowAndNegativeZero:
129 return earlier == later;
133 inline bool producesInteger(Arith::RoundingMode mode)
135 return mode == Arith::RoundingMode::Int32WithNegativeZeroCheck || mode == Arith::RoundingMode::Int32;
138 inline bool shouldCheckNegativeZero(Arith::RoundingMode mode)
140 return mode == Arith::RoundingMode::Int32WithNegativeZeroCheck;
143 } } // namespace JSC::DFG
148 void printInternal(PrintStream&, JSC::DFG::Arith::Mode);
152 #endif // ENABLE(DFG_JIT)
154 #endif // DFGArithMode_h