ashldi3.c revision 165903
1263320Sdim/*-
2263320Sdim * Copyright (c) 1992, 1993
3263320Sdim *	The Regents of the University of California.  All rights reserved.
4263320Sdim *
5269012Semaste * This software was developed by the Computer Systems Engineering group
6263320Sdim * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7263320Sdim * contributed to Berkeley.
8263320Sdim *
9263320Sdim * Redistribution and use in source and binary forms, with or without
10263320Sdim * modification, are permitted provided that the following conditions
11263320Sdim * are met:
12263320Sdim * 1. Redistributions of source code must retain the above copyright
13263320Sdim *    notice, this list of conditions and the following disclaimer.
14263320Sdim * 2. Redistributions in binary form must reproduce the above copyright
15263320Sdim *    notice, this list of conditions and the following disclaimer in the
16263320Sdim *    documentation and/or other materials provided with the distribution.
17263320Sdim * 4. Neither the name of the University nor the names of its contributors
18263320Sdim *    may be used to endorse or promote products derived from this software
19263320Sdim *    without specific prior written permission.
20263320Sdim *
21263320Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22263320Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23263320Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24263320Sdim * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25263320Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26263320Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27263320Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28263320Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29263320Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30263320Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31263320Sdim * SUCH DAMAGE.
32263320Sdim */
33263320Sdim
34263320Sdim#if defined(LIBC_SCCS) && !defined(lint)
35263320Sdimstatic char sccsid[] = "@(#)ashldi3.c	8.1 (Berkeley) 6/4/93";
36263320Sdim#endif /* LIBC_SCCS and not lint */
37263320Sdim#include <sys/cdefs.h>
38263320Sdim__FBSDID("$FreeBSD: head/lib/libc/quad/ashldi3.c 165903 2007-01-09 00:28:16Z imp $");
39263320Sdim
40263320Sdim#include "quad.h"
41263320Sdim
42263320Sdim/*
43263320Sdim * Shift a (signed) quad value left (arithmetic shift left).
44263320Sdim * This is the same as logical shift left!
45263320Sdim */
46263320Sdimquad_t
47263320Sdim__ashldi3(a, shift)
48263320Sdim	quad_t a;
49263320Sdim	qshift_t shift;
50263320Sdim{
51263320Sdim	union uu aa;
52263320Sdim
53263320Sdim	aa.q = a;
54263320Sdim	if (shift >= LONG_BITS) {
55263320Sdim		aa.ul[H] = shift >= QUAD_BITS ? 0 :
56263320Sdim		    aa.ul[L] << (shift - LONG_BITS);
57263320Sdim		aa.ul[L] = 0;
58263320Sdim	} else if (shift > 0) {
59263320Sdim		aa.ul[H] = (aa.ul[H] << shift) |
60263320Sdim		    (aa.ul[L] >> (LONG_BITS - shift));
61263320Sdim		aa.ul[L] <<= shift;
62263320Sdim	}
63263320Sdim	return (aa.q);
64263320Sdim}
65263320Sdim