bluespec.com Forum Index bluespec.com
Bluespec Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how to peform shift left or right operation ?

 
Post new topic   Reply to topic    bluespec.com Forum Index -> Designing with BSV's Rules, Interfaces, ...
View previous topic :: View next topic  
Author Message
tyeowkwa



Joined: 09 Feb 2010
Posts: 7

PostPosted: Thu Mar 11, 2010 2:48 pm    Post subject: how to peform shift left or right operation ? Reply with quote

was trying to do a left shift operation. Value in m is 5 but after this command the value of tmp2 return is 1. May I know what is the correct format to write the shift command.
I just want to shift the register m by 1 bit to the left.
Thanks.

initial value of m =5

tmp2 <= 1 << m; // tmp2=1

tmp2 <= \<< (m,1) //tmp2 =0
Back to top
View user's profile Send private message
quark



Joined: 02 Nov 2007
Posts: 65

PostPosted: Thu Mar 11, 2010 3:19 pm    Post subject: Re: how to peform shift left or right operation ? Reply with quote

If you want to shift "m" to the left one bit, you can do this:
Code:
tmp2 <=  m << 1;

This should be identical to the second line that you wrote. The first line that you wrote is shifting the value 1 to left by "m" bits.

Note that shifting will not increase the bit-size of the value. If you shift 3'b101 by 1 bit, it will become the value 3'b010.
Back to top
View user's profile Send private message
tyeowkwa



Joined: 09 Feb 2010
Posts: 7

PostPosted: Thu Mar 11, 2010 4:20 pm    Post subject: Re: how to peform shift left or right operation ? Reply with quote

quark wrote:
If you want to shift "m" to the left one bit, you can do this:
Code:
tmp2 <=  m << 1;


This should be identical to the second line that you wrote. The first line that you wrote is shifting the value 1 to left by "m" bits.

Note that shifting will not increase the bit-size of the value. If you shift 3'b101 by 1 bit, it will become the value 3'b010.



thanks. i got mixed up with 1<< m and m << 1.
Yes the below command is also similar to m << 1
tmp2 <= \<< (m,1)

--> Noted Very Happy

If I want to combine two separate 18 bits registers value to form a 36 bits reg value what will be the best way to do it in bluespec. I was think using this method

1) Take the first(MSB) 18 bit value and store it into the 36 bit reg
2) shift the 36bit register left by 18bits, which will bring the value up to the MSB.
3) 'OR' the 36bit register with the LSB 18bit register.
Back to top
View user's profile Send private message
quark



Joined: 02 Nov 2007
Posts: 65

PostPosted: Thu Mar 11, 2010 4:52 pm    Post subject: Re: how to peform shift left or right operation ? Reply with quote

What you propose for concatenating two values will work, but there is a concatenation syntax which is simpler:
Code:
Bit#(18) v1 = ...;
Bit#(18) v2 = ...;
Bit#(36) c = {v1, v2};
Back to top
View user's profile Send private message
tyeowkwa



Joined: 09 Feb 2010
Posts: 7

PostPosted: Thu Mar 11, 2010 5:20 pm    Post subject: Re: how to peform shift left or right operation ? Reply with quote

quark wrote:
What you propose for concatenating two values will work, but there is a concatenation syntax which is simpler:
Code:
Bit#(18) v1 = ...;
Bit#(18) v2 = ...;
Bit#(36) c = {v1, v2};


Thanks. Will give it a try.. that's really make the job simple. Razz
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    bluespec.com Forum Index -> Designing with BSV's Rules, Interfaces, ... All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
bluespec.com topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP