Skip to content

Rotate functions over BitVector of length 0 throws devide by zero exception #2980

Description

@MrDurion

Description

The simulation code of the rotateL# and rotateR#, functions of the BitVector throw a divide by zero exception when applied on a BitVector of length 0.

Steps to reproduce

  1. Write a Clash file that uses a rotateL or rotateR on a BitVector of length 0, for example:
module Example.Project where

import Clash.Prelude

topEntity :: (BitVector 0) -> (BitVector 0)
topEntity x = rotateL x 2
  1. Go into the repl using cabal repl
  2. Load the file: :l Example/Project
  3. run an example by executing the topEntity function, eg: topEntity 4

The same error occurs when I compile the code using cabal run clash -- /src/Example/Project.hs --verilog.

Expected result:

The rotate function and thus the repl execution should return a BitVector of length 0, shown as 0.

Actual result:

The repl shows *** Exception: divide by zero.

Possible causes

I think it has something to do with the mod in b' = formIntegral b `mod` sz being partial.
This is on line 1313 in the clash-prelude/src/Clash/Sized/Internal/BitVector.hs file

Meta info

  • Cabal version: 3.12.1.0
  • Clash version: 1.8.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions