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


Groups > comp.lang.forth > #54613

Re: CASEs compared

From "HAA" <someone@microsoft.com>
Newsgroups comp.lang.forth
Subject Re: CASEs compared
Date 2017-02-04 12:39 +1100
Organization Aioe.org NNTP Server
Message-ID <o73bhd$h72$1@gioia.aioe.org> (permalink)
References <o6n8ad$191s$1@gioia.aioe.org><2017Jan30.165616@mips.complang.tuwien.ac.at><097d4d65-5777-4dae-b1b8-6210d2807fc4@googlegroups.com><o6p01r$3sb$2@gioia.aioe.org><fb35470d-27ba-4bc2-8ad6-e05404cd2b79@googlegroups.com><o6ralk$26n$1@gioia.aioe.org><c11c660a-9699-423a-abce-9aaf0ae48b6a@googlegroups.com><3ba54b8a-380a-4fc5-84d7-80271d7cd313@googlegroups.com><o6v0nr$1id1$1@gioia.aioe.org> <o70kdn$j50$1@dont-email.me>

Show all headers | View raw


rickman wrote:
> On 2/2/2017 5:12 AM, HAA wrote:
> > ...
> > Having the selector left on the stack when all comparisons fail seems natural and
> > can be useful.  What gets in the way is ENDCASE wanting to DROP it for you.
>
> I've thought the same thing.  Would it make sense for the selector to be
> held on the return stack so that it can be be accessible and out of the
> way?  Every iteration of "OF" requires an OVER for the comparison, R@
> isn't really any harder and the ENDCASE still removes it.  In fact,
> rather than have OF remove the selector with a DROP, it can be left on
> the return stack until jumping to the ENDCASE where it is removed.  That
> saves a bit of code.  It would be a change to the standard of course.

See below.  Newer versions of VFX may do better but in general it's faster to test
against items on the data stack than return stack.  For native code optimizers DROP
can disappear - unlike R> DROP.  Hence the expected code saving never materialized.

: CASE1  0 ; immediate
: OF1  postpone over  postpone =  postpone if  postpone drop ; immediate
: ENDCASE1  postpone drop  begin ?dup while postpone then repeat ; immediate

: CASE2  postpone >r  0 ; immediate
: OF2  postpone r@  postpone =  postpone if ; immediate
: ENDCASE2  begin ?dup while postpone then repeat  postpone r>  postpone drop ; immediate

: ENDOF  postpone else ; immediate

: test1  case1
    1  of1  8  endof
    2  of1  9  endof
    3  of1  10  endof
    dup
  endcase1 ;

: test2   case2
    1  of2  8  endof
    2  of2  9  endof
    3  of2  10  endof
    r@
  endcase2 ;

see test1
TEST1
( 004AB110    83FB01 )                CMP       EBX, 01
( 004AB113    0F850A000000 )          JNZ/NE    004AB123
( 004AB119    BB08000000 )            MOV       EBX, 00000008
( 004AB11E    E926000000 )            JMP       004AB149
( 004AB123    83FB02 )                CMP       EBX, 02
( 004AB126    0F850A000000 )          JNZ/NE    004AB136
( 004AB12C    BB09000000 )            MOV       EBX, 00000009
( 004AB131    E913000000 )            JMP       004AB149
( 004AB136    83FB03 )                CMP       EBX, 03
( 004AB139    0F850A000000 )          JNZ/NE    004AB149
( 004AB13F    BB0A000000 )            MOV       EBX, 0000000A
( 004AB144    E900000000 )            JMP       004AB149
( 004AB149    C3 )                    NEXT,
( 58 bytes, 13 instructions )
 ok

see test2
TEST2
( 004AB170    53 )                    PUSH      EBX
( 004AB171    8B1C24 )                MOV       EBX, [ESP]
( 004AB174    83FB01 )                CMP       EBX, 01
( 004AB177    8B5D00 )                MOV       EBX, [EBP]
( 004AB17A    8D6D04 )                LEA       EBP, [EBP+04]
( 004AB17D    0F8510000000 )          JNZ/NE    004AB193
( 004AB183    8D6DFC )                LEA       EBP, [EBP+-04]
( 004AB186    895D00 )                MOV       [EBP], EBX
( 004AB189    BB08000000 )            MOV       EBX, 00000008
( 004AB18E    E943000000 )            JMP       004AB1D6
( 004AB193    8B1424 )                MOV       EDX, [ESP]
( 004AB196    83FA02 )                CMP       EDX, 02
( 004AB199    0F8510000000 )          JNZ/NE    004AB1AF
( 004AB19F    8D6DFC )                LEA       EBP, [EBP+-04]
( 004AB1A2    895D00 )                MOV       [EBP], EBX
( 004AB1A5    BB09000000 )            MOV       EBX, 00000009
( 004AB1AA    E927000000 )            JMP       004AB1D6
( 004AB1AF    8B1424 )                MOV       EDX, [ESP]
( 004AB1B2    83FA03 )                CMP       EDX, 03
( 004AB1B5    0F8510000000 )          JNZ/NE    004AB1CB
( 004AB1BB    8D6DFC )                LEA       EBP, [EBP+-04]
( 004AB1BE    895D00 )                MOV       [EBP], EBX
( 004AB1C1    BB0A000000 )            MOV       EBX, 0000000A
( 004AB1C6    E90B000000 )            JMP       004AB1D6
( 004AB1CB    8B1424 )                MOV       EDX, [ESP]
( 004AB1CE    8D6DFC )                LEA       EBP, [EBP+-04]
( 004AB1D1    895D00 )                MOV       [EBP], EBX
( 004AB1D4    8BDA )                  MOV       EBX, EDX
( 004AB1D6    8D642404 )              LEA       ESP, [ESP+04]
( 004AB1DA    C3 )                    NEXT,
( 107 bytes, 30 instructions )
 ok


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


Thread

CASEs compared "HAA" <someone@microsoft.com> - 2017-01-30 22:34 +1100
  Re: CASEs compared anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-01-30 15:56 +0000
    Re: CASEs compared hughaguilar96@gmail.com - 2017-01-30 09:57 -0800
      Re: CASEs compared "HAA" <someone@microsoft.com> - 2017-01-31 14:26 +1100
        Re: CASEs compared hughaguilar96@gmail.com - 2017-01-31 08:12 -0800
          Re: CASEs compared "HAA" <someone@microsoft.com> - 2017-02-01 11:39 +1100
            Re: CASEs compared hughaguilar96@gmail.com - 2017-01-31 22:37 -0800
              Re: CASEs compared hughaguilar96@gmail.com - 2017-02-01 12:26 -0800
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-01 16:50 -0800
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-01 18:02 -0800
                Re: CASEs compared "HAA" <someone@microsoft.com> - 2017-02-02 21:12 +1100
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-02 13:46 -0800
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-02 17:01 -0800
                Re: CASEs compared "HAA" <someone@microsoft.com> - 2017-02-04 12:43 +1100
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-03 17:52 -0800
                Re: CASEs compared Alex <alex@rivadpm.com> - 2017-02-04 11:10 +0000
                Re: CASEs compared rickman <gnuarm@gmail.com> - 2017-02-02 19:57 -0500
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-02 17:05 -0800
                Re: CASEs compared rickman <gnuarm@gmail.com> - 2017-02-02 21:55 -0500
                Re: CASEs compared Mark Wills <markwills1970@gmail.com> - 2017-02-03 02:11 -0800
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-03 10:52 -0800
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-03 17:38 -0800
                Re: CASEs compared rickman <gnuarm@gmail.com> - 2017-02-03 22:08 -0500
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-03 21:40 -0800
                Re: CASEs compared rickman <gnuarm@gmail.com> - 2017-02-04 01:16 -0500
                Re: CASEs compared rickman <gnuarm@gmail.com> - 2017-02-03 14:40 -0500
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-03 17:47 -0800
                Re: CASEs compared rickman <gnuarm@gmail.com> - 2017-02-03 22:04 -0500
                Re: CASEs compared "HAA" <someone@microsoft.com> - 2017-02-04 12:39 +1100
                Re: CASEs compared rickman <gnuarm@gmail.com> - 2017-02-03 23:32 -0500
                Re: CASEs compared "HAA" <someone@microsoft.com> - 2017-02-04 22:50 +1100
                Re: CASEs compared rickman <gnuarm@gmail.com> - 2017-02-04 11:07 -0500
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-04 08:48 -0800
                Re: CASEs compared Mark Wills <markwills1970@gmail.com> - 2017-02-04 10:01 -0800
                Re: CASEs compared rickman <gnuarm@gmail.com> - 2017-02-04 16:43 -0500
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-04 18:53 -0800
                Re: CASEs compared "HAA" <someone@microsoft.com> - 2017-02-05 19:12 +1100
    Re: CASEs compared "HAA" <someone@microsoft.com> - 2017-01-31 14:25 +1100
  Re: CASEs compared Elliott Chapin <elliott.chapin@gmail.com> - 2017-02-05 08:25 -0800
    Re: CASEs compared Coos Haak <htrofhc@gmail.com> - 2017-02-06 00:42 +0100
  Re: CASEs compared jacko <jackokring@gmail.com> - 2017-02-16 17:46 -0800
    Re: CASEs compared hughaguilar96@gmail.com - 2017-02-17 09:09 -0800

csiph-web