Giter Site home page Giter Site logo

yjwen / hada Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 216 KB

Experimental Haskell-to-HDL compiler

License: GNU Lesser General Public License v3.0

Haskell 95.05% Verilog 0.10% SystemVerilog 1.02% Makefile 2.25% Yacc 0.98% Logos 0.60%

hada's People

Contributors

yjwen avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

mariszo

hada's Issues

Compile combinational logics

Let's start from a very primitive Haskell function:

abs :: Word -> Word -> Word
abs a b | a < b = b - a
        | otherwise = a - b

Ideally, the Haskell function abs should be compiled to a Verilog module

module abs (a, b, out);
  input [0:63] a;
  input [0:63] b;
  output [0:63] out;
  assign out = (a < b) ? b - a : a - b;
endmodule

Simple numbers with data constructor

To translate

module MaybePlus where
maybe_plus :: Maybe Int -> Maybe Int -> Maybe Int
maybe_plus (Just a) (Just b) = Just (a + b)
maybe_plus _ _ = Nothing

to

typedef struct {
   logic ctor;
   logic [63 : 0] body;
} MaybeInt;

module maybe_plus(MaybeInt a, MaybeInt b, output MaybeInt o);
   assign o.ctor = a.ctor && b.ctor;
   assign o.body = o.ctor ? a.body + b.body : 'x;
endmodule

Type for fixed-width integer computation

Fixed-width integer computation is common in HDL simulation and design, but a rare case for programming languages. There should be pre-defined types for Haskell to model fixed-width integer computation of arbitrary width.

The ideal implementation for "arbitrary width" should be done at compile time, one type instance for one possible width, by template Haskell.

The expected sample usage of fixed-width integer types is like:

import FixedWidth

-- To declare a type Bit7, which is a fixed-width integer type of 7 bit
$(declareFW Bit7 7)

Adaptive base type for fixed-width types

Fixed-width types are now derived from Int and Word, regardless of the specified width.

It is a waste to use Int, which is usually 64bit, to represent a 7-bit fixed-width values.

To reduce memory cost, the fixed-width types should be represented by an integer type of width as few as possible. For example, the 7-bit fixed-width type should be represented by Int8 or Word8, the 15-bit one by Int16 or Word16.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.