Recent

Author Topic: FFS: step  (Read 2964 times)

BeniBela

  • Hero Member
  • *****
  • Posts: 948
    • homepage
Re: FFS: step
« Reply #15 on: August 07, 2025, 01:17:52 am »
But the while loop is three to four times faster than the enumerator

See the assembler examples above.  Adding "step" to the statement makes zero change to the compiled code.

Not sure why you believe a while loop would be faster.

I was comparing alpine's enumerator with Fred's while loop

jamie

  • Hero Member
  • *****
  • Posts: 7400
Re: FFS: step
« Reply #16 on: August 07, 2025, 02:17:42 am »

for i := 0 to 100 step 5 do


PLEASE!!!!

Having to work around the lack of a 'step' in for loops is inelegant, inefficient and prone to error.

 It was left out of the language to save you and others like yourself from themselves!

 The extra processing needed to decide what to do with remainder when the Step size is not evenly divisible.

 Using more control techniques allows a coder to decide what to do with the remainder, throw it out in last week's trash or
donate the remainder to a worthy cause!

 The Step-For loop leaves you hanging with only one choice, throw it out since you are not supposed to use the counter variable outside the loop!

  Just think about the use of DOWNTO with a non-divisible step! They have transportation busses for those types of coders, there normally licking the windows! :o

 Jamie

The only true wisdom is knowing you know nothing

AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 407
  • My software never cras....
Re: FFS: step
« Reply #17 on: August 07, 2025, 02:31:41 am »

for i := 0 to 100 step 5 do


PLEASE!!!!

Having to work around the lack of a 'step' in for loops is inelegant, inefficient and prone to error.

 It was left out of the language to save you and others like yourself from themselves!

 The extra processing needed to decide what to do with remainder when the Step size is not evenly divisible.

 Using more control techniques allows a coder to decide what to do with the remainder, throw it out in last week's trash or
donate the remainder to a worthy cause!

 The Step-For loop leaves you hanging with only one choice, throw it out since you are not supposed to use the counter variable outside the loop!

  Just think about the use of DOWNTO with a non-divisible step! They have transportation busses for those types of coders, there normally licking the windows! :o

 Jamie

Thank you for the attempts at humour - don't wait by the phone - Vegas will not be calling.

Really? So why did Wirth include it in Modula-2?
Why is it in uber-efficient C?
Rust?
etc.

Remainder?

Coders are smart enough to:
- make the end condition a "landing" value of the variable, or
- know that in most cases it is as inconsequential as it would be in a similarly set up while/repeat loop

/Beast.
Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 407
  • My software never cras....
Re: FFS: step
« Reply #18 on: August 07, 2025, 02:33:16 am »

I was comparing alpine's enumerator with Fred's while loop

Whooshed right over me as those examples are, well, pretty much proof that Pascal needs to step up its for play.

Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

Fred vS

  • Hero Member
  • *****
  • Posts: 3720
    • StrumPract is the musicians best friend
Re: FFS: step
« Reply #19 on: August 07, 2025, 02:46:07 am »
Pascal needs to step up its for play.

Maybe but definitely not associated with for ... to/downto ... do.
« Last Edit: August 07, 2025, 02:58:01 am by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 3720
    • StrumPract is the musicians best friend
Re: FFS: step
« Reply #20 on: August 07, 2025, 03:05:37 am »
Really? So why did Wirth include it in Modula-2?

No, sorry but STEP is not defined in Modula-2 (but there is BY that has same idea).

« Last Edit: August 07, 2025, 03:07:37 am by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 407
  • My software never cras....
Re: FFS: step
« Reply #21 on: August 07, 2025, 11:20:13 pm »
Really? So why did Wirth include it in Modula-2?

No, sorry but STEP is not defined in Modula-2 (but there is BY that has same idea).

You're quibbling - the notion is exactly the same.
Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

Fred vS

  • Hero Member
  • *****
  • Posts: 3720
    • StrumPract is the musicians best friend
Re: FFS: step
« Reply #22 on: August 07, 2025, 11:42:51 pm »
Really? So why did Wirth include it in Modula-2?

No, sorry but STEP is not defined in Modula-2 (but there is BY that has same idea).

You're quibbling - the notion is exactly the same.

Like the codes we presented to you.
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

cdbc

  • Hero Member
  • *****
  • Posts: 2518
    • http://www.cdbc.dk
Re: FFS: step
« Reply #23 on: August 08, 2025, 09:04:19 am »
Hi
Just write an 'Enumerator' and be done with it -- it's a 5 minute job!
...or use the 'Iterator'-callback pattern -- also 5 minutes --
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

Thaddy

  • Hero Member
  • *****
  • Posts: 18511
  • Here stood a man who saw the Elbe and jumped it.
Re: FFS: step
« Reply #24 on: August 08, 2025, 07:06:12 pm »
@cdbc
Or use my second example... :D if you are on trunk.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

BeniBela

  • Hero Member
  • *****
  • Posts: 948
    • homepage
Re: FFS: step
« Reply #25 on: August 08, 2025, 07:22:41 pm »
Hi
Just write an 'Enumerator' and be done with it -- it's a 5 minute job!
...or use the 'Iterator'-callback pattern -- also 5 minutes --
Regards Benny

 but that is so slow

Code: ASM  [Select][+][-]
  1. project1.lpr:86                           for i in ForStep<Integer>(0, N).By(5) do
  2. 00000000004012E3 be00e1f505               mov    $0x5f5e100,%esi
  3. 00000000004012E8 31ff                     xor    %edi,%edi
  4. 00000000004012EA e841feffff               call   0x401130 <FORSTEP$1$CRC9F312717>
  5. 00000000004012EF 488944240c               mov    %rax,0xc(%rsp)
  6. 00000000004012F4 89542414                 mov    %edx,0x14(%rsp)
  7. 00000000004012F8 488d7c240c               lea    0xc(%rsp),%rdi
  8. 00000000004012FD be05000000               mov    $0x5,%esi
  9. 0000000000401302 e8e9fdffff               call   0x4010f0 <BY>
  10. 0000000000401307 4889442418               mov    %rax,0x18(%rsp)
  11. 000000000040130C 89542420                 mov    %edx,0x20(%rsp)
  12. 0000000000401310 488d7c2418               lea    0x18(%rsp),%rdi
  13. 0000000000401315 e8a6fdffff               call   0x4010c0 <GETENUMERATOR>
  14. 000000000040131A 4889442424               mov    %rax,0x24(%rsp)
  15. 000000000040131F 8954242c                 mov    %edx,0x2c(%rsp)
  16. 0000000000401323 488b442424               mov    0x24(%rsp),%rax
  17. 0000000000401328 48890424                 mov    %rax,(%rsp)
  18. 000000000040132C 8b44242c                 mov    0x2c(%rsp),%eax
  19. 0000000000401330 89442408                 mov    %eax,0x8(%rsp)
  20. 0000000000401334 eb0c                     jmp    0x401342 <G2+114>
  21. 0000000000401336 6690                     xchg   %ax,%ax
  22. 0000000000401338 448b2424                 mov    (%rsp),%r12d
  23. project1.lpr:87                           res+=(i);
  24. 000000000040133C 4963c4                   movslq %r12d,%rax
  25. 000000000040133F 4901c5                   add    %rax,%r13
  26. project1.lpr:86                           for i in ForStep<Integer>(0, N).By(5) do
  27. 0000000000401342 8b0424                   mov    (%rsp),%eax
  28. 0000000000401345 03442408                 add    0x8(%rsp),%eax
  29. 0000000000401349 890424                   mov    %eax,(%rsp)
  30. 000000000040134C 837c240800               cmpl   $0x0,0x8(%rsp)
  31. 0000000000401351 7e0c                     jle    0x40135f <G2+143>
  32. 0000000000401353 8b0424                   mov    (%rsp),%eax
  33. 0000000000401356 3b442404                 cmp    0x4(%rsp),%eax
  34. 000000000040135A 0f9ec0                   setle  %al
  35. 000000000040135D eb0a                     jmp    0x401369 <G2+153>
  36. 000000000040135F 8b1424                   mov    (%rsp),%edx
  37. 0000000000401362 3b542404                 cmp    0x4(%rsp),%edx
  38. 0000000000401366 0f9dc0                   setge  %al
  39. 0000000000401369 84c0                     test   %al,%al
  40. 000000000040136B 75cb                     jne    0x401338 <G2+104>
  41.  

perhaps fpc needs a peephole optimizer for cmp-setge-test-jne?

AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 407
  • My software never cras....
Re: FFS: step
« Reply #26 on: August 08, 2025, 10:52:42 pm »
Hi
Just write an 'Enumerator' and be done with it -- it's a 5 minute job!
...or use the 'Iterator'-callback pattern -- also 5 minutes --

This is something that should be done in language - and has no impact on instructions (v. a single step) as it is just the step that changes from a 1 to something else.  (see my earlier assembler examples).

My point is : I should not have to code for steps (other than the added step function) - it should be a feature of the language.
Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

creaothceann

  • Full Member
  • ***
  • Posts: 221
Re: FFS: step
« Reply #27 on: August 09, 2025, 09:45:41 am »
it should be a feature of the language

Why?
In the very rare cases I needed something like that, multiplying the counter variable (for for) or incrementing a second variable (e.g. a pointer) was perfectly fine too.

 

TinyPortal © 2005-2018