/**************************************************************************/
/*                                                                        */
/*                                 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_shru.c,v 1.2 1997/09/25 17:07:03 ae59 Exp $ */
/*
$Log: b_shru.c,v $
 * Revision 1.2  1997/09/25  17:07:03  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:21:41  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : b_shru.c                              */
/*                                                              */
/*      Entries         : void b_shru(lang,laenge,dist);        */
/*                        a_btyp *lang;                         */
/*                        a_intg laenge,dist;                   */
/*                                                              */
/*      Arguments       : lang = array of length laenge         */
/*                        laenge = length of array lang         */
/*                        dist = number of bits to be shifted   */
/*                                                              */
/*      Description     : Shift a_btyp array lang of length     */
/*                        laenge by dist positions to right     */
/*                                                              */
/*      Date            : 1993-05-28                            */
/*      1993-05-28 : B_ASHR() arithmetic shift right 4 Cray =b= */
/*      1991-01-29 : B_ASHR() arithmetic shift right.           */
/*      1990-07-16 : LINT_ARGS prototype                        */
/*      1990-09-03 : loop for dist!=0 corrected                 */
/****************************************************************/

#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_shru(a_btyp *lang,a_intg laenge,a_intg dist)
#else
local void b_shru(lang,laenge,dist)

a_btyp *lang;
a_intg laenge;
a_intg dist;
#endif
        {
        a_intg i,bigdist;

        /* shift by blocks of B_LENGTH                          */
        if ( (bigdist = B_ASHR(dist,LOG_B_LENGTH))!=0 ) {
                for ( i=laenge-1; i>=bigdist; i-- )
                        lang[i] = lang[i-bigdist];
                for ( i=0; i<bigdist && i<laenge; i++ ) lang[i] = ZERO;
                dist &= (B_LENGTH-1);
                }

        /* shift by block of length dist                        */
        if (dist) {
            for ( i=laenge-1; i>bigdist; i-- )
                lang[i] = (lang[i]>>dist) |
                        (lang[i-1]<<(B_LENGTH-dist));
#if CRAY_UNIX_C
            lang[bigdist]  = B_ASHR(lang[bigdist],dist);
#else
            lang[bigdist] >>= dist;
#endif
            }

        return;
        }
