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


Groups > comp.lang.forth > #21646

Re: Portability

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups comp.lang.forth
Subject Re: Portability
Date 2013-04-13 11:59 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2013Apr13.135920@mips.complang.tuwien.ac.at> (permalink)
References (1 earlier) <gLGdnaPZpbm3TPrMnZ2dnUVZ_qydnZ2d@supernews.com> <2013Apr12.154339@mips.complang.tuwien.ac.at> <D4SdnUAv5-fwrPXMnZ2dnUVZ_vydnZ2d@supernews.com> <5168577e$0$26887$e4fe514c@dreader37.news.xs4all.nl> <qaCdnRznMZtugPTMnZ2dnUVZ_s6dnZ2d@supernews.com>

Show all headers | View raw


Andrew Haley <andrew29@littlepinkcloud.invalid> writes:
>Albert van der Horst <albert@spenarnc.xs4all.nl> wrote:
>> In article <D4SdnUAv5-fwrPXMnZ2dnUVZ_vydnZ2d@supernews.com>,
>> Andrew Haley  <andrew29@littlepinkcloud.invalid> wrote:
>>>Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>>>> Andrew Haley <andrew29@littlepinkcloud.invalid> writes:
>>>>>Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>>>>>> Andrew Haley <andrew29@littlepinkcloud.invalid> writes:
>>>>>>>Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>>>>>>>> Andrew Haley <andrew29@littlepinkcloud.invalid> writes:
>>>>>>>>>Albert van der Horst <albert@spenarnc.xs4all.nl> wrote:
>>>>>>>>>> It clearly states that < is supposed
>>>>>>>>>> to work on signed numbers. So the behaviour you describe would be a
>>>>>>>>>> defect ("or bug") as in "deviation from the specification".
>>>>>>>>>
>>>>>>>>>Not really, no, any more than this is a deviation from the
>>>>>>>>>specification:
>>>>>>>>>
>>>>>>>>>2147483647 dup + . -2  ok
...
>>>fig-FORTH's actual < is
>>>
>>>: <   - 0<  ;
>>>
>>>I'm looking at the original source code.
>> 
>> Okay. It is a curious historical side note.
>> I've looked into 6 or 7 versions (mostly even in print) and they
>> differ from this.
>
>Sure, but it's the fig-FORTH model (for 6502, written in Forth) on
>which all the others were based

So the first implementation contained a bug, or they would not have
changed it.  So they did not share your idea that it is "not really,
no" a bug.

Although, looking at two versions, the code looks still funny:

6502 v1.1:

L1254     .BYTE $81,$BC
          .WORD L1246    ; link to U<
LESS      .WORD *+2
          SEC
          LDA 2,X
          SBC 0,X        ; subtract
          LDA 3,X
          SBC 1,X
          STY 3,X        ; zero high byte
          BVC L1258
          EOR #$80       ; correct overflow
L1258     BPL L1260
          INY            ; invert boolean
L1260     STY 2,X        ; leave boolean
          JMP POP

8086 v1.0:
       DB   81H
       DB   '<'+80H
       DW   EQUAL-4
LESS   DW   $+2
       POP  DX
       POP  AX
       MOV  BX,DX
       XOR  BX,AX    ; T E S T FOR EQUAL S I G N S
       JS   LES1    ; SIGNS NOT T H E SAME
       SUB  AX,DX
LES 1: OR   AX, AX   ; TEST SIGN S I T
       MOV  AX ,0    ; ASSUME FALSE C O N D I T I O N
       JNS  LES2     ; NOT L E S S TEEN
       INC  AX       ; TRUE (1)
LES2:  JMP  APUSH

It seems the authors did not like the cmp instructions of these
architectures.  I am not sure that these implementations are correct.
Correct implementations that are shorter are certainly possible.

What's even funnier is:

6502 v1.1:

;                                       U<
;                                       Unsigned less than
;
L1246     .BYTE $82,'U',$BC
          .WORD L1244    ; link to =
ULESS     .WORD DOCOL
          .WORD SUB      ; subtract two values
          .WORD ZLESS    ; test sign
          .WORD SEMIS

Why have U< if you are implementing circular comparison?  And vice
versa, why implement U< as circular comparison?

Concerning your integer overflow argument, I found this within two
minutes of reading the "Installation Manual and Glossary"
<http://www.forth.org/fig-forth/contents.html>:

|Unless otherwise noted, all references to numbers are for 16 bit signed
|integers. [...]
|
|All arithmetic is implicitly 16 bit signed integer math, with error and
|under-flow indication unspecified.

So wraparound on overflow is compliant with the specification,
circular comparison for < is not.

- 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

 Portability kenney@cix.compulink.co.uk - 2013-04-06 04:12 -0500
  Re: Portability albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-04-06 11:31 +0000
    Re: Portability "Elizabeth D. Rather" <erather@forth.com> - 2013-04-06 10:34 -1000
      Re: Portability "Ed" <invalid@nospam.com> - 2013-04-09 09:56 +1000
        Re: Portability albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-04-09 01:30 +0000
          Re: Portability anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-04-09 07:21 +0000
            Re: Portability "Elizabeth D. Rather" <erather@forth.com> - 2013-04-08 22:18 -1000
              Re: Portability anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-04-09 12:41 +0000
                Re: Portability Coos Haak <chforth@hccnet.nl> - 2013-04-09 17:21 +0200
                Re: Portability "Elizabeth D. Rather" <erather@forth.com> - 2013-04-09 08:06 -1000
                Re: Portability Bernd Paysan <bernd.paysan@gmx.de> - 2013-04-09 22:34 +0200
                Re: Portability "Elizabeth D. Rather" <erather@forth.com> - 2013-04-09 12:05 -1000
                Re: Portability "Elizabeth D. Rather" <erather@forth.com> - 2013-04-09 14:19 -1000
                Re: Portability Chris <xrissmith@me.com> - 2013-04-09 20:45 -0700
                Re: Portability "Ed" <invalid@nospam.com> - 2013-04-10 14:02 +1000
                Re: Portability Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-04-09 23:00 -0700
                Re: Portability "WJ" <w_a_x_man@yahoo.com> - 2013-04-12 14:41 +0000
                Re: Portability "Ed" <invalid@nospam.com> - 2013-04-13 15:34 +1000
                Re: Portability anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-04-10 15:19 +0000
                Re: Portability albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-04-10 11:46 +0000
                Re: Portability anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-04-10 15:03 +0000
                Re: Portability Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-04-09 18:28 -0700
            Re: Portability Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-04-09 17:00 -0700
          Re: Portability "Ed" <invalid@nospam.com> - 2013-04-10 13:00 +1000
            Re: Portability albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-04-10 11:55 +0000
              Re: Portability Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-10 10:10 -0500
                Re: Portability anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-04-10 15:56 +0000
                Re: Portability Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-10 16:18 -0500
                Re: Portability anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-04-11 13:24 +0000
                Re: Portability Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-04-11 20:50 -0700
                Re: Portability Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-12 04:17 -0500
                Re: Portability anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-04-12 13:43 +0000
                Re: Portability Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-12 11:08 -0500
                Re: Portability albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-04-12 18:50 +0000
                Re: Portability Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-13 03:57 -0500
                Re: Portability anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-04-13 11:59 +0000
                Re: Portability Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-13 14:47 -0500
                Re: Portability rickman <gnuarm@gmail.com> - 2013-04-12 10:44 -0400
                Re: Portability Bernd Paysan <bernd.paysan@gmx.de> - 2013-04-15 16:20 +0200
                Re: Portability "Elizabeth D. Rather" <erather@forth.com> - 2013-04-16 08:12 -1000
                Re: Portability "A.K." <akk@nospam.org> - 2013-04-16 22:21 +0200
                Re: Portability Bernd Paysan <bernd.paysan@gmx.de> - 2013-04-16 22:33 +0200
                Re: Portability "Ed" <invalid@nospam.com> - 2013-04-19 15:04 +1000
                Re: Portability anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-04-15 15:46 +0000
                Re: Portability Sieur de Bienville <morrimichael@gmail.com> - 2013-04-15 19:19 -0700
                Re: Portability anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-04-16 12:53 +0000
                Re: Portability rickman <gnuarm@gmail.com> - 2013-04-16 17:29 -0400
                Re: Portability "Elizabeth D. Rather" <erather@forth.com> - 2013-04-16 11:44 -1000
                Re: Portability rickman <gnuarm@gmail.com> - 2013-04-16 18:00 -0400
                Re: Portability Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-16 17:33 -0500
                Re: Portability "Elizabeth D. Rather" <erather@forth.com> - 2013-04-16 12:46 -1000
                Re: Portability rickman <gnuarm@gmail.com> - 2013-04-17 13:09 -0400
                Re: Portability Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-17 12:20 -0500
                Re: Portability "Elizabeth D. Rather" <erather@forth.com> - 2013-04-17 07:38 -1000
                Re: Portability Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-17 16:43 -0500
                Re: Portability rickman <gnuarm@gmail.com> - 2013-04-17 20:03 -0400
                Re: Portability Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-18 16:53 -0500
                Re: Portability rickman <gnuarm@gmail.com> - 2013-04-18 18:02 -0400
                Re: Portability Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-19 03:30 -0500
                Re: Portability rickman <gnuarm@gmail.com> - 2013-04-19 15:31 -0400
                Re: Portability anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-04-22 09:59 +0000
                Re: Portability Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-22 07:28 -0500
                Re: Portability anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-04-22 15:27 +0000
                Re: Portability Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-04-22 18:16 -0700
                Re: Portability anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-04-17 10:23 +0000
                Re: Portability rickman <gnuarm@gmail.com> - 2013-04-17 13:46 -0400
                Re: Portability anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-04-22 09:47 +0000
                Re: Portability Brad Eckert <hwfwguy@gmail.com> - 2013-04-17 10:32 -0700
                Re: Portability nobody@nowhere - 2013-04-17 17:36 +0000
                Re: Portability rickman <gnuarm@gmail.com> - 2013-04-17 14:21 -0400
                Re: Portability Brad Eckert <hwfwguy@gmail.com> - 2013-04-17 15:03 -0700
                Re: Portability rickman <gnuarm@gmail.com> - 2013-04-17 18:22 -0400
                Re: Portability rickman <gnuarm@gmail.com> - 2013-04-17 18:24 -0400
                Re: Portability rickman <gnuarm@gmail.com> - 2013-04-18 00:51 -0400
                Re: Portability rickman <gnuarm@gmail.com> - 2013-04-18 17:19 -0400
                Re: Portability Brad Eckert <hwfwguy@gmail.com> - 2013-04-19 12:37 -0700
                Re: Portability rickman <gnuarm@gmail.com> - 2013-04-19 15:53 -0400
                Re: Portability Lars Brinkhoff <lars.spam@nocrew.org> - 2013-04-17 19:26 +0200
                Re: Portability albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-04-10 18:50 +0000
                Re: Portability Bernd Paysan <bernd.paysan@gmx.de> - 2013-04-10 22:14 +0200
                Re: Portability Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-12 04:18 -0500
                Re: Portability "Elizabeth D. Rather" <erather@forth.com> - 2013-04-12 08:30 -1000
                Re: Portability albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-04-12 18:58 +0000
                Re: Portability "Elizabeth D. Rather" <erather@forth.com> - 2013-04-12 11:29 -1000
              Re: Portability "Ed" <invalid@nospam.com> - 2013-04-13 14:57 +1000
        Re: Portability Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-09 04:11 -0500

csiph-web