Update etc/bench.pl. Optimize push mode a little (the yyn change

deserves most of the credit).
* Makefile.am (SUBDIRS): Add etc subdirectory.
* configure.ac (AC_CONFIG_FILES): Add etc/bench.pl and etc/Makefile.
* data/push.c (b4_declare_parser_state_variables): Move yyn, yyresult,
yytoken, yyval, and yyloc declarations to...
(yyparse or yypush_parse): ... here to improve performance.  For
yypush_parse invocations after the first, be sure to assign yyn its old
value again.
(yypstate_new): Don't bother initializing the yyresult field since the
initial value isn't used.
(yyn, yyresult, yytoken, yyval, yyloc): For each NAME in this list,
remove the #define that, in push mode, set it to yyps->NAME.
* etc/Makefile.am: New.
* etc/bench.pl: Remove and build it instead from...
* etc/bench.pl.in: ... this new file.  Use @abs_top_builddir@ to invoke
"tests/bison" from the build directory by default rather than just
invoking "bison" from $PATH.
(calc_grammar): Update push parser code: don't declare yylval globally,
don't define yyparse_wrapper, and don't #define yyparse.
(bench_grammar): Update to check all working combinations of yacc.c,
push.c, impure, pure, pull, and push.
This commit is contained in:
Joel E. Denny
2006-12-26 18:09:53 +00:00
parent c3d503425f
commit 2e7944cbb2
6 changed files with 70 additions and 50 deletions

View File

@@ -1,3 +1,28 @@
2006-12-26 Joel E. Denny <jdenny@ces.clemson.edu>
Update etc/bench.pl. Optimize push mode a little (the yyn change
deserves most of the credit).
* Makefile.am (SUBDIRS): Add etc subdirectory.
* configure.ac (AC_CONFIG_FILES): Add etc/bench.pl and etc/Makefile.
* data/push.c (b4_declare_parser_state_variables): Move yyn, yyresult,
yytoken, yyval, and yyloc declarations to...
(yyparse or yypush_parse): ... here to improve performance. For
yypush_parse invocations after the first, be sure to assign yyn its old
value again.
(yypstate_new): Don't bother initializing the yyresult field since the
initial value isn't used.
(yyn, yyresult, yytoken, yyval, yyloc): For each NAME in this list,
remove the #define that, in push mode, set it to yyps->NAME.
* etc/Makefile.am: New.
* etc/bench.pl: Remove and build it instead from...
* etc/bench.pl.in: ... this new file. Use @abs_top_builddir@ to invoke
"tests/bison" from the build directory by default rather than just
invoking "bison" from $PATH.
(calc_grammar): Update push parser code: don't declare yylval globally,
don't define yyparse_wrapper, and don't #define yyparse.
(bench_grammar): Update to check all working combinations of yacc.c,
push.c, impure, pure, pull, and push.
2006-12-25 Joel E. Denny <jdenny@ces.clemson.edu> 2006-12-25 Joel E. Denny <jdenny@ces.clemson.edu>
For push mode, add pull wrappers around yypush_parse. For push mode, add pull wrappers around yypush_parse.

View File

@@ -18,7 +18,7 @@
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
SUBDIRS = build-aux po runtime-po lib data src doc examples tests SUBDIRS = build-aux po runtime-po lib data src doc examples tests etc
# Files installed for use by Automake. # Files installed for use by Automake.
aclocaldir = @aclocaldir@ aclocaldir = @aclocaldir@

View File

@@ -118,6 +118,9 @@ AC_CONFIG_FILES([runtime-po/Makefile.in])
aclocaldir='${datadir}/aclocal' aclocaldir='${datadir}/aclocal'
AC_SUBST([aclocaldir]) AC_SUBST([aclocaldir])
# Create the benchmark script.
AC_CONFIG_FILES([etc/bench.pl], [chmod +x etc/bench.pl])
# Initialize the test suite. # Initialize the test suite.
AC_CONFIG_TESTDIR(tests) AC_CONFIG_TESTDIR(tests)
AC_CONFIG_FILES([tests/Makefile tests/atlocal]) AC_CONFIG_FILES([tests/Makefile tests/atlocal])
@@ -137,6 +140,7 @@ AC_CONFIG_FILES([Makefile
build-aux/Makefile build-aux/Makefile
po/Makefile.in po/Makefile.in
data/Makefile data/Makefile
etc/Makefile
examples/Makefile examples/Makefile
examples/calc++/Makefile examples/calc++/Makefile
lib/Makefile src/Makefile doc/Makefile]) lib/Makefile src/Makefile doc/Makefile])

View File

@@ -1042,12 +1042,8 @@ m4_define([b4_declare_parser_state_variables],
int yynerrs; int yynerrs;
]])[ ]])[
int yystate; int yystate;
int yyn;
int yyresult;
/* Number of tokens to shift before error messages enabled. */ /* Number of tokens to shift before error messages enabled. */
int yyerrstatus; int yyerrstatus;
/* Look-ahead token as an internal (translated) token number. */
int yytoken;
/* Three stacks and their tools: /* Three stacks and their tools:
`yyss': related to states, `yyss': related to states,
@@ -1076,12 +1072,7 @@ m4_define([b4_declare_parser_state_variables],
YYLTYPE yyerror_range[2]; YYLTYPE yyerror_range[2];
]])[ ]])[
YYSIZE_T yystacksize; YYSIZE_T yystacksize;
]])
/* The variables used to return semantic value and location from the
action routines. */
YYSTYPE yyval;
]b4_locations_if([[ YYLTYPE yyloc;
]])])
m4_divert_pop([KILL])dnl# ====================== End of M4 code. m4_divert_pop([KILL])dnl# ====================== End of M4 code.
@@ -1125,7 +1116,6 @@ b4_push_if(
]b4_c_function_def([[yypstate_new]], [[yypstate *]])[ ]b4_c_function_def([[yypstate_new]], [[yypstate *]])[
{ {
yypstate *yyps = (yypstate *) malloc (sizeof *yyps); yypstate *yyps = (yypstate *) malloc (sizeof *yyps);
yyps->yyresult = -1;
yyps->yynew = 1; yyps->yynew = 1;
return yyps; return yyps;
} }
@@ -1138,10 +1128,7 @@ b4_push_if(
]b4_pure_if([[#define ]b4_prefix[nerrs yyps->]b4_prefix[nerrs ]b4_pure_if([[#define ]b4_prefix[nerrs yyps->]b4_prefix[nerrs
]])[#define yystate yyps->yystate ]])[#define yystate yyps->yystate
#define yyn yyps->yyn
#define yyresult yyps->yyresult
#define yyerrstatus yyps->yyerrstatus #define yyerrstatus yyps->yyerrstatus
#define yytoken yyps->yytoken
#define yyssa yyps->yyssa #define yyssa yyps->yyssa
#define yyss yyps->yyss #define yyss yyps->yyss
#define yyssp yyps->yyssp #define yyssp yyps->yyssp
@@ -1153,9 +1140,7 @@ b4_push_if(
#define yylsp yyps->yylsp #define yylsp yyps->yylsp
#define yyerror_range yyps->yyerror_range #define yyerror_range yyps->yyerror_range
]])[#define yystacksize yyps->yystacksize ]])[#define yystacksize yyps->yystacksize
#define yyval yyps->yyval ]])[
]b4_locations_if([[#define yyloc yyps->yyloc
]])])[
/*-------------------------. /*-------------------------.
| yyparse or yypush_parse. | | yyparse or yypush_parse. |
@@ -1180,7 +1165,15 @@ b4_c_function_def([yyparse], [int], b4_parse_param)
]b4_locations_if([[YYLTYPE yypushed_loc = yylloc; ]b4_locations_if([[YYLTYPE yypushed_loc = yylloc;
]])])], ]])])],
[b4_declare_parser_state_variables])[ [b4_declare_parser_state_variables])[
int yyn;
int yyresult;
/* Look-ahead token as an internal (translated) token number. */
int yytoken;
/* The variables used to return semantic value and location from the
action routines. */
YYSTYPE yyval;
]b4_locations_if([[ YYLTYPE yyloc;
]])[
#if YYERROR_VERBOSE #if YYERROR_VERBOSE
/* Buffer for error messages, and its allocated size. */ /* Buffer for error messages, and its allocated size. */
char yymsgbuf[128]; char yymsgbuf[128];
@@ -1195,7 +1188,10 @@ b4_c_function_def([yyparse], [int], b4_parse_param)
int yylen = 0; int yylen = 0;
]b4_push_if([[ ]b4_push_if([[
if (!yyps->yynew) if (!yyps->yynew)
goto yyread_pushed_token; {
yyn = yypact[yystate];
goto yyread_pushed_token;
}
]])[ ]])[
yytoken = 0; yytoken = 0;
yyss = yyssa; yyss = yyssa;

18
etc/Makefile.am Normal file
View File

@@ -0,0 +1,18 @@
## Copyright (C) 2006 Free Software Foundation, Inc.
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301 USA
nodist_noinst_SCRIPTS = bench.pl

View File

@@ -22,7 +22,7 @@
use IO::File; use IO::File;
use Benchmark qw (:all); use Benchmark qw (:all);
my $bison = $ENV{'BISON'} || 'bison'; my $bison = $ENV{'BISON'} || '@abs_top_builddir@/tests/bison';
my $cc = $ENV{'CC'} || 'gcc'; my $cc = $ENV{'CC'} || 'gcc';
################################################################## ##################################################################
@@ -260,12 +260,6 @@ read_signed_integer (void)
return sign * n; return sign * n;
} }
#if YYPUSH
#ifndef HAVE_YYSTYPE
static YYSTYPE yylval;
#endif
#endif
static int static int
#if YYPURE #if YYPURE
# define yylval (*yylvalp) # define yylval (*yylvalp)
@@ -310,21 +304,6 @@ power (int base, int exponent)
} }
#if YYPUSH
static int
yyparse_wrapper ()
{
struct yypvars *ctx = yypvarsinit ();
do {
set_yychar (ctx, yylex ());
ctx->yylval = yylval;
yyparse (ctx);
} while (get_yyresult (ctx) != 0);
free (ctx);
}
#define yyparse yyparse_wrapper
#endif
int int
main (int argc, const char **argv) main (int argc, const char **argv)
{ {
@@ -366,14 +345,12 @@ sub bench_grammar ($)
my ($gram) = @_; my ($gram) = @_;
my %test = my %test =
( (
"yacc-yacc" => '', "yacc.c-pull-impure" => '',
"yacc-pure" => '%pure-parser', "yacc.c-pull-pure" => '%pure-parser',
"push-yacc" => '%skeleton "push.c"', "push.c-pull-impure" => '%skeleton "push.c"',
"push-pure" => '%skeleton "push.c" %pure-parser', "push.c-pull-pure" => '%skeleton "push.c" %pure-parser',
"push-push" => '%skeleton "push.c" %push-parser', "push.c-push-impure" => '%skeleton "push.c" %push-parser',
"popt-yacc" => '%skeleton "push_opt.c"', "push.c-push-pure" => '%skeleton "push.c" %push-parser %pure-parser',
"popt-pure" => '%skeleton "push_opt.c" %pure-parser',
"popt-push" => '%skeleton "push_opt.c" %push-parser',
); );
my %bench; my %bench;