现在的位置: 首页 > 综合 > 正文

want to port JIT to MIPS – how patchOffset* constant determined?

2013年01月16日 ⁄ 综合 ⁄ 共 1970字 ⁄ 字号 评论关闭

https://lists.webkit.org/pipermail/webkit-dev/2009-March/006884.html

want to port JIT to MIPS - how patchOffset* constant determined?

On x86, the size of the instructions are fixed. If you want to access
multiple instructions in the instruction stream, you only need to store
the address of the first one, and can access the others by their relative
address. This saves a little memory.

Example (see JIT::linkCall):
  instruction at callLinkInfo->hotPathBegin: points to callee comparison
  instruction at
    callLinkInfo->hotPathBegin + patchOffsetOpCallCompareToJump:
       points to the slow case entry jump

Zoltan

> in jit.h, for example:
>         static const int patchOffsetOpCallCompareToJump = 9;
>         static const int patchOffsetPutByIdStructure = 7;
>         static const int patchOffsetPutByIdPropertyMapOffset = 22;
>         static const int patchOffsetGetByIdBranchToSlowCase = 13;

they generate instructions, which size is known in advance.

Think about the following sequence:
hotPathBegin:
  mov regX, 32bit_const <- 6 bytes (*) (**)
  add regX, regY <- 2 bytes
  jo 32bit_addr <- 5 bytes (*)

* (Note) : these instructions will be modified during runtime.

** (Note) : there is a short form for "mov regX, 8bit_const", which length
is only 3 bytes, but they force the longer version in such cases to keep
the size of the instruction.

As you can see, the address of "jo" is always (hotPathBegin + 6 + 2). They
simply introduce a new constant: patchOffsetXXX = 8, and use this constant
to access the "jo" instruction later.

In ARM we can't rely on such constant, because the constant pool can be
placed after any instruction.

hotPathBegin:
  ldr rX, [pc + const_pool_addr] ; 32 bit const
  [...] <- the const pool can be placed here
  add rX, rX, rY
  [...] <- the const pool can be placed here
hotPath2:
  ldr pc, [pc + const_pool_addr] ; 32 bit target address

We need to store both pointers (hotPathBegin and hotPath2).

Zoltan

> Zoltan,
> Thanks for reply, I'm trying to understand your example. But,X86
> instruction size is from 1 to 17bytes, not constant. I may misunderstand
> your comments?
> Many X86 instruction can have imm32 at the end, thus this pointer can be
> used for patch as well as next address after call. Does Arm have similar
> things? or else you still need to figure out why
> "patchOffsetOpCallCompareToJump = 9;"? may be some instruction lengths
> relates to the 9?

抱歉!评论已关闭.