Page 1 of 1

what is faster in asm

Posted: Tue Apr 10, 2007 3:16 am
by os64dev
for my interrupt handler routines i have a question regarding some asm statements

here is my code

Code: Select all

#define wrapper(x)          extern "C" void x(isr_stack_frame*);               \
                            extern "C" void wrapper_##x(void);                 \
                            asm volatile (".align 0x10;"                       \
                                          "wrapper_"#x": "                     \
                                          "leaq     (%rsp), %rdi;"             \
                                          "call "#x"; iretq"                   \
                                         )

#define vector(x)           (vintpc)wrapper_isr##x
#define interrupt(x)        dummy(void); wrapper(isr##x); void isr##x

void interrupt(DivideByZero)(isr_stack_frame * frame) {
    frame = (isr_stack_frame *)((vintp)frame - 8);
    printf("#DivideByZero\n");
    printf("- errorCode               : %x\n", frame->errorCode);
    printf("- returnInstructionPointer: %x\n", frame->returnInstructionPointer);
    printf("- returnCodeSelector      : %x\n", frame->returnCodeSelector);
    printf("- flags                   : %x\n", frame->flags);
    printf("- stackPointer            : %x\n", frame->stackPointer);
    printf("- stackSelector           : %x\n", frame->stackSelector);
    for(;;);
}
this will define the functions isrDivideByZero and wrapper_isrDivideByZero my question is regarding the leaq statement. When an interrupt service routine does not have an error code i will use leaq $-8(%rsp), %rdi otherwise leaq (%rsp), %rdi

is this faster then using the movq %rsp, %rdi; addq $-8, %rdi alternative?

Re: what is faster in asm

Posted: Tue Apr 10, 2007 4:15 am
by Brendan
Hi,

This depends on which CPU you're using. For Pentium 4 (netburst architecture) LEA is slow and "MOV & ADD" would be faster (especially if you can put another instruction between the MOV and the ADD to break register dependancies). For other CPUs (those derived from the P6 architecture - Core, CoreDuo, etc) I'm not so sure, and wouldn't be surprised if LEA was faster (or equivelent speed).

In either case the difference will be negligable compared to the time it takes the CPU to invoke the exception handler and the CALL/RET pair.


Cheers,

Brendan