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 $
70 #include <gnu/i386/fpemul/fpu_asm.h>
74 /*---------------------------------------------------------------------------+
75 | unsigned shrx(void *arg1, unsigned arg2) |
77 | Extended shift right function. |
78 | Fastest for small shifts. |
79 | Shifts the 64 bit quantity pointed to by the first arg (arg1) |
80 | right by the number of bits specified by the second arg (arg2). |
81 | Forms a 96 bit quantity from the 64 bit arg and eax: |
82 | [ 64 bit arg ][ eax ] |
83 | shift right ---------> |
84 | The eax register is initialized to 0 before the shifting. |
85 | Results returned in the 64 bit arg and eax. |
86 +---------------------------------------------------------------------------*/
94 cmpl $32,%ecx /* shrd only works for 0..31 bits */
97 /* less than 32 bits */
99 movl (%esi),%ebx /* lsl */
100 movl 4(%esi),%edx /* msl */
101 xorl %eax,%eax /* extension */
117 movl (%esi),%eax /* lsl */
118 movl 4(%esi),%edx /* msl */
132 movl 4(%esi),%eax /* msl */
150 /*---------------------------------------------------------------------------+
151 | unsigned shrxs(void *arg1, unsigned arg2) |
153 | Extended shift right function (optimized for small floating point |
155 | Shifts the 64 bit quantity pointed to by the first arg (arg1) |
156 | right by the number of bits specified by the second arg (arg2). |
157 | Forms a 96 bit quantity from the 64 bit arg and eax: |
158 | [ 64 bit arg ][ eax ] |
159 | shift right ---------> |
160 | The eax register is initialized to 0 before the shifting. |
161 | The lower 8 bits of eax are lost and replaced by a flag which is |
162 | set (to 0x01) if any bit, apart from the first one, is set in the |
163 | part which has been shifted out of the arg. |
164 | Results returned in the 64 bit arg and eax. |
165 +---------------------------------------------------------------------------*/
174 cmpl $64,%ecx /* shrd only works for 0..31 bits */
177 cmpl $32,%ecx /* shrd only works for 0..31 bits */
180 /* We got here without jumps by assuming that the most common requirement
181 is for small integers */
182 /* Shift by [32..63] bits */
184 movl (%esi),%eax /* lsl */
185 movl 4(%esi),%edx /* msl */
190 orl %ebx,%ebx /* test these 32 bits */
192 test $0x7fffffff,%eax /* and 31 bits here */
194 orw %bx,%bx /* Any of the 63 bit set ? */
203 /* Shift by [0..31] bits */
205 movl (%esi),%ebx /* lsl */
206 movl 4(%esi),%edx /* msl */
207 xorl %eax,%eax /* extension */
211 test $0x7fffffff,%eax /* only need to look at eax here */
220 /* Shift by [64..95] bits */
226 movl (%esi),%ebx /* lsl */
227 movl 4(%esi),%eax /* msl */
228 xorl %edx,%edx /* extension */
234 test $0x7fffffff,%eax /* only need to look at eax here */
239 movl %edx,(%esi) /* set to zero */
240 movl %edx,4(%esi) /* set to zero */
247 /* Shift by [96..inf) bits */