[M3devel] C backend -- mode or call quake?

Rodney M. Bates rodney_bates at lcwb.coop
Wed Oct 17 18:05:07 CEST 2012



On 10/15/2012 07:21 PM, Jay wrote:
> The current usage of C backend is noticeably much slower than cm3cg. I really don't like it.
>

At first thought, this didn't surprise me.  Leaving out combinatorially heavy
back-end optimizations, the usual primary speed bottleneck in compilers has
always been lexical scanning.  Not because it is fundamentally an inefficient
task, but because of fundamentally high iteration count.  It has to look at
files one character at a time, for every character.  In contrast, parsing,
which is not a lot different in algorithmic efficiency (perhaps slower), only
has to process lexical tokens, minus comments and white space.  This gives
iteration counts lower by a factor of several.  Mostly ditto for the rest
of the phases.

So, for a back-end that generates source code in some character-encoded
language, an every-character-one-at-a-time process has to happen twice,
once in generating the source code, and again in scanning it.  The cm3cg
approach skips both these.  This difference is fundamental to the two
approaches, and not a lot can be done about it.

But on second thought, if I understand correctly, both gcc reading
text file input and cm3cg do the same at a later stage by generating
assembly source code, then passing it to an assembler.  And I would
expect equivalent assembly code to have higher character count than
C code, by a factor of a few.  (In a quick look, I see one case giving
a 3-to-1 expansion from Modula-2 source to assembly code.)

I would expect this to dilute the extra time spent generating/scanning
the C code.  But maybe slowdowns in the neighborhood of 10% to 20%
might be explainable this way.

>   - Jay (briefly/pocket-sized-computer-aka-phone)
>
> On Oct 15, 2012, at 11:35 AM, <mika at async.caltech.edu> wrote:
>
>> Jay K writes:
>> ...
>>> "External" anything is convenient for development and testing=2C bad for pe=
>>> rformance.  It writes and reads the .mc files.   Besides development/testin=
>>> g=2C it also is used for licensing reasons -- communication through files i=
>>> nstead of "linking" code.
>> ...
>>
>> Jay you keep coming back to this issue of the performance of the compiler.
>> Do you use Modula-3 for some large projects I'm not aware of?  I compile
>> quite a bit of code with it, and sure it would be cool (always is) if it
>> were faster but it's not like the lack of speed has ever bothered me (not
>> since the silly 0.1-second delay was removed from Process.Wait).  I also
>> implemented a parallelized back-end mode a while ago (it's in the tree).
>> The speed of the compiler is mainly an issue when recompiling the world,
>> which is something that happens mainly during "development/testing",
>> and then not by regular users, normally...
>>
>>     Mika
>




More information about the M3devel mailing list