Skip to content

Commit 750e4ad

Browse files
authored
Merge pull request #11 from jakobj/feat/basic-adders
Add carry save adder
2 parents 87bec42 + fd39399 commit 750e4ad

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 carry_save_adder(chan?(int<N>) a_in, b_in, c_in; chan!(int<N>) s_out, d_out) {
27+
int<N> a, b, c;
28+
int<1> s[N], d[N];
29+
int<N> st, dt;
30+
31+
chp {
32+
*[ a_in?a, b_in?b, c_in?c;
33+
(, i : N : s[i] := (a{i} ^ b{i} ^ c{i}), d[i] := (a{i} & b{i} | ((a{i} ^ b{i}) & c{i})));
34+
st := (| i : N : s[i] << i),
35+
dt := (| i : N : d[i] << i);
36+
s_out!st, d_out!(dt << 1)
37+
]
38+
}
39+
}
40+
41+
}

0 commit comments

Comments
 (0)