Port-vax archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Speed up SimH by using C++ exceptions instead of setjmp/longjmp



While I was testing the little benchmark I wrote on SimH, I got a chance to change something that I suspected would speed up the code quite a bit, and in fact it did. I'll send out a patch a little later after I've cleaned it up, but basically with a few changes to the C code of SimH to fix things that are illegal in C++, you can compile the entire thing as C++ instead of C, and then redefine the "ABORT(X)" macro from a "longjmp" call to a C++ "throw ((int) x)" call, to throw an exception with the specified value, instead of returning it through the setjmp() call in the main simulator loop in vax_cpu.c. I had to move around the handler for non-zero return from setjmp() (the case when longjmp() was called) to a catch {} block below a try {} block surrounding all the code inside the for (;;) block, but I think the rest of the code can be set up to compile as C or as C++ with a few ifdefs.

Preliminary tests were that it took about 40 clock cycles for a "nop" (on a 3.3 GHz Xeon E3-1230), for the C version (compiled for 64-bit FreeBSD with GCC 4.8.5 and GCC 5.3.0), the equivalent of an 82.5 MHz VAX, which decreased to about 38 cycles when compiled as C++ (with no other changes!), and down to about 34 clock cycles when setjmp()/longjmp() is changed to try/catch/throw, the equivalent of a 96.5 MHz VAX. So, a fairly nice speedup for a few hours of work.

I'll try to get at least the two VAX emulators and PDP-11 compiling as C or C++ and then send some diffs to the list and to the SimH maintainer this evening.

Cheers,
Jake


Home | Main Index | Thread Index | Old Index