Commit fb604109 by Zachary Snow

don't sign-extend signed unsized numbers with a leading 1 bit

I'm opting for iverilog's interpretation of the specifications here. The
commercial simulators I tested seem to agree.
parent 32250f37
...@@ -41,7 +41,7 @@ jobs: ...@@ -41,7 +41,7 @@ jobs:
- macOS-11 - macOS-11
needs: build needs: build
env: env:
IVERILOG_REF: 8ee1d56e1acbc130aa63da3c8ef0d535a551cf28 IVERILOG_REF: f31d0dcbc5ddcd97e1e2e6f7bc7eb0f5a547fe16
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- name: Install Dependencies (macOS) - name: Install Dependencies (macOS)
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
### Bug Fixes ### Bug Fixes
* Fixed an issue that prevented parsing tasks and functions with `inout` ports * Fixed an issue that prevented parsing tasks and functions with `inout` ports
* Fixed signed unsized literals with a leading 1 bit (e.g., `'sb1`, `'sh8f`)
incorrectly sign-extending in size and type casts
* Fixed conflicting genvar names when inlining interfaces and modules that use * Fixed conflicting genvar names when inlining interfaces and modules that use
them; all genvars are now given a design-wide unique name them; all genvars are now given a design-wide unique name
* Fixed byte order of strings in size casts * Fixed byte order of strings in size casts
......
...@@ -153,12 +153,17 @@ parseNormalized oversizedNumbers str = ...@@ -153,12 +153,17 @@ parseNormalized oversizedNumbers str =
-- high-order X or Z is extended up to the size of the literal -- high-order X or Z is extended up to the size of the literal
leadDigit = head digits leadDigit = head digits
numDigits = length digits numDigits = length digits + if isSignedUnsizedWithLeading1 then 1 else 0
leadDigitIsXZ = elem leadDigit xzDigits leadDigitIsXZ = elem leadDigit xzDigits
digitsExtended = digitsExtended =
if leadDigitIsXZ if leadDigitIsXZ
then replicate (sizeDigits - numDigits) leadDigit ++ digits then replicate (sizeDigits - numDigits) leadDigit ++ digits
else digits else digits
isSignedUnsizedWithLeading1 =
maybeBase /= Nothing &&
not leadDigitIsXZ &&
signed &&
digitToInt leadDigit >= div (baseSize base) 2
-- determine the number of digits needed based on the size -- determine the number of digits needed based on the size
sizeDigits = ((abs size) `div` bitsPerDigit) + sizeExtraDigit sizeDigits = ((abs size) `div` bitsPerDigit) + sizeExtraDigit
......
...@@ -47,6 +47,16 @@ ...@@ -47,6 +47,16 @@
`TEST_ALL(7'so0x) `TEST_ALL(7'so0x)
`TEST_ALL(7'sox1) `TEST_ALL(7'sox1)
`TEST_ALL(7'soz0) `TEST_ALL(7'soz0)
`TEST_ALL('so7)
`TEST_ALL('so37)
`TEST_ALL('so47)
`TEST_ALL('so57)
`TEST_ALL('so07)
`TEST_ALL('o7)
`TEST_ALL('o37)
`TEST_ALL('o47)
`TEST_ALL('o57)
`TEST_ALL('o07)
`TEST_ALL('bx) `TEST_ALL('bx)
`TEST_ALL('ozx) `TEST_ALL('ozx)
...@@ -58,6 +68,18 @@ ...@@ -58,6 +68,18 @@
`TEST_ALL('bzzz1) `TEST_ALL('bzzz1)
`TEST_ALL('ozzz1) `TEST_ALL('ozzz1)
`TEST_ALL('hzzz1) `TEST_ALL('hzzz1)
`TEST_ALL('shf)
`TEST_ALL('sh6f)
`TEST_ALL('sh7f)
`TEST_ALL('sh8f)
`TEST_ALL('sh9f)
`TEST_ALL('sh0f)
`TEST_ALL('hf)
`TEST_ALL('h6f)
`TEST_ALL('h7f)
`TEST_ALL('h8f)
`TEST_ALL('h9f)
`TEST_ALL('h0f)
`TEST_ALL(1'ox) `TEST_ALL(1'ox)
`TEST_ALL(1'oz) `TEST_ALL(1'oz)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment