Jump to content

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now