/**************************************************************************/
/*                                                                        */
/*                                 Sources                                */
/*                                from  the                               */
/*                           XSC SOFTWARE PACKAGE                         */
/*                                                                        */
/*                Copyright (c) 1997 University of Karlsruhe              */
/*                     Institute for Appl. Mathematics                    */
/*                                                                        */
/* This program is free software for non-commercial use. For details, see */
/* the file LICENSE.XSC, distributed with this software package.          */
/*                                                                        */
/* This program is distributed WITHOUT ANY WARRANTY. For details, see the */
/* file LICENSE.XSC, distributed with this software package.              */
/*                                                                        */
/**************************************************************************/

/* RCS $Id: b_addu.c,v 1.2 1997/09/25 16:55:00 ae59 Exp $ */
/*
$Log: b_addu.c,v $
 * Revision 1.2  1997/09/25  16:55:00  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:20:55  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : b_addu.c                              */
/*                                                              */
/*      Entry           : void b_addu(a,b,cin,c,cout)           */
/*                        a_btyp a,b,*c;                        */
/*                        a_intg cin,*cout;                     */
/*                                                              */
/*      Arguments       : a = first operand of addition         */
/*                        b = second operand of addition        */
/*                        cin = carry in                        */
/*                        c = a+b+cin                           */
/*                        cout = carry out                      */
/*                                                              */
/*      Description     : Addition of a_btyp digits             */
/*                        with carry                            */
/*                                                              */
/*      Date            : 1990-07-16                            */
/*      1990-07-16 : LINT_ARGS prototype                        */
/****************************************************************/

#ifndef ALL_IN_ONE
#ifdef AIX
#include "/u/p88c/runtime/o_defs.h"
#else
#include "o_defs.h"
#endif
#define local
#endif

#ifdef LINT_ARGS
local void b_addu(a_btyp a,a_btyp b,a_intg cin,a_btyp *c,a_intg *cout)
#else
local void b_addu(a,b,cin,c,cout)

a_btyp a;
a_btyp b;
a_intg cin;
a_btyp *c;
a_intg *cout;
#endif
        {
#if C_P_1
        *c = a+b+cin;
        *cout = (~a<b || (*c==ZERO && cin)) ? 1 : 0;
#else
        /* a+b produce no carry                                 */
        if ( ~a>=b )
                {
                *c = a+b;

                /* add cin to (a+b)                             */
                if (cin && *c==MAX_BASETYPE ) {
                        *c    = ZERO;
                        *cout = 1;
                        }
                else
                        {
                        *c += cin;
                        *cout = 0;
                        }
                return;
                }

        /* a+b produces carry                                   */
        if (a & MSB)
            if (b & MSB) *c = ((a^MSB)+(b^MSB))+cin;
            else *c = (((a^MSB)+b)^MSB)+cin;
        else *c = (((b^MSB)+a)^MSB)+cin;
        *cout = 1;
#endif

        return;
        }

