Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.42!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.glorb.com!news-xfer.nntp.sonic.net!posts.news.sonic.net!nnrp1.nntp.sonic.net!not-for-mail Message-ID: <4EC0496A.6060503@bitblocks.com> Date: Sun, 13 Nov 2011 14:49:14 -0800 From: Bakul Shah User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:8.0) Gecko/20111103 Thunderbird/8.0 MIME-Version: 1.0 Newsgroups: comp.arch Subject: Re: big-little References: <3r2dnXmsb44LVi_TnZ2dnUVZ87-dnZ2d@telenor.com> <%Gctq.21959$yY3.7294@newsfe01.iad> <0v8go8-jqg1.ln1@ntp6.tmsw.no> <1ka9v9g.1jhyz5n1o6blj4N%wclodius@lost-alamos.pet> <1kal8ks.3q8n72roou6wN%wclodius@lost-alamos.pet> <87sjltnj52.fsf@GraySage.com> <87hb27oixg.fsf@GraySage.com> In-Reply-To: <87hb27oixg.fsf@GraySage.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Lines: 65 Organization: Sonic.Net NNTP-Posting-Date: 13 Nov 2011 22:49:14 GMT NNTP-Posting-Host: 567a0c0e.news.sonic.net X-Trace: DXC=@ZBc3ULAGh_W;TRF BGB writes: > >> mine is plain C, so no GCC'isms here. >> my stuff builds with both GCC and MSVC, with me using MSVC as the main >> compiler when building on Windows. > > Conditional compilation: > > #ifdef __GNUC__ > #define USE_COMPUTED_GOTO 1 > #else > #define USE_COMPUTED_GOTO 0 > #endif > > plus some macros "CASE" and "BREAK" to do the right things. > This brings back some happy hacking memories! From some very old code: [IIRC on a 33Mhz 386 the simulator was faster than the real 2Mhz 8bitter] #define DO1(op, arg, ticks) { \ Byte vb; Word vw; Byte* a; \ COUNT += ticks; if (COUNT >= cpu->trigger) INTR |= ITIME; \ arg; op; \ NEXT; \ } #define DO(op, ticks) DO1(op, 0, ticks) # if __GNUC__ > 1 && defined DIRECT_JUMP static const void * const caselab[256] = { &&x00, &&x01, &&x02, &&x03, &&x04, &&x05, &&x06, &&x07, &&x08, &&x09, &&x0a, &&x0b, &&x0c, &&x0d, &&x0e, &&x0f, ... &&xf0, &&xf1, &&xf2, &&xf3, &&xf4, &&xf5, &&xf6, &&xf7, &&xf8, &&xf9, &&xfa, &&xfb, &&xfc, &&xfd, &&xfe, &&xff, }; # define SWITCH(x) goto *caselab[x]; # define CASE(y) cat(x,y) # define NEXT if (INTR) goto ret; goto *caselab[nexti()] # define ENDSWITCH #else # define SWITCH(x) switch(x) { # define CASE(y) case cat(0x,y) # define NEXT if (INTR) goto ret; continue # define ENDSWITCH } #endif ... void simulate(register CPU *cpu, register Byte *mem) { for (;;) { SWITCH(nextinst()) CASE(01): DO(NOP, 2); CASE(02): DO(IDIV, 41); CASE(03): DO(FDIV, 41); ... CASE(12): DO1(BRSET, DIR, 6); ... ENDSWITCH } ret: RESTORE; }