Skip to content
/ RegCpp Public

C++17实现类似Chisel风格的时序逻辑 Chisel-style Reg in cpp

Notifications You must be signed in to change notification settings

MrAMS/RegCpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RegCpp

中文

tldr: A C++ 17 header-only library to write Chisel-style sequential logic Reg

Overview

A Reg example:

using WordT = uint32_t;
Reg<WordT> r1(0);
r1=r1+1;
for(int i=1;i<10;++i){
    SeqLogic::clock_step();
    assert(r1.out() == i);
}

Another Reg example:

using WordT = uint32_t;
Reg<WordT> r1(0);
r1=r1+1;
Reg<WordT> r2(r1*2);
assert(r1.out()==0);
SeqLogic::clock_step();
for(int i=1;i<10;++i){
    assert(r1.out() == i);
    assert(r2.out() == (i-1)*2);
    SeqLogic::clock_step();
}

A RegEnable example(a reg with enable signal):

using WordT = uint32_t;
Reg<WordT> r1(0);
r1=r1+1;
Reg<WordT> r2(r1*2, r1<=5);
assert(r1.out()==0);
SeqLogic::clock_step();
for(int i=1;i<10;++i){
    assert(r1.out() == i);
    assert(r2.out() == i>5?10:((i-1)*2));
    SeqLogic::clock_step();
}

A ShiftReg example:

using WordT = uint32_t;
const auto ShiftN = 3;
Reg<WordT> r1(0);
r1=r1+1;
ShiftReg<WordT, ShiftN> shift;
shift.in(r1);
for(int i=0;i<ShiftN;++i){
    SeqLogic::clock_step();
}
for(int i=0;i<ShiftN;++i){
    assert(shift.out().out()==i);
    SeqLogic::clock_step();
}

Purpose

A toy, try to automatically manages timing logic without having to manually manage.

Usage

header-only library, just include .hpp

Test

Install XMake, and run:

$ xmake build FrameworkTest
$ xmake run FrameworkTest

About

C++17实现类似Chisel风格的时序逻辑 Chisel-style Reg in cpp

Resources

Stars

Watchers

Forks