| View previous topic :: View next topic |
| Author |
Message |
tyeowkwa
Joined: 09 Feb 2010 Posts: 7
|
Posted: Thu Mar 11, 2010 2:48 pm Post subject: how to peform shift left or right operation ? |
|
|
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 |
|
 |
quark
Joined: 02 Nov 2007 Posts: 65
|
Posted: Thu Mar 11, 2010 3:19 pm Post subject: Re: how to peform shift left or right operation ? |
|
|
If you want to shift "m" to the left one bit, you can do this:
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 |
|
 |
tyeowkwa
Joined: 09 Feb 2010 Posts: 7
|
Posted: Thu Mar 11, 2010 4:20 pm Post subject: Re: how to peform shift left or right operation ? |
|
|
| quark wrote: | If you want to shift "m" to the left one bit, you can do this:
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
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 |
|
 |
quark
Joined: 02 Nov 2007 Posts: 65
|
Posted: Thu Mar 11, 2010 4:52 pm Post subject: Re: how to peform shift left or right operation ? |
|
|
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 |
|
 |
tyeowkwa
Joined: 09 Feb 2010 Posts: 7
|
Posted: Thu Mar 11, 2010 5:20 pm Post subject: Re: how to peform shift left or right operation ? |
|
|
| 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.  |
|
| Back to top |
|
 |
|