xref: /netbsd-src/external/lgpl3/gmp/dist/mpn/x86_64/missing-inline.m4 (revision f0fde9902fd4d72ded2807793acc7bfaa1ebf243)
1dnl  AMD64 MULX/ADX simulation support, inline version.
2
3dnl  Contributed to the GNU project by Torbjörn Granlund.
4
5dnl  Copyright 2013 Free Software Foundation, Inc.
6
7dnl  This file is part of the GNU MP Library.
8dnl
9dnl  The GNU MP Library is free software; you can redistribute it and/or modify
10dnl  it under the terms of either:
11dnl
12dnl    * the GNU Lesser General Public License as published by the Free
13dnl      Software Foundation; either version 3 of the License, or (at your
14dnl      option) any later version.
15dnl
16dnl  or
17dnl
18dnl    * the GNU General Public License as published by the Free Software
19dnl      Foundation; either version 2 of the License, or (at your option) any
20dnl      later version.
21dnl
22dnl  or both in parallel, as here.
23dnl
24dnl  The GNU MP Library is distributed in the hope that it will be useful, but
25dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
26dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
27dnl  for more details.
28dnl
29dnl  You should have received copies of the GNU General Public License and the
30dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
31dnl  see https://www.gnu.org/licenses/.
32
33
34define(`adox',`
35	push	$2
36	push	%rcx
37	push	%rbx
38	push	%rax
39	mov	$1, %rcx
40	pushfq
41	pushfq
42C copy 0(%rsp):11 to 0(%rsp):0
43	mov	(%rsp), %rbx
44	shr	%rbx
45	bt	$`'10, %rbx
46	adc	%rbx, %rbx
47	mov	%rbx, (%rsp)
48C put manipulated flags into eflags, execute a plain adc
49	popfq
50	adc	%rcx, 32(%rsp)
51C copy CF to 0(%rsp):11
52	mov	(%rsp), %rbx
53	sbb	R32(%rax), R32(%rax)
54	and	$`'0x800, R32(%rax)
55	and	$`'0xfffffffffffff7ff, %rbx
56	or	%rax, %rbx
57	mov	%rbx, (%rsp)
58C put manipulated flags into eflags
59	popfq
60	pop	%rax
61	pop	%rbx
62	pop	%rcx
63	pop	$2
64')
65
66define(`adcx',`
67	push	$2
68	push	%rcx
69	push	%rbx
70	push	%rax
71	mov	$1, %rcx
72	pushfq
73	adc	%rcx, 32(%rsp)
74	mov	(%rsp), %rbx
75	sbb	R32(%rax), R32(%rax)
76	and	$`'0xfffffffffffffffe, %rbx
77	sub	%rax, %rbx
78	mov	%rbx, (%rsp)
79	popfq
80	pop	%rax
81	pop	%rbx
82	pop	%rcx
83	pop	$2
84')
85
86define(`mulx',`
87	lea	-16(%rsp), %rsp
88	push	%rax
89	push	%rdx
90	pushfq			C preserve all flags
91	mov	$1, %rax
92	mul	%rdx
93	mov	%rax, 24(%rsp)
94	mov	%rdx, 32(%rsp)
95	popfq			C restore eflags
96	pop	%rdx
97	pop	%rax
98	pop	$2
99	pop	$3
100')
101