write a c program to execute x/2^y in single clock cycle

Status
Not open for further replies.

Maharshi

Newbie level 3
Joined
Apr 26, 2012
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,328
write a c program to execute x/2^y in single clock cycle
 

You're always dividing by a power of 2. This is equivalent to right shifting in a binary arithmetic processor.

Consider the following values of Y and resultant outputs:
Y = 0, OUT = X / 1; X >> 0
Y = 1, OUT = X / 2; X >> 1
Y = 2, OUT = X / 4; X >> 2
Y = 3, OUT = X / 8; X >> 3
Y = Y, OUT = X / 2^Y; X >> Y

(Recalling that X / POW( Y, 2 ) is X >> Y)

The code is:
OUT = X >> Y;

Of course, this question is poorly worded in that it assumes that a barrel shifter is present. On older processors (such as the 6502) a variable shift could take multiple single cycle shifts due to the absence of a barrel shifter. Semantics aside... this is probably what you're looking for. :wink:
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…