Article View: comp.lang.asm.x86
Article #169Re: Jump table without the table?
From: Matt Taylor
Date: Wed, 12 Feb 2003 19:57
Date: Wed, 12 Feb 2003 19:57
82 lines
4715 bytes
4715 bytes
Compilers can do well, but I have found it trivial to consistently beat the latest and greatest in local optimizations. If you are not overly concerned with portability, I would still suggest dynamic recompilation. Even inefficient native code will execute an order of magnitude faster than emulation. -Matt "Vis Mike" <visionary25@_nospam_hotmail.com> wrote in message news:b2d6f7$fne$1@bob.news.rcn.net... > Actually, I get worse performance the more aligned the jumps! (8, 16 bytes). > I give up, I'll leave the details to the person who knows best - the > compiler writer :) > > Mike > > "Vis Mike" <visionary25@_nospam_hotmail.com> wrote in message > news:b2d1sj$8j4$1@bob.news.rcn.net... > > I found a nice feature in gcc - -malign-jumps=n > > > > > wcc -O3 -malign-jumps=3 vmtest2.cpp > > > a.exe > > Testing stack4... > > &&addi = 0x401180 +4 +8 +16 > > > > 0x401180 is the address of the first label, followed by the offset of the > > rest of the labels. So if I can squeeze the code in, all I need is a "jmp > > (opcode*4)". This is sooo unportable :) I'll just use conditional > > compilation. > > > > I don't quite understand gcc's inline assembly syntax, any help for the > jmp? > > Or am I just going overboard? > > > > Cheers! > > Mike > > > > "James Van Buskirk" <not_valid@attbi.com> wrote in message > > news:dCk2a.80786$HN5.307889@rwcrnsc51.ops.asp.att.net... > > > > > > "Matt Taylor" <para@tampabay.rr.com> wrote in message > > > news:h2j2a.61691$AQ3.981480@twister.tampabay.rr.com... > > > > > > > Any good compiler will convert switch/case to a jump table for you. VC > > > does > > > > this; I'm quite sure that GCC does too. Unless you're writing in > > assembly, > > > > don't try to pad things out. The compiler should do this for you. I > > don't > > > > know when specifically VC/GCC do and when they don't. > > > > > > I think I have a different interpretation of Mike's question than > > > you: my take on it is that he has code where all branches are just > > > little snippets no longer than some nice easy number of bytes to > > > multiply by, e.g. if all his branches were less than 32 bytes > > > long and he had 16 possible cases numbered 0:15 he could, assuming > > > the branch number were in EAX do something like: > > > > > > lea EAX, [4*EAX] > > > jmp branch_implementation_start[8*EAX] > > > > > > In this way he could avoid waiting for the address of a previous > > > write to memory to be computed before prefetching the code > > > following the branch. Maybe ALIGN directives or ORG > > > directives could tell the assembler where to insert padding > > > without having to maintain it by hand every time the code > > > is modified? > > > > > > > > > > > > > > > > > > >
Technical Details
Message-ID:
<Zqx2a.65293$AQ3.1060197@twister.tampabay.rr.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sn-xit-03!sn-xit-01!sn-post-01!supernews.com!corp.supernews.com!news.crayne.org!clax86!robomod!not-for-mailReferences:
<b2c5s4$p9p$1@bob.news.rcn.net> <h2j2a.61691$AQ3.981480@twister.tampabay.rr.com> <dCk2a.80786$HN5.307889@rwcrnsc51.ops.asp.att.net> <b2d1sj$8j4$1@bob.news.rcn.net> <b2d6f7$fne$1@bob.news.rcn.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,d7bccf0f48f83a38 X-Google-Attributes: gid11318c,public X-Google-Thread: 114917,fa3250fb672bd972 X-Google-Attributes: gid114917,public X-Google-ArrivalTime: 2003-02-12 11:57:35 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sn-xit-03!sn-xit-01!sn-post-01!supernews.com!corp.supernews.com!news.crayne.org!clax86!robomod!not-for-mail From: "Matt Taylor" <para@tampabay.rr.com> Newsgroups: comp.lang.asm.x86,gnu.gcc.help Subject: Re: Jump table without the table? Approved: CLAX86 Moderators <ccrayne@crayne.org> Date: Wed, 12 Feb 2003 19:57:12 +0000 (UTC) Organization: RoadRunner - Tampa Bay Message-ID: <Zqx2a.65293$AQ3.1060197@twister.tampabay.rr.com> Sender: clax86@wotan.asgard References: <b2c5s4$p9p$1@bob.news.rcn.net> <h2j2a.61691$AQ3.981480@twister.tampabay.rr.com> <dCk2a.80786$HN5.307889@rwcrnsc51.ops.asp.att.net> <b2d1sj$8j4$1@bob.news.rcn.net> <b2d6f7$fne$1@bob.news.rcn.net> X-CLAX86-Policy: http://www.pacificsites.com/~ccrayne/clax86.html X-CLAX86-Faq: http://www2.dgsys.com/~raymoon/x86faqs.html X-CLAX86-Info-1: Send submissions to comp-lang-asm-x86@moderators.isc.org X-CLAX86-Info-2: Send technical complaints to ccrayne@crayne.org X-CLAX86-Info-3: Send complaints about policy to ccrayne@crayne.org X-Comment: moderators do not necessarily agree or disagree with this article. X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-MailScanner: Found to be clean X-MailScanner-SpamCheck: not spam (whitelisted), SpamAssassin (score=0.3, required 5, NOSPAM_INC, PRIORITY_NO_NAME, QUOTED_EMAIL_TEXT, REFERENCES, SPAM_PHRASE_00_01) X-UIDL: K~S!!1aX"!QT_"!S:/!! X-Complaints-To: abuse@supernews.com Lines: 84