[webkit-dev] Fwd: Native code generation for put_global_var instruction on X86_64 platform

Filip Pizlo fpizlo at apple.com
Thu Feb 23 09:14:42 PST 2012

> 1.  What is mean of currentInstruction[2]?  As I Understand it's holds information about "Int32: 6(@k1)". Am I right??

It's a register index.  Usually, it means that that index times 8 plus whatever is in the call frame register, you'll find the data for the register.  But if it's larger than 0x40000000, it means it's a constant index (i.e. subtract 0x40000000 from it and you get the index of the constant in the code block).  In this case, "k1" means that it's a constant register index, so currentInstruction[2] has the value 0x40000001.

> 2.  As I understand  after emitGetVirtualRegister(currentInstruction[2].u.operand, regT0) we have encoded value of "Int32: 6(@k1)" in regT0.

It means we have emitted a move-immediate-to-register instruction that places the value of constant at index 1 into regT0.

> 3.  Cant't understad mean of  move(TrustedImmPtr(globalObject), regT1). globalObject is a pretty big class. Can't figure out what is happening here

This is another move-immediate-to-register instruction.  globalObject is not a class, nor is it an object; it's a pointer.  We're just moving a pointer immediate (64 bits of data) into regT1.

> 4.  loadPtr(Address(regT1, JSVariableObject::offsetOfRegisters()), regT1); // What the mean of JSVariableObject::offsetOfRegisters()??

We're loading from the globalObject->m_registers.  This is a load instruction, which takes an address consisting of a base (a register) and an offset (an immediate).  regT1 is the base, which contains a pointer to the globalObject.  JSVariableObject::offsetOfRegisters() is a helper that gives us the offset of the JSVariableObject::m_registers field.  This makes sense since JSGlobalData inherits from JSVariableObject.

Think of this instruction as if we were emitting the following line of C code:

regT1 = static_cast<JSVariableObject*>(regT1)->m_registers;

> 5.   storePtr(regT0, Address(regT1, currentInstruction[1].u.operand * sizeof(Register))); // As I understand currentInstruction[1].u.operand holds address where to put my constant, i.e "4". Am I right?

currentInstruction[1] is not an address.  It's an index into the global variable's registers.  This is emitting a store instruction that places the value of register regT0 into the address specified by the sum of regT1and the immediate offset, currentInstuctin[1].u.operand * sizeof(Register).  regT1 holds a pointer to a Register* (i.e. a pointer to an array of Registers).  So think of this code as if it were emitting the following line of C code:

static_cast<Register*>(regT1)[currentInstruction[1].u.operand] = regT0;

> And question about mov instruction on x86_64 platform
> JSC::X86Assembler::movq_i64r 
> void movq_i64r(int64_t imm, RegisterID dst)                                                                                                                                                     
>            {                                                                                                                                                                                                 
>               m_formatter.oneByteOp64(OP_MOV_EAXIv, dst);                                                                                                                       
>               m_formatter.immediate64(imm);                                                                                       
>           }   
> How will look appropriate assembly for this code??

Use the code, Luke!  It's just 9 bytes, with the first byte having the value of OP_MOV_EAXIv (i.e. 0xb8), and the next 8 bytes are just whatever imm is, encoded in little endian.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20120223/01184b54/attachment.html>

More information about the webkit-dev mailing list