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


Groups > comp.lang.forth > #60508

Re: What is Forth anyway?

From "Rudy Velthuis" <newsgroups@rvelthuis.de>
Newsgroups comp.lang.forth
Subject Re: What is Forth anyway?
Date 2017-06-09 17:09 +0000
Organization Aioe.org NNTP Server
Message-ID <xn0kr14q3bbso4000b@nntp.aioe.org> (permalink)
References (5 earlier) <8c451582-6995-4325-a0f5-70c797088836@googlegroups.com> <xn0kqvm3u9fxgfp003@nntp.aioe.org> <rJudnfuBpqoW9qvEnZ2dnUU7-YPNnZ2d@supernews.com> <xn0kqyf6hawugxy007@nntp.aioe.org> <TemdnSxu_qURaqXEnZ2dnUU7-a3NnZ2d@supernews.com>

Show all headers | View raw


Andrew Haley wrote:

> Rudy Velthuis <newsgroups@rvelthuis.de> wrote:
> > Andrew Haley wrote:
> > 
> >> Rudy Velthuis <newsgroups@rvelthuis.de> wrote:
> >> >> > 
> >> >> > But it also requires quite a lot of stack juggling, which is
> not >> >> > required with registers. I am not sure if you have the
> same >> number >> > of memory accesses without a stack, especially if
> dat can >> be passed >> > in registers directly.
> >> >> 
> >> >> Thank you very much, Captain Obvious!
> >> > 
> >> > It may be obvious, but it also shows why stack based passing is
> not >> > so optimal as you claim it to be. It is nice concept, but I
> doubt it >> > is the most efficient way to pass parameters. After
> all, it used to >> > be the main way to pass parameters in most other
> languages too. But >> > these had/have ways to access each of them by
> name, not just the >> > one(s) on the top of the stack.
> >> 
> >> That's all true, but there are disadvantages too.
> >> 
> >> If I've already paid for those registers, which require large and
> >> complex electronics, I probably also have multiple functional units
> >> and instructions per clock, so I might as well use them all as
> much as >> possible.  All other things being equal, that is, but they
> rarely are!  >> 
> >> To translate any programming language into near-optimum code for a
> >> register machine is a hard problem.  And I'm going to end up with a
> >> lot of software to do that.
> > 
> > Oh? Why are you going to end up with a lot of software to do that?
> > Parameter passing is generally governed by ABIs or calling
> > conventions.  There is no need to allocate registers for that.
> > 
> > And parameter passing through a stack is also governed by a certain
> > order. Why would that be more optimal, especially if you must do
> > extra work to access anything but the top of the stack and to
> > prevent values from being consumed?
> 
> A Forth compiler doesn't need to do any extra work.
> 
> > What makes random access to such a stack (like in older versions of
> > popular programming languages, which use the machine stack to pass
> > parameters) harder to use?
> 
> Forth doesn't use random access to the stack.  (Except PICK and ROLL,
> but bleurgh.)
> 
> > Sure, you must have a good register allocator to be able to keep as
> > many values in registers. But how is that different for a stack
> > based language?
> 
> Stack allocation is trivial because you can have as many stack slots
> as you want.  Register allocation is hard because there is a fixed
> number of them, and there is a lot of shuffling to be done when you
> run out.
> 
> > Forth stacks are, as far as I know, generally in memory, like local
> > variables and parameters in other non-stack-based languages, who
> > also, most of the time, live on a stack (the machine stack).
> > 
> > And yes, I know there are optimizing Forth implementations. But I
> > assume these have a register allocator too, and don't constantly
> > push and pop items. That probably means they need "a lot of
> > software" too, or do they?
> 
> Yes, they do.  To take advantage of registers for parameter passing,
> you need a way to allocate them efficiently: if you don't do that
> you're going to have lot of moves at every call site.  On the other
> hand, stack allocation is trivial.

I don't see what is more trivial about it. Or alternatively, it puts a
much higher burden on the programmer, because the programmer must do
the stack juggling (oftentimes involving a lot of copying). And I
rather have most of my values in registers than in memory.
 
> > So I still don't see why parameter passing, or register allocation
> > is easier or more optimal in a stack based language.
> 
> Stack allocation is certainly easier: when you want a lot to use, you
> push it on the top.  Register allocation, not so much.

In non-stack-based languages, local variables are easily accessed and
easily allocated: just one change of the stack pointer. No stack
juggling required. No constant push/pops.
> 
> > I personally find random access to values like parameters or local
> > variables easier to handle than stack juggling.
> 
> It's not a matter of what you personally find, but what a compiler has
> to do.

Yes, indeed. It is easier for the compiler if it can do random access
to (local) variables and parameters than if it must do this in a LIFO
way.
-- 
Rudy Velthuis        http://www.rvelthuis.de

"A most important, but also most elusive, aspect of any tool is
 its influence on the habits of those who train themselves in its
 use. If the tool is a programming language this influence is, 
 whether we like it or not, an influence on our thinking habits." 
 -- Edsger Dijkstra

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


Thread

What is Forth anyway? Brad Eckert <hwfwguy@gmail.com> - 2017-06-03 20:31 -0700
  Re: What is Forth anyway? lehs <skydda.barnen@gmail.com> - 2017-06-03 23:05 -0700
    Re: What is Forth anyway? Howerd <howerdo@yahoo.co.uk> - 2017-06-04 03:23 -0700
      Re: What is Forth anyway? lehs <skydda.barnen@gmail.com> - 2017-06-04 03:39 -0700
  Re: What is Forth anyway? Howerd <howerdo@yahoo.co.uk> - 2017-06-04 03:17 -0700
    Re: What is Forth anyway? Howerd <howerdo@yahoo.co.uk> - 2017-06-04 03:18 -0700
  What is Forth anyway? Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-06-04 05:17 -0700
    Re: What is Forth anyway? Howerd <howerdo@yahoo.co.uk> - 2017-06-04 07:13 -0700
    Re: What is Forth anyway? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-06-05 02:38 -0500
  Re: What is Forth anyway? NN <november.nihal@gmail.com> - 2017-06-04 05:27 -0700
  Re: What is Forth anyway? "HAA" <someone@microsoft.com> - 2017-06-04 23:07 +1000
    Re: What is Forth anyway? Alex <alex@rivadpm.com> - 2017-06-04 19:12 +0100
      Re: What is Forth anyway? Howerd <howerdo@yahoo.co.uk> - 2017-06-04 12:55 -0700
        Re: What is Forth anyway? Alex <alex@rivadpm.com> - 2017-06-04 21:41 +0100
        Re: What is Forth anyway? "HAA" <someone@microsoft.com> - 2017-06-05 15:54 +1000
          Re: What is Forth anyway? Howerd <howerdo@yahoo.co.uk> - 2017-06-05 02:05 -0700
      Re: What is Forth anyway? Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-06-04 17:33 -0700
        Re: What is Forth anyway? "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-06-05 12:54 +0000
    Re: What is Forth anyway? "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-06-04 22:14 +0000
      Re: What is Forth anyway? hughaguilar96@gmail.com - 2017-06-04 16:39 -0700
        Re: What is Forth anyway? "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-06-05 12:44 +0000
          Re: What is Forth anyway? hughaguilar96@gmail.com - 2017-06-05 08:10 -0700
            Re: What is Forth anyway? gavino himself <jackvanc3@gmail.com> - 2017-06-05 10:01 -0700
            Re: What is Forth anyway? "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-06-05 19:29 +0000
              Re: What is Forth anyway? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-06-06 03:44 -0500
                Re: What is Forth anyway? "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-06-07 19:26 +0000
                Re: What is Forth anyway? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-06-08 02:06 -0500
                Re: What is Forth anyway? "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-06-09 17:09 +0000
            Re: What is Forth anyway? "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-06-05 19:41 +0000
              Re: What is Forth anyway? lehs <skydda.barnen@gmail.com> - 2017-06-06 02:19 -0700
                Re: What is Forth anyway? Alex <alex@rivadpm.com> - 2017-06-06 10:41 +0100
                Re: What is Forth anyway? Ron Aaron <rambamist@gmail.com> - 2017-06-06 12:45 +0300
                Re: What is Forth anyway? Alex <alex@rivadpm.com> - 2017-06-06 11:23 +0100
                Re: What is Forth anyway? Ron Aaron <rambamist@gmail.com> - 2017-06-06 13:30 +0300
                Re: What is Forth anyway? Alex <alex@rivadpm.com> - 2017-06-06 12:55 +0100
                Re: What is Forth anyway? Ron Aaron <rambamist@gmail.com> - 2017-06-06 14:57 +0300
                Re: What is Forth anyway? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-06-06 13:34 +0000
                Re: What is Forth anyway? Ron Aaron <rambamist@gmail.com> - 2017-06-06 17:07 +0300
                Re: What is Forth anyway? Coos Haak <htrofhc@gmail.com> - 2017-06-06 16:51 +0200
                Re: What is Forth anyway? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-06-06 16:32 +0000
                Re: What is Forth anyway? Coos Haak <htrofhc@gmail.com> - 2017-06-07 01:37 +0200
                Re: What is Forth anyway? "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-06-07 19:29 +0000
                Re: What is Forth anyway? Cecil Bayona <cbayona@cbayona.com> - 2017-06-07 14:56 -0500
                Re: What is Forth anyway? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-06-06 04:48 -0500
                Re: What is Forth anyway? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-06-06 10:10 +0000
                Re: What is Forth anyway? "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-06-07 19:28 +0000
                Re: What is Forth anyway? Cecil Bayona <cbayona@cbayona.com> - 2017-06-07 14:54 -0500
                Re: What is Forth anyway? lehs <skydda.barnen@gmail.com> - 2017-06-07 19:42 -0700
                Re: What is Forth anyway? "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-06-09 17:12 +0000
      Re: What is Forth anyway? Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-06-04 17:40 -0700
        Re: What is Forth anyway? "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-06-05 12:51 +0000
          Re: What is Forth anyway? Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-06-05 17:19 -0700
            Re: What is Forth anyway? "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-06-07 19:32 +0000
              Re: What is Forth anyway? Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-06-07 16:50 -0700
                Re: What is Forth anyway? "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-06-09 17:15 +0000
                Re: What is Forth anyway? Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-06-09 13:04 -0700
                Re: What is Forth anyway? "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-06-09 21:27 +0000
          Re: What is Forth anyway? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-06-06 10:19 +0000
            Re: What is Forth anyway? "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-06-07 19:38 +0000
              Re: What is Forth anyway? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-06-08 11:52 +0000
                Re: What is Forth anyway? "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-06-09 17:23 +0000
  Re: What is Forth anyway? gavino himself <jackvanc3@gmail.com> - 2017-06-05 07:16 -0700
  Re: What is Forth anyway? gavino himself <jackvanc3@gmail.com> - 2017-06-05 07:35 -0700

csiph-web