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


Groups > comp.lang.forth > #133853

Re: LOOP (was: OOS approach revisited)

Newsgroups comp.lang.forth
References <fdbeb48de8ceb748d44c67dc3981a566@www.novabbs.com> <0087b3b084f8af01cf9fb29bf50c389a104e1ffa@i2pn2.org> <mc77onF8d4vU1@mid.individual.net> <2025Jun28.122351@mips.complang.tuwien.ac.at>
From albert@spenarnc.xs4all.nl
Subject Re: LOOP (was: OOS approach revisited)
Message-ID <nnd$46c18462$0d258ebe@fa384eb8eaee39fa> (permalink)
Organization KPN B.V.
Date 2025-06-28 14:26 +0200

Show all headers | View raw


In article <2025Jun28.122351@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>minforth <minforth@gmx.net> writes:
>>Most CPUs have operators for register-based count-down loops
>>that are blazingly fast.
>
>Which "operators" do you have in mind, and what do you mean with
>"blazingly fast".
>
>Anyway, we have discussed this repeatedly, e.g., in
><2022Feb13.231208@mips.complang.tuwien.ac.at> I wrote in reply to your
>posting <f4b89e0b-2ded-4b18-8dc1-bba6dcda47bbn@googlegroups.com>, and
>cited earlier discussions in the topic.
>
>|"minf...@arcor.de" <minforth@arcor.de> writes:
>[...]
>|>F.ex. match NEXT efficiently to x_86 processor LOOP instruction (counter in=
>|> _CX register)
>|>and you'll happily count down from 5 to 1.
>|
>|Yes, but why would one do this?  As we have established in an earlier
>|discussion (see below), the LOOP instruction is typically not faster
>|than a sequence of simpler instructions:
>|
>|<2018Jun6.184616@mips.complang.tuwien.ac.at>:
>||minforth@arcor.de writes:
>||>FOR..NEXT matches easily with the x86 LOOP instruction and ECX as counter.
>||>Should do speedy enough.  ;-)
>||
>||Have you measured it?  I have
>||<2017Mar14.183125@mips.complang.tuwien.ac.at>
>||<2017Mar15.141411@mips.complang.tuwien.ac.at> and compared the
>||following loops:
>||
>||.L5:                            .L5:
>||     subq    $1, %rax            loop    .L5
>||     jne     .L5
>||
>||I found that for these loops Sandy Bridge, Haswell, and Skylake take
>||~4 cycles per iteration using LOOP, and 1-2 cycles per iteration when
>||using jne.
>|
>|<2018Jun7.141731@mips.complang.tuwien.ac.at>:
>||cycles for 1000 iterations
>||  K10        Excavator       Zen
>||Phenom II  Athlon X4 845  Ryzen 1600X
>||  3021        1314            1051     loop
>||  2020        1484            1051     sub; jne
>||  2026        1489            1053     add; cmp; jne
>|
>|There is no performance advantage on modern AMD and Intel CPUs for the
>|instruction LOOP over a good implementation of the Forth word LOOP (as
>|in the third example).
>
>>If they can be used within Forth-based loop constructs
>>I would expect a greater speed increase than what you measured.
>
>You obviously ignore repeated refutations of your claims of superior
>performance for LOOP-instruction-based counted loops.  Maybe you
>should implement and measure such a counted loop yourself and compare
>it to the LOOP word on SwiftForth and VFX Forth.

It is good to remember how the severe CISC instruction came about.
Early Intel processors 8086 were severely cramped in memory space.
While the 16 bit 68000 has a generous 32 bit space, they were restricted
to 16 bit. They added a segmented memory and 1 byte version for two byte
instructions until finally the 386 arrived.
Compiler writers were not inclined to gain (or even loss) a moderate speed
advantage to save a few bytes.
There is more to it.
The first thing e.g. I had to do in my optimiser to expand 1 byte
instructions to not explode the possibilities I had to consider.

>
>- anton

Groetjes Albert
-- 
The Chinese government is satisfied with its military superiority over USA.
The next 5 year plan has as primary goal to advance life expectancy
over 80 years, like Western Europe.

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


Thread

OOS approach revisited zbigniew2011@gmail.com (LIT) - 2025-06-23 05:09 +0000
  Re: OOS approach revisited dxf <dxforth@gmail.com> - 2025-06-24 23:28 +1000
    Re: OOS approach revisited zbigniew2011@gmail.com (LIT) - 2025-06-26 17:27 +0000
      Re: OOS approach revisited minforth@gmx.net (minforth) - 2025-06-27 02:16 +0000
        Re: OOS approach revisited dxf <dxforth@gmail.com> - 2025-06-27 17:29 +1000
          Re: OOS approach revisited minforth <minforth@gmx.net> - 2025-06-27 11:49 +0200
            Re: OOS approach revisited zbigniew2011@gmail.com (LIT) - 2025-06-27 16:55 +0000
              Re: OOS approach revisited albert@spenarnc.xs4all.nl - 2025-06-27 20:15 +0200
                Re: OOS approach revisited minforth <minforth@gmx.net> - 2025-06-27 22:35 +0200
                Re: OOS approach revisited albert@spenarnc.xs4all.nl - 2025-06-28 11:34 +0200
                Re: OOS approach revisited Stephen Pelc <stephen@vfxforth.com> - 2025-06-28 09:37 +0000
              Re: OOS approach revisited dxf <dxforth@gmail.com> - 2025-06-28 12:03 +1000
            LOOP (was: OOS approach revisited) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-06-28 10:23 +0000
              Re: LOOP (was: OOS approach revisited) albert@spenarnc.xs4all.nl - 2025-06-28 14:26 +0200
              Re: LOOP dxf <dxforth@gmail.com> - 2025-06-28 22:41 +1000
                Re: LOOP sean@conman.org - 2025-06-28 20:04 +0000
                Re: LOOP anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-06-28 21:01 +0000
                Re: LOOP minforth@gmx.net (minforth) - 2025-07-03 19:33 +0000
                Re: LOOP Gerry Jackson <do-not-use@swldwa.uk> - 2025-07-07 07:54 +0100
                Re: LOOP minforth <minforth@gmx.net> - 2025-07-07 10:46 +0200
                Re: LOOP dxf <dxforth@gmail.com> - 2025-06-29 13:04 +1000
              Re: LOOP (was: OOS approach revisited) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-06-28 16:04 +0000
        DO..LOOP and stack shuffling (was: OOS approach revisited) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-06-28 17:46 +0000
          Re: DO..LOOP and stack shuffling Hans Bezemer <the.beez.speaks@gmail.com> - 2025-07-01 13:53 +0200
            Re: DO..LOOP and stack shuffling dxf <dxforth@gmail.com> - 2025-07-03 13:59 +1000
            Re: DO..LOOP and stack shuffling anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-07-03 07:50 +0000
        Re: OOS approach revisited Hans Bezemer <the.beez.speaks@gmail.com> - 2025-06-30 15:43 +0200
      Re: OOS approach revisited dxf <dxforth@gmail.com> - 2025-06-27 13:39 +1000

csiph-web