public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/46219] New: Generate indirect jump instruction on x86-64
@ 2010-10-28 22:52 adam at consulting dot net.nz
  2010-10-28 22:58 ` [Bug target/46219] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: adam at consulting dot net.nz @ 2010-10-28 22:52 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46219

           Summary: Generate indirect jump instruction on x86-64
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: adam@consulting.net.nz
            Target: x86-64


Is there a less brutal way to coax gcc into generating an indirect jump
instruction on x86-64?

typedef void (*dispatch_t)(long offset);

dispatch_t dispatch[256];

void make_indirect_jump(long offset) {
  dispatch[offset](offset);
}

void force_use_of_indirect_jump_instruction(long offset) {
  asm ("jmp *dispatch( ,%0, 8)\n" : : "r" (offset));
  __builtin_unreachable();
}

int main() {
  return 0;
}

$ gcc-snapshot.sh -std=gnu99 -O3 use-indirect-jump-instruction.c && objdump -d
-m i386:x86-64:intel a.out|less

0000000000400480 <make_indirect_jump>:
  400480:       48 8b 04 fd 20 12 60    mov    rax,QWORD PTR [rdi*8+0x601220]
  400487:       00 
  400488:       ff e0                   jmp    rax
  40048a:       66 0f 1f 44 00 00       nop    WORD PTR [rax+rax*1+0x0]

0000000000400490 <force_use_of_indirect_jump_instruction>:
  400490:       ff 24 fd 20 12 60 00    jmp    QWORD PTR [rdi*8+0x601220]
  400497:       66 0f 1f 84 00 00 00    nop    WORD PTR [rax+rax*1+0x0]
  40049e:       00 00 

This combination of inline assembly and __builtin_unreachable() is not a
generally usable architecture-specific solution (there needs to be a way to
ensure the results of modified input arguments end up in the same registers for
the opaque tail call. It works in this case because offset remains unmodified,
satisfying the ABI for dispatch_t).


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-11-28  5:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-28 22:52 [Bug rtl-optimization/46219] New: Generate indirect jump instruction on x86-64 adam at consulting dot net.nz
2010-10-28 22:58 ` [Bug target/46219] " pinskia at gcc dot gnu.org
2010-10-29  8:17 ` ubizjak at gmail dot com
2010-10-29 16:46 ` rth at gcc dot gnu.org
2014-06-05 17:04 ` ktietz at gcc dot gnu.org
2014-06-05 17:05 ` ktietz at gcc dot gnu.org
2014-09-05  0:29 ` adam at consulting dot net.nz
2021-11-28  5:48 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).