]> git.saurik.com Git - apple/javascriptcore.git/blame - dfg/DFGAssemblyHelpers.cpp
JavaScriptCore-1097.3.tar.gz
[apple/javascriptcore.git] / dfg / DFGAssemblyHelpers.cpp
CommitLineData
6fe7ccc8
A
1/*
2 * Copyright (C) 2011 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 "DFGAssemblyHelpers.h"
28
29#if ENABLE(DFG_JIT)
30
31namespace JSC { namespace DFG {
32
33const double AssemblyHelpers::twoToThe32 = (double)0x100000000ull;
34
35Vector<BytecodeAndMachineOffset>& AssemblyHelpers::decodedCodeMapFor(CodeBlock* codeBlock)
36{
37 ASSERT(codeBlock == codeBlock->baselineVersion());
38 ASSERT(codeBlock->getJITType() == JITCode::BaselineJIT);
39 ASSERT(codeBlock->jitCodeMap());
40
41 HashMap<CodeBlock*, Vector<BytecodeAndMachineOffset> >::AddResult result = m_decodedCodeMaps.add(codeBlock, Vector<BytecodeAndMachineOffset>());
42
43 if (result.isNewEntry)
44 codeBlock->jitCodeMap()->decode(result.iterator->second);
45
46 return result.iterator->second;
47}
48
49#if ENABLE(SAMPLING_FLAGS)
50void AssemblyHelpers::setSamplingFlag(int32_t flag)
51{
52 ASSERT(flag >= 1);
53 ASSERT(flag <= 32);
54 or32(TrustedImm32(1u << (flag - 1)), AbsoluteAddress(SamplingFlags::addressOfFlags()));
55}
56
57void AssemblyHelpers::clearSamplingFlag(int32_t flag)
58{
59 ASSERT(flag >= 1);
60 ASSERT(flag <= 32);
61 and32(TrustedImm32(~(1u << (flag - 1))), AbsoluteAddress(SamplingFlags::addressOfFlags()));
62}
63#endif
64
65#if DFG_ENABLE(JIT_ASSERT)
66#if USE(JSVALUE64)
67void AssemblyHelpers::jitAssertIsInt32(GPRReg gpr)
68{
69#if CPU(X86_64)
70 Jump checkInt32 = branchPtr(BelowOrEqual, gpr, TrustedImmPtr(reinterpret_cast<void*>(static_cast<uintptr_t>(0xFFFFFFFFu))));
71 breakpoint();
72 checkInt32.link(this);
73#else
74 UNUSED_PARAM(gpr);
75#endif
76}
77
78void AssemblyHelpers::jitAssertIsJSInt32(GPRReg gpr)
79{
80 Jump checkJSInt32 = branchPtr(AboveOrEqual, gpr, GPRInfo::tagTypeNumberRegister);
81 breakpoint();
82 checkJSInt32.link(this);
83}
84
85void AssemblyHelpers::jitAssertIsJSNumber(GPRReg gpr)
86{
87 Jump checkJSNumber = branchTestPtr(MacroAssembler::NonZero, gpr, GPRInfo::tagTypeNumberRegister);
88 breakpoint();
89 checkJSNumber.link(this);
90}
91
92void AssemblyHelpers::jitAssertIsJSDouble(GPRReg gpr)
93{
94 Jump checkJSInt32 = branchPtr(AboveOrEqual, gpr, GPRInfo::tagTypeNumberRegister);
95 Jump checkJSNumber = branchTestPtr(MacroAssembler::NonZero, gpr, GPRInfo::tagTypeNumberRegister);
96 checkJSInt32.link(this);
97 breakpoint();
98 checkJSNumber.link(this);
99}
100
101void AssemblyHelpers::jitAssertIsCell(GPRReg gpr)
102{
103 Jump checkCell = branchTestPtr(MacroAssembler::Zero, gpr, GPRInfo::tagMaskRegister);
104 breakpoint();
105 checkCell.link(this);
106}
107#elif USE(JSVALUE32_64)
108void AssemblyHelpers::jitAssertIsInt32(GPRReg gpr)
109{
110 UNUSED_PARAM(gpr);
111}
112
113void AssemblyHelpers::jitAssertIsJSInt32(GPRReg gpr)
114{
115 Jump checkJSInt32 = branch32(Equal, gpr, TrustedImm32(JSValue::Int32Tag));
116 breakpoint();
117 checkJSInt32.link(this);
118}
119
120void AssemblyHelpers::jitAssertIsJSNumber(GPRReg gpr)
121{
122 Jump checkJSInt32 = branch32(Equal, gpr, TrustedImm32(JSValue::Int32Tag));
123 Jump checkJSDouble = branch32(Below, gpr, TrustedImm32(JSValue::LowestTag));
124 breakpoint();
125 checkJSInt32.link(this);
126 checkJSDouble.link(this);
127}
128
129void AssemblyHelpers::jitAssertIsJSDouble(GPRReg gpr)
130{
131 Jump checkJSDouble = branch32(Below, gpr, TrustedImm32(JSValue::LowestTag));
132 breakpoint();
133 checkJSDouble.link(this);
134}
135
136void AssemblyHelpers::jitAssertIsCell(GPRReg gpr)
137{
138 Jump checkCell = branch32(Equal, gpr, TrustedImm32(JSValue::CellTag));
139 breakpoint();
140 checkCell.link(this);
141}
142#endif // USE(JSVALUE32_64)
143
144void AssemblyHelpers::jitAssertHasValidCallFrame()
145{
146 Jump checkCFR = branchTestPtr(Zero, GPRInfo::callFrameRegister, TrustedImm32(7));
147 breakpoint();
148 checkCFR.link(this);
149}
150#endif // DFG_ENABLE(JIT_ASSERT)
151
152} } // namespace JSC::DFG
153
154#endif // ENABLE(DFG_JIT)
155