intel / rohd

The Rapid Open Hardware Development (ROHD) framework is a framework for describing and verifying hardware in the Dart programming language.
https://intel.github.io/rohd-website
BSD 3-Clause "New" or "Revised" License
374 stars 67 forks source link

Shifting large bit vectors (width > 64) can sometimes result in unexpected Dart exception. #404

Closed kimmeljo closed 1 year ago

kimmeljo commented 1 year ago

Describe the bug

When performing a shift operation on a Logic whose width is large (>64), in some cases we get a Dart exception complaining about int vs. BigInt, as follows (including example full stack trace through ROHD libraries):

In this case, the width of the Logic being shifted is 144 (as well as the the width of the Const it is being shifted by). However, the Const value (==32) fits into an int.

Unhandled exception: Exception: LogicValue width 144 is too long to convert to int. Use toBigInt() instead.

0 _BigLogicValue.toInt (package:rohd/src/values/big_logic_value.dart:131:7)

1 LogicValue._shift (package:rohd/src/values/logic_value.dart:1085:24)

2 LogicValue.<< (package:rohd/src/values/logic_value.dart:1069:44)

3 new LShift. (package:rohd/src/modules/gates.dart:579:31)

4 _ShiftGate._execute (package:rohd/src/modules/gates.dart:383:16)

5 _ShiftGate._setup (package:rohd/src/modules/gates.dart:372:5)

6 new _ShiftGate (package:rohd/src/modules/gates.dart:367:5)

7 new LShift (package:rohd/src/modules/gates.dart:579:9)

8 Logic.<< (package:rohd/src/signals/logic.dart:351:39)

To Reproduce

  1. Create a Logic with a large width (say, 144)
  2. Perform a left shift of that Logic by either an integer or a Const (in the case of Const, use the same width of 144). Note that the in either case the shift amount should/can fit into a int.

Logic test = Logic(name: 'test', width: 144); Logic shiftTest = Logic(name: 'shiftTest', width: 144);

// test 1 shiftTest <= (test << 32);

// test 2 shiftTest <= (test << Const(32, width: 144));

Expected behavior

This operation should be successful - at least for shift amounts that fit into the int size.

Actual behavior

Dart exception.

Additional: Dart SDK info

No response

Additional: pubspec.yaml

No response

Additional: Context

No response

mkorbel1 commented 1 year ago

May be related to #110