public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "adam at consulting dot net.nz" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/46219] New: Generate indirect jump instruction on x86-64 Date: Thu, 28 Oct 2010 22:52:00 -0000 [thread overview] Message-ID: <bug-46219-4@http.gcc.gnu.org/bugzilla/> (raw) 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).
next reply other threads:[~2010-10-28 22:52 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2010-10-28 22:52 adam at consulting dot net.nz [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-46219-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).