Jump to content
campo85

2 Complement with sc_fixed type and HLS

Recommended Posts

Hi all,

I'm quite new to all the SystemC world. As far as I got the sc_fixed type should be synthesizable. My problem at the moment is that I have a number, and I need the negative version of that number. The easiest way to do it is to multiply for -1. The problem is the HLS. I actually don't know how this it will be handled by the tool. I would like to avoid to instantiate a multiplier just to do a simple 2 complement operation ( flip the bits and adding 1 to the LSB ).

If I can't trust the HLS tools I guess the safest way would be to do the 2 complement by myself, but even there I have some concern :

sc_fixed <8,3,SC_RND,SC_SAT> foo, foo_neg;
foo_neg = ~foo + 2^(8-3)      ( PSEUDOCODE : I still need to figure out )

I don't really like to add 2^-5, it isn't clean. Even here probably it's easier to convert in int and add 1, but still it's quite messy in my opinion. Does anyone know if the tools are smart enough to handle correctly a multiplication between  sc_fixed type  and -1 and to implement correctly the 2 complement operation? If not how should I need to proceed ?

Share this post


Link to post
Share on other sites

Yes, it should be ok to write:

foo_neg = - neg;

It's important to know that most modern HLS tools do not generate gates directly. Instead they generate synthesizable RTL. So flow looks like this:

SystemC -> HLS -> Logic synthesis -> Gates

So even if your HLS is not smart and will generate (-1) * foo in RTL,  Logic synthesis will still optimize this multiplication away.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...