Averest
// ************************************************************************** //
//                                                                            //
//    eses                   eses                                             //
//   eses                     eses                                            //
//  eses    eseses  esesese    eses   Embedded Systems Group                  //
//  ese    ese  ese ese         ese                                           //
//  ese    eseseses eseseses    ese   Department of Computer Science          //
//  eses   eses          ese   eses                                           //
//   eses   eseses  eseseses  eses    University of Kaiserslautern            //
//    eses                   eses                                             //
//                                                                            //
// ************************************************************************** //
// This module implements a full adder for the most significant digits of     //
// B-complement numbers. The difference to the radix-B full adder is that the //
// operands x and y are first interpreted by function alpha to their integer  //
// value and that the resulting cout-digit is mapped by function gamma so that//
// the interpretation of cout by alpha is correct.                            //
// Note that for even B=2b, alpha(x) and alpha(y) have type int{b} and thus,  //
// we have sm <= (b-1)+(b-1)+1 = 2b-1 = B-1 and -2b=(-b)+(-b)+0<= sm, so that //
// sm has type int{2b}=int{B}. For odd B=2b+1, alpha(x) and alpha(y) have type//
// int{b+1} and thus, we have sm <= b+b+1 = 2b+1 = B and (-b-1)+(-b-1)+0<= sm,//
// so that sm has type int{B+1}. In both cases, cout has type nat{B}.         // 
// ************************************************************************** //

macro B = 4;      // base of the radix numbers
macro alpha(x) = (x<B/2 ? +x : +x-B);
macro gamma(y) = (y<0 ? y+B : y);


module FullAddBC(nat{B} ?x,?y,nat{2} ?cin,nat{B} cout,nat{B} s) {
    event int{B+(B%2)} sm;
    sm = alpha(x) + alpha(y) + cin;
    s = sm % B;
    cout = gamma(sm / B);
}

           

averest