153434Sbostic /*- 253434Sbostic * Copyright (c) 1992 The Regents of the University of California. 353434Sbostic * All rights reserved. 453434Sbostic * 5*53794Sbostic * This software was developed by the Computer Systems Engineering group 6*53794Sbostic * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 7*53794Sbostic * contributed to Berkeley. 8*53794Sbostic * 953434Sbostic * %sccs.include.redist.c% 1053434Sbostic */ 1153434Sbostic 1253434Sbostic #if defined(LIBC_SCCS) && !defined(lint) 13*53794Sbostic static char sccsid[] = "@(#)ashrdi3.c 5.4 (Berkeley) 06/02/92"; 1453434Sbostic #endif /* LIBC_SCCS and not lint */ 1553434Sbostic 16*53794Sbostic #include "quad.h" 1753459Sbostic 18*53794Sbostic /* 19*53794Sbostic * Shift a (signed) quad value right (arithmetic shift right). 20*53794Sbostic */ 21*53794Sbostic quad 22*53794Sbostic __ashrdi3(quad a, register unsigned int shift) 2353434Sbostic { 24*53794Sbostic union uu aa; 2553434Sbostic 26*53794Sbostic aa.q = a; 27*53794Sbostic if (shift >= LONG_BITS) { 28*53794Sbostic long s; 2953434Sbostic 30*53794Sbostic /* 31*53794Sbostic * Smear bits rightward using the machine's right-shift 32*53794Sbostic * method, whether that is sign extension or zero fill, 33*53794Sbostic * to get the `sign word' s. Note that shifting by 34*53794Sbostic * LONG_BITS is undefined, so we shift (LONG_BITS-1), 35*53794Sbostic * then 1 more, to get our answer. 36*53794Sbostic */ 37*53794Sbostic s = (aa.sl[H] >> (LONG_BITS - 1)) >> 1; 38*53794Sbostic aa.ul[L] = shift >= QUAD_BITS ? s : 39*53794Sbostic aa.sl[H] >> (shift - LONG_BITS); 40*53794Sbostic aa.ul[H] = s; 41*53794Sbostic } else if (shift > 0) { 42*53794Sbostic aa.ul[L] = (aa.ul[L] >> shift) | 43*53794Sbostic (aa.ul[H] << (LONG_BITS - shift)); 44*53794Sbostic aa.sl[H] >>= shift; 45*53794Sbostic } 46*53794Sbostic return (aa.q); 4753434Sbostic } 48