-
Notifications
You must be signed in to change notification settings - Fork 0
/
gates.cpp
135 lines (113 loc) · 2.21 KB
/
gates.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include"gates.h"
/*These are the available logic gates. Most other gates can be created by combining these core gates
* They are all reversible and can be implemented like classical gates.*/
//defines the valley current variable type
typedef std::vector<double> valley_volt;
c_valley :: c_valley(){}
//not gate
valley_volt c_valley :: vnot(double V_G1, double V_S)
{
valley_volt V_out(2);
if(V_G1!=0)
{
V_out[0]=0;
V_out[1]=0;
return V_out;
}
else
{
V_out[0] = V_S;
V_out[1] = 1;
return V_out;
}
}
//and gate
valley_volt c_valley :: vand(double V_G1, double V_G2, double V_S, double V_ref)
{
valley_volt v1(2);
v1 = vnand(V_G1, V_G2, V_S, V_ref);
double temp = v1[0];
v1 = vnot(temp, V_S);
return v1;
}
//nand gate
valley_volt c_valley :: vnand(double V_G1, double V_G2, double V_S, double V_ref)
{
valley_volt V_out(2);
valley_volt V_t(2);
V_t = vnot(V_G1, V_S);
double V_test = V_t[0]-V_ref;
if(V_test!=0)
{
if(V_G2>0)
{
V_out[0]=0;
V_out[1]=0;
return V_out;
}
else
{
V_out[0] = V_S;
V_out[1] = -1;
}
}
else
{
V_out[0] = V_S;
if(V_G2==0)
{
V_out[1]=0;
return V_out;
}
else V_out[1] = 1;
}
return V_out;
}
//or gate
valley_volt c_valley :: vor(double V_G1, double V_G2, double V_S, double V_ref)
{
valley_volt Vout(2);
valley_volt Vt;
Vt = vnot(V_G1,V_S);
double Vtest = V_G2-V_ref;
if(Vt[0]==0)
{
Vout[0]=10;
if(Vtest==0) Vout[1]=0;
else Vout[1]=-1;
}
else
{
if(Vtest==0)
{
Vout[0]=10;
Vout[1]=1;
}
else
{
Vout[0]=0;
Vout[1]=0;
}
}
return Vout;
}
//nand based xor gate
valley_volt c_valley :: vxor(double V_G1, double V_G2, double V_S, double V_ref)
{
valley_volt v1(2);
v1 = vnand(V_G1, V_G2, V_S, V_ref);
double temp = v1[0];
valley_volt v2(2);
valley_volt v3(2);
v2 = vnand(V_G1,temp,V_S,V_ref);
v3 = vnand(temp,V_G2,V_S,V_ref);
double temp1 = v2[0];
double temp2 = v3[0];
valley_volt Vout(2);
Vout = vnand(temp1,temp2,V_S,V_ref);
return Vout;
}
c_valley :: ~c_valley(){}