Thursday Oct 23, 2008

Long absolute jumps on AMD64

Sometimes it may be required to perform calls and jumps to absolute address on 64-bit AMD. Unfortunately, x86_64 instruction set only allows 32-bit displacements, so traditional approach is to move desired address into register and call or jump using it. Unfortunately, it requires scratch register, or push/pop of register. In case of jump, it also problematic if we wish not touch registers. Here I suggest alternative approach, using ret instructions for long jumps. While not too complicated, this trick can help some compiler/JIT writers to handle very long jumps.
DECLINLINE(void) tcg_out_pushq(TCGContext \*s, tcg_target_long val)
{
     tcg_out8(s, 0x68); /\* push imm32, subs 8 from rsp \*/
     tcg_out32(s, val); /\* imm32 \*/
     if ((val >> 32) != 0)
     {
         tcg_out8(s, 0xc7); /\* mov imm32, 4(%rsp) \*/ 
         tcg_out8(s, 0x44); 
         tcg_out8(s, 0x24);
         tcg_out8(s, 0x04);
         tcg_out32(s, ((uint64_t)val) >> 32); /\* imm32 \*/
     }
}
DECLINLINE(void) tcg_out_long_jmp(TCGContext \*s, tcg_target_long dst)
{
    tcg_out_pushq(s, dst);
    tcg_out8(s, 0xc3); /\* ret \*/
}

Monday Jun 25, 2007

memory debugger for linux

Debugging complex memory problems using x86 CPU debugging registers.[Read More]

Sunday Jun 24, 2007

More fun with SEH

How to modify other frame's exception handler (don't try this at home).[Read More]

Thursday Jun 21, 2007

Simple JIT compiler for your application

Using dynamical code generation for squeezing optimal performance out of your application.[Read More]

Wednesday Jun 20, 2007

Fixing FPU control word on Win32

Fixing FPU fault on Win32.[Read More]

Tuesday Jun 19, 2007

Context sensitive function behavior

Context sensitive behavior for function written in C.[Read More]

Friday Jun 15, 2007

Self printing program in assembly (part 2)

69 byte quine.[Read More]

Thursday Jun 14, 2007

Self printing program in assembly

Assembly to print out its own machine code.[Read More]

Wednesday Jun 13, 2007

Handling of synchronous faults on Unix

Synchronous faults in MT application on Unices.[Read More]

Saturday Jun 09, 2007

Fast thread local areas for amd64

Fast and high volume thread local storage for AMD64 CPUs.[Read More]

Friday Jun 08, 2007

Hiding instruction on CISC CPUs

Instruction hiding on machine code level.[Read More]

Thursday Jun 07, 2007

spawn for Unix

Way to implement functionality similar to Win32 spawn() on Unix.[Read More]

von Neuman's dream

Once, fortune(6) said to me: "Some people's programs are some other people's data" - now I have great example of that. [Read More]

Fast interpreter using gcc's computed goto

Writing effective interpreters in C.[Read More]

Wednesday Jun 06, 2007

Computing function body size in more or less portable way

How to figure out from C program size of machine code generated for particular function?[Read More]
About

nike

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today