alpha: Update for pthread_attr_t typedef changes.
[glibc-ports.git] / sysdeps / m68k / m680x0 / lshift.S
blob047241ff5a99b61f4541072fdc9b13296efaeaa1
1 /* mc68020 __mpn_lshift -- Shift left a low-level natural-number integer.
3 Copyright (C) 1996, 1998, 2012 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or (at your
10 option) any later version.
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 MA 02111-1307, USA. */
23   INPUT PARAMETERS
24   res_ptr       (sp + 4)
25   s_ptr         (sp + 8)
26   s_size        (sp + 16)
27   cnt           (sp + 12)
30 #include "sysdep.h"
31 #include "asm-syntax.h"
33 #define res_ptr a1
34 #define s_ptr a0
35 #define s_size d6
36 #define cnt d4
38         TEXT
39 ENTRY(__mpn_lshift)
41 /* Save used registers on the stack.  */
42         moveml  R(d2)-R(d6)/R(a2),MEM_PREDEC(sp)
43         cfi_adjust_cfa_offset (6*4)
44         cfi_rel_offset (R(d2), 0)
45         cfi_rel_offset (R(d3), 4)
46         cfi_rel_offset (R(d4), 8)
47         cfi_rel_offset (R(d5), 12)
48         cfi_rel_offset (R(d6), 16)
49         cfi_rel_offset (R(a2), 20)
51 /* Copy the arguments to registers.  */
52         movel   MEM_DISP(sp,28),R(res_ptr)
53         movel   MEM_DISP(sp,32),R(s_ptr)
54         movel   MEM_DISP(sp,36),R(s_size)
55         movel   MEM_DISP(sp,40),R(cnt)
57         moveql  #1,R(d5)
58         cmpl    R(d5),R(cnt)
59         bne     L(Lnormal)
60         cmpl    R(s_ptr),R(res_ptr)
61         bls     L(Lspecial)             /* jump if s_ptr >= res_ptr */
62 #if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020))
63         lea     MEM_INDX1(s_ptr,s_size,l,4),R(a2)
64 #else /* not mc68020 */
65         movel   R(s_size),R(d0)
66         asll    #2,R(d0)
67         lea     MEM_INDX(s_ptr,d0,l),R(a2)
68 #endif
69         cmpl    R(res_ptr),R(a2)
70         bls     L(Lspecial)             /* jump if res_ptr >= s_ptr + s_size */
72 L(Lnormal:)
73         moveql  #32,R(d5)
74         subl    R(cnt),R(d5)
76 #if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020))
77         lea     MEM_INDX1(s_ptr,s_size,l,4),R(s_ptr)
78         lea     MEM_INDX1(res_ptr,s_size,l,4),R(res_ptr)
79 #else /* not mc68000 */
80         movel   R(s_size),R(d0)
81         asll    #2,R(d0)
82         addl    R(s_size),R(s_ptr)
83         addl    R(s_size),R(res_ptr)
84 #endif
85         movel   MEM_PREDEC(s_ptr),R(d2)
86         movel   R(d2),R(d0)
87         lsrl    R(d5),R(d0)             /* compute carry limb */
89         lsll    R(cnt),R(d2)
90         movel   R(d2),R(d1)
91         subql   #1,R(s_size)
92         beq     L(Lend)
93         lsrl    #1,R(s_size)
94         bcs     L(L1)
95         subql   #1,R(s_size)
97 L(Loop:)
98         movel   MEM_PREDEC(s_ptr),R(d2)
99         movel   R(d2),R(d3)
100         lsrl    R(d5),R(d3)
101         orl     R(d3),R(d1)
102         movel   R(d1),MEM_PREDEC(res_ptr)
103         lsll    R(cnt),R(d2)
104 L(L1:)
105         movel   MEM_PREDEC(s_ptr),R(d1)
106         movel   R(d1),R(d3)
107         lsrl    R(d5),R(d3)
108         orl     R(d3),R(d2)
109         movel   R(d2),MEM_PREDEC(res_ptr)
110         lsll    R(cnt),R(d1)
112         dbf     R(s_size),L(Loop)
113         subl    #0x10000,R(s_size)
114         bcc     L(Loop)
116 L(Lend:)
117         movel   R(d1),MEM_PREDEC(res_ptr) /* store least significant limb */
119 /* Restore used registers from stack frame.  */
120         moveml  MEM_POSTINC(sp),R(d2)-R(d6)/R(a2)
121         cfi_remember_state
122         cfi_adjust_cfa_offset (-6*4)
123         cfi_restore (R(d2))
124         cfi_restore (R(d3))
125         cfi_restore (R(d4))
126         cfi_restore (R(d5))
127         cfi_restore (R(d6))
128         cfi_restore (R(a2))
129         rts
131 /* We loop from least significant end of the arrays, which is only
132    permissible if the source and destination don't overlap, since the
133    function is documented to work for overlapping source and destination.  */
135         cfi_restore_state
136 L(Lspecial:)
137         clrl    R(d0)                   /* initialize carry */
138         eorw    #1,R(s_size)
139         lsrl    #1,R(s_size)
140         bcc     L(LL1)
141         subql   #1,R(s_size)
143 L(LLoop:)
144         movel   MEM_POSTINC(s_ptr),R(d2)
145         addxl   R(d2),R(d2)
146         movel   R(d2),MEM_POSTINC(res_ptr)
147 L(LL1:)
148         movel   MEM_POSTINC(s_ptr),R(d2)
149         addxl   R(d2),R(d2)
150         movel   R(d2),MEM_POSTINC(res_ptr)
152         dbf     R(s_size),L(LLoop)
153         addxl   R(d0),R(d0)             /* save cy in lsb */
154         subl    #0x10000,R(s_size)
155         bcs     L(LLend)
156         lsrl    #1,R(d0)                /* restore cy */
157         bra     L(LLoop)
159 L(LLend:)
160 /* Restore used registers from stack frame.  */
161         moveml  MEM_POSTINC(sp),R(d2)-R(d6)/R(a2)
162         cfi_adjust_cfa_offset (-6*4)
163         cfi_restore (R(d2))
164         cfi_restore (R(d3))
165         cfi_restore (R(d4))
166         cfi_restore (R(d5))
167         cfi_restore (R(d6))
168         cfi_restore (R(a2))
169         rts
170 END(__mpn_lshift)