Loop unrolling is a loop optimization strategy.
Questions tagged [loop-unrolling]
164 questions
2
votes
1 answer
Why does the following loop unrolling lead to a wrong result?
I am currently trying to optimize some MIPS assembler that I've written for a program that triangulates a 24x24 matrix. My current goal is to utilize delayed branching and manual loop unrolling to try and cut down on the cycles. Note: I am using…

NoName123
- 273
- 3
- 12
2
votes
1 answer
Standalone loop collapsing in OpenMP
I have a nested loop that looks as follows -
for(int i=0; i

Atharva Dubey
- 832
- 1
- 8
- 25
2
votes
2 answers
Forcing loop unrolling in MSVC C++
Imagine following code:
for (int i = 0; i < 8; ++i) {
// ... some code
}
I want this loop to be unrolled in MSVC. In CLang I can add #pragma unroll before loop. But how to do same in MSVC?
I understand that anyway compilers often will unroll…

Arty
- 14,883
- 6
- 36
- 69
2
votes
1 answer
Loop unrolling in BASIC
I have an embedded processor that is running a trimmed down version of BASIC (Parallax BASIC Stamp). In a loop, I am writing 1024 values via the SPI bus.
In compiled languages, more speed can be gained by unrolling the loop (putting more…

Thomas Matthews
- 56,849
- 17
- 98
- 154
2
votes
2 answers
Optimizing a program with loop unrolling
I had a question regarding loop unrolling in a for loop and how to make use in a for loop given you don't know the number of iterations until user input.
I've seen examples of loop unrolling in loops where the number of iterations are given and…

Saul
- 311
- 1
- 2
- 10
2
votes
0 answers
Is their any mathematical correlation between cache size and max optimal value of loop unrolling factor that can be reached?
The loop unrolling factor should be chosen meticulously. It should be chosen in such way that the unrolled loop will not overflow the instruction cache, cause it will cause capacity cache misses.
I was looking to find if their is a limit for the…

DINA TAKLIT
- 7,074
- 10
- 69
- 74
2
votes
0 answers
Why does pragma unroll 1 mean not unrolling at all?
If I have this code:
#pragma unroll 1
for (i=0;i<5;i++)
{
a[i]=i;
}
I read somewhere said #pragma unroll 1 will prevent the compiler from unrolling the for loop. Why is that? And why does it not unroll the loop the first time, and run the for…

pg405
- 65
- 6
2
votes
2 answers
Disable unrolling of a particular loop in GCC
I have the following 4x4 matrix-vector multiply code:
double const __restrict__ a[16];
double const __restrict__ x[4];
double __restrict__ y[4];
//#pragma GCC unroll 1 - does not work either
#pragma GCC nounroll
for ( int j = 0; j < 4; ++j…

user2052436
- 4,321
- 1
- 25
- 46
2
votes
2 answers
Generic pattern for a loop- pintool
I'm trying to find a generic pattern to be able to run a pintool program so it will always give me where is the index or what is it, and to which value the loop goes to.
For example, here is the assembly of a certain loop:
40c374: 48 8b 55 e8 …

sijaan hallak
- 47
- 1
- 8
2
votes
1 answer
Chisel, Generate Blocks and Large Intermediate/Output Files
Is there a construct in Chisel to generate Verilog generate blocks instead of unrolling Scala for-loops into very large (>100k line) output Verilog and FIRRTL files.
For example, I have the following code, that constructs a 2D lattice of…

ssb
- 7,422
- 10
- 36
- 61
2
votes
1 answer
Why is loop unrolling off by default in XCode?
It seems the Unroll Loops optimization settings under the Apple LLVM 8.0 - Code Generation section is turned off by default in the latest XCode, 8.2.1, even for the Release configuration. Any good reason for that? I thought loop unrolling was one of…

Danra
- 9,546
- 5
- 59
- 117
2
votes
0 answers
First call to C function slower than subsequent calls
I am trying to approximate the function call overhead in C. So I have an empty function with the attribute((optimize("O0"))), so that it is not optimized away by GCC.
int __attribute__((optimize("O0"))) func(int a)
{
return (a+a);
}
I am using…

AbhinavChoudhury
- 1,167
- 1
- 18
- 38
2
votes
2 answers
Does this optimization even matter?
This page recommends "loop unrolling" as an optimization:
Loop overhead can be reduced by reducing the number of iterations and
replicating the body of the loop.
Example:
In the code fragment below, the body of the loop can be replicated
once…

user5301775
- 21
- 1
2
votes
1 answer
Can anyone please explain this in a easier way?
I had take up a computer organization course a year ago and now I have a follow up to it as 'Computer architecture' , I am using the 3rd edition of John Hennessy's book 'Quantitative approach to computer architecture', I went through the MIPS ISA…

Sainath S.R
- 3,074
- 9
- 41
- 72
2
votes
1 answer
Unrolled Loops of Static Arrays
If I call the function
/** Check if all Elements, possibly recursively, of $(D x) are zero. */
bool allZero(T)(in T x) @safe pure nothrow {
import std.range: isIterable;
static if (isIterable!T) {
foreach (ref elt; x) {
…

Nordlöw
- 11,838
- 10
- 52
- 99