Tizen 2.1 base
[external/gmp.git] / mpn / x86_64 / x86_64-defs.m4
1 divert(-1)
2
3 dnl  m4 macros for amd64 assembler.
4
5 dnl  Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009 Free
6 dnl  Software Foundation, Inc.
7 dnl
8 dnl  This file is part of the GNU MP Library.
9 dnl
10 dnl  The GNU MP Library is free software; you can redistribute it and/or
11 dnl  modify it under the terms of the GNU Lesser General Public License as
12 dnl  published by the Free Software Foundation; either version 3 of the
13 dnl  License, or (at your option) any later version.
14 dnl
15 dnl  The GNU MP Library is distributed in the hope that it will be useful,
16 dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
17 dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 dnl  Lesser General Public License for more details.
19 dnl
20 dnl  You should have received a copy of the GNU Lesser General Public License
21 dnl  along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
22
23
24 dnl  Usage: CPUVEC_FUNCS_LIST
25 dnl
26 dnl  A list of the functions from gmp-impl.h x86 struct cpuvec_t, in the
27 dnl  order they appear in that structure.
28
29 define(CPUVEC_FUNCS_LIST,
30 ``add_n',
31 `addmul_1',
32 `copyd',
33 `copyi',
34 `divexact_1',
35 `divexact_by3c',
36 `divrem_1',
37 `gcd_1',
38 `lshift',
39 `mod_1',
40 `mod_34lsub1',
41 `modexact_1c_odd',
42 `mul_1',
43 `mul_basecase',
44 `preinv_divrem_1',
45 `preinv_mod_1',
46 `rshift',
47 `sqr_basecase',
48 `sub_n',
49 `submul_1'')
50
51
52 dnl  Called: PROLOGUE_cpu(GSYM_PREFIX`'foo)
53 dnl
54 dnl  In the amd64 code we use explicit TEXT and ALIGN() calls in the code,
55 dnl  since different alignments are wanted in various circumstances.  So for
56 dnl  instance,
57 dnl
58 dnl                  TEXT
59 dnl                  ALIGN(16)
60 dnl          PROLOGUE(mpn_add_n)
61 dnl                  ...
62 dnl          EPILOGUE()
63
64 define(`PROLOGUE_cpu',
65 m4_assert_numargs(1)
66 `       GLOBL   $1
67         TYPE($1,`function')
68 $1:
69 ')
70
71
72 dnl  Usage: ASSERT([cond][,instructions])
73 dnl
74 dnl  If WANT_ASSERT is 1, output the given instructions and expect the given
75 dnl  flags condition to then be satisfied.  For example,
76 dnl
77 dnl         ASSERT(ne, `cmpq %rax, %rbx')
78 dnl
79 dnl  The instructions can be omitted to just assert a flags condition with
80 dnl  no extra calculation.  For example,
81 dnl
82 dnl         ASSERT(nc)
83 dnl
84 dnl  When `instructions' is not empty, a pushfq/popfq is added for
85 dnl  convenience to preserve the flags, but the instructions themselves must
86 dnl  preserve any registers that matter.
87 dnl
88 dnl  The condition can be omitted to just output the given instructions when
89 dnl  assertion checking is wanted.  In this case the pushf/popf is omitted.
90 dnl  For example,
91 dnl
92 dnl         ASSERT(, `movq %rax, VAR_KEEPVAL')
93
94 define(ASSERT,
95 m4_assert_numargs_range(1,2)
96 m4_assert_defined(`WANT_ASSERT')
97 `ifelse(WANT_ASSERT,1,
98 `ifelse(`$1',,
99 `       $2',
100 `ifelse(`$2',,,
101 `       pushfq')
102         $2
103         j`$1'   L(ASSERT_ok`'ASSERT_counter)
104         ud2     C assertion failed
105 L(ASSERT_ok`'ASSERT_counter):
106 ifelse(`$2',,,` popfq')
107 define(`ASSERT_counter',incr(ASSERT_counter))')')')
108
109 define(ASSERT_counter,1)
110
111 define(`LEA',`
112         mov     $1@GOTPCREL(%rip), $2
113 ')
114
115
116 define(`DEF_OBJECT',
117 m4_assert_numargs_range(1,2)
118 `       RODATA
119         ALIGN(ifelse($#,1,2,$2))
120 $1:
121 ')
122
123 define(`END_OBJECT',
124 m4_assert_numargs(1)
125 `       SIZE(`$1',.-`$1')')
126
127
128 define(`R32',
129         `ifelse($1,`%rax',`%eax',
130                 $1,`%rbx',`%ebx',
131                 $1,`%rcx',`%ecx',
132                 $1,`%rdx',`%edx',
133                 $1,`%rsi',`%esi',
134                 $1,`%rdi',`%edi',
135                 $1,`%rbp',`%ebp',
136                 $1,`%r8',`%r8d',
137                 $1,`%r9',`%r9d',
138                 $1,`%r10',`%r10d',
139                 $1,`%r11',`%r11d',
140                 $1,`%r12',`%r12d',
141                 $1,`%r13',`%r13d',
142                 $1,`%r14',`%r14d',
143                 $1,`%r15',`%r15d')')
144 define(`R8',
145         `ifelse($1,`%rax',`%al',
146                 $1,`%rbx',`%bl',
147                 $1,`%rcx',`%cl',
148                 $1,`%rdx',`%dl',
149                 $1,`%rsi',`%sil',
150                 $1,`%rdi',`%dil',
151                 $1,`%rbp',`%bpl',
152                 $1,`%r8',`%r8b',
153                 $1,`%r9',`%r9b',
154                 $1,`%r10',`%r10b',
155                 $1,`%r11',`%r11b',
156                 $1,`%r12',`%r12b',
157                 $1,`%r13',`%r13b',
158                 $1,`%r14',`%r14b',
159                 $1,`%r15',`%r15b')')
160
161
162 dnl  Usage: CALL(funcname)
163 dnl
164
165 ifdef(`PIC',
166   `define(`CALL',`call  GSYM_PREFIX`'$1@PLT')',
167   `define(`CALL',`call  GSYM_PREFIX`'$1')')
168
169
170 define(`JUMPTABSECT', `.section .data.rel.ro.local,"aw",@progbits')
171
172 divert`'dnl