1dnl  mpn_addsub
2
3dnl  Copyright 2011 The Code Cavern
4
5dnl  This file is part of the MPIR Library.
6
7dnl  The MPIR Library is free software; you can redistribute it and/or modify
8dnl  it under the terms of the GNU Lesser General Public License as published
9dnl  by the Free Software Foundation; either version 2.1 of the License, or (at
10dnl  your option) any later version.
11
12dnl  The MPIR Library is distributed in the hope that it will be useful, but
13dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15dnl  License for more details.
16
17dnl  You should have received a copy of the GNU Lesser General Public License
18dnl  along with the MPIR Library; see the file COPYING.LIB.  If not, write
19dnl  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20dnl  Boston, MA 02110-1301, USA.
21
22include(`../config.m4')
23
24ASM_START()
25PROLOGUE(mpn_addsub_n)
26push %rbx
27xor %r9,%r9
28push %rbp
29xor %rax,%rax
30mov $3,%r10d
31sub %r8,%r10
32lea -24(%rdi,%r8,8),%rdi
33lea -24(%rsi,%r8,8),%rsi
34lea -24(%rdx,%r8,8),%rdx
35lea -24(%rcx,%r8,8),%rcx
36jnc skiplp
37.align 16
38lp:     .byte 0x9e      # sahf
39	mov (%rdx,%r10,8),%r8
40	sbb (%rcx,%r10,8),%r8
41	mov 8(%rdx,%r10,8),%rbx
42	sbb 8(%rcx,%r10,8),%rbx
43	mov 24(%rdx,%r10,8),%r11
44	mov 16(%rdx,%r10,8),%rbp
45	sbb 16(%rcx,%r10,8),%rbp
46	sbb 24(%rcx,%r10,8),%r11
47        .byte 0x9f      # lahf
48	add $255,%r9b
49	adc (%rsi,%r10,8),%r8
50	adc 8(%rsi,%r10,8),%rbx
51	mov %r8,(%rdi,%r10,8)
52	adc 16(%rsi,%r10,8),%rbp
53	adc 24(%rsi,%r10,8),%r11
54	setc %r9b
55	mov %r11,24(%rdi,%r10,8)
56	mov %rbp,16(%rdi,%r10,8)
57	mov %rbx,8(%rdi,%r10,8)
58	add $4,%r10
59	jnc lp
60skiplp:
61cmp $2,%r10
62jg case0
63je case1
64jp case2
65case3:  .byte 0x9e      # sahf
66	mov (%rdx),%r8
67	sbb (%rcx),%r8
68	mov 8(%rdx),%rbx
69	sbb 8(%rcx),%rbx
70	mov 16(%rdx),%rbp
71	sbb 16(%rcx),%rbp
72        .byte 0x9f      # lahf
73	add $255,%r9b
74	adc (%rsi),%r8
75	adc 8(%rsi),%rbx
76	mov %r8,(%rdi)
77	adc 16(%rsi),%rbp
78	setc %r9b
79	mov %rbp,16(%rdi)
80	mov %rbx,8(%rdi)
81        .byte 0x9e      # sahf
82	mov $0,%eax
83	sbb $0,%rax
84	add $255,%r9b
85	adc $0,%rax
86	pop %rbp
87	pop %rbx
88	ret
89case2:  .byte 0x9e      # sahf
90	mov 8(%rdx),%r8
91	sbb 8(%rcx),%r8
92	mov 16(%rdx),%rbx
93	sbb 16(%rcx),%rbx
94        .byte 0x9f      # lahf
95	add $255,%r9b
96	adc 8(%rsi),%r8
97	adc 16(%rsi),%rbx
98	mov %r8,8(%rdi)
99	setc %r9b
100	mov %rbx,16(%rdi)
101        .byte 0x9e      # sahf
102	mov $0,%eax
103	sbb $0,%rax
104	add $255,%r9b
105	adc $0,%rax
106	pop %rbp
107	pop %rbx
108	ret
109case1:  .byte 0x9e      # sahf
110	mov 16(%rdx),%r8
111	sbb 16(%rcx),%r8
112        .byte 0x9f      # lahf
113	add $255,%r9b
114	adc 16(%rsi),%r8
115	mov %r8,16(%rdi)
116	setc %r9b
117case0:  .byte 0x9e      # sahf
118	mov $0,%eax
119	sbb $0,%rax
120	add $255,%r9b
121	adc $0,%rax
122	pop %rbp
123	pop %rbx
124	ret
125EPILOGUE()
126