PROGRAM 14:

Write a program to perform loop unrolling. 

ALGORITHM:

1.Start
2.Intialise value N
3.Initialize the count value 
4.If  perform loop unrolling then,
   4.1 Perform each operation upto count.
5.Else, loop rolling
  5.1 check the condition.
  5.2 Perform the operation.
  5.3 increment the count.
6.Print the result.
7.Stop 


/* Loop unrolling, also known as loop unwinding, is a loop transformation technique that 

attempts to optimize a program's execution speed at the expense of its binary size, which is an 

approach known as the space-time tradeoff. The transformation can be undertaken manually by 

the programmer or by an optimizing compiler. */

 PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
unsigned int n;
int x;
char ch;
clrscr();
printf("\nEnter N\n");
scanf("%u",&n);
printf("\n1. Loop Roll\n2. Loop UnRoll\n");
printf("\nEnter ur choice\n");
scanf(" %c",&ch);
switch(ch)
{
case '1':
  x=countbit1(n);
  printf("\nLoop Roll: Count of  1's    :  %d" ,x);
  break;
case '2':
  x=countbit2(n);
  printf("\nLoop UnRoll:  Count of 1's  :  %d" ,x);
  break;
default:
  printf("\n Wrong Choice\n");

}
getch();
}
int countbit1(unsigned int n)
{
    int bits = 0,i=0;
    while (n != 0)
    {
if (n & 1) bits++;
n >>= 1;
i++;
    }
    printf("\n no of iterations  %d",i);
    return bits;
}
int countbit2(unsigned int n)
{
    int bits = 0,i=0;
    while (n != 0)
    {
if (n & 1) bits++;
if (n & 2) bits++;
if (n & 4) bits++;
if (n & 8) bits++;
n >>= 4;
i++;
    }
    printf("\n no of iterations  %d",i);
    return bits;
OUTPUT:


../Desktop/Screen%20Shot%202019-01-30%20at%203.34.56%20PM.png