Loop unrolling is a loop optimization strategy.
Questions tagged [loop-unrolling]
164 questions
0
votes
2 answers
Will a C++ compiler inline a for-loop with a small number of terms?
Suppose I have a class Matrix5x5 (with suitably overloaded index operators) and I write a method trace for calculating the sum of its diagonal elements:
double Matrix5x5::trace(void){
double t(0.0);
for(int i(0); i <= 4; ++i){
t +=…

user1892304
- 617
- 1
- 6
- 11
0
votes
1 answer
C for loop has different effect than rolled out loop
I am writing a simple queue in c using a linked list that keeps track of the last element.
This is my code:
#include
#include
#include
#include
typedef struct node_s {
uint32_t x, y;
} node;
//…

Matthias
- 737
- 8
- 14
0
votes
1 answer
How to use loop unrolling and reassociation?
I'm trying to use loop unrolling to optimize my code.
This was the original code
int a[N]; //arbitrary array
int vara; //arbitrary variable
int varb; //arbitrary variable
for (int i=0;i

Nikhil Srikumar
- 51
- 1
- 6
0
votes
3 answers
When a loop is unrolled, what are the final iterations called?
If a loop is unrolled by N, duplicating the body N times and reducing the trip-count by a factor of N, you may need 0 to N-1 "final iterations" after the loop - the non-zero cases occurring if your original trip-count wasn't a multiple of N.
What…

BeeOnRope
- 60,350
- 16
- 207
- 386
0
votes
1 answer
Loop unrolling doesn't work with remaining elements
I have a typical algorithm for matrix multiplication. I am trying to apply and understand loop unrolling, but I am having a problem implementing the algorithm when I am trying to unroll k times when k isn't a multiple of the matrices size. (I get…

Luc Aux
- 149
- 10
0
votes
0 answers
C : Matrix Multiplication stuck if matrix size 4096x4096
Here is the code, matrix multiplication in C, the matrix's fill is integer. Optimization for loop nest and loop unrolling. Run well till N is 7168. For N 8196, insufficient memory.If you run it, just screen, wait till get time result. This is an…

afni
- 75
- 2
- 12
0
votes
1 answer
Loop Unrolling, Performance Lab
I'm trying to optimize this code by loop unrolling,
void naive_flip(int dim, pixel *src, pixel *dst)
{
int i, j;
for (i = 0; i < dim; i++){
for (j = 0; j < dim; j++){
dst[RIDX_F(i, j, dim)].red = src[RIDX(i, j,…

MJS
- 1
- 4
0
votes
2 answers
Chisel: How to model a variable incremented in a unrolled loop
Let's say I have a Vec of Bool. I want to fill a new Vec of the same size with values equal to a number of true values I've seen up to this index in the original Vec. I want to do it combinationally.
With my HLS background and coding style settled…

aayupov
- 267
- 1
- 10
0
votes
1 answer
Is array initialization in for loop slower then non-for loop initialization in C++
I was wondering if this code
for (int i=0; i <= n; i++)
{
someArray[i] = i;
}
will be slower than initializing array line by line like this
someArray[0] = 0;
someArray[1] = 1;
.
.
.
someArray[n] = n;
It seems like if there is no compiler…

Saik
- 993
- 1
- 16
- 40
0
votes
1 answer
How does loop unrolling reduce branch penalty?
I am trying to understand the concepts of loop unrolling, and according to Wikipedia, it limits/minimizes branch penalty?
Now, I understand what loop unrolling is. It is basically increasing the loop increment step, and repeating the statements…

Max
- 9,100
- 25
- 72
- 109
0
votes
2 answers
Unrolling pointer increment loop for auto vectorization
I was wondering if unrolling this loop:
for (int i = 0; i < n; i++) {
*p = a[i]*b[i];
p++;
}
into
for (int i = 0; i < n; i+=4) {
*(p + 0) = a[i + 0]*b[i + 0];
*(p + 1) = a[i + 1]*b[i + 1];
*(p + 2) = a[i + 2]*b[i + 2];
*(p +…

Armen Avetisyan
- 1,140
- 10
- 29
0
votes
0 answers
Why is the elapsed time 0?
I made a program that unrolls loops and measures the time taken for it to sort an array, but the problem I have is that sometimes the unrolled loop program gives me an answer of 0 in nano seconds and that just can't be. I tried it with MONOTONIC too…

Erlandas Aksomaitis
- 11
- 4
0
votes
3 answers
Remove Switch From Loop
I have a loop with a switch inside that looks something like this (but much more complex).
for(int i = 0; i < N; i += inc)
{
v = 0.0;
switch(ConstVal)
{
case 2: v += A[i];
case 1: v += A[i+k];
case 0: v += A[i+j];
}
…

Todd
- 475
- 4
- 15
0
votes
0 answers
Loop unrolling in inlined functions in C for speed optimized multiple register multiple bit access
I have a question how to most elegantly solve following problem related to discrete IO checks of a micro controller:
Contents of .c file:
struct transfers {
uint32t *RegisterAddr;
uint8_t RegBit;
};
static const struct transfers DIO[] = {
{…

Embed
- 11
- 1
0
votes
2 answers
unrolling nested for loops - C
I'm having trouble unrolling nested forloops. I understand the concept, I'm trying to put it into practice, but I'm getting tripped up on editing the statements within my for loops to match the unrolling.
If someone could just show me an efficient…

slippeel
- 103
- 2
- 10