source: webkit/trunk/Source/JavaScriptCore/jit/JITLeftShiftGenerator.cpp

Last change on this file was 250094, checked in by [email protected], 6 years ago

Replace JSValue #defines with static constexpr values.
https://bugs.webkit.org/show_bug.cgi?id=201966

Reviewed by Yusuke Suzuki.

static constexpr is the modern C++ way to define these constants.

Some of the values are typed int64_t and some are int32_t. The original #define
values are int64_t. Hence, we adopt int64_t as the default type to use here.

However, some of these constants are being used as 32-bit values, and the code
was static_cast'ing them into int32_t. This set of constants are all the small
values that fit in an int32_t anyway. So, we're putting these in int32_t instead
so that we don't have to keep casting them. In the few places where they are
used as int64_t, they will automatically get up-casted anyway.

In this patch, we also did the following:

  1. Renamed TagMask to NotCellMask, because everywhere in the code, we're basically using it to filter out cells like this:

if (value & NotCellMask) then goto handleNotCellCase;

  1. Renamed TagTypeNumber to NumberTag for a shorter name.

Ditto for TagBitTypeOther, TagBitBool, TagBitUndefined, TagBitsWasm, and TagWasmMask.
They are now OtherTag, BoolTag, UndefinedTag, WasmTag, and WasmMask.

  1. Introduced DoubleEncodeOffsetBit so that client code do not embed this value as a literal constant. We now define DoubleEncodeOffset based on DoubleEncodeOffsetBit ensuring consistency.
  1. Introduced MiscTag so that clients don't have to put this set of tags together themselves.
  1. Removed static asserts for tags in LLIntData.cpp because the offlineasm now captures these values correctly with constexpr statements. These static asserts were holdovers from the old days back when we had to define LLInt constant values manually, and we needed a mechanism to detect when the values have changed in the source.
  1. Replaced some runtime asserts in RegisterSet.cpp with static_asserts.
  1. In Wasm::wasmToJS(), we were constructing the value of JSValue::DoubleEncodeOffset constant by left shifting 1 by JSValue::DoubleEncodeOffsetBit. There's no need to do this for ARM64 because the constant can be loaded efficiently with a single MOVZ instruction. So, we add a CPU(ARM64) case to just move the constant into the target register.
  • assembler/AbortReason.h:
  • bytecode/AccessCase.cpp:

(JSC::AccessCase::generateWithGuard):

  • dfg/DFGOSRExit.cpp:

(JSC::DFG::OSRExit::executeOSRExit):
(JSC::DFG::OSRExit::compileExit):

  • dfg/DFGSpeculativeJIT.cpp:

(JSC::DFG::SpeculativeJIT::silentFill):
(JSC::DFG::SpeculativeJIT::checkArgumentTypes):
(JSC::DFG::SpeculativeJIT::compileValueToInt32):
(JSC::DFG::SpeculativeJIT::compileDoubleRep):
(JSC::DFG::SpeculativeJIT::getIntTypedArrayStoreOperand):
(JSC::DFG::SpeculativeJIT::speculateMisc):

  • dfg/DFGSpeculativeJIT.h:

(JSC::DFG::SpeculativeJIT::spill):

  • dfg/DFGSpeculativeJIT64.cpp:

(JSC::DFG::SpeculativeJIT::fillJSValue):
(JSC::DFG::SpeculativeJIT::nonSpeculativeNonPeepholeCompareNullOrUndefined):
(JSC::DFG::SpeculativeJIT::nonSpeculativePeepholeBranchNullOrUndefined):
(JSC::DFG::SpeculativeJIT::emitCall):
(JSC::DFG::SpeculativeJIT::fillSpeculateBoolean):
(JSC::DFG::SpeculativeJIT::compileObjectStrictEquality):
(JSC::DFG::SpeculativeJIT::compileObjectToObjectOrOtherEquality):
(JSC::DFG::SpeculativeJIT::compilePeepHoleObjectToObjectOrOtherEquality):
(JSC::DFG::SpeculativeJIT::compileInt52Compare):
(JSC::DFG::SpeculativeJIT::compileObjectOrOtherLogicalNot):
(JSC::DFG::SpeculativeJIT::compileLogicalNot):
(JSC::DFG::SpeculativeJIT::emitObjectOrOtherBranch):
(JSC::DFG::SpeculativeJIT::emitBranch):
(JSC::DFG::SpeculativeJIT::compile):
(JSC::DFG::SpeculativeJIT::moveTrueTo):
(JSC::DFG::SpeculativeJIT::moveFalseTo):
(JSC::DFG::SpeculativeJIT::blessBoolean):

  • ftl/FTLLowerDFGToB3.cpp:

(JSC::FTL::DFG::LowerDFGToB3::lower):
(JSC::FTL::DFG::LowerDFGToB3::compileDoubleRep):
(JSC::FTL::DFG::LowerDFGToB3::compileBooleanToNumber):
(JSC::FTL::DFG::LowerDFGToB3::compileUnaryMathIC):
(JSC::FTL::DFG::LowerDFGToB3::compileBinaryMathIC):
(JSC::FTL::DFG::LowerDFGToB3::compilePutById):
(JSC::FTL::DFG::LowerDFGToB3::compileGetByVal):
(JSC::FTL::DFG::LowerDFGToB3::compileArrayIndexOf):
(JSC::FTL::DFG::LowerDFGToB3::compileGetArgument):
(JSC::FTL::DFG::LowerDFGToB3::compileCallOrConstruct):
(JSC::FTL::DFG::LowerDFGToB3::compileDirectCallOrConstruct):
(JSC::FTL::DFG::LowerDFGToB3::compileTailCall):
(JSC::FTL::DFG::LowerDFGToB3::compileCallOrConstructVarargsSpread):
(JSC::FTL::DFG::LowerDFGToB3::compileCallOrConstructVarargs):
(JSC::FTL::DFG::LowerDFGToB3::compileCallEval):
(JSC::FTL::DFG::LowerDFGToB3::compileInById):
(JSC::FTL::DFG::LowerDFGToB3::compileInstanceOf):
(JSC::FTL::DFG::LowerDFGToB3::compileGetEnumeratorStructurePname):
(JSC::FTL::DFG::LowerDFGToB3::compileGetEnumeratorGenericPname):
(JSC::FTL::DFG::LowerDFGToB3::getById):
(JSC::FTL::DFG::LowerDFGToB3::getByIdWithThis):
(JSC::FTL::DFG::LowerDFGToB3::compileCheckSubClass):
(JSC::FTL::DFG::LowerDFGToB3::compileCallDOMGetter):
(JSC::FTL::DFG::LowerDFGToB3::emitBinarySnippet):
(JSC::FTL::DFG::LowerDFGToB3::emitBinaryBitOpSnippet):
(JSC::FTL::DFG::LowerDFGToB3::emitRightShiftSnippet):
(JSC::FTL::DFG::LowerDFGToB3::equalNullOrUndefined):
(JSC::FTL::DFG::LowerDFGToB3::buildTypeOf):
(JSC::FTL::DFG::LowerDFGToB3::isInt32):
(JSC::FTL::DFG::LowerDFGToB3::isNotInt32):
(JSC::FTL::DFG::LowerDFGToB3::boxInt32):
(JSC::FTL::DFG::LowerDFGToB3::isCellOrMisc):
(JSC::FTL::DFG::LowerDFGToB3::isNotCellOrMisc):
(JSC::FTL::DFG::LowerDFGToB3::unboxDouble):
(JSC::FTL::DFG::LowerDFGToB3::boxDouble):
(JSC::FTL::DFG::LowerDFGToB3::isNotCell):
(JSC::FTL::DFG::LowerDFGToB3::isCell):
(JSC::FTL::DFG::LowerDFGToB3::isNotMisc):
(JSC::FTL::DFG::LowerDFGToB3::isNotBoolean):
(JSC::FTL::DFG::LowerDFGToB3::boxBoolean):
(JSC::FTL::DFG::LowerDFGToB3::isNotOther):
(JSC::FTL::DFG::LowerDFGToB3::isOther):

  • ftl/FTLOSRExitCompiler.cpp:

(JSC::FTL::reboxAccordingToFormat):
(JSC::FTL::compileStub):

  • interpreter/CalleeBits.h:

(JSC::CalleeBits::boxWasm):
(JSC::CalleeBits::isWasm const):
(JSC::CalleeBits::asWasmCallee const):

  • jit/AssemblyHelpers.cpp:

(JSC::AssemblyHelpers::jitAssertIsJSInt32):
(JSC::AssemblyHelpers::jitAssertIsJSNumber):
(JSC::AssemblyHelpers::jitAssertIsJSDouble):
(JSC::AssemblyHelpers::jitAssertIsCell):
(JSC::AssemblyHelpers::jitAssertTagsInPlace):
(JSC::AssemblyHelpers::emitConvertValueToBoolean):

  • jit/AssemblyHelpers.h:

(JSC::AssemblyHelpers::emitSaveThenMaterializeTagRegisters):
(JSC::AssemblyHelpers::emitRestoreSavedTagRegisters):
(JSC::AssemblyHelpers::emitMaterializeTagCheckRegisters):
(JSC::AssemblyHelpers::branchIfNotCell):
(JSC::AssemblyHelpers::branchIfCell):
(JSC::AssemblyHelpers::branchIfOther):
(JSC::AssemblyHelpers::branchIfNotOther):
(JSC::AssemblyHelpers::branchIfInt32):
(JSC::AssemblyHelpers::branchIfNotInt32):
(JSC::AssemblyHelpers::branchIfNumber):
(JSC::AssemblyHelpers::branchIfNotNumber):
(JSC::AssemblyHelpers::branchIfNotDoubleKnownNotInt32):
(JSC::AssemblyHelpers::branchIfBoolean):
(JSC::AssemblyHelpers::branchIfNotBoolean):
(JSC::AssemblyHelpers::boxDouble):
(JSC::AssemblyHelpers::unboxDoubleWithoutAssertions):
(JSC::AssemblyHelpers::boxInt52):
(JSC::AssemblyHelpers::boxBooleanPayload):
(JSC::AssemblyHelpers::boxInt32):

  • jit/CallFrameShuffleData.h:
  • jit/CallFrameShuffler.cpp:

(JSC::CallFrameShuffler::CallFrameShuffler):
(JSC::CallFrameShuffler::dump const):
(JSC::CallFrameShuffler::prepareAny):

  • jit/CallFrameShuffler.h:

(JSC::CallFrameShuffler::getFreeRegister const):

  • jit/CallFrameShuffler64.cpp:

(JSC::CallFrameShuffler::emitBox):
(JSC::CallFrameShuffler::tryAcquireNumberTagRegister):
(JSC::CallFrameShuffler::tryAcquireTagTypeNumber): Deleted.

  • jit/GPRInfo.h:

(JSC::GPRInfo::reservedRegisters):

  • jit/JITArithmetic.cpp:

(JSC::JIT::emit_compareAndJumpSlow):

  • jit/JITBitAndGenerator.cpp:

(JSC::JITBitAndGenerator::generateFastPath):

  • jit/JITBitOrGenerator.cpp:

(JSC::JITBitOrGenerator::generateFastPath):

  • jit/JITBitXorGenerator.cpp:

(JSC::JITBitXorGenerator::generateFastPath):

  • jit/JITCall.cpp:

(JSC::JIT::compileTailCall):

  • jit/JITDivGenerator.cpp:

(JSC::JITDivGenerator::generateFastPath):

  • jit/JITInlines.h:

(JSC::JIT::emitPatchableJumpIfNotInt):

  • jit/JITLeftShiftGenerator.cpp:

(JSC::JITLeftShiftGenerator::generateFastPath):

  • jit/JITMulGenerator.cpp:

(JSC::JITMulGenerator::generateFastPath):

  • jit/JITOpcodes.cpp:

(JSC::JIT::emit_op_overrides_has_instance):
(JSC::JIT::emit_op_is_undefined):
(JSC::JIT::emit_op_is_undefined_or_null):
(JSC::JIT::emit_op_is_boolean):
(JSC::JIT::emit_op_is_number):
(JSC::JIT::emit_op_is_cell_with_type):
(JSC::JIT::emit_op_is_object):
(JSC::JIT::emit_op_not):
(JSC::JIT::emit_op_jeq_null):
(JSC::JIT::emit_op_jneq_null):
(JSC::JIT::emit_op_jundefined_or_null):
(JSC::JIT::emit_op_jnundefined_or_null):
(JSC::JIT::emit_op_eq_null):
(JSC::JIT::emit_op_neq_null):

  • jit/JITPropertyAccess.cpp:

(JSC::JIT::emitGenericContiguousPutByVal):
(JSC::JIT::emitFloatTypedArrayPutByVal):

  • jit/JITRightShiftGenerator.cpp:

(JSC::JITRightShiftGenerator::generateFastPath):

  • jit/RegisterSet.cpp:

(JSC::RegisterSet::runtimeTagRegisters):
(JSC::RegisterSet::llintBaselineCalleeSaveRegisters):
(JSC::RegisterSet::dfgCalleeSaveRegisters):
(JSC::RegisterSet::ftlCalleeSaveRegisters):

  • jit/SpecializedThunkJIT.h:

(JSC::SpecializedThunkJIT::returnDouble):
(JSC::SpecializedThunkJIT::tagReturnAsInt32):

  • jit/ThunkGenerators.cpp:

(JSC::virtualThunkFor):
(JSC::nativeForGenerator):
(JSC::arityFixupGenerator):
(JSC::absThunkGenerator):

  • llint/LLIntData.cpp:

(JSC::LLInt::Data::performAssertions):

  • llint/LowLevelInterpreter.asm:
  • llint/LowLevelInterpreter.cpp:

(JSC::CLoop::execute):

  • llint/LowLevelInterpreter64.asm:
  • offlineasm/arm64.rb:
  • offlineasm/cloop.rb:
  • offlineasm/x86.rb:
  • runtime/JSCJSValue.h:
  • runtime/JSCJSValueInlines.h:

(JSC::JSValue::isUndefinedOrNull const):
(JSC::JSValue::isCell const):
(JSC::JSValue::isInt32 const):
(JSC::JSValue::JSValue):
(JSC::JSValue::asDouble const):
(JSC::JSValue::isNumber const):

  • wasm/js/WasmToJS.cpp:

(JSC::Wasm::wasmToJS):

  • wasm/js/WebAssemblyFunction.cpp:

(JSC::WebAssemblyFunction::jsCallEntrypointSlow):

File size: 3.0 KB
Line 
1/*
2 * Copyright (C) 2015-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 "JITLeftShiftGenerator.h"
28
29#if ENABLE(JIT)
30
31namespace JSC {
32
33void JITLeftShiftGenerator::generateFastPath(CCallHelpers& jit)
34{
35 ASSERT(m_scratchGPR != InvalidGPRReg);
36 ASSERT(m_scratchGPR != m_left.payloadGPR());
37 ASSERT(m_scratchGPR != m_right.payloadGPR());
38#if USE(JSVALUE32_64)
39 ASSERT(m_scratchGPR != m_left.tagGPR());
40 ASSERT(m_scratchGPR != m_right.tagGPR());
41#endif
42
43 ASSERT(!m_leftOperand.isConstInt32() || !m_rightOperand.isConstInt32());
44
45 m_didEmitFastPath = true;
46
47 if (m_rightOperand.isConstInt32()) {
48 // Try to do (intVar << intConstant).
49 m_slowPathJumpList.append(jit.branchIfNotInt32(m_left));
50
51 jit.moveValueRegs(m_left, m_result);
52 jit.lshift32(CCallHelpers::Imm32(m_rightOperand.asConstInt32()), m_result.payloadGPR());
53
54 } else {
55 // Try to do (intConstant << intVar) or (intVar << intVar).
56 m_slowPathJumpList.append(jit.branchIfNotInt32(m_right));
57
58 GPRReg rightOperandGPR = m_right.payloadGPR();
59 if (rightOperandGPR == m_result.payloadGPR()) {
60 jit.move(rightOperandGPR, m_scratchGPR);
61 rightOperandGPR = m_scratchGPR;
62 }
63
64 if (m_leftOperand.isConstInt32()) {
65#if USE(JSVALUE32_64)
66 jit.move(m_right.tagGPR(), m_result.tagGPR());
67#endif
68 jit.move(CCallHelpers::Imm32(m_leftOperand.asConstInt32()), m_result.payloadGPR());
69 } else {
70 m_slowPathJumpList.append(jit.branchIfNotInt32(m_left));
71 jit.moveValueRegs(m_left, m_result);
72 }
73
74 jit.lshift32(rightOperandGPR, m_result.payloadGPR());
75 }
76
77#if USE(JSVALUE64)
78 jit.or64(GPRInfo::numberTagRegister, m_result.payloadGPR());
79#endif
80}
81
82} // namespace JSC
83
84#endif // ENABLE(JIT)
Note: See TracBrowser for help on using the repository browser.