1 | /* |
2 | * Copyright (C) 2012-2019 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 | #include "config.h" |
27 | #include "MacroAssembler.h" |
28 | |
29 | #if ENABLE(ASSEMBLER) |
30 | |
31 | #include "Options.h" |
32 | #include "ProbeContext.h" |
33 | #include <wtf/PrintStream.h> |
34 | #include <wtf/ScopedLambda.h> |
35 | |
36 | namespace JSC { |
37 | |
38 | const double MacroAssembler::twoToThe32 = (double)0x100000000ull; |
39 | |
40 | void MacroAssembler::jitAssert(const ScopedLambda<Jump(void)>& functor) |
41 | { |
42 | if (Options::enableJITDebugAssertions()) { |
43 | Jump passed = functor(); |
44 | breakpoint(); |
45 | passed.link(this); |
46 | } |
47 | } |
48 | |
49 | #if ENABLE(MASM_PROBE) |
50 | static void stdFunctionCallback(Probe::Context& context) |
51 | { |
52 | auto func = context.arg<const Function<void(Probe::Context&)>*>(); |
53 | (*func)(context); |
54 | } |
55 | |
56 | void MacroAssembler::probe(Function<void(Probe::Context&)> func) |
57 | { |
58 | probe(stdFunctionCallback, new Function<void(Probe::Context&)>(WTFMove(func))); |
59 | } |
60 | #endif // ENABLE(MASM_PROBE) |
61 | |
62 | } // namespace JSC |
63 | |
64 | namespace WTF { |
65 | |
66 | using namespace JSC; |
67 | |
68 | void printInternal(PrintStream& out, MacroAssembler::RelationalCondition cond) |
69 | { |
70 | switch (cond) { |
71 | case MacroAssembler::Equal: |
72 | out.print("Equal" ); |
73 | return; |
74 | case MacroAssembler::NotEqual: |
75 | out.print("NotEqual" ); |
76 | return; |
77 | case MacroAssembler::Above: |
78 | out.print("Above" ); |
79 | return; |
80 | case MacroAssembler::AboveOrEqual: |
81 | out.print("AboveOrEqual" ); |
82 | return; |
83 | case MacroAssembler::Below: |
84 | out.print("Below" ); |
85 | return; |
86 | case MacroAssembler::BelowOrEqual: |
87 | out.print("BelowOrEqual" ); |
88 | return; |
89 | case MacroAssembler::GreaterThan: |
90 | out.print("GreaterThan" ); |
91 | return; |
92 | case MacroAssembler::GreaterThanOrEqual: |
93 | out.print("GreaterThanOrEqual" ); |
94 | return; |
95 | case MacroAssembler::LessThan: |
96 | out.print("LessThan" ); |
97 | return; |
98 | case MacroAssembler::LessThanOrEqual: |
99 | out.print("LessThanOrEqual" ); |
100 | return; |
101 | } |
102 | RELEASE_ASSERT_NOT_REACHED(); |
103 | } |
104 | |
105 | void printInternal(PrintStream& out, MacroAssembler::ResultCondition cond) |
106 | { |
107 | switch (cond) { |
108 | case MacroAssembler::Overflow: |
109 | out.print("Overflow" ); |
110 | return; |
111 | case MacroAssembler::Signed: |
112 | out.print("Signed" ); |
113 | return; |
114 | case MacroAssembler::PositiveOrZero: |
115 | out.print("PositiveOrZero" ); |
116 | return; |
117 | case MacroAssembler::Zero: |
118 | out.print("Zero" ); |
119 | return; |
120 | case MacroAssembler::NonZero: |
121 | out.print("NonZero" ); |
122 | return; |
123 | } |
124 | RELEASE_ASSERT_NOT_REACHED(); |
125 | } |
126 | |
127 | void printInternal(PrintStream& out, MacroAssembler::DoubleCondition cond) |
128 | { |
129 | switch (cond) { |
130 | case MacroAssembler::DoubleEqual: |
131 | out.print("DoubleEqual" ); |
132 | return; |
133 | case MacroAssembler::DoubleNotEqual: |
134 | out.print("DoubleNotEqual" ); |
135 | return; |
136 | case MacroAssembler::DoubleGreaterThan: |
137 | out.print("DoubleGreaterThan" ); |
138 | return; |
139 | case MacroAssembler::DoubleGreaterThanOrEqual: |
140 | out.print("DoubleGreaterThanOrEqual" ); |
141 | return; |
142 | case MacroAssembler::DoubleLessThan: |
143 | out.print("DoubleLessThan" ); |
144 | return; |
145 | case MacroAssembler::DoubleLessThanOrEqual: |
146 | out.print("DoubleLessThanOrEqual" ); |
147 | return; |
148 | case MacroAssembler::DoubleEqualOrUnordered: |
149 | out.print("DoubleEqualOrUnordered" ); |
150 | return; |
151 | case MacroAssembler::DoubleNotEqualOrUnordered: |
152 | out.print("DoubleNotEqualOrUnordered" ); |
153 | return; |
154 | case MacroAssembler::DoubleGreaterThanOrUnordered: |
155 | out.print("DoubleGreaterThanOrUnordered" ); |
156 | return; |
157 | case MacroAssembler::DoubleGreaterThanOrEqualOrUnordered: |
158 | out.print("DoubleGreaterThanOrEqualOrUnordered" ); |
159 | return; |
160 | case MacroAssembler::DoubleLessThanOrUnordered: |
161 | out.print("DoubleLessThanOrUnordered" ); |
162 | return; |
163 | case MacroAssembler::DoubleLessThanOrEqualOrUnordered: |
164 | out.print("DoubleLessThanOrEqualOrUnordered" ); |
165 | return; |
166 | } |
167 | |
168 | RELEASE_ASSERT_NOT_REACHED(); |
169 | } |
170 | |
171 | } // namespace WTF |
172 | |
173 | #endif // ENABLE(ASSEMBLER) |
174 | |
175 | |