Page 1 of 1

Dynamic trace results for three complex programs

Posted: Mon May 11, 2015 7:21 am
by barrym95838
I was about to post this over in Charlie's split-stack thread, but I already felt a bit guilty for contributing to thread drift over there, so I figured that it was best to start a new one (on which to drift around).

Awhile ago, Anton Ertl seemed to have modified Gforth's NEXT to trace and study the execution frequencies of primitives and combinations of primitives in preparation for trying to implement something he called a "pin-hole optimizer".

More details are here:

i drop and - ended up lower on the list than I expected, but I'm not a Forth programmer, so my expectations should be taken with a grain of salt. It also seems that programming style doesn't really become much of a factor until the sequence var: @ appears, outside the top 10.

Code: Select all

These data are derived from dynamic traces of real applications running on Gforth,
	not from small benchmarks that might provide unrealistic results:

cross
	is a Forth cross compiler written mainly by Bernd Paysan. 
	Length 5,779,740 primitives.

gs
	is a data and control flow analysis program written by Anton Ertl. 
	It uses locals a lot. Length 3,540,682 primitives.

prims2x
	is a filter that converts primitives specifications into C code.
	Anton Ertl wrote most of it. Length 5,822,924 primitives.

(Here, Anton uses the term "primitive" for anything that performs a NEXT or NEXT1;
	this includes routines like docol and dovar).

  Total		  cross		   gs		 prims2x
--------	--------	--------	--------
15143346	 5779740	 3540682	 5822924	NEXTS
--------	--------	--------	--------
 2038446	  793119	  442464	  802863	;s
 1995025	  787457	  428114	  779454	col:
 1355759	  503162	  283813	  568784	@
  765602	  275772	  183685	  306145	?branch
  700996	  246049	  141642	  313305	lit
  674069	  270409	  125561	  278099	col: col:
  519952	  151876	   36627	  331449	var:
  515649	  208841	  126882	  179926	dup
  486243	  254487	  131630	  100126	user:
  457720	  109479	   44542	  303699	swap
  419537	  156910	   98260	  164367	+
  402746	  208519	  109785	   84442	user: @
  402579	  209151	  103852	   89576	@ ;s
  401507	  174555	   73650	  153302	;s ;s
  381210	   98308	   17331	  265571	var: @
  377418	  164606	   70945	  141867	con:
  354087	   95407	   33153	  225527	;s col:
  309835	  182862	   60124	   66849	>r
  292806	  173229	   57072	   62505	r>
  275656	   28804	   16214	  230638	0=
  251576	  126970	   68518	   56088	user: @ ;s
  248438	  121046	   70632	   56760	col: user:
  248104	  120712	   70632	   56760	col: user: @
  216244	  105626	   60494	   50124	col: col: user: @
  216244	  105626	   60494	   50124	col: col: user:
  212251	  104129	   58946	   49176	col: user: @ ;s
  203922	  100088	   56464	   47370	col: col: user: @ ;s
  199820	   91949	    8004	   99867	col: var:
  196434	   55035	   27799	  113600	and
  192467	   68884	   21938	  101645	c@
  187718	   83969	   57687	   46062	!
  182861	   99558	   41195	   42108	over
  170810	   36514	   22562	  111734	col: lit
  169028	   44781	   19153	  105094	col: con:
  167571	   31201	   41220	   95150	cells
  167474	   57880	   12340	   97254	rot
  165683	   82438	   47254	   35991	2dup
  164287	   46640	   18903	   98744	lit col:
  159526	   63073	    6175	   90278	col: var: @
  153550	   49352	   10997	   93201	;s col: col:
  149816	   73999	   49793	   26024	dup ?branch
  148765	   42409	   18509	   87847	?branch lit
  142644	   66254	   48157	   28233	;s @
  141586	   55741	   43102	   42743	branch
  139323	       0	  139323	       0	@local1
  135658	   48991	     394	   86273	col: col: var:
  132375	   53809	   51672	   26894	;s dup
  131373	   46307	       0	   85066	col: col: var: @
  129236	   46217	   24350	   58669	+!
  127031	   61331	   37581	   28119	col: col: col:
  124565	   73765	   22169	   28631	r@
  121258	   19748	   19543	   81967	=
  118775	   18113	   18986	   81676	= ?branch
  118088	   21332	    6278	   90478	lit col: col:
  116035	   52796	   35160	   28079	! ;s
  112276	   20152	    4945	   87179	+ swap
  111648	   39594	   17275	   54779	+! ;s
  111423	   42444	   34770	   34209	defer:
  109783	   76322	   17118	   16343	con: col:
  108908	   55593	   29618	   23697	;s @ ;s
  108895	   55520	   29678	   23697	user: @ ;s @
  108895	   55520	   29678	   23697	col: user: @ ;s @
  108895	   55520	   29678	   23697	col: col: user: @ ;s @
  108895	   55520	   29678	   23697	@ ;s @
  108835	   55520	   29618	   23697	user: @ ;s @ ;s
  108835	   55520	   29618	   23697	col: user: @ ;s @ ;s
  108835	   55520	   29618	   23697	@ ;s @ ;s
  108626	       0	  108626	       0	>l
  107819	   47709	   34723	   25387	field:
  106079	   55162	   25900	   25017	col: dup
  106058	   43162	   42530	   20366	;s dup ?branch
  103985	   37694	   18983	   47308	<>
  103908	   47701	   31113	   25094	field: @
  102930	   50665	   26789	   25476	lit and
  102443	   12427	    6036	   83980	@ dup
  102351	   11144	    4751	   86456	rot + swap
  102351	   11144	    4751	   86456	rot +
  101933	   11014	    4755	   86164	c@ ;s
  101841	   74745	   12327	   14769	c!
  101661	    8350	    5782	   87529	;s swap
  101650	   36311	   18325	   47014	<> ?branch
  101169	    9853	    5732	   85584	and 0=
  100983	    9776	    4751	   86456	/mod
   99120	   47603	   39014	   12503	i
   97022	   38475	   38079	   20468	drop
   96461	    5054	    5071	   86336	col: col: con:
   96125	   33283	   38718	   24124	cell+
   93268	   44934	   18542	   29792	count
   92563	    2056	    7533	   82974	;s col: lit
   92381	   22723	    8638	   61020	0= ?branch
   92040	   41023	   29797	   21220	;s con:
   89779	   35869	   33024	   20886	-
   88442	    7667	      43	   80732	swap ;s
   88331	    7605	       0	   80726	+ swap ;s
   87343	   45645	   21280	   20418	?branch col:
   87199	   34933	   18457	   33809	;s lit
   85910	       0	       0	   85910	0= 0=
   85420	    4918	      13	   80489	@ =
   85359	    4918	      13	   80428	@ = ?branch
   84258	     249	    2912	   81097	dup var:

	... [ that's the top 100 ] ...

	... [ many, many more lines ] ...

	... [ and the bottom 50 ] ...

       1	       0	       0	       1	+! ;s ! ;s cells
       1	       0	       0	       1	+! ;s ! ;s (loop) unloop
       1	       0	       0	       1	+ @ (loop) unloop var: @
       1	       0	       0	       1	+ @ (loop) unloop var:
       1	       0	       0	       1	+ @ (loop) unloop
       1	       0	       0	       1	+ -rot con: <> ?branch drop
       1	       0	       0	       1	+ ! (next) unloop ;s ;s
       1	       0	       0	       1	+ ! (next) unloop ;s
       1	       0	       0	       1	+ ! (next) unloop
       1	       0	       0	       1	(next) unloop ;s ;s branch col:
       1	       0	       0	       1	(next) unloop ;s ;s branch
       1	       0	       0	       1	(next) unloop ;s ;s
       1	       0	       0	       1	(next) unloop ;s
       1	       0	       0	       1	(next) unloop
       1	       0	       0	       1	(loop) unloop var: @ ;s ;s
       1	       0	       0	       1	(loop) unloop var: @ ;s
       1	       0	       0	       1	(loop) unloop var: @
       1	       0	       0	       1	(loop) unloop var:
       1	       0	       0	       1	(loop) unloop ;s col: lit col:
       1	       0	       0	       1	(loop) unloop ;s col: lit
       1	       0	       0	       1	(for) var: cell+ i cells +
       1	       0	       0	       1	(for) var: cell+ i cells
       1	       0	       0	       1	(for) var: cell+ i
       1	       0	       0	       1	(for) var: cell+
       1	       0	       0	       1	(for) var:
       1	       0	       0	       1	(for)
       1	       0	       0	       1	(do) lit col: col: col: user:
       1	       0	       0	       1	(do) lit col: col: col:
       1	       0	       0	       1	(do) lit col: col:
       1	       0	       0	       1	(do) lit col:
       1	       0	       0	       1	(do) lit
       1	       0	       0	       1	(?do) var: cell+ i cells +
       1	       0	       0	       1	(?do) var: cell+ i cells
       1	       0	       0	       1	(?do) var: cell+ i
       1	       0	       0	       1	(?do) var: cell+
       1	       0	       0	       1	! lit (do) lit col: col:
       1	       0	       0	       1	! lit (do) lit col:
       1	       0	       0	       1	! lit (do) lit
       1	       0	       0	       1	! lit (do)
       1	       0	       0	       1	! ?dup ?branch 1- (for) var:
       1	       0	       0	       1	! ?dup ?branch 1- (for)
       1	       0	       0	       1	! ?dup ?branch 1-
       1	       0	       0	       1	! ;s cells col: col: user:
       1	       0	       0	       1	! ;s cells col: col:
       1	       0	       0	       1	! ;s cells col:
       1	       0	       0	       1	! ;s cells
       1	       0	       0	       1	! (next) unloop ;s ;s branch
       1	       0	       0	       1	! (next) unloop ;s ;s
       1	       0	       0	       1	! (next) unloop ;s
       1	       0	       0	       1	! (next) unloop
Question: What is (next) ?

Mike B.

Re: Dynamic trace results for three complex programs

Posted: Sat Jul 06, 2019 10:43 pm
by JimBoyd
It looks like Gforth has the FOR NEXT control structure ( not to be confused with the address interpreter NEXT ).
My guess is that (NEXT) is a primitive compiled by NEXT , the control flow word.