Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register.__getitem__ does not work for 64-bit wide registers #1018

Open
soramichi opened this issue Mar 23, 2020 · 1 comment
Open

Register.__getitem__ does not work for 64-bit wide registers #1018

soramichi opened this issue Mar 23, 2020 · 1 comment

Comments

@soramichi
Copy link

PYNQ version: v2.5
Board name: PYNQ-Z1

When an overlay has 64-bit wide registers, the register_map member of the overlay cannot be elaborated due to the following error:

Traceback (most recent call last):
  File "./test.py", line 8, in <module>
    print(ip.register_map)
  File "/home/xilinx/pynq/registers.py", line 438, in __repr__
    "  {} = {}".format(k, repr(v)))
  File "/home/xilinx/pynq/registers.py", line 277, in __repr__
    return "Register(value={})".format(self[:])
  File "/home/xilinx/pynq/registers.py", line 166, in __getitem__
    return int((curr_val & mask) >> stop)
TypeError: ufunc 'right_shift' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

The mechanism behind is that type(curr_val & mask) becomes numpy.uint64 when mask does not fit within 32-bit, and numpy.uint64 somehow cannot be right-shifted as shown in this code:

>>> import numpy as np
>>> curr_val = np.uint32(1)
>>> mask = 18446744073709551615
>>> type(curr_val & mask)
<class 'numpy.uint64'>
>>> (curr_val & mask) >> 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: ufunc 'right_shift' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
>>> 

On the other hand, when mask is smaller (e.g., 4294967294), typeof(curr_val & mask) is numpy.int64 (not uint), which can be right-sifted without an error.

@soramichi
Copy link
Author

Update: it seems that stop should also be np.uint64 to conduct this shift operation.
https://stackoverflow.com/questions/30513741/python-bit-shifting-with-numpy

Adding the code below between L165 and L166 looks working. Should I submit a PR?

if isinstance(curr_val & mask, np.uint64):
    stop = np.uint64(stop)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant