xref: /csrg-svn/lib/libc/quad/ashrdi3.c (revision 61156)
153434Sbostic /*-
2*61156Sbostic  * Copyright (c) 1992, 1993
3*61156Sbostic  *	The Regents of the University of California.  All rights reserved.
453434Sbostic  *
553794Sbostic  * This software was developed by the Computer Systems Engineering group
653794Sbostic  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
753794Sbostic  * contributed to Berkeley.
853794Sbostic  *
953434Sbostic  * %sccs.include.redist.c%
1053434Sbostic  */
1153434Sbostic 
1253434Sbostic #if defined(LIBC_SCCS) && !defined(lint)
13*61156Sbostic static char sccsid[] = "@(#)ashrdi3.c	8.1 (Berkeley) 06/04/93";
1453434Sbostic #endif /* LIBC_SCCS and not lint */
1553434Sbostic 
1653794Sbostic #include "quad.h"
1753459Sbostic 
1853794Sbostic /*
1953794Sbostic  * Shift a (signed) quad value right (arithmetic shift right).
2053794Sbostic  */
2154431Sbostic quad_t
__ashrdi3(a,shift)2254431Sbostic __ashrdi3(a, shift)
2354431Sbostic 	quad_t a;
2454431Sbostic 	qshift_t shift;
2553434Sbostic {
2653794Sbostic 	union uu aa;
2753434Sbostic 
2853794Sbostic 	aa.q = a;
2953794Sbostic 	if (shift >= LONG_BITS) {
3053794Sbostic 		long s;
3153434Sbostic 
3253794Sbostic 		/*
3353794Sbostic 		 * Smear bits rightward using the machine's right-shift
3453794Sbostic 		 * method, whether that is sign extension or zero fill,
3553794Sbostic 		 * to get the `sign word' s.  Note that shifting by
3653794Sbostic 		 * LONG_BITS is undefined, so we shift (LONG_BITS-1),
3753794Sbostic 		 * then 1 more, to get our answer.
3853794Sbostic 		 */
3953794Sbostic 		s = (aa.sl[H] >> (LONG_BITS - 1)) >> 1;
4053794Sbostic 		aa.ul[L] = shift >= QUAD_BITS ? s :
4153794Sbostic 		    aa.sl[H] >> (shift - LONG_BITS);
4253794Sbostic 		aa.ul[H] = s;
4353794Sbostic 	} else if (shift > 0) {
4453794Sbostic 		aa.ul[L] = (aa.ul[L] >> shift) |
4553794Sbostic 		    (aa.ul[H] << (LONG_BITS - shift));
4653794Sbostic 		aa.sl[H] >>= shift;
4753794Sbostic 	}
4853794Sbostic 	return (aa.q);
4953434Sbostic }
50