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

VHDL: no div/rem/mod by zero in gen'd code #1873

Merged
merged 1 commit into from
Jul 14, 2021
Merged

VHDL: no div/rem/mod by zero in gen'd code #1873

merged 1 commit into from
Jul 14, 2021

Conversation

christiaanb
Copy link
Member

Because Clash translates to concurrent assignments, things like

if y /= 0 then quot x y else 0

would result in a VHDL sim error (at least on GHDL) because all subterms of the if-then-else expression would be evaluated
concurrently, and x / y would throw a sim error whenever y=0 even though that result could never be observed.

@christiaanb christiaanb force-pushed the no_div_zero branch 2 times, most recently from 7c79129 to 7456c44 Compare July 6, 2021 07:13
@martijnbastiaan
Copy link
Member

Nice work on all the fixes, could you add changelogs? :)

Because Clash translates to concurrent assignments, things like

```
if y /= 0 then quot x y else 0
```

would result in a VHDL sim error (at least on GHDL) because all
subterms of the if-then-else expression would be evaluated
concurrently, and `x / y` would throw a sim error whenever `y=0`
even though that result could never be observed.

So now, for the division operators we add the following:
```
-- pragma translate_off
when (y /= 0) else (others => 'X')
-- pragma translate_on
```
To ensure the division by zero exception isn't thrown during
VHDL simulation.
@christiaanb christiaanb merged commit 9bb5a37 into master Jul 14, 2021
@christiaanb christiaanb deleted the no_div_zero branch July 14, 2021 20:32
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.

2 participants