Hello. There is a Core War simulator (an interpreter for a minimalistic machine, called MARS, with a language named redcode) called fmars (http://www.v-lo.krakow.pl/~michal/fmars.html), which uses computed gotos to achieve very good performance. The original version only uses a subset of the available redcode instructions (~250), instead of the full set (~8000). The author told me GCC dumped core if trying to use all of them (I don't remember if he was referring to 2.95 or 3.3). I decided to try with GCC 4 (4.2.3 20071219 prerelease and 4.3.0 20080111 experimental), and it builds (both) without optimizations (-O0), but runs twice as slower than the reduced fmars built with -O2. Version 3.4.6 (20060305) runs out of memory (with and without optimizations), as 4.x does even with -O1. I have 2GB of RAM (and allowed processes to use it). The strange thing is that when looking at options enabled at different -O levels (trying to remove the ones that were using more memory), ended up with a GCC 4.2.3 command-line that specified exactly all the options enabled by -O2 (as listed in the manpage), and built. But ran at the same speed as without them. The source file is a function with the ~250/~8000 cases like this one (they are generated by an intermediate program): dat_f_immediate_direct: {if (!--w->nprocs) { *death_tab++ = w->id; if (--alive_cnt < 2)goto out; w->prev->next = w->next; w->next->prev = w->prev; cycles -= cycles / alive_cnt; }w = w->next; ip = *w->head;if (++w->head == queue_end) w->head = queue_start;if (!--cycles) goto out; goto *ip->i;} So my question is, what optimizations options can I use in this file without using too much memory (I've read the docs and tried with various ones, but was annoyed about the fact that using equivalent -f* options worked without effect but -O/-O2 didn't)? If more information is needed, please ask. Also please CC me as I'm not subscribed. I'm using FreeBSD 6.2 (with mentioned GCC 3.4.6 as base compiler). Thanks and Best Regards, Ale
Attachment:
signature.asc
Description: PGP signature