ashldi3.c revision 256281
159612Sjasone/*-
250476Speter * Copyright (c) 1992, 1993
338540Sjb *	The Regents of the University of California.  All rights reserved.
4103412Smini *
538540Sjb * This software was developed by the Computer Systems Engineering group
638540Sjb * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
759612Sjasone * contributed to Berkeley.
838540Sjb *
976912Sjasone * Redistribution and use in source and binary forms, with or without
1076912Sjasone * modification, are permitted provided that the following conditions
1176912Sjasone * are met:
1259612Sjasone * 1. Redistributions of source code must retain the above copyright
1376912Sjasone *    notice, this list of conditions and the following disclaimer.
1476912Sjasone * 2. Redistributions in binary form must reproduce the above copyright
1580021Sjasone *    notice, this list of conditions and the following disclaimer in the
1659612Sjasone *    documentation and/or other materials provided with the distribution.
1776912Sjasone * 4. Neither the name of the University nor the names of its contributors
1880021Sjasone *    may be used to endorse or promote products derived from this software
1959612Sjasone *    without specific prior written permission.
2059612Sjasone *
2176912Sjasone * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2259612Sjasone * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2359612Sjasone * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2476912Sjasone * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2559612Sjasone * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2659612Sjasone * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2759612Sjasone * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2859612Sjasone * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29125468Sdavidxu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3059612Sjasone * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3159612Sjasone * SUCH DAMAGE.
32118854Smarcel */
3359612Sjasone
3459612Sjasone#if defined(LIBC_SCCS) && !defined(lint)
3559612Sjasonestatic char sccsid[] = "@(#)ashldi3.c	8.1 (Berkeley) 6/4/93";
3659612Sjasone#endif /* LIBC_SCCS and not lint */
3759612Sjasone#include <sys/cdefs.h>
3859612Sjasone__FBSDID("$FreeBSD: stable/10/lib/libc/quad/ashldi3.c 165903 2007-01-09 00:28:16Z imp $");
3959612Sjasone
4059612Sjasone#include "quad.h"
4159612Sjasone
4259612Sjasone/*
4359612Sjasone * Shift a (signed) quad value left (arithmetic shift left).
4459612Sjasone * This is the same as logical shift left!
4559612Sjasone */
4659612Sjasonequad_t
4776912Sjasone__ashldi3(a, shift)
4859612Sjasone	quad_t a;
4959612Sjasone	qshift_t shift;
5059612Sjasone{
5159612Sjasone	union uu aa;
5259612Sjasone
5359612Sjasone	aa.q = a;
5459612Sjasone	if (shift >= LONG_BITS) {
5559612Sjasone		aa.ul[H] = shift >= QUAD_BITS ? 0 :
5659612Sjasone		    aa.ul[L] << (shift - LONG_BITS);
5759612Sjasone		aa.ul[L] = 0;
5859612Sjasone	} else if (shift > 0) {
5959612Sjasone		aa.ul[H] = (aa.ul[H] << shift) |
6059612Sjasone		    (aa.ul[L] >> (LONG_BITS - shift));
6159612Sjasone		aa.ul[L] <<= shift;
6259612Sjasone	}
6359612Sjasone	return (aa.q);
6459612Sjasone}
6576912Sjasone