Skip to content

[vhdl] Handle garbage truncf input data#1002

Open
zero9178 wants to merge 1 commit into
mainfrom
users/zero9178/truncf-input-sanitize
Open

[vhdl] Handle garbage truncf input data#1002
zero9178 wants to merge 1 commit into
mainfrom
users/zero9178/truncf-input-sanitize

Conversation

@zero9178

@zero9178 zero9178 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

VHDL's to_float32 function may fatally assert in simulation if the float64 input value is out-of-range for a float32 (e.g. exponent too large). This is generally not propblematic in dynamatic since C defines this as UB and therefore this is valid behavior for the compiler.

However, the truncf circuit did not care to check whether valid is set and would just process its input data regardless of whether the input is valid, potentially leading to processing a float64 leading to a simulator crash.

This PR fixes this issue by simply masking the input when valid is not set. Very technically speaking this only exists to appease simulator semantics, though I'd hope synthesis can optimize out the check for equivalent circuits.

Fixes #998

VHDL's `to_float32` function may fatally assert in simulation if the `float64` input value is out-of-range for a `float32` (e.g. exponent too large).
This is generally not propblematic in dynamatic since C defines this as UB and therefore this is valid behavior for the compiler.

However, the `truncf` circuit did not care to check whether `valid` is set and would just process its input data regardless of whether the input is valid, potentially leading to processing a `float64` leading to a simulator crash.

This PR fixes this issue by simply masking the input when `valid` is not set. Very technically speaking this only exists to appease simulator semantics, though I'd hope synthesis can optimize out the check for equivalent circuits.

Fixes #998
@zero9178 zero9178 requested review from Jiahui17 and murphe67 July 6, 2026 19:35
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

Successfully merging this pull request may close these issues.

[sharing] "Fatal: (vsim-3421) Value 521 for shift is out of range 52 downto 0"

1 participant