Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Math.random should have an intrinsic thunk and it should be later han…
…dled as a DFG Node https://bugs.webkit.org/show_bug.cgi?id=152133 Reviewed by Geoffrey Garen. Source/JavaScriptCore: In this patch, we implement new RandomIntrinsic. It emits a machine code to generate random numbers efficiently. And later it will be recognized by DFG and converted to ArithRandom node. It provides type information SpecDoubleReal since Math.random only generates a number within [0, 1.0). Currently, only 64bit version is supported. On 32bit environment, ArithRandom will be converted to callOperation. While it emits a function call, ArithRandom node on 32bit still represents SpecDoubleReal as a result type. * dfg/DFGAbstractHeap.h: * dfg/DFGAbstractInterpreterInlines.h: (JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects): * dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::handleIntrinsicCall): * dfg/DFGClobberize.h: (JSC::DFG::clobberize): * dfg/DFGDoesGC.cpp: (JSC::DFG::doesGC): * dfg/DFGFixupPhase.cpp: (JSC::DFG::FixupPhase::fixupNode): * dfg/DFGNodeType.h: * dfg/DFGOperations.cpp: * dfg/DFGOperations.h: * dfg/DFGPredictionPropagationPhase.cpp: (JSC::DFG::PredictionPropagationPhase::propagate): * dfg/DFGSafeToExecute.h: (JSC::DFG::safeToExecute): * dfg/DFGSpeculativeJIT.h: (JSC::DFG::SpeculativeJIT::callOperation): * dfg/DFGSpeculativeJIT32_64.cpp: (JSC::DFG::SpeculativeJIT::compile): (JSC::DFG::SpeculativeJIT::compileArithRandom): * dfg/DFGSpeculativeJIT64.cpp: (JSC::DFG::SpeculativeJIT::compile): (JSC::DFG::SpeculativeJIT::compileArithRandom): * ftl/FTLCapabilities.cpp: (JSC::FTL::canCompile): * ftl/FTLLowerDFGToLLVM.cpp: (JSC::FTL::DFG::LowerDFGToLLVM::compileNode): (JSC::FTL::DFG::LowerDFGToLLVM::compileArithRandom): * jit/AssemblyHelpers.cpp: (JSC::emitRandomThunkImpl): (JSC::AssemblyHelpers::emitRandomThunk): * jit/AssemblyHelpers.h: * jit/JITOperations.h: * jit/ThunkGenerators.cpp: (JSC::randomThunkGenerator): * jit/ThunkGenerators.h: * runtime/Intrinsic.h: * runtime/JSGlobalObject.h: (JSC::JSGlobalObject::weakRandomOffset): * runtime/MathObject.cpp: (JSC::MathObject::finishCreation): * runtime/VM.cpp: (JSC::thunkGeneratorForIntrinsic): * tests/stress/random-53bit.js: Added. (test): * tests/stress/random-in-range.js: Added. (test): Source/WTF: Change 64bit random to double logic to convert efficiently. * wtf/WeakRandom.h: (WTF::WeakRandom::get): (WTF::WeakRandom::lowOffset): (WTF::WeakRandom::highOffset): LayoutTests: Add new regression test. * js/regress/math-random-expected.txt: Added. * js/regress/math-random.html: Added. * js/regress/script-tests/math-random.js: Added. (test): Canonical link: https://commits.webkit.org/170398@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@194087 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
with
431 additions
and 2 deletions.
- +14 −0 LayoutTests/ChangeLog
- +10 −0 LayoutTests/js/regress/math-random-expected.txt
- +12 −0 LayoutTests/js/regress/math-random.html
- +15 −0 LayoutTests/js/regress/script-tests/math-random.js
- +65 −0 Source/JavaScriptCore/ChangeLog
- +1 −0 Source/JavaScriptCore/dfg/DFGAbstractHeap.h
- +5 −0 Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h
- +8 −0 Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp
- +5 −0 Source/JavaScriptCore/dfg/DFGClobberize.h
- +1 −0 Source/JavaScriptCore/dfg/DFGDoesGC.cpp
- +5 −0 Source/JavaScriptCore/dfg/DFGFixupPhase.cpp
- +1 −0 Source/JavaScriptCore/dfg/DFGNodeType.h
- +7 −0 Source/JavaScriptCore/dfg/DFGOperations.cpp
- +4 −0 Source/JavaScriptCore/dfg/DFGOperations.h
- +5 −0 Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp
- +1 −0 Source/JavaScriptCore/dfg/DFGSafeToExecute.h
- +6 −0 Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h
- +16 −0 Source/JavaScriptCore/dfg/DFGSpeculativeJIT32_64.cpp
- +15 −0 Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp
- +1 −0 Source/JavaScriptCore/ftl/FTLCapabilities.cpp
- +50 −0 Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp
- +97 −0 Source/JavaScriptCore/jit/AssemblyHelpers.cpp
- +5 −0 Source/JavaScriptCore/jit/AssemblyHelpers.h
- +1 −0 Source/JavaScriptCore/jit/JITOperations.h
- +16 −0 Source/JavaScriptCore/jit/ThunkGenerators.cpp
- +1 −0 Source/JavaScriptCore/jit/ThunkGenerators.h
- +1 −0 Source/JavaScriptCore/runtime/Intrinsic.h
- +1 −0 Source/JavaScriptCore/runtime/JSGlobalObject.h
- +1 −1 Source/JavaScriptCore/runtime/MathObject.cpp
- +2 −0 Source/JavaScriptCore/runtime/VM.cpp
- +24 −0 Source/JavaScriptCore/tests/stress/random-53bit.js
- +14 −0 Source/JavaScriptCore/tests/stress/random-in-range.js
- +14 −0 Source/WTF/ChangeLog
- +7 −1 Source/WTF/wtf/WeakRandom.h
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,10 @@ | ||
JSRegress/math-random | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
PASS no exception thrown | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | ||
<html> | ||
<head> | ||
<script src="../../resources/js-test-pre.js"></script> | ||
</head> | ||
<body> | ||
<script src="../../resources/regress-pre.js"></script> | ||
<script src="script-tests/math-random.js"></script> | ||
<script src="../../resources/regress-post.js"></script> | ||
<script src="../../resources/js-test-post.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,15 @@ | ||
function test() | ||
{ | ||
var result = false; | ||
for (var i = 0; i < 100; ++i) { | ||
if (Math.random() < 0.5) | ||
result = true; | ||
if (Math.random() >= 0.5) | ||
result = true; | ||
} | ||
return result; | ||
} | ||
noInline(test); | ||
|
||
for (var i = 0; i < 1e4; ++i) | ||
test(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -85,6 +85,7 @@ bool doesGC(Graph& graph, Node* node) | ||
case ArithMax: | ||
case ArithPow: | ||
case ArithSqrt: | ||
case ArithRandom: | ||
case ArithRound: | ||
case ArithFRound: | ||
case ArithSin: | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -94,6 +94,7 @@ inline CapabilityLevel canCompile(Node* node) | ||
case ArithSin: | ||
case ArithCos: | ||
case ArithPow: | ||
case ArithRandom: | ||
case ArithRound: | ||
case ArithSqrt: | ||
case ArithLog: | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.