**UPGRADE YOUR BROWSER**

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community Forums
- :
- Forums
- :
- Vivado RTL Development
- :
- Design Entry
- :
- Arithmetic Shift

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

altameemi

Observer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-31-2011 11:49 PM

13,303 Views

Registered:
05-21-2009

Arithmetic Shift

Hi All

As Xilinx instruct in ISE language templates that operator "<<" to operate a left logical shift and this on "<<<" to operate a left Arithmetic shift. But when I used both of them, I got a logical shift in both cases. I use ISE 12.4. Is there some thing with my code.

I will be highly appreciated if some body guide.

Regards

alwayes ...

.

.

sh_result[31:16] <= sh_in >> 6; //Do a logical shift

sh_result[31:16] <= sh_in >>> 6; // Should give an Arithmetic shift, but it doesn't (the result as in previous expression)

5 Replies

gszakacs

Professor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-01-2011 06:36 AM

13,291 Views

Registered:
08-14-2007

Re: Arithmetic Shift

Unless your variables are signed, then a logical shift and arithmetic shift

should give the same results. Using signed logic is tricky in Verilog.

mixed operations tend to default to using unsigned arithmetic, rather

than the expected signed arithmetic. How did you define sh_in?

-- Gabor

-- Gabor

bassman59

Historian

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-01-2011 01:08 PM

13,278 Views

Registered:
02-25-2008

Re: Arithmetic Shift

gszakacs wrote:Using signed logic is tricky in Verilog.mixed operations tend to default to using unsigned arithmetic, rather

than the expected signed arithmetic.

-- Gabor

That's why Verilog is the best HDL ever invented, or that will ever be invented.

;)

----------------------------Yes, I do this for a living.

altameemi

Observer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-02-2011 05:51 AM

13,262 Views

Registered:
05-21-2009

Re: Arithmetic Shift

Hi Gabor

I have actually cheked the above operators (>> and >>>) individually. sh_in is the input data, which should be shifted. sh_in is provided from many registers located in a registers file. The supplied data was contain a 1 in MSB, which should refer to the sign bit, shouldn't it ? If not, how can I assign signed and unsigned binary patterns please?

Thanks

eteam00

Instructor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-02-2011 06:14 AM - edited 04-02-2011 06:27 AM

13,259 Views

Registered:
07-21-2009

Re: Arithmetic Shift

From the Stuart Sutherland Verilog (2001) HDL Quick Reference Guide:

__operator__ __example__ __description__

>>> m >>> n shift m right n-times; fill with value of sign bit if

expression is signed, otherwise fill with 0 (Verilog-2001)

>> m >> n shift m right n-times and fill with zeros

If the variable being shifted is unsigned, the operator >> is entirely equivalent to the operator >>>.

The supplied data was contain a 1 in MSB, which should refer to the sign bit, shouldn't it ?

Only if the data type of the variable being shifted is declared as signed. If unsigned, an arithmetic right shift will fill with '0'. You should re-read Gabor's post, I am merely repeating what Gabor has already written.

By the way, if you are interested in Verilog training or are interested in a Verilog book, Stuart Sutherland is an excellent instructor (and author). I've taken his workshop.

-- Bob Elkind

SIGNATURE:

README for newbies is here: http://forums.xilinx.com/t5/New-Users-Forum/README-first-Help-for-new-users/td-p/219369

Summary:

1. Read the manual or user guide. Have you read the manual? Can you find the manual?

2. Search the forums (and search the web) for similar topics.

3. Do not post the same question on multiple forums.

4. Do not post a new topic or question on someone else's thread, start a new thread!

5. Students: Copying code is not the same as learning to design.

6 "It does not work" is not a question which can be answered. Provide useful details (with webpage, datasheet links, please).

7. You are not charged extra fees for comments in your code.

8. I am not paid for forum posts. If I write a good post, then I have been good for nothing.

README for newbies is here: http://forums.xilinx.com/t5/New-Users-Forum/README-first-Help-for-new-users/td-p/219369

Summary:

1. Read the manual or user guide. Have you read the manual? Can you find the manual?

2. Search the forums (and search the web) for similar topics.

3. Do not post the same question on multiple forums.

4. Do not post a new topic or question on someone else's thread, start a new thread!

5. Students: Copying code is not the same as learning to design.

6 "It does not work" is not a question which can be answered. Provide useful details (with webpage, datasheet links, please).

7. You are not charged extra fees for comments in your code.

8. I am not paid for forum posts. If I write a good post, then I have been good for nothing.

altameemi

Observer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-03-2011 09:42 PM

13,189 Views

Registered:
05-21-2009

Re: Arithmetic Shift

Thank you very much for your detailed explanation guys.

Cheers