Skip to content

Commit 33a9a5b

Browse files
committed
Add basic adders (ripple carry, carry save)
1 parent 87bec42 commit 33a9a5b

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

math/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# limitations under the License.
1616
#
1717
#-------------------------------------------------------------------------
18-
TARGETACT=_all_.act fxp.act misc.act sint.act
18+
TARGETACT=_all_.act adders.act fxp.act misc.act sint.act
1919
TARGETACTSUBDIR=math
2020

2121
include $(ACT_HOME)/scripts/Makefile.std

math/_all_.act

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
**************************************************************************
2020
*/
2121

22+
import "math/adders.act";
2223
import "math/fxp.act";
2324
import "math/misc.act";
2425
import "math/sint.act";

math/adders.act

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*************************************************************************
2+
*
3+
* This file is part of ACT standard library
4+
*
5+
* Copyright (c) 2025 Jakob Jordan
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
**************************************************************************
20+
*/
21+
22+
namespace math {
23+
24+
export
25+
template<pint N>
26+
defproc ripple_carry_adder(chan?(int<N>) a_in, b_in; chan!(int<N>) s_out) {
27+
int<N> a, b;
28+
int<1> c[N];
29+
int<1> s[N];
30+
int<N> st;
31+
chp {
32+
*[ a_in?a, b_in?b;
33+
s[0] := (a{0} ^ b{0}),
34+
c[0] := a{0} & b{0};
35+
(;i : N-1 : s[i + 1] := (a{i + 1} ^ b{i + 1} ^ c[i]),
36+
c[i + 1] := (a{i + 1} & b{i + 1} | ((a{i + 1} ^ b{i + 1}) & c[i])));
37+
st := (| i : N : s[i] << i);
38+
s_out!st
39+
]
40+
}
41+
}
42+
43+
export
44+
template<pint N>
45+
defproc carry_save_adder(chan?(int<N>) a_in, b_in, c_in; chan!(int<N>) s_out, d_out) {
46+
int<N> a, b, c;
47+
int<1> s[N], d[N];
48+
int<N> st, dt;
49+
50+
chp {
51+
*[ a_in?a, b_in?b, c_in?c;
52+
(, i : N : s[i] := (a{i} ^ b{i} ^ c{i}), d[i] := (a{i} & b{i} | ((a{i} ^ b{i}) & c{i})));
53+
st := (| i : N : s[i] << i),
54+
dt := (| i : N : d[i] << i);
55+
s_out!st, d_out!(dt << 1)
56+
]
57+
}
58+
}
59+
60+
}

0 commit comments

Comments
 (0)