Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Systemverilog type cast or integer division

Status
Not open for further replies.

parafux

Newbie level 3
Joined
Jul 10, 2019
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
26
Hi all,

i am quite new to systemverilog. I normally code in VHDL. Now i have to do some test bench codings in systemverilog.
I want to get the upper 32 bits of a longint variable.

I do this:
Code:
             pos1_x_0 = pos1_x % (2**32); // lower bits, works
             pos1_x_1 = int'(pos1_x / (2**32)); // upper bits deliver always zero

I try this for a small negative number like
Code:
             pos1_x = -10

I expect to get -1 for pos1_x_1 but i get 0



Another way for me would be to convert the longint pos1_x to a vector but i dont know how.



hope anyone can help me.

best regards
p.
 

now i found a solution that works properly for me, but i dont know why the approach above does not work

Code:
pos1_x_1 = int'(pos1_x >> 32)
 

This is because the compiler is smart, and knows how to do signed divisions properly. And you are doing signed divisions in your original attempts.

If you want to manipulate bits, then you should do bit mask and/or bit shift operations, not signed arithmetic operations.

In your second post, you have done a bit-shift operation, hence it worked as required by you.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top