Skip to content

Commit

Permalink
Add Finite class
Browse files Browse the repository at this point in the history
  • Loading branch information
kleinreact committed Dec 30, 2024
1 parent 8a827e1 commit 540afcf
Show file tree
Hide file tree
Showing 14 changed files with 899 additions and 22 deletions.
1 change: 1 addition & 0 deletions changelog/2024-12-30T13_36_39+01_00_add_finite_class
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ADDED: Added `Clash.Class.Finite.Finite`: a class for types with only finitely many inhabitants. The class can be considered a more hardware-friendly alternative to `Bounded` and `Enum`, utilizing 'Index' instead of `Int` and vectors instead of lists.
4 changes: 2 additions & 2 deletions clash-cores/src/Clash/Cores/Crc/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,9 @@ getFGMatrix (CrcLane1 fg) lane
= case compareSNat2 d1 lane of
SNatEQ2 -> fg
_ -> clashCompileError "getFGMatrix, CrcLane1: Absurd, Report this to the Clash compiler team: https://github.com/clash-lang/clash-compiler/issues"
getFGMatrix (CrcLaneN lanes fg next) lane
getFGMatrix (CrcLaneN lanes fg next') lane
= case compareSNat2 lane lanes of
SNatLT2 -> getFGMatrix next lane
SNatLT2 -> getFGMatrix next' lane
SNatEQ2 -> fg
_ -> clashCompileError "getFGMatrix, CrcLaneN: Absurd, Report this to the Clash compiler team: https://github.com/clash-lang/clash-compiler/issues"

Expand Down
6 changes: 5 additions & 1 deletion clash-prelude/clash-prelude.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Maintainer: QBayLogic B.V. <[email protected]>
Copyright: Copyright © 2013-2016, University of Twente,
2016-2017, Myrtle Software Ltd,
2017-2019, QBayLogic B.V., Google Inc.,
2021-2023, QBayLogic B.V.
2021-2024, QBayLogic B.V.
Category: Hardware
Build-type: Simple

Expand Down Expand Up @@ -183,6 +183,10 @@ Library
Clash.Class.Counter.Internal
Clash.Class.Counter.TH
Clash.Class.Exp
Clash.Class.Finite
Clash.Class.Finite.Internal
Clash.Class.Finite.Internal.Dictionaries
Clash.Class.Finite.Internal.TH
Clash.Class.HasDomain
Clash.Class.HasDomain.HasSingleDomain
Clash.Class.HasDomain.HasSpecificDomain
Expand Down
18 changes: 18 additions & 0 deletions clash-prelude/src/Clash/Class/Finite.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{-|
Copyright : (C) 2024, QBayLogic B.V.
License : BSD2 (see the file LICENSE)
Maintainer : QBayLogic B.V. <[email protected]>
-}

module Clash.Class.Finite
( -- * Finite Class
Finite(..)
-- * Extensions
, ReversedIndexOrder(..)
, WithUndefined(..)
-- * Deriving Helpers
, FiniteDerive(..)
)
where

import Clash.Class.Finite.Internal
Loading

0 comments on commit 540afcf

Please sign in to comment.