Questions tagged [clash]

CλaSH (pronounced ‘clash’) is a functional hardware description language that borrows both its syntax and semantics from the functional programming language Haskell.

From the CλaSH home page:

CλaSH (pronounced ‘clash’) is a functional hardware description language that borrows both its syntax and semantics from the functional programming language Haskell. It provides a familiar structural design approach to both combinational and synchronous sequential circuits. The CλaSH compiler transforms these high-level descriptions to low-level synthesizable VHDL, Verilog, or SystemVerilog.

20 questions
19
votes
2 answers

Creating a fold that allows the type to change after each repeated function call, in order to call a function n times without recursion

I am trying to use a dfold defined here dfold :: KnownNat k => Proxy (p :: TyFun Nat * -> *) -> (forall l. SNat l -> a -> (p @@ l) -> p @@ (l + 1)) -> (p @@ 0) -> Vec k a -> p @@ k Basically it is a fold that…
8
votes
2 answers

What's the difference between Chisel and Lava and CLaSH?

I've been studying the sources of Chisel and also various Lavas (Kansas, Chalmers and Xilinx flavors) and CLaSH. I'm trying to understand what's the main selling points of Chisel versus the others. The main one I've identified is fast simulation. I…
Michael Fox
  • 3,632
  • 1
  • 17
  • 27
4
votes
0 answers

Monadic API with "backpane" values

I'm creating a library for describing the connection of address lines to memory elements. I think a monadic API would work very nicely for creating components (with an identity, to support mirroring), and then using those component handles at…
Cactus
  • 27,075
  • 9
  • 69
  • 149
4
votes
1 answer

Why does an array update corrupt the element value?

The following standalone VHDL file is simplified from CLaSH's output, which should explain its somewhat weird structure. The intention is to increment s.tup2_sel1(0) in the cycle where s.tup2_sel0 is "01". However, what I see in a VHDL simulator is…
Cactus
  • 27,075
  • 9
  • 69
  • 149
3
votes
1 answer

Is it possible to infer a type that is a reflection-like closure?

With the following "toy model" of Clash: {-# LANGUAGE RankNTypes, KindSignatures, DataKinds, FlexibleContexts #-} -- Simplified model of platform definitions data Domain = DomSys | Dom25 data Signal (dom :: Domain) data Clock (dom ::…
Cactus
  • 27,075
  • 9
  • 69
  • 149
3
votes
1 answer

Why does the inliner choke on this construct?

I am trying to share as much code as possible between emulators and a CLaSH implementations for CPUs. As part of this, I am writing instruction fetching & decoding as something along the lines of fetchInstr :: (Monad m) => m Word8 -> m Instr This…
Cactus
  • 27,075
  • 9
  • 69
  • 149
3
votes
0 answers

nix-shell slow execution of program

I am working with clash (haskell -> verilog) compilation the demo project at https://github.com/mheinzel/clash-yosys-demo provides both a nix branch and one using stack. running time clash -v --verilog src/Top.hs -outputdir build takes ~ 1m if I…
epsilonhalbe
  • 15,637
  • 5
  • 46
  • 74
3
votes
2 answers

Using a quantified type equality constraint from the instance constraints

To set the scene, here are a bunch of language extensions we'll use, and some simplified definitions from CLaSH: {-# LANGUAGE GADTs, StandaloneDeriving #-} {-# LANGUAGE TypeOperators, DataKinds, PolyKinds #-} {-# LANGUAGE TypeFamilyDependencies,…
Cactus
  • 27,075
  • 9
  • 69
  • 149
3
votes
0 answers

Turn a function into a precomputed lookup table without going through Template Haskell

I have the following CLaSH function: toBCD :: Word8 -> Vec 3 Word8 toBCD x = x `div` 100 :> (x `div` 10) `mod` 10 :> x `mod` 10 :> Nil Of course, the resulting HDL module is unsynthesizable because of the division by a non-power of…
Cactus
  • 27,075
  • 9
  • 69
  • 149
3
votes
1 answer

Initializing registers

I have a very simple synchronous circuit that is supposed to blink an LED: module Blinker where import Clash.Prelude import Data.Word {-# NOINLINE topEntity #-} {-# ANN topEntity (Synthesize { t_name = "blinkerTop" , t_inputs =…
Cactus
  • 27,075
  • 9
  • 69
  • 149
3
votes
1 answer

Removing the type constraint on a type to a value that satisfies the constraints. I.e. Num a => a to just Int

I am using a system called CLaSH. For those who are not familiar it is designed in a way that allows you to develop for FPGAs using Haskell. I am trying to create an Unsigned…
error_null_pointer
  • 457
  • 1
  • 6
  • 21
2
votes
1 answer

What is the purpose of 'pure' keyword in the clash tutorial example?

In Clash official website, there is the following example : >>> sampleN @System 4 (register 0 (pure (8 :: Signed 8))) I know what is a pure function, but why this keyword here ? If I remove it I got an error : Clash.Prelude> sampleN @System 4…
FabienM
  • 3,421
  • 23
  • 45
2
votes
1 answer

Type-level conversion between period length and frequency

For ease of reading, I'd like to use clock frequency values as my type indices. However, I'll need to then check these for compatibility with clock domains, which represent their speed as period lengths. To make this a bit more concrete, suppose I…
Cactus
  • 27,075
  • 9
  • 69
  • 149
2
votes
2 answers

Term-level access to clock rate

I'd like to access the clock rate (in Hz) as a term-level value, so that I can use it in counters. One way I've been able to come up with so far involves unpacking the type-level Domain into its clock period (in ps), and then converting it into a…
Cactus
  • 27,075
  • 9
  • 69
  • 149
1
vote
1 answer

errors in running the clash interpreter

Running on an M1 mac, I installed stack via a nix-shell defined with: { pkgs ? import { system = "x86_64-darwin"; } }: pkgs.mkShell { buildInputs = [ pkgs.stack # required for clashi pkgs.libiconv pkgs.libffi ]; } I…
CrepeGoat
  • 2,315
  • 20
  • 24
1
2