[ragel-users] MSVC-friendly -GT2 mode

Victor Khimenko khim at chromium.org
Mon May 14 17:50:01 UTC 2012


Example of the change in -GT2 mode.

Instead of this:

st47:
if ( ++p == pe )
goto _test_eof47;
case 47:
switch( (*p) ) {
case 4u: goto tr118;
case 5u: goto tr119;
case 12u: goto tr118;
case 13u: goto tr119;
case 20u: goto tr118;
case 21u: goto tr119;
case 28u: goto tr118;
case 29u: goto tr119;
case 36u: goto tr118;
case 37u: goto tr119;
case 44u: goto tr118;
case 45u: goto tr119;
case 52u: goto tr118;
case 53u: goto tr119;
case 60u: goto tr118;
case 61u: goto tr119;
case 68u: goto tr121;
case 76u: goto tr121;
case 84u: goto tr121;
case 92u: goto tr121;
case 100u: goto tr121;
case 108u: goto tr121;
case 116u: goto tr121;
case 124u: goto tr121;
case 132u: goto tr123;
case 140u: goto tr123;
case 148u: goto tr123;
case 156u: goto tr123;
case 164u: goto tr123;
case 172u: goto tr123;
case 180u: goto tr123;
case 188u: goto tr123;
}
if ( (*p) < 64u ) {
if ( (*p) <= 63u )
goto tr117;
} else if ( (*p) > 127u ) {
if ( 128u <= (*p) && (*p) <= 191u )
goto tr122;
} else
goto tr120;
goto tr124;

We have this:

st47:
if ( ++p == pe )
goto _test_eof47;
case 47:
{
static const unsigned char jump_table[] = { 0, 0, 0, 0, 1, 2, 0, 0, 0, 0,
0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0,
0, 1, 2, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0,
1, 2, 0, 0, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3, 3, 4,
3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3, 3, 4, 3,
3, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, 5, 5, 5, 5, 6, 5, 5,
5, 5, 5, 5, 5, 6, 5, 5, 5, 5, 5, 5, 5, 6, 5, 5, 5, 5, 5, 5, 5, 6, 5, 5, 5,
5, 5, 5, 5, 6, 5, 5, 5, 5, 5, 5, 5, 6, 5, 5, 5, 5, 5, 5, 5, 6, 5, 5, 5, 5,
5, 5, 5, 6, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 };
cs = jump_table[(*p)] + 933;
goto _again;
}

And this is basically all. Very small, very local change to -G2 mode which,
as I've explained above, makes a world of difference in our case. If you
replace ALL cases with jump tables then speed really suffers and size of
the result grows significantly, if you only do this for cases with large
number of outcomes then size actually shrinks and speed drop is moderate
(negative in case of MSVC because we obviously hit some limits of the
beast) since original code needs to do quite a large number of comparisons
(or may be use some table behind the scene) anyway.

P.S. And is it possible to somehow really remove line numbers from the
generated output? They are removed for all languages except C with -L flag,
but for C they are just commented out. This increases size of generated
file by about 10% needlessly :-( We can just filter them out, of course,
but for all other languages you don't need this. Perhaps second -L can
actually remove line numbers?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.colm.net/pipermail/ragel-users/attachments/20120514/bbb58d7b/attachment-0001.html>
-------------- next part --------------
_______________________________________________
ragel-users mailing list
ragel-users at complang.org
http://www.complang.org/mailman/listinfo/ragel-users


More information about the ragel-users mailing list