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


Groups > comp.lang.forth > #5542

Re: min-max-sum

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Subject Re: min-max-sum
Newsgroups comp.lang.forth
References <2011Sep4.151850@mips.complang.tuwien.ac.at> <10611399948436@frunobulax.edu>
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Date 2011-09-05 08:16 +0000
Message-ID <2011Sep5.101652@mips.complang.tuwien.ac.at> (permalink)

Show all headers | View raw


mhx@iae.nl (Marcel Hendrix) writes:
>anton@mips.complang.tuwien.ac.at (Anton Ertl) writes Re: min-max-sum
>> Not sure what's so slow in the haley code, but if someone wants to
>> investigate, the code is shown below.
>
>You inadvertedly wrote "loop" instead of "1 cells +loop" :-)

I shouldn't let down my guard when copying from a posting, especially
when the results deviate from expectations.  Thanks for catching
this.

After correcting that (corrected code below) I get:

[c8:~/forth:30521] time vfxlin "include min-max-sum.fs bench-simple bye" >/dev/null

real    0m0.695s
user    0m0.684s
sys     0m0.008s
[c8:~/forth:30522] time vfxlin "include min-max-sum.fs bench-rot bye" >/dev/null
 
real    0m0.432s
user    0m0.420s
sys     0m0.008s
[c8:~/forth:30523] time vfxlin "include min-max-sum.fs bench-haley bye" >/dev/null

real    0m0.603s
user    0m0.592s
sys     0m0.008s

>It is important not to use uninitialized HERE for the test area because
>number formatting may overwrite this area between individual benchmarks 
>(your test method has no problem with it).

I don't expect the actual data to have a significant influence on the
timings, so I ignored that.  Still, the corrected code uses
initialized memory (but there was no significant effect on the
performance).

>What is the specification for the machine you tested on? I used a 2.67 GHz
>i7 quad core. The speed for 64 and 32-bit code is (nearly) the same.

It's a 3GHz Xeon 5450 running vfxlin 4.40.

Here are the inner loops of a few words:

amax:
( 080B9E28    8B1424 )                MOV       EDX, [ESP]
( 080B9E2B    8B0A )                  MOV       ECX, 0 [EDX]
( 080B9E2D    3BD9 )                  CMP       EBX, ECX
( 080B9E2F    0F4CD9 )                CMOVL/NGE EBX, ECX
( 080B9E32    83042404 )              ADD       [ESP], 04
( 080B9E36    8344240404 )            ADD       [ESP+04], 04
( 080B9E3B    71EB )                  JNO       080B9E28

sum-min-max (using rot):
( 080B9FD8    8B1424 )                MOV       EDX, [ESP]
( 080B9FDB    8B0A )                  MOV       ECX, 0 [EDX]
( 080B9FDD    034D04 )                ADD       ECX, [EBP+04]
( 080B9FE0    8B1424 )                MOV       EDX, [ESP]
( 080B9FE3    8B4500 )                MOV       EAX, [EBP]
( 080B9FE6    3B02 )                  CMP       EAX, 0 [EDX]
( 080B9FE8    0F4C02 )                CMOVL/NGE EAX, DWord Ptr 0 [EDX]
( 080B9FEB    8B1424 )                MOV       EDX, [ESP]
( 080B9FEE    8D6DFC )                LEA       EBP, [EBP+-04]
( 080B9FF1    895D00 )                MOV       [EBP], EBX
( 080B9FF4    894504 )                MOV       [EBP+04], EAX
( 080B9FF7    894D08 )                MOV       [EBP+08], ECX
( 080B9FFA    8B1A )                  MOV       EBX, 0 [EDX]
( 080B9FFC    8B5500 )                MOV       EDX, [EBP]
( 080B9FFF    3BDA )                  CMP       EBX, EDX
( 080BA001    0F4FDA )                CMOVNLE/G EBX, EDX
( 080BA004    83042404 )              ADD       [ESP], 04
( 080BA008    8344240404 )            ADD       [ESP+04], 04
( 080BA00D    8D6D04 )                LEA       EBP, [EBP+04]
( 080BA010    71C6 )                  JNO       080B9FD8

haley:
( 080BA180    8B1424 )                MOV       EDX, [ESP]
( 080BA183    8B0A )                  MOV       ECX, 0 [EDX]
( 080BA185    010B )                  ADD       0 [EBX], ECX
( 080BA187    8B1424 )                MOV       EDX, [ESP]
( 080BA18A    8BCB )                  MOV       ECX, EBX
( 080BA18C    83C304 )                ADD       EBX, 04
( 080BA18F    8B03 )                  MOV       EAX, 0 [EBX]
( 080BA191    8D6DF4 )                LEA       EBP, [EBP+-0C]
( 080BA194    894500 )                MOV       [EBP], EAX
( 080BA197    895D04 )                MOV       [EBP+04], EBX
( 080BA19A    894D08 )                MOV       [EBP+08], ECX
( 080BA19D    8B1A )                  MOV       EBX, 0 [EDX]
( 080BA19F    8B5500 )                MOV       EDX, [EBP]
( 080BA1A2    3BDA )                  CMP       EBX, EDX
( 080BA1A4    0F4CDA )                CMOVL/NGE EBX, EDX
( 080BA1A7    8B5504 )                MOV       EDX, [EBP+04]
( 080BA1AA    891A )                  MOV       0 [EDX], EBX
( 080BA1AC    8B1C24 )                MOV       EBX, [ESP]
( 080BA1AF    8B5508 )                MOV       EDX, [EBP+08]
( 080BA1B2    83C208 )                ADD       EDX, 08
( 080BA1B5    8B0A )                  MOV       ECX, 0 [EDX]
( 080BA1B7    8B03 )                  MOV       EAX, 0 [EBX]
( 080BA1B9    3BC8 )                  CMP       ECX, EAX
( 080BA1BB    0F4FC8 )                CMOVNLE/G ECX, EAX
( 080BA1BE    890A )                  MOV       0 [EDX], ECX
( 080BA1C0    83042404 )              ADD       [ESP], 04
( 080BA1C4    8344240404 )            ADD       [ESP+04], 04
( 080BA1C9    8B5D08 )                MOV       EBX, [EBP+08]
( 080BA1CC    8D6D0C )                LEA       EBP, [EBP+0C]
( 080BA1CF    71AF )                  JNO       080BA180

Inlining works nicely in VFX.

And finally, below you find the corrected code.

- anton

0 [if]
time vfxlin "include min-max-sum.fs bench-simple bye" >/dev/null
time vfxlin "include min-max-sum.fs bench-rot bye" >/dev/null
time vfxlin "include min-max-sum.fs bench-haley bye" >/dev/null
[then]
    
: asum ( addr ucells -- n )
    0 rot rot cells over + swap ?do
        i @ +
    [ 1 cells ] literal +loop ;

: amin ( addr ucells -- n )
    $7fffffff rot rot cells over + swap ?do
        i @ min
    [ 1 cells ] literal +loop ;

: amax ( addr ucells -- n )
    $80000000 rot rot cells over + swap ?do
        i @ max
    [ 1 cells ] literal +loop ;

: simple ( addr ucells -- nsum nmax nmin )
    2dup amin >r
    2dup amax >r
    asum r> r> ;

: sum-min-max ( addr ucells -- nsum nmax nmin )
 2>r 0 $80000000 $7fffffff 2r> cells over + swap ?do ( nsum' nmax' nmin' )
  rot i @ +
  rot i @ max
  rot i @ min
 1 cells +loop ;

\ define a struct the VFX way :-)
: f_sum ;
: f_max cell+ ;
: f_min 2 cells + ;

create some-f 3 cells allot

: max! ( n addr -- )
    dup @ rot max swap ! ;

: min! ( n addr -- )
    dup @ rot min swap ! ;
    
: haley ( addr ucells f-addr -- )
    0 over f_sum !
    $80000000 over f_max !
    $7fffffff over f_min !
    rot rot cells over + swap do
        i @ over f_sum +!
        i @ over f_max max!
        i @ over f_min min!
    [ 1 cells ] literal +loop  drop ; 

create a 1000000 cells allot
a 1000000 cells erase

: bench-simple ( -- )
    100 0 ?do
        a 1000000 simple . . . cr
    loop ;

: bench-rot ( -- )
    100 0 ?do
        a 1000000 sum-min-max . . . cr
    loop ;

: bench-haley ( -- )
    100 0 ?do
        a 1000000 some-f haley
    loop ;

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


Thread

A Minimal Extended Control Wordset JennyB <jennybrien@googlemail.com> - 2011-08-24 07:01 -0700
  Re: A Minimal Extended Control Wordset JennyB <jennybrien@googlemail.com> - 2011-08-24 07:50 -0700
    Re: A Minimal Extended Control Wordset Alex McDonald <blog@rivadpm.com> - 2011-08-24 08:04 -0700
      Re: A Minimal Extended Control Wordset JennyB <jennybrien@googlemail.com> - 2011-08-24 08:59 -0700
        Re: A Minimal Extended Control Wordset coos haak <chforth@hccnet.nl> - 2011-08-24 20:00 +0200
          Re: A Minimal Extended Control Wordset JennyB <jennybrien@googlemail.com> - 2011-08-24 14:03 -0700
            Re: A Minimal Extended Control Wordset coos haak <chforth@hccnet.nl> - 2011-08-26 20:36 +0200
    Re: A Minimal Extended Control Wordset JennyB <jennybrien@googlemail.com> - 2011-08-24 07:54 -0700
    Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-09-12 09:43 -0700
  Re: A Minimal Extended Control Wordset "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2011-08-24 18:52 -0400
    Re: A Minimal Extended Control Wordset JennyB <jennybrien@googlemail.com> - 2011-08-25 06:52 -0700
      Re: A Minimal Extended Control Wordset "Ed" <nospam@invalid.com> - 2011-08-26 12:23 +1000
        Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-08-25 21:03 -0700
          Re: A Minimal Extended Control Wordset "Ed" <nospam@invalid.com> - 2011-08-26 20:02 +1000
            Re: A Minimal Extended Control Wordset JennyB <jennybrien@googlemail.com> - 2011-08-26 04:36 -0700
              Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-08-26 10:42 -0700
                Re: A Minimal Extended Control Wordset JennyB <jennybrien@googlemail.com> - 2011-08-27 14:45 -0700
                Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-08-27 17:13 -0700
            Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-08-26 10:16 -0700
  Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-08-25 09:46 -0700
    Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-08-25 20:54 -0700
      Re: A Minimal Extended Control Wordset JennyB <jennybrien@googlemail.com> - 2011-08-26 10:24 -0700
        Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-08-26 11:04 -0700
          Re: A Minimal Extended Control Wordset JennyB <jennybrien@googlemail.com> - 2011-08-31 04:14 -0700
            Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-08-31 15:25 -0700
              Re: A Minimal Extended Control Wordset JennyB <jennybrien@googlemail.com> - 2011-09-01 04:00 -0700
                Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-09-01 12:47 -0700
        Re: A Minimal Extended Control Wordset "Ed" <nospam@invalid.com> - 2011-08-27 13:18 +1000
          Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-08-27 04:41 -0700
            Re: A Minimal Extended Control Wordset "Ed" <nospam@invalid.com> - 2011-08-28 13:28 +1000
              Re: A Minimal Extended Control Wordset "Elizabeth D. Rather" <erather@forth.com> - 2011-08-27 18:32 -1000
                Re: A Minimal Extended Control Wordset "Ed" <nospam@invalid.com> - 2011-08-29 12:32 +1000
              Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-08-28 09:22 -0700
                Re: A Minimal Extended Control Wordset "Ed" <nospam@invalid.com> - 2011-08-29 12:30 +1000
                Re: A Minimal Extended Control Wordset "Elizabeth D. Rather" <erather@forth.com> - 2011-08-28 18:17 -1000
                return address manipulation (was: A Minimal Extended Control Wordset) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2011-08-29 09:14 +0000
                Re: return address manipulation Andrew Haley <andrew29@littlepinkcloud.invalid> - 2011-08-29 05:53 -0500
                Re: return address manipulation anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2011-08-29 11:45 +0000
                Re: A Minimal Extended Control Wordset "Ed" <nospam@invalid.com> - 2011-08-30 14:08 +1000
                Re: A Minimal Extended Control Wordset "Elizabeth D. Rather" <erather@forth.com> - 2011-08-29 18:28 -1000
                Re: A Minimal Extended Control Wordset "Ed" <nospam@invalid.com> - 2011-08-31 13:52 +1000
                Re: A Minimal Extended Control Wordset "Elizabeth D. Rather" <erather@forth.com> - 2011-08-30 21:42 -1000
                Re: A Minimal Extended Control Wordset Paul Rubin <no.email@nospam.invalid> - 2011-08-31 00:47 -0700
                Re: A Minimal Extended Control Wordset "Elizabeth D. Rather" <erather@forth.com> - 2011-08-30 21:55 -1000
                Re: A Minimal Extended Control Wordset Paul Rubin <no.email@nospam.invalid> - 2011-09-01 00:44 -0700
                Re: A Minimal Extended Control Wordset Andrew Haley <andrew29@littlepinkcloud.invalid> - 2011-09-01 03:37 -0500
                Re: A Minimal Extended Control Wordset Paul Rubin <no.email@nospam.invalid> - 2011-09-01 02:19 -0700
                Re: A Minimal Extended Control Wordset Andrew Haley <andrew29@littlepinkcloud.invalid> - 2011-09-01 05:05 -0500
                min-max-sum (was: A Minimal Extended Control Wordset) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2011-09-01 14:32 +0000
                Re: min-max-sum Andrew Haley <andrew29@littlepinkcloud.invalid> - 2011-09-01 10:43 -0500
                Re: min-max-sum anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2011-09-01 15:59 +0000
                Re: min-max-sum BruceMcF <agila61@netscape.net> - 2011-09-01 13:13 -0700
                Re: min-max-sum Andrew Haley <andrew29@littlepinkcloud.invalid> - 2011-09-02 04:12 -0500
                Re: min-max-sum Andrew Haley <andrew29@littlepinkcloud.invalid> - 2011-09-02 04:31 -0500
                Re: min-max-sum anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2011-09-02 10:41 +0000
                Re: min-max-sum Andrew Haley <andrew29@littlepinkcloud.invalid> - 2011-09-02 06:31 -0500
                Re: min-max-sum anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2011-09-04 13:18 +0000
                Re: min-max-sum mhx@iae.nl (Marcel Hendrix) - 2011-09-04 22:42 +0200
                Re: min-max-sum anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2011-09-05 08:16 +0000
                Re: min-max-sum Andrew Haley <andrew29@littlepinkcloud.invalid> - 2011-09-05 02:58 -0500
                Re: min-max-sum BruceMcF <agila61@netscape.net> - 2011-09-02 08:43 -0700
                Re: min-max-sum coos haak <chforth@hccnet.nl> - 2011-09-02 20:35 +0200
                Re: min-max-sum BruceMcF <agila61@netscape.net> - 2011-09-03 11:48 -0700
                Re: min-max-sum BruceMcF <agila61@netscape.net> - 2011-09-04 18:31 -0700
                Re: min-max-sum Alex McDonald <blog@rivadpm.com> - 2011-09-02 05:37 -0700
                Re: min-max-sum mhx@iae.nl (Marcel Hendrix) - 2011-09-03 12:06 +0200
                Re: A Minimal Extended Control Wordset Paul Rubin <no.email@nospam.invalid> - 2011-09-04 22:07 -0700
                Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-09-04 22:56 -0700
                Re: A Minimal Extended Control Wordset C G Montgomery <cgm@physics.utoledo.edu> - 2011-09-05 17:44 -0400
                Re: A Minimal Extended Control Wordset Paul Rubin <no.email@nospam.invalid> - 2011-09-05 18:10 -0700
                Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-09-01 11:01 -0700
                Re: A Minimal Extended Control Wordset "Elizabeth D. Rather" <erather@forth.com> - 2011-09-01 09:17 -1000
                Re: A Minimal Extended Control Wordset "Ed" <nospam@invalid.com> - 2011-09-01 13:39 +1000
                Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-09-01 10:21 -0700
                Re: A Minimal Extended Control Wordset "Ed" <nospam@invalid.com> - 2011-09-05 12:24 +1000
                Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-09-04 21:11 -0700
                Re: A Minimal Extended Control Wordset Albert van der Horst <albert@spenarnc.xs4all.nl> - 2011-09-06 18:13 +0000
                Re: A Minimal Extended Control Wordset Alex McDonald <blog@rivadpm.com> - 2011-09-06 12:15 -0700
                Re: A Minimal Extended Control Wordset "Elizabeth D. Rather" <erather@forth.com> - 2011-09-06 09:53 -1000
                Re: A Minimal Extended Control Wordset Alex McDonald <blog@rivadpm.com> - 2011-09-06 14:18 -0700
                Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-09-06 17:32 -0700
                Re: A Minimal Extended Control Wordset "Ed" <nospam@invalid.com> - 2011-09-07 19:43 +1000
                Re: A Minimal Extended Control Wordset Andrew Haley <andrew29@littlepinkcloud.invalid> - 2011-09-07 06:02 -0500
                Re: A Minimal Extended Control Wordset Alex McDonald <blog@rivadpm.com> - 2011-09-07 05:41 -0700
                Re: A Minimal Extended Control Wordset anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2011-09-07 16:00 +0000
                Re: A Minimal Extended Control Wordset "Ed" <nospam@invalid.com> - 2011-09-09 08:52 +1000
                Re: A Minimal Extended Control Wordset Alex McDonald <blog@rivadpm.com> - 2011-09-08 16:08 -0700
                Re: A Minimal Extended Control Wordset George Hubert <georgeahubert@yahoo.co.uk> - 2011-09-09 04:12 -0700
                Re: A Minimal Extended Control Wordset Albert van der Horst <albert@spenarnc.xs4all.nl> - 2011-09-10 09:09 +0000
                Re: A Minimal Extended Control Wordset "Ed" <nospam@invalid.com> - 2011-09-11 18:29 +1000
                Re: A Minimal Extended Control Wordset Alex McDonald <blog@rivadpm.com> - 2011-09-11 09:04 -0700
                Re: A Minimal Extended Control Wordset "Ed" <nospam@invalid.com> - 2011-09-15 19:25 +1000
                Re: A Minimal Extended Control Wordset Alex McDonald <blog@rivadpm.com> - 2011-09-15 03:30 -0700
                Re: A Minimal Extended Control Wordset "Ed" <nospam@invalid.com> - 2011-09-18 15:43 +1000
                Re: A Minimal Extended Control Wordset "Elizabeth D. Rather" <erather@forth.com> - 2011-09-17 20:42 -1000
                Re: A Minimal Extended Control Wordset "Ed" <nospam@invalid.com> - 2011-09-19 05:14 +1000
                Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-09-18 19:31 -0700
                Re: A Minimal Extended Control Wordset Andrew Haley <andrew29@littlepinkcloud.invalid> - 2011-09-18 01:49 -0500
                Re: A Minimal Extended Control Wordset "Elizabeth D. Rather" <erather@forth.com> - 2011-09-08 14:56 -1000
                Re: A Minimal Extended Control Wordset anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2011-09-09 08:20 +0000
                Re: A Minimal Extended Control Wordset "Ed" <nospam@invalid.com> - 2011-09-11 16:22 +1000
                Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-09-11 03:06 -0700
                Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-09-08 19:29 -0700
                Re: A Minimal Extended Control Wordset Brad <hwfwguy@gmail.com> - 2011-09-08 08:58 -0700
                Re: A Minimal Extended Control Wordset Alex McDonald <blog@rivadpm.com> - 2011-09-08 10:00 -0700
                Re: A Minimal Extended Control Wordset coos haak <chforth@hccnet.nl> - 2011-09-08 22:00 +0200
                Re: A Minimal Extended Control Wordset Alex McDonald <blog@rivadpm.com> - 2011-09-08 16:02 -0700
                Re: A Minimal Extended Control Wordset "Ed" <nospam@invalid.com> - 2011-09-09 09:16 +1000
                Re: A Minimal Extended Control Wordset "Elizabeth D. Rather" <erather@forth.com> - 2011-09-08 15:04 -1000
                Re: A Minimal Extended Control Wordset Andrew Haley <andrew29@littlepinkcloud.invalid> - 2011-09-09 04:13 -0500
                Re: A Minimal Extended Control Wordset Brad <hwfwguy@gmail.com> - 2011-08-31 09:20 -0700
                Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-08-28 21:31 -0700
                Re: A Minimal Extended Control Wordset "Ed" <nospam@invalid.com> - 2011-08-31 13:53 +1000
                Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-08-31 04:11 -0700
                Re: A Minimal Extended Control Wordset "Ed" <nospam@invalid.com> - 2011-09-01 14:47 +1000
                Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-09-01 10:32 -0700
                Re: A Minimal Extended Control Wordset BruceMcF <agila61@netscape.net> - 2011-09-01 10:33 -0700

csiph-web