Work around old buggy program which cannot cope with memcpy semantics.
[glibc.git] / sysdeps / x86_64 / rshift.S
blob8ff055169aed59e0a7b1726c7151bbfe2a216bc7
1 /* x86-64 __mpn_rshift --
2    Copyright (C) 2007, 2009 Free Software Foundation, Inc.
3    This file is part of the GNU MP Library.
5    The GNU MP Library is free software; you can redistribute it and/or modify
6    it under the terms of the GNU Lesser General Public License as published by
7    the Free Software Foundation; either version 2.1 of the License, or (at your
8    option) any later version.
10    The GNU MP Library is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
13    License for more details.
15    You should have received a copy of the GNU Lesser General Public License
16    along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
17    the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18    MA 02111-1307, USA. */
20 #include "sysdep.h"
21 #include "asm-syntax.h"
23 #define rp      %rdi
24 #define up      %rsi
25 #define n       %rdx
26 #define cnt     %cl
28         .text
29 ENTRY (__mpn_rshift)
30         mov     %edx, %eax
31         and     $3, %eax
32         jne     L(nb00)
33 L(b00): /* n = 4, 8, 12, ... */
34         mov     (up), %r10
35         mov     8(up), %r11
36         xor     %eax, %eax
37         shrd    %cl, %r10, %rax
38         mov     16(up), %r8
39         lea     8(up), up
40         lea     -24(rp), rp
41         sub     $4, n
42         jmp     L(00)
44 L(nb00):/* n = 1, 5, 9, ... */
45         cmp     $2, %eax
46         jae     L(nb01)
47 L(b01): mov     (up), %r9
48         xor     %eax, %eax
49         shrd    %cl, %r9, %rax
50         sub     $2, n
51         jb      L(le1)
52         mov     8(up), %r10
53         mov     16(up), %r11
54         lea     16(up), up
55         lea     -16(rp), rp
56         jmp     L(01)
57 L(le1): shr     %cl, %r9
58         mov     %r9, (rp)
59         ret
61 L(nb01):/* n = 2, 6, 10, ... */
62         jne     L(b11)
63 L(b10): mov     (up), %r8
64         mov     8(up), %r9
65         xor     %eax, %eax
66         shrd    %cl, %r8, %rax
67         sub     $3, n
68         jb      L(le2)
69         mov     16(up), %r10
70         lea     24(up), up
71         lea     -8(rp), rp
72         jmp     L(10)
73 L(le2): shrd    %cl, %r9, %r8
74         mov     %r8, (rp)
75         shr     %cl, %r9
76         mov     %r9, 8(rp)
77         ret
79         .p2align 4
80 L(b11): /* n = 3, 7, 11, ... */
81         mov     (up), %r11
82         mov     8(up), %r8
83         xor     %eax, %eax
84         shrd    %cl, %r11, %rax
85         mov     16(up), %r9
86         lea     32(up), up
87         sub     $4, n
88         jb      L(end)
90         .p2align 4
91 L(top): shrd    %cl, %r8, %r11
92         mov     -8(up), %r10
93         mov     %r11, (rp)
94 L(10):  shrd    %cl, %r9, %r8
95         mov     (up), %r11
96         mov     %r8, 8(rp)
97 L(01):  shrd    %cl, %r10, %r9
98         mov     8(up), %r8
99         mov     %r9, 16(rp)
100 L(00):  shrd    %cl, %r11, %r10
101         mov     16(up), %r9
102         mov     %r10, 24(rp)
103         add     $32, up
104         lea     32(rp), rp
105         sub     $4, n
106         jnc     L(top)
108 L(end): shrd    %cl, %r8, %r11
109         mov     %r11, (rp)
110         shrd    %cl, %r9, %r8
111         mov     %r8, 8(rp)
112         shr     %cl, %r9
113         mov     %r9, 16(rp)
114         ret
115 END (__mpn_rshift)