5 * 64 bit right shift functions
8 * unsigned shrx(void *arg1, unsigned arg2)
10 * unsigned shrxs(void *arg1, unsigned arg2)
13 * Copyright (C) 1992,1993,1994
14 * W. Metzenthen, 22 Parker St, Ormond, Vic 3163,
15 * Australia. E-mail billm@vaxc.cc.monash.edu.au
16 * All rights reserved.
18 * This copyright notice covers the redistribution and use of the
19 * FPU emulator developed by W. Metzenthen. It covers only its use
20 * in the 386BSD, FreeBSD and NetBSD operating systems. Any other
21 * use is not permitted under this copyright.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
26 * 1. Redistributions of source code must retain the above copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must include information specifying
29 * that source code for the emulator is freely available and include
31 * a) an offer to provide the source code for a nominal distribution
33 * b) list at least two alternative methods whereby the source
34 * can be obtained, e.g. a publically accessible bulletin board
35 * and an anonymous ftp site from which the software can be
37 * 3. All advertising materials specifically mentioning features or use of
38 * this emulator must acknowledge that it was developed by W. Metzenthen.
39 * 4. The name of W. Metzenthen may not be used to endorse or promote
40 * products derived from this software without specific prior written
43 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
44 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
45 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
46 * W. METZENTHEN BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
47 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
48 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
49 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
50 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
51 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
52 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 * The purpose of this copyright, based upon the Berkeley copyright, is to
56 * ensure that the covered software remains freely available to everyone.
58 * The software (with necessary differences) is also available, but under
59 * the terms of the GNU copyleft, for the Linux operating system and for
60 * the djgpp ms-dos extender.
62 * W. Metzenthen June 1994.
65 * $FreeBSD: src/sys/gnu/i386/fpemul/wm_shrx.s,v 1.8 1999/08/28 00:42:59 peter Exp $
66 * $DragonFly: src/sys/platform/pc32/gnu/fpemul/Attic/wm_shrx.s,v 1.4 2003/08/07 21:17:21 dillon Exp $
75 /*---------------------------------------------------------------------------+
76 | unsigned shrx(void *arg1, unsigned arg2) |
78 | Extended shift right function. |
79 | Fastest for small shifts. |
80 | Shifts the 64 bit quantity pointed to by the first arg (arg1) |
81 | right by the number of bits specified by the second arg (arg2). |
82 | Forms a 96 bit quantity from the 64 bit arg and eax: |
83 | [ 64 bit arg ][ eax ] |
84 | shift right ---------> |
85 | The eax register is initialized to 0 before the shifting. |
86 | Results returned in the 64 bit arg and eax. |
87 +---------------------------------------------------------------------------*/
95 cmpl $32,%ecx /* shrd only works for 0..31 bits */
98 /* less than 32 bits */
100 movl (%esi),%ebx /* lsl */
101 movl 4(%esi),%edx /* msl */
102 xorl %eax,%eax /* extension */
118 movl (%esi),%eax /* lsl */
119 movl 4(%esi),%edx /* msl */
133 movl 4(%esi),%eax /* msl */
151 /*---------------------------------------------------------------------------+
152 | unsigned shrxs(void *arg1, unsigned arg2) |
154 | Extended shift right function (optimized for small floating point |
156 | Shifts the 64 bit quantity pointed to by the first arg (arg1) |
157 | right by the number of bits specified by the second arg (arg2). |
158 | Forms a 96 bit quantity from the 64 bit arg and eax: |
159 | [ 64 bit arg ][ eax ] |
160 | shift right ---------> |
161 | The eax register is initialized to 0 before the shifting. |
162 | The lower 8 bits of eax are lost and replaced by a flag which is |
163 | set (to 0x01) if any bit, apart from the first one, is set in the |
164 | part which has been shifted out of the arg. |
165 | Results returned in the 64 bit arg and eax. |
166 +---------------------------------------------------------------------------*/
175 cmpl $64,%ecx /* shrd only works for 0..31 bits */
178 cmpl $32,%ecx /* shrd only works for 0..31 bits */
181 /* We got here without jumps by assuming that the most common requirement
182 is for small integers */
183 /* Shift by [32..63] bits */
185 movl (%esi),%eax /* lsl */
186 movl 4(%esi),%edx /* msl */
191 orl %ebx,%ebx /* test these 32 bits */
193 test $0x7fffffff,%eax /* and 31 bits here */
195 orw %bx,%bx /* Any of the 63 bit set ? */
204 /* Shift by [0..31] bits */
206 movl (%esi),%ebx /* lsl */
207 movl 4(%esi),%edx /* msl */
208 xorl %eax,%eax /* extension */
212 test $0x7fffffff,%eax /* only need to look at eax here */
221 /* Shift by [64..95] bits */
227 movl (%esi),%ebx /* lsl */
228 movl 4(%esi),%eax /* msl */
229 xorl %edx,%edx /* extension */
235 test $0x7fffffff,%eax /* only need to look at eax here */
240 movl %edx,(%esi) /* set to zero */
241 movl %edx,4(%esi) /* set to zero */
248 /* Shift by [96..inf) bits */