Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #21489

Re: MISC - Stack Based vs. Register Based

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups comp.lang.forth
Subject Re: MISC - Stack Based vs. Register Based
Date 2013-04-07 15:31 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2013Apr7.173141@mips.complang.tuwien.ac.at> (permalink)
References <2013Apr7.161345@mips.complang.tuwien.ac.at> <17891896998434@frunobulax.edu>

Show all headers | View raw


mhx@iae.nl (Marcel Hendrix) writes:
>Note that the f2c matmul seems to crash, or maybe bash crashed (core dumped,
>but I still got output from the `time` command).

Looks to me like a 32/64-bit portability issue; the sizes of the
arrays are hard-coded in bytes in the generated C code.  Try compiling
with -m32.

>>>4) The results for fib are a parlor trick for most compilers
>
>> C compilers do cool things with that nowadays (I guess that's the kind
>> of real-world programs that Andrew referred to elsewhere:-).  I would
>> not expect Forth compilers to do that (it does not help on what counts
>> as real world in the Forth world); so what parlor trick do you mean?
>
>FIB is about the only program that I know that benefits so much from 
>having TOS in a register. Even SF is a lot faster than iForth here, while
>it is far slower for all other programs I tested. Maybe it is fundamentally
>better to have the TOS in a register.

Yes, all the data I have indicates that it is a good idea.

1) http://www.complang.tuwien.ac.at/papers/ertl95pldi.ps.gz

Figure 21 shows the benefits (in terms of reduces loads+stores) of
keeping the TOS in a register between primitives (and why more doesn't
help).

Figure 24 shows that, if you optimize basic blocks and have 1 or 2
registers, keeping the TOS in a register at basic block boundaries is
optimal, while for more registers, keeping TOS and NOS in registers is
slightly better (for the performance model assumed there).

2) http://www.complang.tuwien.ac.at/papers/ertl%26gregg05.ps.gz

Here we see timing data from real machines instead of a performance
model, and the discussion says (in Section 4.4):

|The number of instructions executed is smallest for the canonical
|stack representation with one register (except for some of the smaller
|benchmarks).  Similarly, for the single-representation stack caches,
|the one with one register executes the least instructions.
|
|The PPC7400 timings behave quite similar to the instruction counts,
|although the timing reduction is somewhat higher than the instruction
|reduction; on the PPC7447A and especially the PPC970 the times for
|canonical representations with more than one registers rise much more
|slowly (and sometimes not at all).
|
|Nevertheless, even on those CPUs using the one-register representation
|as canonical representation or, for single-representation stack
|caches, as the representation is optimal for many benchmarks, and
|close to optimal on the others.

> I thought that it would become a hindrance
>when the compiler reached a certain level of sophistication, but at least
>for iForth (and Vfx) that level is still a bit far off.

Well, if your compiler works on larger units, it will do much of that
automatically within the units, but at unit boundaries (where you
return to the canonical stack state) it is still an advantage; I think
that, with larger units, keeping more stack items in registers at
boundaries might be beneficial, but have no data on that.

Working on Gforth I originally thought that keeping the TOS in a
register would increase the register pressure, but that turned out not
to be the case.  Most primitives load the TOS at some early point
anyway and store it later, and the point of highest register pressure
is between these points; keeping the TOS in a register across NEXT
does not increase register pressure.

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2013: http://www.euroforth.org/ef13/

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-03-29 17:00 -0400
  Re: MISC - Stack Based vs. Register Based glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-03-29 21:43 +0000
    Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-03-29 20:28 -0400
      Re: MISC - Stack Based vs. Register Based glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-03-31 18:34 +0000
        Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-02 09:54 -0400
          Re: MISC - Stack Based vs. Register Based glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-04-02 17:20 +0000
            Re: MISC - Stack Based vs. Register Based David Brown <david@westcontrol.removethisbit.com> - 2013-04-03 09:12 +0200
    Re: MISC - Stack Based vs. Register Based Jon Elson <jmelson@wustl.edu> - 2013-04-01 15:11 -0500
  Re: MISC - Stack Based vs. Register Based AKE <assadebrahim2000@gmail.com> - 2013-03-29 18:19 -0700
    Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-03-30 18:50 -0400
      Re: MISC - Stack Based vs. Register Based Jecel <jecel@merlintec.com> - 2013-04-01 13:18 -0700
        Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-02 10:50 -0400
          Re: MISC - Stack Based vs. Register Based Jecel <jecel@merlintec.com> - 2013-04-02 23:39 -0700
            Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-03 09:54 -0400
              Re: MISC - Stack Based vs. Register Based Jecel <jecel@merlintec.com> - 2013-04-05 14:30 -0700
                Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-05 17:53 -0400
                Re: MISC - Stack Based vs. Register Based Jecel <jecel@merlintec.com> - 2013-04-06 13:27 -0700
                Re: MISC - Stack Based vs. Register Based Jecel <jecel@merlintec.com> - 2013-04-06 13:37 -0700
        Re: MISC - Stack Based vs. Register Based Paul Rubin <no.email@nospam.invalid> - 2013-04-07 15:21 -0700
          Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-08 01:24 -0400
            Re: MISC - Stack Based vs. Register Based Syd Rumpo <usenet@nononono.co.uk> - 2013-04-08 10:18 +0100
          Re: MISC - Stack Based vs. Register Based Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-08 04:18 -0500
  Re: MISC - Stack Based vs. Register Based Arlet Ottens <usenet+5@c-scape.nl> - 2013-03-30 08:20 +0100
    Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-03-30 19:00 -0400
      Re: MISC - Stack Based vs. Register Based Arlet Ottens <usenet+5@c-scape.nl> - 2013-03-31 13:20 +0200
  Re: MISC - Stack Based vs. Register Based "Rod Pemberton" <do_not_have@notemailnotq.cpm> - 2013-03-30 17:54 -0400
    Re: MISC - Stack Based vs. Register Based Arlet Ottens <usenet+5@c-scape.nl> - 2013-03-31 09:11 +0200
      Re: MISC - Stack Based vs. Register Based "Rod Pemberton" <do_not_have@notemailnotq.cpm> - 2013-04-01 20:10 -0400
        Re: MISC - Stack Based vs. Register Based glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-04-02 00:54 +0000
          Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-02 13:31 -0400
            Re: MISC - Stack Based vs. Register Based glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-04-02 19:03 +0000
        Re: MISC - Stack Based vs. Register Based Arlet Ottens <usenet+5@c-scape.nl> - 2013-04-02 08:25 +0200
          Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-02 13:33 -0400
        Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-02 13:26 -0400
          Re: MISC - Stack Based vs. Register Based "Rod Pemberton" <do_not_have@notemailnotq.cpm> - 2013-04-03 20:34 -0400
            Re: MISC - Stack Based vs. Register Based glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-04-04 02:07 +0000
              Re: MISC - Stack Based vs. Register Based albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-04-04 11:16 +0000
                Re: MISC - Stack Based vs. Register Based Arlet Ottens <usenet+5@c-scape.nl> - 2013-04-04 13:25 +0200
                Re: MISC - Stack Based vs. Register Based glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-04-04 12:44 +0000
                Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-04 17:04 -0400
                Re: MISC - Stack Based vs. Register Based glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-04-04 21:34 +0000
                Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-04 19:30 -0400
                Re: MISC - Stack Based vs. Register Based Mark Wills <markrobertwills@yahoo.co.uk> - 2013-04-05 00:41 -0700
                Re: MISC - Stack Based vs. Register Based Alex McDonald <blog@rivadpm.com> - 2013-04-04 15:30 -0700
                Re: MISC - Stack Based vs. Register Based glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-04-04 23:15 +0000
                Re: MISC - Stack Based vs. Register Based Alex McDonald <blog@rivadpm.com> - 2013-04-04 17:26 -0700
                Re: MISC - Stack Based vs. Register Based albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-04-05 01:17 +0000
                Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-05 18:00 -0400
                Re: MISC - Stack Based vs. Register Based "Rod Pemberton" <do_not_have@notemailnotq.cpm> - 2013-04-08 23:55 -0400
                Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-04 20:07 -0400
                Re: MISC - Stack Based vs. Register Based Mark Wills <markrobertwills@yahoo.co.uk> - 2013-04-05 00:51 -0700
                Re: MISC - Stack Based vs. Register Based Arlet Ottens <usenet+5@c-scape.nl> - 2013-04-05 14:31 +0200
                Re: MISC - Stack Based vs. Register Based Mark Wills <markrobertwills@yahoo.co.uk> - 2013-04-05 07:33 -0700
                Re: MISC - Stack Based vs. Register Based Arlet Ottens <usenet+5@c-scape.nl> - 2013-04-05 17:01 +0200
                Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-05 18:25 -0400
                Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-06 17:44 -0400
                Re: MISC - Stack Based vs. Register Based Brad Eckert <hwfwguy@gmail.com> - 2013-04-05 10:14 -0700
                Re: MISC - Stack Based vs. Register Based Arlet Ottens <usenet+5@c-scape.nl> - 2013-04-05 20:13 +0200
                Re: MISC - Stack Based vs. Register Based Arlet Ottens <usenet+5@c-scape.nl> - 2013-04-05 20:15 +0200
                Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-05 18:54 -0400
                Re: MISC - Stack Based vs. Register Based Brad Eckert <hwfwguy@gmail.com> - 2013-04-08 09:57 -0700
                Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-09 10:13 -0400
                Re: MISC - Stack Based vs. Register Based Brad Eckert <hwfwguy@gmail.com> - 2013-04-09 08:55 -0700
                Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-09 14:40 -0400
                Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-05 18:49 -0400
                Re: MISC - Stack Based vs. Register Based daveyrotten <danw8804@gmail.com> - 2013-04-09 13:02 -0700
                Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-09 16:07 -0400
                Re: MISC - Stack Based vs. Register Based daveyrotten <danw8804@gmail.com> - 2013-04-09 13:26 -0700
                Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-10 00:33 -0400
                Re: MISC - Stack Based vs. Register Based daveyrotten <danw8804@gmail.com> - 2013-04-10 07:08 -0700
                Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-10 10:13 -0400
                Re: MISC - Stack Based vs. Register Based Sieur de Bienville <morrimichael@gmail.com> - 2013-04-10 21:08 -0700
                Re: MISC - Stack Based vs. Register Based Paul Rubin <no.email@nospam.invalid> - 2013-04-10 22:47 -0700
                Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-11 16:32 -0400
                Re: MISC - Stack Based vs. Register Based "Rod Pemberton" <do_not_have@notemailnotq.cpm> - 2013-04-18 06:23 -0400
                Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-18 17:06 -0400
                Re: MISC - Stack Based vs. Register Based glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-04-05 17:33 +0000
                Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-06 17:37 -0400
                Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-05 18:08 -0400
                Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-06 17:32 -0400
                Re: MISC - Stack Based vs. Register Based Brian Davis <brimdavis@aol.com> - 2013-04-07 14:59 -0700
                Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-08 01:16 -0400
                Re: MISC - Stack Based vs. Register Based albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-04-08 09:52 +0000
            Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-03 22:42 -0400
            Re: MISC - Stack Based vs. Register Based Alex McDonald <blog@rivadpm.com> - 2013-04-04 16:07 -0700
              Re: MISC - Stack Based vs. Register Based glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-04-05 04:10 +0000
                Re: MISC - Stack Based vs. Register Based Alex McDonald <blog@rivadpm.com> - 2013-04-04 23:49 -0700
    Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-02 12:04 -0400
      Re: MISC - Stack Based vs. Register Based "Rod Pemberton" <do_not_have@notemailnotq.cpm> - 2013-04-03 20:35 -0400
        Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-04 00:09 -0400
  Re: MISC - Stack Based vs. Register Based the_gavino_himself <visphatesjava@gmail.com> - 2013-04-02 11:17 -0700
  Re: MISC - Stack Based vs. Register Based Syd Rumpo <usenet@nononono.co.uk> - 2013-04-04 09:38 +0100
    Re: MISC - Stack Based vs. Register Based Arlet Ottens <usenet+5@c-scape.nl> - 2013-04-04 11:31 +0200
      Re: MISC - Stack Based vs. Register Based "Elizabeth D. Rather" <erather@forth.com> - 2013-04-04 08:36 -1000
        Re: MISC - Stack Based vs. Register Based Brad Eckert <hwfwguy@gmail.com> - 2013-04-05 10:21 -0700
          Re: MISC - Stack Based vs. Register Based "Elizabeth D. Rather" <erather@forth.com> - 2013-04-05 07:53 -1000
    Re: MISC - Stack Based vs. Register Based glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-04-04 12:49 +0000
      Re: MISC - Stack Based vs. Register Based Arlet Ottens <usenet+5@c-scape.nl> - 2013-04-04 15:02 +0200
    Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-04 18:57 -0400
  Re: MISC - Stack Based vs. Register Based AKE <assadebrahim2000@gmail.com> - 2013-04-05 15:29 -0700
    Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-05 19:32 -0400
      Re: MISC - Stack Based vs. Register Based anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-04-06 14:16 +0000
        Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-06 15:50 -0400
          Re: MISC - Stack Based vs. Register Based mhx@iae.nl (Marcel Hendrix) - 2013-04-07 01:33 +0200
            Re: MISC - Stack Based vs. Register Based AKE <assadebrahim2000@gmail.com> - 2013-04-07 02:57 -0700
              Re: MISC - Stack Based vs. Register Based stephenXXX@mpeforth.com (Stephen Pelc) - 2013-04-07 11:02 +0000
              Re: MISC - Stack Based vs. Register Based anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-04-07 13:51 +0000
                Re: MISC - Stack Based vs. Register Based "Elizabeth D. Rather" <erather@forth.com> - 2013-04-07 09:16 -1000
            Re: MISC - Stack Based vs. Register Based anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-04-07 14:13 +0000
              Re: MISC - Stack Based vs. Register Based mhx@iae.nl (Marcel Hendrix) - 2013-04-07 17:14 +0200
                Re: MISC - Stack Based vs. Register Based anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-04-07 15:31 +0000
            Re: MISC - Stack Based vs. Register Based Bernd Paysan <bernd.paysan@gmx.de> - 2013-04-08 18:53 +0200
          Re: MISC - Stack Based vs. Register Based anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-04-07 14:22 +0000
  Re: MISC - Stack Based vs. Register Based "WJ" <w_a_x_man@yahoo.com> - 2013-04-14 00:19 +0000
    Re: MISC - Stack Based vs. Register Based rickman <gnuarm@gmail.com> - 2013-04-14 09:44 -0400
    Re: MISC - Stack Based vs. Register Based Brad Eckert <hwfwguy@gmail.com> - 2013-04-15 09:39 -0700
      Re: MISC - Stack Based vs. Register Based Bernd Paysan <bernd.paysan@gmx.de> - 2013-04-15 19:28 +0200

csiph-web