forked from cdkersey/chdl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gates.h
50 lines (42 loc) · 1.05 KB
/
gates.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Basic gates.
#ifndef __GATES_H
#define __GATES_H
#include "node.h"
#include "hierarchy.h"
namespace chdl {
// Functions to instantiate the basic logic types.
node Nand(const node &a, const node &b);
node Inv (const node &in);
// Simple combinations of the basic logic types.
static node Nor(const node &a, const node &b) {
HIERARCHY_ENTER();
node r(Inv(Nand(Inv(a), Inv(b))));
HIERARCHY_EXIT();
return r;
}
static node And(const node &a, const node &b) {
HIERARCHY_ENTER();
node r(Inv(Nand(a, b)));
HIERARCHY_EXIT();
return r;
}
static node Or(const node &a, const node &b) {
HIERARCHY_ENTER();
node r(Nand(Inv(a), Inv(b)));
HIERARCHY_EXIT();
return r;
}
static node Xor(const node &a, const node &b) {
HIERARCHY_ENTER();
node r(And(Or(a, b), Nand(a, b)));
HIERARCHY_EXIT();
return r;
}
static node Mux(const node &s, const node &i0, const node &i1) {
HIERARCHY_ENTER();
node r(Nand(Nand(Inv(s), i0), Nand(s, i1)));
HIERARCHY_EXIT();
return r;
}
};
#endif