xref: /titanic_52/usr/src/lib/libc/sparc/gen/lshiftl.s (revision c1ecd8b9404ee0d96d93f02e82c441b9bb149a3d)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27/*	Copyright (c) 1988 AT&T	*/
28/*	  All Rights Reserved	*/
29
30#pragma ident	"%Z%%M%	%I%	%E% SMI"
31
32	.file	"%M%"
33
34/*
35 * Shift a double long value. Ported from m32 version to sparc.
36 *
37 *	dl_t
38 *	lshiftl (op, cnt)
39 *		dl_t	op;
40 *		int	cnt;
41 */
42
43#include "SYS.h"
44
45	ENTRY(lshiftl)
46
47	ld	[%o7+8],%o4		! Instruction at ret-addr should be a
48	cmp     %o4,8			! 'unimp 8' indicating a valid call.
49	be	1f			! if OK, go forward.
50	nop				! delay instruction.
51	jmp	%o7+8			! return
52	nop				! delay instruction.
53
541:
55	ld	[%o0+0],%o2		! fetch op.dl_hop
56	ld	[%o0+4],%o3		! fetch op.dl_lop
57	subcc	%g0,%o1,%o4		! test cnt < 0 and save reciprocol
58	bz	.done
59	ld	[%sp+(16*4)],%o0	! address to store result into
60	bg	.right			!
61	nop
62					! Positive (or null) shift (left)
63	and	%o1,0x3f,%o1		! Reduce range to 0..63
64	subcc	%o1,32,%o5		! cnt - 32 (also test cnt >= 32)
65	bneg,a	.leftsmall		!
66	add	%o4,32,%o4		! 32 - cnt (actually ((-cnt) + 32)
67	sll	%o3,%o5,%o2		! R.h = R.l << (cnt - 32)
68	ba	.done			!
69	or	%g0,%g0,%o3		! R.l = 0
70
71.leftsmall:
72	srl	%o3,%o4,%o5		! temp = R.l >> (31 - cnt)
73	sll	%o3,%o1,%o3		! R.l = R.l << cnt
74	sll	%o2,%o1,%o2		! R.h = R.h << cnt
75	ba	.done			!
76	or	%o2,%o5,%o2		! R.h = R.h | temp
77
78.right:					! Negative shift (right)
79	and	%o4,0x3f,%o4		! Reduce range to 0..63
80	subcc	%o4,32,%o5		! cnt - 32 (also test cnt >= 32)
81	bneg,a	.rightsmall		!
82	add	%o1,32,%o1		! 32 - cnt (actually ((-cnt) + 32)
83	srl	%o2,%o5,%o3		! R.l = R.h >> (cnt - 32)
84	ba	.done			!
85	or	%g0,%g0,%o2		! R.h = 0
86
87.rightsmall:
88	sll	%o2,%o1,%o5		! temp = R.h << (31 - cnt)
89	srl	%o3,%o4,%o3		! R.l = R.l >> cnt
90	srl	%o2,%o4,%o2		! R.h = R.h >> cnt
91	ba	.done			!
92	or	%o3,%o5,%o3		! R.l = R.l | temp
93
94.done:
95	st	%o2,[%o0+0]		! store result, dl_hop
96	jmp	%o7+12			! return
97	st	%o3,[%o0+4]		! store result, dl_lop
98
99	SET_SIZE(lshiftl)
100