11414Scindi/*-
21414Scindi * Copyright (c) 1992, 1993
31414Scindi *	The Regents of the University of California.  All rights reserved.
41414Scindi *
51414Scindi * This software was developed by the Computer Systems Engineering group
61414Scindi * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
71414Scindi * contributed to Berkeley.
81414Scindi *
91414Scindi * Redistribution and use in source and binary forms, with or without
101414Scindi * modification, are permitted provided that the following conditions
111414Scindi * are met:
121414Scindi * 1. Redistributions of source code must retain the above copyright
131414Scindi *    notice, this list of conditions and the following disclaimer.
141414Scindi * 2. Redistributions in binary form must reproduce the above copyright
151414Scindi *    notice, this list of conditions and the following disclaimer in the
161414Scindi *    documentation and/or other materials provided with the distribution.
171414Scindi * 4. Neither the name of the University nor the names of its contributors
181414Scindi *    may be used to endorse or promote products derived from this software
191414Scindi *    without specific prior written permission.
201414Scindi *
211414Scindi * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221414Scindi * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
234328Scindi * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241414Scindi * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251414Scindi * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261414Scindi * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271414Scindi * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281414Scindi * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291414Scindi * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301414Scindi * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311414Scindi * SUCH DAMAGE.
321414Scindi */
331414Scindi
341414Scindi#if defined(LIBC_SCCS) && !defined(lint)
353062Scindistatic char sccsid[] = "@(#)lshrdi3.c	8.1 (Berkeley) 6/4/93";
363062Scindi#endif /* LIBC_SCCS and not lint */
373062Scindi#include <sys/cdefs.h>
383062Scindi__FBSDID("$FreeBSD$");
393062Scindi
401414Scindi#include "quad.h"
411414Scindi
423062Scindi/*
431414Scindi * Shift an (unsigned) quad value right (logical shift right).
441414Scindi */
451414Scindiquad_t
461414Scindi__lshrdi3(a, shift)
471414Scindi	quad_t a;
481414Scindi	qshift_t shift;
492027Ssethg{
501414Scindi	union uu aa;
511414Scindi
522027Ssethg	aa.q = a;
531414Scindi	if (shift >= LONG_BITS) {
541414Scindi		aa.ul[L] = shift >= QUAD_BITS ? 0 :
552027Ssethg		    aa.ul[H] >> (shift - LONG_BITS);
561414Scindi		aa.ul[H] = 0;
572027Ssethg	} else if (shift > 0) {
581414Scindi		aa.ul[L] = (aa.ul[L] >> shift) |
591414Scindi		    (aa.ul[H] << (LONG_BITS - shift));
601414Scindi		aa.ul[H] >>= shift;
612027Ssethg	}
622027Ssethg	return (aa.q);
631414Scindi}
641414Scindi