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


Groups > comp.lang.forth > #52476 > unrolled thread

Average swaps per word?

Started bytrans <transfire@gmail.com>
First post2016-11-08 22:03 -0800
Last post2016-11-11 15:54 -0800
Articles 17 on this page of 97 — 21 participants

Back to article view | Back to comp.lang.forth


Contents

  Average swaps per word? trans <transfire@gmail.com> - 2016-11-08 22:03 -0800
    Re: Average swaps per word? "Elizabeth D. Rather" <erather@forth.com> - 2016-11-08 20:20 -1000
    Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-09 08:16 +0000
    Re: Average swaps per word? Rod Pemberton <NeedNotReplyHere@xrsevnneqk.cem> - 2016-11-09 03:34 -0500
      Re: Average swaps per word? trans <transfire@gmail.com> - 2016-11-09 02:53 -0800
        Re: Average swaps per word? rickman <gnuarm@gmail.com> - 2016-11-09 11:50 -0500
          Re: Average swaps per word? stephen@mpeforth.com (Stephen Pelc) - 2016-11-09 18:37 +0000
            Re: Average swaps per word? Harold <hzrabbie@gmail.com> - 2016-11-10 16:28 -0800
              Re: Average swaps per word? stephen@mpeforth.com (Stephen Pelc) - 2016-11-11 17:51 +0000
              Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-12 12:23 +0000
                Re: Average swaps per word? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-11-12 16:09 +0100
                  Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-13 14:55 +0000
                    Re: Average swaps per word? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-11-13 20:34 +0100
                      Re: Average swaps per word? Paul Rubin <no.email@nospam.invalid> - 2016-11-13 11:43 -0800
                        Re: Average swaps per word? hughaguilar96@gmail.com - 2016-11-13 16:58 -0800
                          Re: Average swaps per word? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-11-14 16:41 +0100
                            Re: Average swaps per word? hughaguilar96@gmail.com - 2016-11-14 16:38 -0800
                        Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-14 17:42 +0000
                          Re: Average swaps per word? Rod Pemberton <NeedNotReplyHere@xrsevnneqk.cem> - 2016-11-14 16:39 -0500
                            Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-17 12:40 +0000
                              Re: Average swaps per word? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-11-17 14:10 +0100
                                Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-18 15:14 +0000
                                  Re: Average swaps per word? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-11-20 18:16 +0100
                                    Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-22 10:29 +0000
                                      Re: Average swaps per word? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-11-22 15:54 +0100
                                      Re: Average swaps per word? James Kuyper <jameskuyper@verizon.net> - 2016-11-22 11:50 -0500
                                        Re: Average swaps per word? raltbos@xs4all.nl (Richard Bos) - 2016-11-24 17:27 +0000
                          Re: Average swaps per word? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-11-15 03:55 -0600
                            Re: Average swaps per word? Rod Pemberton <NeedNotReplyHere@xrsevnneqk.cem> - 2016-11-15 17:49 -0500
                              Re: Average swaps per word? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-11-16 02:59 -0600
                              Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-17 13:07 +0000
                            Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-16 22:57 +0000
                              Re: Average swaps per word? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-11-17 03:12 -0600
                                Re: Average swaps per word? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-11-17 12:32 +0100
                                  Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-18 15:02 +0000
                                Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-17 13:23 +0000
                                  Re: Average swaps per word? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-11-17 08:54 -0600
                                    Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-18 15:54 +0000
                                      Re: Average swaps per word? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-11-18 12:37 -0600
                      Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-14 17:32 +0000
                        Re: Average swaps per word? Mark Wills <markwills1970@gmail.com> - 2016-11-15 02:09 -0800
                        Re: Average swaps per word? jim <anon@example.com> - 2016-11-15 10:44 +0000
                          Re: Average swaps per word? Mark Wills <markwills1970@gmail.com> - 2016-11-15 03:12 -0800
                          Re: Average swaps per word? Alex <alex@rivadpm.com> - 2016-11-15 13:01 +0000
                            Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-17 12:51 +0000
                              Re: Average swaps per word? Alex <alex@rivadpm.com> - 2016-11-17 14:02 +0000
                                Re: Average swaps per word? Alex <alex@rivadpm.com> - 2016-11-17 14:06 +0000
                                Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-18 15:26 +0000
                                  Re: Average swaps per word? Alex <alex@rivadpm.com> - 2016-11-18 18:33 +0000
                                    Re: Average swaps per word? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-11-19 03:32 -0600
                            Re: Average swaps per word? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-11-17 14:29 +0100
                        Re: Average swaps per word? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-11-15 13:51 +0100
                          Re: Average swaps per word? jim <anon@example.com> - 2016-11-15 13:01 +0000
                          Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-17 12:46 +0000
                            Re: Average swaps per word? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-11-17 14:16 +0100
                Re: Average swaps per word? Harold <hzrabbie@gmail.com> - 2016-11-13 11:08 -0800
                  Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-14 17:08 +0000
                    Re: Average swaps per word? Mark Wills <markwills1970@gmail.com> - 2016-11-15 02:04 -0800
                    Re: Average swaps per word? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-11-15 14:04 +0100
                      Re: Average swaps per word? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-11-15 14:05 +0100
                      Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-17 12:58 +0000
                        Re: Average swaps per word? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-11-17 15:16 +0100
                          Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-18 15:41 +0000
                            Re: Average swaps per word? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-11-20 18:12 +0100
    Re: Average swaps per word? minforth@arcor.de - 2016-11-09 03:15 -0800
      Re: Average swaps per word? trans <transfire@gmail.com> - 2016-11-09 11:22 -0800
      Re: Average swaps per word? "HAA" <someone@microsoft.com> - 2016-11-10 12:20 +1100
        Re: Average swaps per word? "Elizabeth D. Rather" <erather@forth.com> - 2016-11-09 21:04 -1000
        Re: Average swaps per word? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-11-10 03:45 -0600
          Re: Average swaps per word? rickman <gnuarm@gmail.com> - 2016-11-10 11:52 -0500
            Re: Average swaps per word? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-11-10 11:42 -0600
              Re: Average swaps per word? rickman <gnuarm@gmail.com> - 2016-11-10 13:34 -0500
                Re: Average swaps per word? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-11-10 12:54 -0600
                  Re: Average swaps per word? rickman <gnuarm@gmail.com> - 2016-11-10 16:33 -0500
                    Re: Average swaps per word? "Elizabeth D. Rather" <erather@forth.com> - 2016-11-10 15:56 -1000
                      Re: Average swaps per word? rickman <gnuarm@gmail.com> - 2016-11-10 21:30 -0500
                        Re: Average swaps per word? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-11-11 03:04 -0600
                          Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-12 13:25 +0000
                            Re: Average swaps per word? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-11-14 03:34 -0600
                      Re: Average swaps per word? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-11-11 10:41 +0000
                      Re: Average swaps per word? hughaguilar96@gmail.com - 2016-11-11 16:45 -0800
        Re: Average swaps per word? jim <anon@example.com> - 2016-11-10 11:17 +0000
          Re: Average swaps per word? Raimond Dragomir <raimond.dragomir@gmail.com> - 2016-11-10 04:34 -0800
            Re: Average swaps per word? jim <anon@example.com> - 2016-11-10 12:44 +0000
              Re: Average swaps per word? Raimond Dragomir <raimond.dragomir@gmail.com> - 2016-11-10 07:27 -0800
                Re: Average swaps per word? Ron Aaron <rambamist@gmail.com> - 2016-11-10 18:26 +0200
                Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-10 16:05 +0000
          Re: Average swaps per word? stephen@mpeforth.com (Stephen Pelc) - 2016-11-10 14:55 +0000
            Re: Average swaps per word? "HAA" <someone@microsoft.com> - 2016-11-12 11:36 +1100
              Re: Average swaps per word? hughaguilar96@gmail.com - 2016-11-11 16:56 -0800
              Re: Average swaps per word? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-11-12 16:14 +0100
            Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-12 12:14 +0000
              Re: Average swaps per word? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-11-12 16:16 +0100
                Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-13 14:51 +0000
                  Re: Average swaps per word? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-11-13 20:41 +0100
        Re: Average swaps per word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-10 14:42 +0000
    Re: Average swaps per word? hughaguilar96@gmail.com - 2016-11-11 15:54 -0800

Page 5 of 5 — ← Prev page 1 2 3 4 [5]


#52549

Fromhughaguilar96@gmail.com
Date2016-11-11 16:45 -0800
Message-ID<a30f0f9d-d404-4aa9-9469-e989c62afbf9@googlegroups.com>
In reply to#52524
On Thursday, November 10, 2016 at 6:56:21 PM UTC-7, Elizabeth D. Rather wrote:
> The other point of view is that it's easier on the brain not to have to 
> remember so many names of things :-) I think you hit the nail on the 
> head when you said you didn't use Forth very often, and your analogy to 
> driving with a stick or automatic is pretty good. A person who normally 
> drives a stick shift car never thinks explicitly about shifting gears, 
> they just do it. And they like not having to buy as much gas as the 
> folks using the automatics.
> 
> If you use Forth regularly, you rarely think much about the stack, 
> because all you're concerned about in the moment are the one or two 
> arguments to the word you're writing, and you document them so you'll 
> know next time. We find that easier on the mind than having to think up 
> more names and document what they do. As I've often said, it's like 
> learning to ride a bicycle: wobbly at first, but thereafter smooth and 
> natural. It's a different paradigm from most other programming 
> languages, so unfamiliar at first, but comfortable thereafter.

This is nonsense. 

For one thing, remembering the names of local variables is not difficult because they are defined at the beginning of the function --- if the function is 7 lines long or less (typical) then you don't have to move your eyes very far to find the definition of the locals, in the unlikely case that you have forgotten what locals you have or what their names are.

For another thing, you do have to think explicitly about what is on the stack. I've been programming Forth since 1984 and I have to think when I write Forth code, because otherwise it doesn't work. Also, I've been driving a stick-shift since 1974 and I have to think about what gear I'm in, because otherwise I will put the vehicle into the wrong gear. 

Anybody who claims that they can produce working computer programs without thinking, is just blowing hot air. Computers can't think, and users are notorious for not thinking --- so, if the programmer isn't thinking, that means that nobody is thinking (generally a recipe for disaster, although this was the path to riches for Bill Gates).

On Friday, November 11, 2016 at 2:05:03 AM UTC-7, Andrew Haley wrote:
> I'd like to stress Elizabeth's point about not thinking about the
> stack.  An experienced reader of a Forth program doesn't think about
> the stack all the time, but about phrases and the flow of code.  

Andrew Haley is an employee of Forth Inc. --- this is why Elizabeth Rather appointed him to the Forth-200x committee --- this is also why he routinely agrees with everything that she says, even when it is just hot air.

Welcome to comp.lang.forth! --- where it is not necessary to think about the stack when programming in Forth --- instead, you gaze at our own belly-button (this trick also works well when driving a car!).

[toc] | [prev] | [next] | [standalone]


#52500

Fromjim <anon@example.com>
Date2016-11-10 11:17 +0000
Message-ID<MPG.328e67bb4a0d0409896bd@news.virginmedia.com>
In reply to#52494
> In article <o00i0v$1a87$1@gioia.aioe.org>, someone@microsoft.com says...

> If you don't have an optimizing compiler, then what?  Forth is about
> the stack and the efficient use thereof.  Terms like "stack juggling"
> give newcomers (and the rest of the world) the impression the stack
> is something to be avoided.  Optimizing compilers may reduce stack
> operations and/or correct redundancy, however I consider it a bonus
> - not a goal.

I wouldn't go quite as far as to call an optimiser a bonus but I think I agree
with HAA on this.

I see a couple of  points I think I'd make: 
 
If you dont have a compiler that can deal with 'swap swap' I'd say you need
to look for a different compiler.
Stephens examp;e of VFX handling demonstrates how this sort of thing
might even fall out of the bounds of an optimiser and into a standard compiler.
(OK it only LOOKS that way I know)

But presumably this thread is relating to more complext swaps rots and so on?
In which case isn't that more down to programmer training? It ranks close
to GOTO spaghetti in Basic I'd suggest.

And if there is something that falls in between the two levels then yes
an optimiser squeezing the last cycle out is a requirement  - or is it?...

in todays hardware running at 3Ghz and upwards is an occasionaly lost cycle
the end of the world? Academicly - yes - in practice I'm not so sure. perhaps
it would be better to clock the processor 0.1% faster than spend time worrying?

Of course in an environment with lower clocked embedded hardware
it might make a difference ... or would it?  an occasional wasted swap or drop?

how many of us write applications where it would be that critical? I'd certainly be looking
to move up to a better processor if I was working to that sort of  capability boundry?

Surely the task is to get the job done efficiently - and that doesn't mean the compiler
has to be churning out perfectly optimised code? Sometimes other factors are involved.

There comes a point where the anorak should come off?










[toc] | [prev] | [next] | [standalone]


#52501

FromRaimond Dragomir <raimond.dragomir@gmail.com>
Date2016-11-10 04:34 -0800
Message-ID<5053a4d7-1c90-4363-a5e4-948ead174bf9@googlegroups.com>
In reply to#52500
> If you dont have a compiler that can deal with 'swap swap' I'd say you need
> to look for a different compiler.

If you see 'swap swap' there may be a reason for this. Maybe the programmer 
wants the processor to do two swaps. who knows? And in his/her opinion the 
VFX generated code ma be just plain wrong...

[toc] | [prev] | [next] | [standalone]


#52502

Fromjim <anon@example.com>
Date2016-11-10 12:44 +0000
Message-ID<MPG.328e7c0a1976ce569896be@news.virginmedia.com>
In reply to#52501
In article <5053a4d7-1c90-4363-a5e4-948ead174bf9@googlegroups.com>, 
raimond.dragomir@gmail.com says...
> 
> > If you dont have a compiler that can deal with 'swap swap' I'd say you need
> > to look for a different compiler.
> 
> If you see 'swap swap' there may be a reason for this. Maybe the programmer 
> wants the processor to do two swaps. who knows? And in his/her opinion the 
> VFX generated code ma be just plain wrong...

no - in this case the programmer is wrong.
If you want to do a nop then do a nop
If you want to change a flag will a swap swap do it? doubtful
and if it did what does that say about the system?

just my opinion but I welcome your example of how
it might be useful ?  



[toc] | [prev] | [next] | [standalone]


#52507

FromRaimond Dragomir <raimond.dragomir@gmail.com>
Date2016-11-10 07:27 -0800
Message-ID<3e4d5545-6477-41fd-96d8-fc814f789cdc@googlegroups.com>
In reply to#52502
joi, 10 noiembrie 2016, 14:46:26 UTC+2, jim a scris:
> In article <5053a4d7-1c90-4363-a5e4-948ead174bf9@googlegroups.com>, 
> raimond.dragomir@gmail.com says...
> > 
> > > If you dont have a compiler that can deal with 'swap swap' I'd say you need
> > > to look for a different compiler.
> > 
> > If you see 'swap swap' there may be a reason for this. Maybe the programmer 
> > wants the processor to do two swaps. who knows? And in his/her opinion the 
> > VFX generated code ma be just plain wrong...
> 
> no - in this case the programmer is wrong.

Why a 'swap swap' is wrong?

> If you want to do a nop then do a nop

I didn't say or think 'swap swap' used as a nop.

> If you want to change a flag will a swap swap do it? doubtful
> and if it did what does that say about the system?
> 

You seem you are trying to get a usefull meaning of a 'swap swap'.
What if it hasn't one? Is it worth it to optimize it to the trash bin?

> just my opinion but I welcome your example of how
> it might be useful ?

It may catch a 'stack underflow' situation. 

My point was not against the compiler, in fact it does quite a good job.
My point was against your statement that a compiler that DOESN'T do that
optimization is not worth considering... For example, I don't care if my
compiler optimizes 'swap swap' or 'dup drop' but I care if it optimizes
'128 /' to bit shifting.

[toc] | [prev] | [next] | [standalone]


#52508

FromRon Aaron <rambamist@gmail.com>
Date2016-11-10 18:26 +0200
Message-ID<o0272l$d9d$1@dont-email.me>
In reply to#52507

On 10/11/2016 17:27, Raimond Dragomir wrote:
> joi, 10 noiembrie 2016, 14:46:26 UTC+2, jim a scris:

>> just my opinion but I welcome your example of how
>> it might be useful ?
> 
> It may catch a 'stack underflow' situation. 

Or it might be part of a small delay-loop.  Not a particularly well
written one, but that's not the compiler's purview.

[toc] | [prev] | [next] | [standalone]


#52509

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2016-11-10 16:05 +0000
Message-ID<2016Nov10.170526@mips.complang.tuwien.ac.at>
In reply to#52507
Raimond Dragomir <raimond.dragomir@gmail.com> writes:
>joi, 10 noiembrie 2016, 14:46:26 UTC+2, jim a scris:
>> In article <5053a4d7-1c90-4363-a5e4-948ead174bf9@googlegroups.com>, 
>> raimond.dragomir@gmail.com says...
>> > 
>> > > If you dont have a compiler that can deal with 'swap swap' I'd say you need
>> > > to look for a different compiler.
>> > 
>> > If you see 'swap swap' there may be a reason for this. Maybe the programmer 
>> > wants the processor to do two swaps. who knows? And in his/her opinion the 
>> > VFX generated code ma be just plain wrong...
>> 
>> no - in this case the programmer is wrong.
>
>Why a 'swap swap' is wrong?

The expectation of the programmer would be wrong, whatever he may be
expecting if he expects the processor to do two swaps (mainstream
processors don't have SWAP instructions).

If the programmer wants naive code generation, there are a number of
Forth systems to choose from that offer that (I have never seen it
advertised as a feature, so I guess there is not a big market for
that).  There may also be a way to get VFX to be more naive for this
code sequence, but don't ask me what it is.

>> If you want to change a flag will a swap swap do it? doubtful
>> and if it did what does that say about the system?
>> 
>
>You seem you are trying to get a usefull meaning of a 'swap swap'.
>What if it hasn't one?

Then why would the programmer expect a specific naive code sequence
for it?

> Is it worth it to optimize it to the trash bin?

In VFX that is just a fallout of the way that stack handling is dealt
with in the general case.  In a compiler that would require an extra
rule to optimize SWAP SWAP (such as SwiftForth), it would not be worth
adding that rule (and SwiftForth does not optimize it).

However, the number of occurences in real-world code where I have seen
"SWAP +" is surprising (IIRC 2 independent places, and I already found
one surprising).

>> just my opinion but I welcome your example of how
>> it might be useful ?
>
>It may catch a 'stack underflow' situation.

You mean, you insert SWAP SWAP as a placeholder for something that
accesses the stack 2-deep, and expect a stack underflow error?  You
apparently have been pampered by Gforth, which works that way on
decent OSs.  However, neither VFX nor SwiftForth catch a stack
underflow in this condition (even when doing the SWAP SWAP in a way
that is not optimized); and gforth-fast does not catch it, either.

>For example, I don't care if my
>compiler optimizes 'swap swap' or 'dup drop' but I care if it optimizes
>'128 /' to bit shifting.

Would you like it to, or complain about it?  Neither VFX nor
SwiftForth do it, and it's admittedly not totally trivial: 128 / on
these systems is not equivalent to an arithmetic shift right by 7;
they would have to do some correction for negative dividends.  If you
want a shift right, just use a shift right.  Gforth even has ARSHIFT
for signed dividends (and in Gforth 128 / is equivalent to 7 ARSHIFT).

- 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 2016: http://www.euroforth.org/ef16/

[toc] | [prev] | [next] | [standalone]


#52504

Fromstephen@mpeforth.com (Stephen Pelc)
Date2016-11-10 14:55 +0000
Message-ID<5824820f.39416351@news.eternal-september.org>
In reply to#52500
On Thu, 10 Nov 2016 11:17:55 -0000, jim <anon@example.com> wrote:

>in todays hardware running at 3Ghz and upwards is an occasionaly lost cycle
>the end of the world? Academicly - yes - in practice I'm not so sure. perhaps
>it would be better to clock the processor 0.1% faster than spend time worrying?
>
>Of course in an environment with lower clocked embedded hardware
>it might make a difference ... or would it?  an occasional wasted swap or drop?

A good code generator is an enabling technology. Any small improvement
in code generation affects all code passed through the compiler.

For example, I have not written an ARM or Cortex interrupt routine in
assembler for the last 15 years or so. There are at least three
significant code generation switches for the old ARM32 instruction
set, and at least another three for the Cortex-M0/M1/M3/M4/M7 set.
Instruction set changes are frequent these days.

There is no assembler code in our embedded USB stack. There is
no assembler code in our TCP/IP stack except for the TCP checksum.
There is no assembler code in the FAT12/16/32 file system.

High-level-only code improves portability and reuse. The downside
for the FOSS crew is that all the good Forth code generators are
either proprietary or from commercial vendors. That may change,
but writing a really good code generator is a lot of work.

The stack handling example is important. If you *know* that a
code generator will always produce the best stack shuffling code,
regardless of how it is expressed in the source code, you can
write the code for readability. 

Stephen

-- 
Stephen Pelc, stephenXXX@mpeforth.com
MicroProcessor Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
web: http://www.mpeforth.com - free VFX Forth downloads

[toc] | [prev] | [next] | [standalone]


#52548

From"HAA" <someone@microsoft.com>
Date2016-11-12 11:36 +1100
Message-ID<o05o6h$vlr$1@gioia.aioe.org>
In reply to#52504
Stephen Pelc wrote:
> ...
> A good code generator is an enabling technology. Any small improvement
> in code generation affects all code passed through the compiler.
>
> For example, I have not written an ARM or Cortex interrupt routine in
> assembler for the last 15 years or so.

But you could have.  An assembler has always been part of a Forth
programmer's toolkit.

> High-level-only code improves portability and reuse. The downside
> for the FOSS crew is that all the good Forth code generators are
> either proprietary or from commercial vendors. That may change,
> but writing a really good code generator is a lot of work.

It's also to a vendor's advantage to be able to claim their system
generates 'better code' than a competitor's.  No assembler required!
And for some customers that will be enough.  But after the 'gee whiz'
has worn off, the realization comes there is no magic bullet and a
program is only as good the person programming it.  A good
programmer is less likely to be impressed by, or reliant upon, the
code generator.

> The stack handling example is important. If you *know* that a
> code generator will always produce the best stack shuffling code,
> regardless of how it is expressed in the source code, you can
> write the code for readability.

Forth notions of readability differ from other languages.  As you
say elsewhere "Forth has always relied to some extent on the
idea that you get what you programmed."  Understanding this,
a good programmer is more likely program in the traditional
manner which produces effective code on a variety of systems.


[toc] | [prev] | [next] | [standalone]


#52550

Fromhughaguilar96@gmail.com
Date2016-11-11 16:56 -0800
Message-ID<2a101a1b-9d66-49f8-9b32-2b3ab0e48eb2@googlegroups.com>
In reply to#52548
On Friday, November 11, 2016 at 5:36:39 PM UTC-7, HAA wrote:
> Stephen Pelc wrote:
> > ...
> > A good code generator is an enabling technology. Any small improvement
> > in code generation affects all code passed through the compiler.
> >
> > For example, I have not written an ARM or Cortex interrupt routine in
> > assembler for the last 15 years or so.
> 
> But you could have.  An assembler has always been part of a Forth
> programmer's toolkit.
> 
> > High-level-only code improves portability and reuse. The downside
> > for the FOSS crew is that all the good Forth code generators are
> > either proprietary or from commercial vendors. That may change,
> > but writing a really good code generator is a lot of work.
> 
> It's also to a vendor's advantage to be able to claim their system
> generates 'better code' than a competitor's.  No assembler required!
> And for some customers that will be enough.  But after the 'gee whiz'
> has worn off, the realization comes there is no magic bullet and a
> program is only as good the person programming it.  A good
> programmer is less likely to be impressed by, or reliant upon, the
> code generator.

I pretty much agree with HAA on this. For quite a long time (including the time period when I was employed at Testra and wrote MFX) I thought of Forth as being an over-grown macro-assembler. All my Forth programs involved assembly-language --- I liked assembly-language --- only recently with my design of Straight Forth have I begun to think of Forth as being a language that novice programmers could use.

> > The stack handling example is important. If you *know* that a
> > code generator will always produce the best stack shuffling code,
> > regardless of how it is expressed in the source code, you can
> > write the code for readability.
> 
> Forth notions of readability differ from other languages.  As you
> say elsewhere "Forth has always relied to some extent on the
> idea that you get what you programmed."  Understanding this,
> a good programmer is more likely program in the traditional
> manner which produces effective code on a variety of systems.

I pretty much agree with Stephen Pelc on this. When writing Forth code, it is best to focus on readability --- for the obvious reason that, if you can't read your own code, it is almost certainly not going to work --- also, it is useful to have other people be able to read it.

Focusing your mind on manual-optimization is a waste of time while you are writing code --- this will delay getting the code to debugged and working --- optimization is something to worry about after the program is written and working.

[toc] | [prev] | [next] | [standalone]


#52558

Fromalbert@cherry.spenarnc.xs4all.nl (Albert van der Horst)
Date2016-11-12 16:14 +0100
Message-ID<o07bl6$s0j$1@cherry.spenarnc.xs4all.nl>
In reply to#52548
In article <o05o6h$vlr$1@gioia.aioe.org>, HAA <someone@microsoft.com> wrote:
>Stephen Pelc wrote:
>> ...
>> A good code generator is an enabling technology. Any small improvement
>> in code generation affects all code passed through the compiler.
>>
>> For example, I have not written an ARM or Cortex interrupt routine in
>> assembler for the last 15 years or so.
>
>But you could have.  An assembler has always been part of a Forth
>programmer's toolkit.

Translating that to the Pentium, I've severe doubts.
A Pentium assembler is part of my ciforth, but it is almost
unthinkable to add an interrupt routine to a Linux or Windows
system.

Groetjes Albert.
>
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

[toc] | [prev] | [next] | [standalone]


#52553

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2016-11-12 12:14 +0000
Message-ID<2016Nov12.131430@mips.complang.tuwien.ac.at>
In reply to#52504
stephen@mpeforth.com (Stephen Pelc) writes:
>High-level-only code improves portability and reuse. The downside
>for the FOSS crew is that all the good Forth code generators are
>either proprietary or from commercial vendors.

Either-or?  Looks mostly like "and" to me.

Of course, there is also FLK, distributed non-commercially under GPL:

http://www.complang.tuwien.ac.at/forth/flk.1.3.tar.gz

- 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 2016: http://www.euroforth.org/ef16/

[toc] | [prev] | [next] | [standalone]


#52559

Fromalbert@cherry.spenarnc.xs4all.nl (Albert van der Horst)
Date2016-11-12 16:16 +0100
Message-ID<o07bot$s1c$1@cherry.spenarnc.xs4all.nl>
In reply to#52553
In article <2016Nov12.131430@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>stephen@mpeforth.com (Stephen Pelc) writes:
>>High-level-only code improves portability and reuse. The downside
>>for the FOSS crew is that all the good Forth code generators are
>>either proprietary or from commercial vendors.
>
>Either-or?  Looks mostly like "and" to me.

I'd say inclusive OR instead of XOR.

>
>Of course, there is also FLK, distributed non-commercially under GPL:
>
>http://www.complang.tuwien.ac.at/forth/flk.1.3.tar.gz

I see speedups of a factor 5 w.r.t. gForth.

Why do we hear so little about this flk?

>
>- anton
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

[toc] | [prev] | [next] | [standalone]


#52584

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2016-11-13 14:51 +0000
Message-ID<2016Nov13.155139@mips.complang.tuwien.ac.at>
In reply to#52559
albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) writes:
>In article <2016Nov12.131430@mips.complang.tuwien.ac.at>,
>Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>>Of course, there is also FLK, distributed non-commercially under GPL:
>>
>>http://www.complang.tuwien.ac.at/forth/flk.1.3.tar.gz
>
>I see speedups of a factor 5 w.r.t. gForth.
>
>Why do we hear so little about this flk?

Good question.  It's orphaned and nobody has adopted it, so it's not
being promoted by its developer.  I have mentioned it now and then
over the years, but apparently the interest ist still limited.  I
gues, Forth users either want to have a supported system, or they want
to do their own system.

- 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 2016: http://www.euroforth.org/ef16/

[toc] | [prev] | [next] | [standalone]


#52590

Fromalbert@cherry.spenarnc.xs4all.nl (Albert van der Horst)
Date2016-11-13 20:41 +0100
Message-ID<o0aflr$5tt$1@cherry.spenarnc.xs4all.nl>
In reply to#52584
In article <2016Nov13.155139@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) writes:
>>In article <2016Nov12.131430@mips.complang.tuwien.ac.at>,
>>Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>>>Of course, there is also FLK, distributed non-commercially under GPL:
>>>
>>>http://www.complang.tuwien.ac.at/forth/flk.1.3.tar.gz
>>
>>I see speedups of a factor 5 w.r.t. gForth.
>>
>>Why do we hear so little about this flk?
>
>Good question.  It's orphaned and nobody has adopted it, so it's not
>being promoted by its developer.  I have mentioned it now and then
>over the years, but apparently the interest ist still limited.  I
>gues, Forth users either want to have a supported system, or they want
>to do their own system.

I tried to compile it, but got a considerable number of errors.
The same happened with old c-lisps. I've had at least two old
sources that failed because of signal.h.
I got the impression that the portability of c is waning.

Now it is more trouble to try it, and I may not get around doing
that for some time.

>
>- anton

Groetjes Albert
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

[toc] | [prev] | [next] | [standalone]


#52505

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2016-11-10 14:42 +0000
Message-ID<2016Nov10.154254@mips.complang.tuwien.ac.at>
In reply to#52494
"HAA" <someone@microsoft.com> writes:
>If you don't have an optimizing compiler, then what?

Then you pay a run-time penalty in addition to the brain load.

>Forth is about
>the stack and the efficient use thereof.

Not primarily.  It's about simplicity, and the stack is a means for
that.

>Terms like "stack juggling"
>give newcomers (and the rest of the world) the impression the stack
>is something to be avoided.

Why would it give that expression?  Ideally we avoid stack juggling,
not the stack.  And we avoid it by using the stack well and designing
the stack effects such that stack juggling is unnecessary or mostly
happens in a few select (low-level) words.  The relative scarcity of
SWAP in source code indicates that this works relatively well.

The first code example in Starting Forth is

: washer  wash spin rinse spin ;

not

: washer  swap wash over spin rot rinse dup spin drop ;

>Optimizing compilers may reduce stack
>operations and/or correct redundancy, however I consider it a bonus
>- not a goal.

For the compiler writer it may be a goal.  For the programmer, it's
nice if he can write the code for readability instead of having to
balance this goal against performance (which may or may not be aligned
with readability; consider the 3DUP versions of TAK compared to the
3DUP-less ones).

- 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 2016: http://www.euroforth.org/ef16/

[toc] | [prev] | [next] | [standalone]


#52546

Fromhughaguilar96@gmail.com
Date2016-11-11 15:54 -0800
Message-ID<061b4598-513f-45c6-8e19-9af6f170d719@googlegroups.com>
In reply to#52476
On Tuesday, November 8, 2016 at 11:03:02 PM UTC-7, trans wrote:
> Are there any statistics on the average swaps per word in Forth code?

When you write a function, the order of the parameters given to the function should be convenient for the caller of the function, not necessarily to the function itself. So, if a SWAP or ROT is needed, it will be inside of the function called, rather than in front of the call to the function every time that the function is called.

Way back in the 1980s, a simple optimization done in ITC systems was to have both DOCOLON and SWAP-DOCOLON written in assembly-language. If a colon word started with SWAP then the SWAP was not compiled, but instead DOCOLON was replaced with SWAP-DOCOLON --- this helped a lot, because most of the time that SWAP was used, it was used only once and at the beginning.

In general, you should have parameters that are typically constants to be on top of parameters that are variable. For example, here is COMBINE from LIST.4TH in my novice-package:

: combine ( head delimiter -- str )    
    swap  <cstr
    each[  .line @ +cstr  dup char+cstr  ]each drop
    1 -cstr                            
    cstr> ;

The delimiter is on top because it is typically a constant, whereas the head (pointer to the head of the SEQ list) will be different every time that COMBINE is used.

You could write a word like this:

: comma-combine ( head -- str )
    [char] , combine ;

This would be good factoring if the comma is the most common delimiter, which is likely.



[toc] | [prev] | [standalone]


Page 5 of 5 — ← Prev page 1 2 3 4 [5]

Back to top | Article view | comp.lang.forth


csiph-web