Changeset 39370 in webkit


Ignore:
Timestamp:
Dec 17, 2008 7:38:10 PM (15 years ago)
Author:
barraclough@apple.com
Message:

2008-12-17 Gavin Barraclough <barraclough@apple.com>

Reviewed by Sam Weinig.

print("Hello, 64-bit jitted world!");
Get hello-world working through the JIT, on x86-64.

  • assembler/X86Assembler.h:

Fix encoding of opcode + RegisterID format instructions for 64-bit.

  • interpreter/Interpreter.cpp:
  • interpreter/Interpreter.h:

Make VoidPtrPair actually be a pair of void*s.
(Possibly should make this change for 32-bit Mac platforms, too - but won't change 32-bit behaviour in this patch).

  • jit/JIT.cpp:
  • jit/JIT.h:

Provide names for the timeoutCheckRegister & callFrameRegister on x86-64,
force x86-64 ctiTrampoline arguments onto the stack,
implement the asm trampolines for x86-64,
implement the restoreArgumentReference methods for x86-64 calling conventions.

  • jit/JITCall.cpp:
  • jit/JITInlineMethods.h:
  • wtf/Platform.h:

Add switch settings to ENABLE(JIT), on PLATFORM(X86_64) (currently still disabled).

Location:
trunk/JavaScriptCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r39368 r39370  
     12008-12-17  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        print("Hello, 64-bit jitted world!");
     6        Get hello-world working through the JIT, on x86-64.
     7
     8        * assembler/X86Assembler.h:
     9            Fix encoding of opcode + RegisterID format instructions for 64-bit.
     10        * interpreter/Interpreter.cpp:
     11        * interpreter/Interpreter.h:
     12            Make VoidPtrPair actually be a pair of void*s.
     13            (Possibly should make this change for 32-bit Mac platforms, too - but won't change 32-bit behaviour in this patch).
     14        * jit/JIT.cpp:
     15        * jit/JIT.h:
     16            Provide names for the timeoutCheckRegister & callFrameRegister on x86-64,
     17            force x86-64 ctiTrampoline arguments onto the stack,
     18            implement the asm trampolines for x86-64,
     19            implement the restoreArgumentReference methods for x86-64 calling conventions.
     20        * jit/JITCall.cpp:
     21        * jit/JITInlineMethods.h:
     22        * wtf/Platform.h:
     23            Add switch settings to ENABLE(JIT), on PLATFORM(X86_64) (currently still disabled).
     24
    1252008-12-17  Sam Weinig  <sam@webkit.org>
    226
  • trunk/JavaScriptCore/assembler/X86Assembler.h

    r39342 r39370  
    11181118        {
    11191119            m_buffer.ensureSpace(maxInstructionSize);
    1120             emitRexIfNeeded(reg, 0, 0);
    1121             m_buffer.putByteUnchecked(opcode + reg);
     1120            emitRexIfNeeded(0, 0, reg);
     1121            m_buffer.putByteUnchecked(opcode + (reg & 7));
    11221122        }
    11231123
     
    12061206        {
    12071207            m_buffer.ensureSpace(maxInstructionSize);
    1208             emitRexW(reg, 0, 0);
    1209             m_buffer.putByteUnchecked(opcode + reg);
     1208            emitRexW(0, 0, reg);
     1209            m_buffer.putByteUnchecked(opcode + (reg & 7));
    12101210        }
    12111211
  • trunk/JavaScriptCore/interpreter/Interpreter.cpp

    r39354 r39370  
    42114211#endif
    42124212
     4213#if USE(CTI_ARGUMENT)
     4214#define SETUP_VL_ARGS
     4215#else
     4216#define SETUP_VL_ARGS va_list vl_args; va_start(vl_args, args)
     4217#endif
     4218
    42134219#ifndef NDEBUG
    42144220
     
    42404246};
    42414247
    4242 #define CTI_STACK_HACK() va_list vl_args; va_start(vl_args, args); StackHack stackHack(&CTI_RETURN_ADDRESS_SLOT)
     4248#define CTI_STACK_HACK() SETUP_VL_ARGS; StackHack stackHack(&CTI_RETURN_ADDRESS_SLOT)
    42434249#define CTI_SET_RETURN_ADDRESS(address) stackHack.savedReturnAddress = address
    42444250#define CTI_RETURN_ADDRESS stackHack.savedReturnAddress
     
    42464252#else
    42474253
    4248 #define CTI_STACK_HACK() va_list vl_args; va_start(vl_args, args)
     4254#define CTI_STACK_HACK() SETUP_VL_ARGS
    42494255#define CTI_SET_RETURN_ADDRESS(address) ctiSetReturnAddress(&CTI_RETURN_ADDRESS_SLOT, address);
    42504256#define CTI_RETURN_ADDRESS CTI_RETURN_ADDRESS_SLOT
     
    42774283    do { \
    42784284        VM_THROW_EXCEPTION_AT_END(); \
    4279         VoidPtrPairValue pair = {{ 0, 0 }}; \
    4280         return pair.i; \
     4285        RETURN_PAIR(0, 0); \
    42814286    } while (0)
    42824287#define VM_THROW_EXCEPTION_AT_END() \
     
    48494854            ARG_setCallFrame(oldCallFrame);
    48504855            throwStackOverflowError(oldCallFrame, ARG_globalData, ARG_returnAddress2, CTI_RETURN_ADDRESS);
    4851             VoidPtrPairValue pair = {{ 0, 0 }};
    4852             return pair.i;
     4856            RETURN_PAIR(0, 0);
    48534857        }
    48544858
     
    48614865    }
    48624866
    4863     VoidPtrPairValue pair = {{ newCodeBlock, callFrame }};
    4864     return pair.i;
     4867    RETURN_PAIR(newCodeBlock, callFrame);
    48654868}
    48664869
     
    51615164            CHECK_FOR_EXCEPTION_AT_END();
    51625165
    5163             VoidPtrPairValue pair = {{ thisObj, asPointer(result) }};
    5164             return pair.i;
     5166            RETURN_PAIR(thisObj, asPointer(result));
    51655167        }
    51665168        ++iter;
     
    54425444    CHECK_FOR_EXCEPTION_AT_END();
    54435445
    5444     VoidPtrPairValue pair = {{ asPointer(number), asPointer(jsNumber(ARG_globalData, number->uncheckedGetNumber() + 1)) }};
    5445     return pair.i;
     5446    RETURN_PAIR(asPointer(number), asPointer(jsNumber(ARG_globalData, number->uncheckedGetNumber() + 1)));
    54465447}
    54475448
     
    55585559            CHECK_FOR_EXCEPTION_AT_END();
    55595560
    5560             VoidPtrPairValue pair = {{ base, asPointer(result) }};
    5561             return pair.i;
     5561            RETURN_PAIR(base, asPointer(result));
    55625562        }
    55635563        ++iter;
     
    56275627    CHECK_FOR_EXCEPTION_AT_END();
    56285628
    5629     VoidPtrPairValue pair = {{ asPointer(number), asPointer(jsNumber(ARG_globalData, number->uncheckedGetNumber() - 1)) }};
    5630     return pair.i;
     5629    RETURN_PAIR(asPointer(number), asPointer(jsNumber(ARG_globalData, number->uncheckedGetNumber() - 1)));
    56315630}
    56325631
  • trunk/JavaScriptCore/interpreter/Interpreter.h

    r39325 r39370  
    8181#endif
    8282
    83 #endif
    84 
     83#endif // USE(FAST_CALL_CTI_ARGUMENT)
     84
     85
     86// FIXME: Could this be #if COMPILER(MSVC)? - or #if !PLATFORM(MAC)?
     87#if !PLATFORM(X86_64)
    8588    typedef uint64_t VoidPtrPair;
    86 
    87     typedef union
    88     {
     89    union VoidPtrPairValue {
    8990        struct { void* first; void* second; } s;
    9091        VoidPtrPair i;
    91     } VoidPtrPairValue;
    92 #endif
     92    };
     93#define RETURN_PAIR(a,b) VoidPtrPairValue pair = {{ a, b }}; return pair.i
     94#else
     95    struct VoidPtrPair {
     96        void* first;
     97        void* second;
     98    };
     99#define RETURN_PAIR(a,b) VoidPtrPair pair = { a, b }; return pair
     100#endif
     101
     102#endif // ENABLE(JIT)
    93103
    94104    enum DebugHookID {
  • trunk/JavaScriptCore/jit/JIT.cpp

    r39342 r39370  
    110110".globl " SYMBOL_STRING(ctiTrampoline) "\n"
    111111SYMBOL_STRING(ctiTrampoline) ":" "\n"
    112     "int3" "\n"
     112    "pushq %rbp" "\n"
     113    "movq %rsp, %rbp" "\n"
     114    "pushq %r12" "\n"
     115    "pushq %r13" "\n"
     116    "pushq %rbx" "\n"
     117    "subq $0x38, %rsp" "\n"
     118    "movq $512, %r12" "\n"
     119    "movq 0x70(%rsp), %r13" "\n" // Ox70 = 0x0E * 8, 0x0E = CTI_ARGS_callFrame (see assertion above)
     120    "call *0x60(%rsp)" "\n" // Ox60 = 0x0C * 8, 0x0C = CTI_ARGS_code (see assertion above)
     121    "addq $0x38, %rsp" "\n"
     122    "popq %rbx" "\n"
     123    "popq %r13" "\n"
     124    "popq %r12" "\n"
     125    "popq %rbp" "\n"
     126    "ret" "\n"
    113127);
    114128
     
    116130".globl " SYMBOL_STRING(ctiVMThrowTrampoline) "\n"
    117131SYMBOL_STRING(ctiVMThrowTrampoline) ":" "\n"
    118     "int3" "\n"
     132#if USE(CTI_ARGUMENT) && !USE(FAST_CALL_CTI_ARGUMENT)
     133    "movq %rsp, %rdi" "\n"
     134    "call " SYMBOL_STRING(_ZN3JSC11Interpreter12cti_vm_throwEPPv) "\n"
     135#else
     136#error "CTI_ARGUMENT configuration not supported."
     137#endif
     138    "addq $0x38, %rsp" "\n"
     139    "popq %rbx" "\n"
     140    "popq %r13" "\n"
     141    "popq %r12" "\n"
     142    "popq %rbp" "\n"
     143    "ret" "\n"
    119144);
    120145   
     
    229254void JIT::emitSlowScriptCheck()
    230255{
    231     Jump skipTimeout = jnzSub32(Imm32(1), X86::esi);
     256    Jump skipTimeout = jnzSub32(Imm32(1), timeoutCheckRegister);
    232257    emitCTICall(Interpreter::cti_timeout_check);
    233     move(X86::eax, X86::esi);
     258    move(X86::eax, timeoutCheckRegister);
    234259    skipTimeout.link(this);
    235260
     
    970995            emitPutJITStubArgFromVirtualRegister(currentInstruction[1].u.operand, 1, X86::ecx);
    971996            emitCTICall(Interpreter::cti_op_throw);
    972             __ addl_ir(0x1c, X86::esp);
    973             __ pop_r(X86::ebx);
    974             __ pop_r(X86::edi);
    975             __ pop_r(X86::esi);
    976             __ pop_r(X86::ebp);
    977             __ ret();
     997#if PLATFORM(X86_64)
     998            addPtr(Imm32(0x38), X86::esp);
     999            pop(X86::ebx);
     1000            pop(X86::r13);
     1001            pop(X86::r12);
     1002            pop(X86::ebp);
     1003            ret();
     1004#else
     1005            addPtr(Imm32(0x1c), X86::esp);
     1006            pop(X86::ebx);
     1007            pop(X86::edi);
     1008            pop(X86::esi);
     1009            pop(X86::ebp);
     1010            ret();
     1011#endif
    9781012            NEXT_OPCODE(op_throw);
    9791013        }
     
    18531887    }
    18541888#endif
     1889#if ENABLE(JIT_OPTIMIZE_CALL)
    18551890    for (unsigned i = 0; i < m_codeBlock->numberOfCallLinkInfos(); ++i) {
    18561891        CallLinkInfo& info = m_codeBlock->callLinkInfo(i);
     
    18601895        info.coldPathOther = X86Assembler::getRelocatedAddress(code, m_callStructureStubCompilationInfo[i].coldPathOther);
    18611896    }
     1897#endif
    18621898
    18631899    m_codeBlock->setJITCode(codeRef);
  • trunk/JavaScriptCore/jit/JIT.h

    r39351 r39370  
    189189
    190190    extern "C" {
    191         JSValue* ctiTrampoline(void* code, RegisterFile*, CallFrame*, JSValue** exception, Profiler**, JSGlobalData*);
     191        JSValue* ctiTrampoline(
     192#if PLATFORM(X86_64)
     193            // FIXME: (bug #22910) this will force all arguments onto the stack (regparm(0) does not appear to have any effect).
     194            // We can allow register passing here, and move the writes of these values into the trampoline.
     195            void*, void*, void*, void*, void*, void*,
     196#endif
     197            void* code, RegisterFile*, CallFrame*, JSValue** exception, Profiler**, JSGlobalData*);
    192198        void ctiVMThrowTrampoline();
    193199    };
     
    201207        using MacroAssembler::Label;
    202208
     209#if PLATFORM(X86_64)
     210        static const RegisterID timeoutCheckRegister = X86::r12;
     211        static const RegisterID callFrameRegister = X86::r13;
     212#else
     213        static const RegisterID timeoutCheckRegister = X86::esi;
    203214        static const RegisterID callFrameRegister = X86::edi;
     215#endif
    204216
    205217        static const int repatchGetByIdDefaultStructure = -1;
     
    304316        inline static JSValue* execute(void* code, RegisterFile* registerFile, CallFrame* callFrame, JSGlobalData* globalData, JSValue** exception)
    305317        {
    306             return ctiTrampoline(code, registerFile, callFrame, exception, Profiler::enabledProfilerReference(), globalData);
     318            return ctiTrampoline(
     319#if PLATFORM(X86_64)
     320                0, 0, 0, 0, 0, 0,
     321#endif
     322                code, registerFile, callFrame, exception, Profiler::enabledProfilerReference(), globalData);
    307323        }
    308324
  • trunk/JavaScriptCore/jit/JITCall.cpp

    r39351 r39370  
    7474void JIT::compileOpCallInitializeCallFrame()
    7575{
    76     store32(X86::edx, Address(X86::edi, RegisterFile::ArgumentCount * static_cast<int>(sizeof(Register))));
     76    store32(X86::edx, Address(callFrameRegister, RegisterFile::ArgumentCount * static_cast<int>(sizeof(Register))));
    7777
    7878    loadPtr(Address(X86::ecx, FIELD_OFFSET(JSFunction, m_scopeChain) + FIELD_OFFSET(ScopeChain, m_node)), X86::edx); // newScopeChain
    7979
    80     storePtr(ImmPtr(noValue()), Address(X86::edi, RegisterFile::OptionalCalleeArguments * static_cast<int>(sizeof(Register))));
    81     storePtr(X86::ecx, Address(X86::edi, RegisterFile::Callee * static_cast<int>(sizeof(Register))));
    82     storePtr(X86::edx, Address(X86::edi, RegisterFile::ScopeChain * static_cast<int>(sizeof(Register))));
     80    storePtr(ImmPtr(noValue()), Address(callFrameRegister, RegisterFile::OptionalCalleeArguments * static_cast<int>(sizeof(Register))));
     81    storePtr(X86::ecx, Address(callFrameRegister, RegisterFile::Callee * static_cast<int>(sizeof(Register))));
     82    storePtr(X86::edx, Address(callFrameRegister, RegisterFile::ScopeChain * static_cast<int>(sizeof(Register))));
    8383}
    8484
     
    158158
    159159    // Speculatively roll the callframe, assuming argCount will match the arity.
    160     storePtr(X86::edi, Address(X86::edi, (RegisterFile::CallerFrame + registerOffset) * static_cast<int>(sizeof(Register))));
    161     addPtr(Imm32(registerOffset * static_cast<int>(sizeof(Register))), X86::edi);
     160    storePtr(callFrameRegister, Address(callFrameRegister, (RegisterFile::CallerFrame + registerOffset) * static_cast<int>(sizeof(Register))));
     161    addPtr(Imm32(registerOffset * static_cast<int>(sizeof(Register))), callFrameRegister);
    162162    move(Imm32(argCount), X86::edx);
    163163
  • trunk/JavaScriptCore/jit/JITInlineMethods.h

    r39325 r39370  
    206206ALWAYS_INLINE void JIT::restoreArgumentReference()
    207207{
     208#if PLATFORM(X86_64)
     209#if USE(FAST_CALL_CTI_ARGUMENT) || !USE(CTI_ARGUMENT)
     210#error "CTI_ARGUMENT configuration not supported."
     211#endif
     212    move(X86::esp, X86::edi);
     213#else
    208214#if USE(CTI_ARGUMENT)
    209215#if USE(FAST_CALL_CTI_ARGUMENT)
    210     m_assembler.movl_rr(X86::esp, X86::ecx);
     216    move(X86::esp, X86::ecx);
    211217#else
    212     m_assembler.movl_rm(X86::esp, 0, X86::esp);
     218    storePtr(X86::esp, X86::esp);
     219#endif
    213220#endif
    214221#endif
     
    218225{
    219226#if USE(CTI_ARGUMENT) && USE(FAST_CALL_CTI_ARGUMENT)
    220     m_assembler.movl_rr(X86::esp, X86::ecx);
    221     m_assembler.addl_ir(4, X86::ecx);
     227    move(X86::esp, X86::ecx);
     228    addPtr(Imm32(4), X86::ecx);
    222229#endif
    223230}
  • trunk/JavaScriptCore/wtf/Platform.h

    r39362 r39370  
    435435#define ENABLE_JIT_OPTIMIZE_ARITHMETIC 1
    436436#endif
     437#if !defined(ENABLE_JIT) && PLATFORM(X86_64) && PLATFORM(MAC)
     438#define ENABLE_JIT 0
     439#define WTF_USE_CTI_ARGUMENT 0
     440#endif
    437441
    438442/* WREC supports x86 & x86-64, and has been tested on Mac and Windows ('cept on 64-bit on Mac). */
Note: See TracChangeset for help on using the changeset viewer.