Jump to content

sc_signed_subref and sc_unsigned_subref


Recommended Posts

Hi,

I have a trivial piece of code that looks a bit like this:

sc_bigint<N+1> p;    // Signed
sc_biguint<N>  q, r; // Unsigned

for(i=1; i<L; i++)
{
  ..... /* some logic */= test ? p.range(i, 0) : q.range(i, 0);
}

 

However it won't compile as I get this error:

Quote

operands to ?: have different types 'sc_dt::sc_signed_subref' and 'sc_dt::sc_unsigned_subref'

 

I have to say I'm a bit disconcerted because (in my mind at least), the bit-slicing operation using the .range() operator returns a bit-pattern without any clearly defined interpretation (so I don't expect concepts such as a "signed" bit-pattern and an "unsigned" bit-pattern to even exist).

One question is of course the motivation for defining these concepts. Though I'm curious and interested to hear about it, I suppose there is a good reason for doing that and it is not the main point that I'm interested in.

The question I'm mostly interested in, is very practical: what is the clean way to get the code to compile with the desired effect ? Thanks !

 

Link to comment
Share on other sites

I guess I was a bit tired when asking that question... The practical solution is as trivial as a cast it seems:

  r = test ? (sc_biguint<N>)p.range(i, 0) : q.range(i, 0);

Having said that, I'm still curious to understand why this cast is necessary at all. In fact, the very same code based on sc_int / sc_uint rather than sc_bigint / sc_biguint works perfectly well without any cast.

Why does the .range() operator return signed/unsigned patterns when applied to sc_bigint, but not when applied to sc_int ?

 

 

Link to comment
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...