fvutils / pyvsc

Python packages providing a library for Verification Stimulus and Coverage
https://fvutils.github.io/pyvsc
Apache License 2.0
113 stars 26 forks source link

Returns two's complement of negative number #69

Closed edcote closed 3 years ago

edcote commented 3 years ago

Consider the following testcase tested on pyvsc==0.3.3.20210422.1:

from vsc import *

@randobj
class cl:
  def __init__(self):
    self.x = rand_list_t(rand_int_t(32), 3)  # intentionally using rand_int_t because I want signed

  @constraint
  def cx(self):
    with foreach(self.x) as it:
      it >= -32768
      it <= 32768

c = cl()
c.randomize()
for i in c.x:
  print(i)

... and its output:

7192
4294934585
3103

I am guessing the answer isn't wrong. I didn't check the 2s complement.

mballance commented 3 years ago

Ah, good catch @edcote. Yes, Boolector returns results in 2's complement form and additional conversion is needed to get a Python signed integer. Fixed in version 0.3.4.

-Matthew

edcote commented 3 years ago

Thank you!!

Can I https://www.buymeacoffee.com/ ?