ROHD is written in Dart, and Dart can compile to JavaScript, so it should be possible to compile ROHD to JavaScript. In practice, there are a handful of differences when compiling Dart to JavaScript that make ROHD not quite work properly (mostly related to how numbers are handled).
This PR makes changes so that ROHD can compile and run correctly in JavaScript. Most of the test suite has been adjusted to be runnable (and meaningful) when compiled to JavaScript, which validates that most functionality works properly now.
Additionally, the changes have revealed bugs in the native Dart ROHD functionality, so this PR fixes those bugs in both platforms.
Some of the changes:
Added isZero to LogicValue.
Fixed bug where clog2 was off-by-one on width == INT_BITS with only the upper-most bit set.
Fixed crash bug when comparing two positive LogicValues of width == INT_BITS
Fixed bug where conversion of BigInts to unsigned ints of width < INT_BITS could carry upper bits, causing incorrect functionality in places like arithmetic right shift under some scenarios.
NOTE: The translations test is failing in JavaScript, still not sure why.
Related Issue(s)
N/A
Testing
Added new tests, updated existing tests
Backwards-compatibility
Is this a breaking change that will not be backwards-compatible? If yes, how so?
Some minor things:
Division (and modulo) by 0 in LogicValue now returns x instead of throwing an exception
Documentation
Does the change require any updates to documentation? If so, where? Are they included?
Description & Motivation
ROHD is written in Dart, and Dart can compile to JavaScript, so it should be possible to compile ROHD to JavaScript. In practice, there are a handful of differences when compiling Dart to JavaScript that make ROHD not quite work properly (mostly related to how numbers are handled).
See here for some details: https://dart.dev/guides/language/numbers#bitwise-operations
This PR makes changes so that ROHD can compile and run correctly in JavaScript. Most of the test suite has been adjusted to be runnable (and meaningful) when compiled to JavaScript, which validates that most functionality works properly now.
Additionally, the changes have revealed bugs in the native Dart ROHD functionality, so this PR fixes those bugs in both platforms.
Some of the changes:
isZero
toLogicValue
.clog2
was off-by-one onwidth == INT_BITS
with only the upper-most bit set.LogicValue
s ofwidth == INT_BITS
BigInt
s to unsignedint
s of width< INT_BITS
could carry upper bits, causing incorrect functionality in places like arithmetic right shift under some scenarios.NOTE: The translations test is failing in JavaScript, still not sure why.
Related Issue(s)
N/A
Testing
Added new tests, updated existing tests
Backwards-compatibility
Some minor things:
LogicValue
now returnsx
instead of throwing an exceptionDocumentation
No