xref: /netbsd-src/common/lib/libc/quad/lshldi3.c (revision c98323355a7e39795f5db0b5d75d23878f23c85a)
1*c9832335Schristos /*	$NetBSD: lshldi3.c,v 1.4 2012/12/07 15:41:02 christos Exp $	*/
237c9f0a6Schristos 
337c9f0a6Schristos /*-
437c9f0a6Schristos  * Copyright (c) 1992, 1993
537c9f0a6Schristos  *	The Regents of the University of California.  All rights reserved.
637c9f0a6Schristos  *
737c9f0a6Schristos  * This software was developed by the Computer Systems Engineering group
837c9f0a6Schristos  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
937c9f0a6Schristos  * contributed to Berkeley.
1037c9f0a6Schristos  *
1137c9f0a6Schristos  * Redistribution and use in source and binary forms, with or without
1237c9f0a6Schristos  * modification, are permitted provided that the following conditions
1337c9f0a6Schristos  * are met:
1437c9f0a6Schristos  * 1. Redistributions of source code must retain the above copyright
1537c9f0a6Schristos  *    notice, this list of conditions and the following disclaimer.
1637c9f0a6Schristos  * 2. Redistributions in binary form must reproduce the above copyright
1737c9f0a6Schristos  *    notice, this list of conditions and the following disclaimer in the
1837c9f0a6Schristos  *    documentation and/or other materials provided with the distribution.
1937c9f0a6Schristos  * 3. Neither the name of the University nor the names of its contributors
2037c9f0a6Schristos  *    may be used to endorse or promote products derived from this software
2137c9f0a6Schristos  *    without specific prior written permission.
2237c9f0a6Schristos  *
2337c9f0a6Schristos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2437c9f0a6Schristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2537c9f0a6Schristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2637c9f0a6Schristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2737c9f0a6Schristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2837c9f0a6Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2937c9f0a6Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3037c9f0a6Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3137c9f0a6Schristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3237c9f0a6Schristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3337c9f0a6Schristos  * SUCH DAMAGE.
3437c9f0a6Schristos  */
3537c9f0a6Schristos 
3637c9f0a6Schristos #include <sys/cdefs.h>
3737c9f0a6Schristos #if defined(LIBC_SCCS) && !defined(lint)
3837c9f0a6Schristos #if 0
3937c9f0a6Schristos static char sccsid[] = "@(#)lshldi3.c	8.1 (Berkeley) 6/4/93";
4037c9f0a6Schristos #else
41*c9832335Schristos __RCSID("$NetBSD: lshldi3.c,v 1.4 2012/12/07 15:41:02 christos Exp $");
4237c9f0a6Schristos #endif
4337c9f0a6Schristos #endif /* LIBC_SCCS and not lint */
4437c9f0a6Schristos 
4537c9f0a6Schristos #include "quad.h"
4637c9f0a6Schristos 
ARM_EABI_ALIAS(__aeabi_llsl,__lshldi3)47e2b9512bSmatt ARM_EABI_ALIAS(__aeabi_llsl, __lshldi3)	/* no semicolon */
48e2b9512bSmatt 
4937c9f0a6Schristos /*
5037c9f0a6Schristos  * Shift an (unsigned) quad value left (logical shift left).
5137c9f0a6Schristos  * This is the same as arithmetic shift left!
5237c9f0a6Schristos  */
5337c9f0a6Schristos quad_t
54103c3602Scegger __lshldi3(quad_t a, qshift_t shift)
5537c9f0a6Schristos {
5637c9f0a6Schristos 	union uu aa;
5737c9f0a6Schristos 
5837c9f0a6Schristos 	if (shift == 0)
5937c9f0a6Schristos 		return(a);
6037c9f0a6Schristos 	aa.q = a;
6137c9f0a6Schristos 	if (shift >= INT_BITS) {
62*c9832335Schristos 		aa.ul[H] = aa.ul[L] << (unsigned int)(shift - INT_BITS);
6337c9f0a6Schristos 		aa.ul[L] = 0;
6437c9f0a6Schristos 	} else {
6537c9f0a6Schristos 		aa.ul[H] = (aa.ul[H] << shift) |
6637c9f0a6Schristos 		    (aa.ul[L] >> (INT_BITS - shift));
6737c9f0a6Schristos 		aa.ul[L] <<= shift;
6837c9f0a6Schristos 	}
6937c9f0a6Schristos 	return (aa.q);
7037c9f0a6Schristos }
71