Changeset 224938 in webkit for trunk/Source/JavaScriptCore/tools


Ignore:
Timestamp:
Nov 16, 2017, 3:44:12 PM (8 years ago)
Author:
[email protected]
Message:

Add some X86 intrinsics to $vm to help with some perf testing
https://bugs.webkit.org/show_bug.cgi?id=179693

Reviewed by Mark Lam.

I've been doing some local perf testing of various ideas and have
had these come in handy. I'm going to land them to dollarVM to prevent
having to add them to my local build every time I do perf testing.

  • assembler/MacroAssemblerX86Common.h:

(JSC::MacroAssemblerX86Common::mfence):
(JSC::MacroAssemblerX86Common::rdtsc):
(JSC::MacroAssemblerX86Common::pause):
(JSC::MacroAssemblerX86Common::cpuid):

  • assembler/X86Assembler.h:

(JSC::X86Assembler::rdtsc):
(JSC::X86Assembler::pause):
(JSC::X86Assembler::cpuid):

  • 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/DFGGraph.cpp:

(JSC::DFG::Graph::dump):

  • dfg/DFGNode.h:

(JSC::DFG::Node::intrinsic):

  • dfg/DFGNodeType.h:
  • dfg/DFGPredictionPropagationPhase.cpp:
  • dfg/DFGSafeToExecute.h:

(JSC::DFG::safeToExecute):

  • dfg/DFGSpeculativeJIT32_64.cpp:

(JSC::DFG::SpeculativeJIT::compile):

  • dfg/DFGSpeculativeJIT64.cpp:

(JSC::DFG::SpeculativeJIT::compile):

  • dfg/DFGValidate.cpp:
  • ftl/FTLCapabilities.cpp:

(JSC::FTL::canCompile):

  • ftl/FTLLowerDFGToB3.cpp:

(JSC::FTL::DFG::LowerDFGToB3::compileNode):
(JSC::FTL::DFG::LowerDFGToB3::compileCPUIntrinsic):

  • runtime/Intrinsic.cpp:

(JSC::intrinsicName):

  • runtime/Intrinsic.h:
  • tools/JSDollarVM.cpp:

(JSC::functionCpuMfence):
(JSC::functionCpuRdtsc):
(JSC::functionCpuCpuid):
(JSC::functionCpuPause):
(JSC::functionCpuClflush):
(JSC::JSDollarVM::finishCreation):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/tools/JSDollarVM.cpp

    r224838 r224938  
    2929#include "CodeBlock.h"
    3030#include "FunctionCodeBlock.h"
     31#include "JSArrayBuffer.h"
    3132#include "JSCInlines.h"
    3233#include "VMInspector.h"
     34#include <wtf/Atomics.h>
    3335#include <wtf/DataLog.h>
    3436#include <wtf/ProcessID.h>
     
    5860{
    5961    return JSValue::encode(jsBoolean(false));
     62}
     63
     64static EncodedJSValue JSC_HOST_CALL functionCpuMfence(ExecState*)
     65{
     66#if CPU(X86_64) && !OS(WINDOWS)
     67    asm volatile("mfence" ::: "memory");
     68#endif
     69    return JSValue::encode(jsUndefined());
     70}
     71
     72static EncodedJSValue JSC_HOST_CALL functionCpuRdtsc(ExecState*)
     73{
     74#if CPU(X86_64) && !OS(WINDOWS)
     75    unsigned high;
     76    unsigned low;
     77    asm volatile ("rdtsc" : "=a"(low), "=d"(high));
     78    return JSValue::encode(jsNumber(low));
     79#else
     80    return JSValue::encode(jsNumber(0));
     81#endif
     82}
     83
     84static EncodedJSValue JSC_HOST_CALL functionCpuCpuid(ExecState*)
     85{
     86#if CPU(X86_64) && !OS(WINDOWS)
     87    WTF::x86_cpuid();
     88#endif
     89    return JSValue::encode(jsUndefined());
     90}
     91
     92static EncodedJSValue JSC_HOST_CALL functionCpuPause(ExecState*)
     93{
     94#if CPU(X86_64) && !OS(WINDOWS)
     95    asm volatile ("pause" ::: "memory");
     96#endif
     97    return JSValue::encode(jsUndefined());
     98}
     99
     100// This takes either a JSArrayBuffer, JSArrayBufferView*, or any other object as its first
     101// argument. The second argument is expected to be an integer.
     102//
     103// If the first argument is a JSArrayBuffer, it'll clflush on that buffer
     104// plus the second argument as a byte offset. It'll also flush on the object
     105// itself so its length, etc, aren't in the cache.
     106//
     107// If the first argument is not a JSArrayBuffer, we load the butterfly
     108// and clflush at the address of the butterfly.
     109static EncodedJSValue JSC_HOST_CALL functionCpuClflush(ExecState* exec)
     110{
     111#if CPU(X86_64) && !OS(WINDOWS)
     112    VM& vm = exec->vm();
     113
     114    if (!exec->argument(1).isInt32())
     115        return JSValue::encode(jsBoolean(false));
     116
     117    auto clflush = [] (void* ptr) {
     118        char* ptrToFlush = static_cast<char*>(ptr);
     119        asm volatile ("clflush %0" :: "m"(*ptrToFlush) : "memory");
     120    };
     121
     122    uint32_t offset = exec->argument(1).asUInt32();
     123
     124    char* ptr = nullptr;
     125    if (JSArrayBuffer* buffer = jsDynamicCast<JSArrayBuffer*>(vm, exec->argument(0))) {
     126        if (ArrayBuffer* impl = buffer->impl()) {
     127            if (offset < impl->byteLength()) {
     128                clflush(impl);
     129                ptr = bitwise_cast<char*>(impl) + offset;
     130            }
     131        }
     132    } else if (JSArrayBufferView* view = jsDynamicCast<JSArrayBufferView*>(vm, exec->argument(0)))
     133        ptr = bitwise_cast<char*>(view);
     134    else if (JSObject* object = jsDynamicCast<JSObject*>(vm, exec->argument(0))) {
     135        switch (object->indexingType()) {
     136        case ALL_INT32_INDEXING_TYPES:
     137        case ALL_CONTIGUOUS_INDEXING_TYPES:
     138        case ALL_DOUBLE_INDEXING_TYPES:
     139            clflush(object);
     140            ptr = bitwise_cast<char*>(object->butterfly()) + offset;
     141        }
     142    }
     143
     144    if (!ptr)
     145        return JSValue::encode(jsBoolean(false));
     146
     147    clflush(ptr);
     148    return JSValue::encode(jsBoolean(true));
     149#else
     150    UNUSED_PARAM(exec);
     151    return JSValue::encode(jsBoolean(false));
     152#endif
    60153}
    61154
     
    271364   
    272365    putDirectNativeFunction(vm, globalObject, Identifier::fromString(&vm, "dfgTrue"), 0, functionDFGTrue, DFGTrueIntrinsic, static_cast<unsigned>(PropertyAttribute::DontEnum));
     366
     367    putDirectNativeFunction(vm, globalObject, Identifier::fromString(&vm, "cpuMfence"), 0, functionCpuMfence, CPUMfenceIntrinsic, 0);
     368    putDirectNativeFunction(vm, globalObject, Identifier::fromString(&vm, "cpuRdtsc"), 0, functionCpuRdtsc, CPURdtscIntrinsic, 0);
     369    putDirectNativeFunction(vm, globalObject, Identifier::fromString(&vm, "cpuCpuid"), 0, functionCpuCpuid, CPUCpuidIntrinsic, 0);
     370    putDirectNativeFunction(vm, globalObject, Identifier::fromString(&vm, "cpuPause"), 0, functionCpuPause, CPUPauseIntrinsic, 0);
     371    addFunction(vm, globalObject, "cpuClflush", functionCpuClflush, 2);
    273372   
    274373    addFunction(vm, globalObject, "llintTrue", functionLLintTrue, 0);
Note: See TracChangeset for help on using the changeset viewer.