1 /*- 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This software was developed by the Computer Systems Engineering group 6 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 7 * contributed to Berkeley. 8 * 9 * %sccs.include.redist.c% 10 */ 11 12 #if defined(LIBC_SCCS) && !defined(lint) 13 static char sccsid[] = "@(#)ashrdi3.c 8.1 (Berkeley) 06/04/93"; 14 #endif /* LIBC_SCCS and not lint */ 15 16 #include "quad.h" 17 18 /* 19 * Shift a (signed) quad value right (arithmetic shift right). 20 */ 21 quad_t 22 __ashrdi3(a, shift) 23 quad_t a; 24 qshift_t shift; 25 { 26 union uu aa; 27 28 aa.q = a; 29 if (shift >= LONG_BITS) { 30 long s; 31 32 /* 33 * Smear bits rightward using the machine's right-shift 34 * method, whether that is sign extension or zero fill, 35 * to get the `sign word' s. Note that shifting by 36 * LONG_BITS is undefined, so we shift (LONG_BITS-1), 37 * then 1 more, to get our answer. 38 */ 39 s = (aa.sl[H] >> (LONG_BITS - 1)) >> 1; 40 aa.ul[L] = shift >= QUAD_BITS ? s : 41 aa.sl[H] >> (shift - LONG_BITS); 42 aa.ul[H] = s; 43 } else if (shift > 0) { 44 aa.ul[L] = (aa.ul[L] >> shift) | 45 (aa.ul[H] << (LONG_BITS - shift)); 46 aa.sl[H] >>= shift; 47 } 48 return (aa.q); 49 } 50