Recent

Author Topic: [CLOSED] FOR loop unrolling  (Read 7900 times)

julkas

  • Guest
Re: FOR loop unrolling
« Reply #15 on: December 21, 2019, 11:01:09 am »
Code: Pascal  [Select][+][-]
  1. {$optimization noloopunroll}
Thanks. But why it's undocumented?
$OPTIMIZATION : Enable Optimizations - https://www.freepascal.org/docs-html/current/prog/progsu58.html#x65-640001.2.58.

And main question - when compiler unrolls ?
Quote
In  some  cases,  we  could  unroll  loops  to  speed  up  the  code  execution.  This  is 
especially effective for short loops.

FPC AVR with -O3 unrolls for loop with 30 iterations.
GCC AVR compiler unrolls not only for loops. See (p.13) - https://ww1.microchip.com/downloads/en/AppNotes/doc8453.pdf

Laksen

  • Hero Member
  • *****
  • Posts: 794
    • J-Software
Re: FOR loop unrolling
« Reply #16 on: December 21, 2019, 12:41:31 pm »
It's a documentation bug. Please put an issue in the bugtracker

The loop unroller should probably be fine tuned for AVR. It's mostly tuned for high end processors right now. It either way only triggers on loops with known bounds

julkas

  • Guest
Re: FOR loop unrolling
« Reply #17 on: December 21, 2019, 02:18:23 pm »
It's a documentation bug. Please put an issue in the bugtracker

The loop unroller should probably be fine tuned for AVR. It's mostly tuned for high end processors right now. It either way only triggers on loops with known bounds
Check - https://bugs.freepascal.org/view.php?id=36464.


julkas

  • Guest
Re: FOR loop unrolling
« Reply #18 on: December 21, 2019, 02:23:17 pm »
It's a documentation bug. Please put an issue in the bugtracker

The loop unroller should probably be fine tuned for AVR. It's mostly tuned for high end processors right now. It either way only triggers on loops with known bounds
only triggers on loops with known bounds - Can you give more info?

Laksen

  • Hero Member
  • *****
  • Posts: 794
    • J-Software
Re: FOR loop unrolling
« Reply #19 on: December 21, 2019, 07:03:01 pm »
The loop unroll pass first calculates number of unrolls. It does this by dividing an estimated loop body complexity with a fixed processor specified number.
Then it looks at the lower and upper bounds. If they are constant it can find out exactly how many times to unroll and where to possibly insert an odd entry (if you are unrolling a loop 4 times but it runs 10 iterations originally)

If the lower and upper bounds are not constant then it doesn't do anything:
https://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/compiler/optloop.pas?view=markup#l234

This has constant bounds:
Code: Pascal  [Select][+][-]
  1. for i:=0 to 7 do
  2.  

This does not have constant bounds:
Code: Pascal  [Select][+][-]
  1. for i:=0 to some_variable do
  2.  

julkas

  • Guest
Re: FOR loop unrolling
« Reply #20 on: December 22, 2019, 11:48:45 am »
Thanks for help.

 

TinyPortal © 2005-2018