]> git.proxmox.com Git - ceph.git/blob - ceph/src/isa-l/igzip/stdmac.asm
a4c2b6fe2f90dcbbc5ac471540491bd7044b57e5
[ceph.git] / ceph / src / isa-l / igzip / stdmac.asm
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ; Copyright(c) 2011-2016 Intel Corporation All rights reserved.
3 ;
4 ; Redistribution and use in source and binary forms, with or without
5 ; modification, are permitted provided that the following conditions
6 ; are met:
7 ; * Redistributions of source code must retain the above copyright
8 ; notice, this list of conditions and the following disclaimer.
9 ; * Redistributions in binary form must reproduce the above copyright
10 ; notice, this list of conditions and the following disclaimer in
11 ; the documentation and/or other materials provided with the
12 ; distribution.
13 ; * Neither the name of Intel Corporation nor the names of its
14 ; contributors may be used to endorse or promote products derived
15 ; from this software without specific prior written permission.
16 ;
17 ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 ; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 ; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 ; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 ; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 ; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 ; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 ; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 ; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 ; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29
30
31 ;; internal macro used by push_all
32 ;; push args L to R
33 %macro push_all_ 1-*
34 %xdefine _PUSH_ALL_REGS_COUNT_ %0
35 %rep %0
36 push %1
37 %rotate 1
38 %endrep
39 %endmacro
40
41 ;; internal macro used by pop_all
42 ;; pop args R to L
43 %macro pop_all_ 1-*
44 %rep %0
45 %rotate -1
46 pop %1
47 %endrep
48 %endmacro
49
50 %xdefine _PUSH_ALL_REGS_COUNT_ 0
51 %xdefine _ALLOC_STACK_VAL_ 0
52 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
53 ;; STACK_OFFSET
54 ;; Number of bytes subtracted from stack due to PUSH_ALL and ALLOC_STACK
55 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
56 %define STACK_OFFSET (_PUSH_ALL_REGS_COUNT_ * 8 + _ALLOC_STACK_VAL_)
57
58 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
59 ;; PUSH_ALL reg1, reg2, ...
60 ;; push args L to R, remember regs for pop_all
61 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
62 %macro PUSH_ALL 1+
63 %xdefine _PUSH_ALL_REGS_ %1
64 push_all_ %1
65 %endmacro
66
67 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68 ;; POP_ALL
69 ;; push args from prev "push_all" R to L
70 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
71 %macro POP_ALL 0
72 pop_all_ _PUSH_ALL_REGS_
73 %xdefine _PUSH_ALL_REGS_COUNT_ 0
74 %endmacro
75
76 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
77 ;; ALLOC_STACK n
78 ;; subtract n from the stack pointer and remember the value for restore_stack
79 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
80 %macro ALLOC_STACK 1
81 %xdefine _ALLOC_STACK_VAL_ %1
82 sub rsp, %1
83 %endmacro
84
85 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
86 ;; RESTORE_STACK
87 ;; add n to the stack pointer, where n is the arg to the previous alloc_stack
88 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
89 %macro RESTORE_STACK 0
90 add rsp, _ALLOC_STACK_VAL_
91 %xdefine _ALLOC_STACK_VAL_ 0
92 %endmacro
93
94
95 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
96 ;; NOPN n
97 ;; Create n bytes of NOP, using nops of up to 8 bytes each
98 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
99 %macro NOPN 1
100
101 %assign %%i %1
102 %rep 200
103 %if (%%i < 9)
104 nopn %%i
105 %exitrep
106 %else
107 nopn 8
108 %assign %%i (%%i - 8)
109 %endif
110 %endrep
111 %endmacro
112
113 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
114 ;; nopn n
115 ;; Create n bytes of NOP, where n is between 1 and 9
116 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
117 %macro nopn 1
118 %if (%1 == 1)
119 nop
120 %elif (%1 == 2)
121 db 0x66
122 nop
123 %elif (%1 == 3)
124 db 0x0F
125 db 0x1F
126 db 0x00
127 %elif (%1 == 4)
128 db 0x0F
129 db 0x1F
130 db 0x40
131 db 0x00
132 %elif (%1 == 5)
133 db 0x0F
134 db 0x1F
135 db 0x44
136 db 0x00
137 db 0x00
138 %elif (%1 == 6)
139 db 0x66
140 db 0x0F
141 db 0x1F
142 db 0x44
143 db 0x00
144 db 0x00
145 %elif (%1 == 7)
146 db 0x0F
147 db 0x1F
148 db 0x80
149 db 0x00
150 db 0x00
151 db 0x00
152 db 0x00
153 %elif (%1 == 8)
154 db 0x0F
155 db 0x1F
156 db 0x84
157 db 0x00
158 db 0x00
159 db 0x00
160 db 0x00
161 db 0x00
162 %elif (%1 == 9)
163 db 0x66
164 db 0x0F
165 db 0x1F
166 db 0x84
167 db 0x00
168 db 0x00
169 db 0x00
170 db 0x00
171 db 0x00
172 %else
173 %error Invalid value to nopn
174 %endif
175 %endmacro
176
177 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
178 ;; rolx64 dst, src, amount
179 ;; Emulate a rolx instruction using rorx, assuming data 64 bits wide
180 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
181 %macro rolx64 3
182 rorx %1, %2, (64-%3)
183 %endm
184
185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
186 ;; rolx32 dst, src, amount
187 ;; Emulate a rolx instruction using rorx, assuming data 32 bits wide
188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
189 %macro rolx32 3
190 rorx %1, %2, (32-%3)
191 %endm
192
193
194 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
195 ;; Define a function void ssc(uint64_t x)
196 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
197 %macro DEF_SSC 0
198 global ssc
199 ssc:
200 mov rax, rbx
201 mov rbx, rcx
202 db 0x64
203 db 0x67
204 nop
205 mov rbx, rax
206 ret
207 %endm