Changeset 43372 in webkit for trunk/JavaScriptCore/jit/JIT.cpp


Ignore:
Timestamp:
May 7, 2009, 3:52:19 PM (16 years ago)
Author:
[email protected]
Message:

Improve native call performance

Reviewed by Gavin Barraclough.

Fix the windows build by adding calling convention declarations everywhere,
chose fastcall as that seemed most sensible given we were having to declare
the convention explicitly. In addition switched to fastcall on mac in the
deluded belief that documented fastcall behavior on windows would match
actual its actual behavior.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/jit/JIT.cpp

    r43363 r43372  
    18231823    emitGetFromCallFrameHeader(RegisterFile::ArgumentCount, regT0);
    18241824
    1825     struct NativeFunctionSignature {
    1826         CallFrame* callFrame;
     1825    /* We have two structs that we use to describe the stackframe we set up for our
     1826     * call to native code.  NativeCallFrameStructure describes the how we set up the stack
     1827     * in advance of the call.  NativeFunctionCalleeSignature describes the callframe
     1828     * as the native code expects it.  We do this as we are using the fastcall calling
     1829     * convention which results in the callee popping its arguments off the stack, but
     1830     * not the rest of the callframe so we need a nice way to ensure we increment the
     1831     * stack pointer by the right amount after the call.
     1832     */
     1833#if COMPILER(MSVC)
     1834    struct NativeCallFrameStructure {
     1835      //  CallFrame* callFrame; // passed in EDX
    18271836        JSObject* callee;
    18281837        JSValue thisValue;
    18291838        ArgList* argPointer;
    18301839        ArgList args;
     1840        JSValue result;
    18311841    };
    1832     const int NativeCallFrameSize = (sizeof(NativeFunctionSignature) + 15) & ~15;
     1842    struct NativeFunctionCalleeSignature {
     1843        JSObject* callee;
     1844        JSValue thisValue;
     1845        ArgList* argPointer;
     1846    };
     1847#else
     1848    struct NativeCallFrameStructure {
     1849      //  CallFrame* callFrame; // passed in ECX
     1850      //  JSObject* callee; // passed in EDX
     1851        JSValue thisValue;
     1852        ArgList* argPointer;
     1853        ArgList args;
     1854    };
     1855    struct NativeFunctionCalleeSignature {
     1856        JSValue thisValue;
     1857        ArgList* argPointer;
     1858    };
     1859#endif
     1860    const int NativeCallFrameSize = (sizeof(NativeCallFrameStructure) + 15) & ~15;
    18331861    // Allocate system stack frame
    18341862    subPtr(Imm32(NativeCallFrameSize), stackPointerRegister);
     
    18381866
    18391867    // push argcount
    1840     storePtr(regT0, Address(stackPointerRegister, FIELD_OFFSET(NativeFunctionSignature, args) + FIELD_OFFSET(ArgList, m_argCount)));
     1868    storePtr(regT0, Address(stackPointerRegister, FIELD_OFFSET(NativeCallFrameStructure, args) + FIELD_OFFSET(ArgList, m_argCount)));
    18411869   
    18421870    // Calculate the start of the callframe header, and store in regT1
     
    18461874    mul32(Imm32(sizeof(Register)), regT0, regT0);
    18471875    subPtr(regT0, regT1);
    1848     storePtr(regT1, Address(stackPointerRegister, FIELD_OFFSET(NativeFunctionSignature, args) + FIELD_OFFSET(ArgList, m_args)));
     1876    storePtr(regT1, Address(stackPointerRegister, FIELD_OFFSET(NativeCallFrameStructure, args) + FIELD_OFFSET(ArgList, m_args)));
    18491877
    18501878    // ArgList is passed by reference so is stackPointerRegister + 4 * sizeof(Register)
    1851     addPtr(Imm32(FIELD_OFFSET(NativeFunctionSignature, args)), stackPointerRegister, regT0);
    1852     storePtr(regT0, Address(stackPointerRegister, FIELD_OFFSET(NativeFunctionSignature, argPointer)));
     1879    addPtr(Imm32(FIELD_OFFSET(NativeCallFrameStructure, args)), stackPointerRegister, regT0);
     1880    storePtr(regT0, Address(stackPointerRegister, FIELD_OFFSET(NativeCallFrameStructure, argPointer)));
    18531881
    18541882    // regT1 currently points to the first argument, regT1 - sizeof(Register) points to 'this'
    18551883    loadPtr(Address(regT1, -(int)sizeof(Register)), regT1);
    1856     poke(regT1, 2);
    1857     storePtr(regT1, Address(stackPointerRegister, FIELD_OFFSET(NativeFunctionSignature, thisValue)));
     1884    storePtr(regT1, Address(stackPointerRegister, FIELD_OFFSET(NativeCallFrameStructure, thisValue)));
     1885
     1886#if COMPILER(MSVC)
     1887    // ArgList is passed by reference so is stackPointerRegister + 4 * sizeof(Register)
     1888    addPtr(Imm32(FIELD_OFFSET(NativeCallFrameStructure, result)), stackPointerRegister, X86::ecx);
    18581889
    18591890    // Plant callee
    1860     emitGetFromCallFrameHeader(RegisterFile::Callee, regT2);
    1861     storePtr(regT2, Address(stackPointerRegister, FIELD_OFFSET(NativeFunctionSignature, callee)));
     1891    emitGetFromCallFrameHeader(RegisterFile::Callee, X86::eax);
     1892    storePtr(X86::eax, Address(stackPointerRegister, FIELD_OFFSET(NativeCallFrameStructure, callee)));
    18621893
    18631894    // Plant callframe
    1864     storePtr(callFrameRegister, Address(stackPointerRegister, FIELD_OFFSET(NativeFunctionSignature, callFrame)));
    1865 
    1866     call(Address(regT2, FIELD_OFFSET(JSFunction, m_data)));
    1867     addPtr(Imm32(NativeCallFrameSize), stackPointerRegister);
     1895    move(callFrameRegister, X86::edx);
     1896
     1897    call(Address(X86::eax, FIELD_OFFSET(JSFunction, m_data)));
     1898
     1899    // JSValue is a non-POD type
     1900    loadPtr(Address(X86::eax), X86::eax);
     1901#else
     1902    // Plant callee
     1903    emitGetFromCallFrameHeader(RegisterFile::Callee, X86::edx);
     1904
     1905    // Plant callframe
     1906    move(callFrameRegister, X86::ecx);
     1907    call(Address(X86::edx, FIELD_OFFSET(JSFunction, m_data)));
     1908#endif
     1909
     1910    // We've put a few temporaries on the stack in addition to the actual arguments
     1911    // so pull them off now
     1912    addPtr(Imm32(NativeCallFrameSize - sizeof(NativeFunctionCalleeSignature)), stackPointerRegister);
     1913
    18681914#endif
    18691915
Note: See TracChangeset for help on using the changeset viewer.