/**************************************************************************/
/*                                                                        */
/*                                 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_muad.c,v 1.2 1997/09/25 17:04:33 ae59 Exp $ */
/*
$Log: b_muad.c,v $
 * Revision 1.2  1997/09/25  17:04:33  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:21:32  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : b_muad.c                              */
/*                                                              */
/*      Entry           : void b_muad(a,b,lang)                 */
/*                        a_btyp a,b,*lang;                     */
/*                                                              */
/*      Arguments       : a = first operand for product         */
/*                        b = second operand for product        */
/*                        lang = a_btyp array (position for     */
/*                               least significant product part)*/
/*                                                              */
/*      Description     : Multiply a_btyp digits and add        */
/*                        product to a_btyp array               */
/*                                                              */
/*      Note            : Carry is propagated within array lang */
/*                                                              */
/*      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_muad(a_btyp a,a_btyp b,a_btyp *lang)
#else
local void b_muad(a,b,lang)

a_btyp a;
a_btyp b;
a_btyp *lang;
#endif
        {
        a_btyp ahigh,alow,bhigh,blow,chigh,clow,d,dummy;
        a_intg cout;

        ahigh = GETHIGH(a);
        alow  = GETLOW(a);
        bhigh = GETHIGH(b);
        blow  = GETLOW(b);

        /* product of cross terms                               */
        dummy = ahigh*blow;
        d = MOVEHIGH(dummy);

#if C_P_1
        clow = alow*blow;
        cout = (~clow<d) ? 1 : 0;
        clow += d;
#else
        b_addu(alow*blow,d,(a_intg)0,&clow,&cout);
#endif
        d = GETHIGH(dummy);
        chigh = ahigh*bhigh+d+cout;
        dummy = alow*bhigh;
        d = MOVEHIGH(dummy);
#if C_P_1
        cout = (~clow<d) ? 1 : 0;
        clow += d;
#else
        b_addu(clow,d,(a_intg)0,&clow,&cout);
#endif
        d = GETHIGH(dummy);
        chigh += d+cout;

        /* add product                                          */
#if C_P_1
        cout = (~*lang<clow) ? 1 : 0;
        *lang += clow;
        clow = lang[-1]+chigh+cout;
        if (~lang[-1]<chigh || clow==ZERO && cout)
                b_addc(lang-2);
        lang[-1] = clow;
#else
        b_addu(*lang,clow,(a_intg)0,lang,&cout);
        b_addu(lang[-1],chigh,cout,lang-1,&cout);
        if (cout) b_addc(lang-2);
#endif
        return;
        }
