|
| 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 | +} |