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


Groups > comp.lang.forth > #52509

Re: Average swaps per word?

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups comp.lang.forth
Subject Re: Average swaps per word?
Date 2016-11-10 16:05 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2016Nov10.170526@mips.complang.tuwien.ac.at> (permalink)
References (2 earlier) <o00i0v$1a87$1@gioia.aioe.org> <MPG.328e67bb4a0d0409896bd@news.virginmedia.com> <5053a4d7-1c90-4363-a5e4-948ead174bf9@googlegroups.com> <MPG.328e7c0a1976ce569896be@news.virginmedia.com> <3e4d5545-6477-41fd-96d8-fc814f789cdc@googlegroups.com>

Show all headers | View raw


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/

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


Thread

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

csiph-web