1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ; Copyright(c) 2011-2016 Intel Corporation All rights reserved.
4 ; Redistribution and use in source and binary forms, with or without
5 ; modification, are permitted provided that the following conditions
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
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.
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
32 ;; internal macro used by push_all
35 %xdefine _PUSH_ALL_REGS_COUNT_ %0
42 ;; internal macro used by pop_all
51 %xdefine _PUSH_ALL_REGS_COUNT_ 0
52 %xdefine _ALLOC_STACK_VAL_ 0
53 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
55 ;; Number of bytes subtracted from stack due to PUSH_ALL and ALLOC_STACK
56 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
57 %define STACK_OFFSET (_PUSH_ALL_REGS_COUNT_ * 8 + _ALLOC_STACK_VAL_)
59 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
60 ;; PUSH_ALL reg1, reg2, ...
61 ;; push args L to R, remember regs for pop_all
62 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
64 %xdefine _PUSH_ALL_REGS_ %1
68 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
70 ;; push args from prev "push_all" R to L
71 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
73 pop_all_ _PUSH_ALL_REGS_
74 %xdefine _PUSH_ALL_REGS_COUNT_ 0
77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
79 ;; subtract n from the stack pointer and remember the value for restore_stack
80 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
82 %xdefine _ALLOC_STACK_VAL_ %1
86 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
88 ;; add n to the stack pointer, where n is the arg to the previous alloc_stack
89 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
90 %macro RESTORE_STACK 0
91 add rsp, _ALLOC_STACK_VAL_
92 %xdefine _ALLOC_STACK_VAL_ 0
96 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
98 ;; Create n bytes of NOP, using nops of up to 8 bytes each
99 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
109 %assign %%i (%%i - 8)
114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
116 ;; Create n bytes of NOP, where n is between 1 and 9
117 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
174 %error Invalid value to nopn
178 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
179 ;; rolx64 dst, src, amount
180 ;; Emulate a rolx instruction using rorx, assuming data 64 bits wide
181 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
187 ;; rolx32 dst, src, amount
188 ;; Emulate a rolx instruction using rorx, assuming data 32 bits wide
189 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
195 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
196 ;; Define a function void ssc(uint64_t x)
197 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
210 ;; Implement BZHI instruction on older architectures
211 ;; Clobbers rcx, unless rcx is %%index
219 bzhi %%dest, %%src, %%index
228 %ifnidn %%src, %%dest
236 ;; Implement shrx instruction on older architectures
237 ;; Clobbers rcx, unless rcx is %%index
244 shrx %%dest, %%src, %%index
246 %ifnidn %%src, %%dest
256 ;; Implement shlx instruction on older architectures
257 ;; Clobbers rcx, unless rcx is %%index
264 shlx %%dest, %%src, %%index
266 %ifnidn %%src, %%dest
279 %if ((ARCH == 02) || (ARCH == 03) || (ARCH == 04))
280 vmovdqu %%dest, %%src
289 %if (ARCH == 02 || ARCH == 03 || ARCH == 04)
299 %if (ARCH == 02 || ARCH == 03 || ARCH == 04)
310 %if ((ARCH == 02) || (ARCH == 03) || (ARCH == 04))
311 vpinsrd %%dest, %%src, %%offset
313 pinsrd %%dest, %%src, %%offset
321 %if ((ARCH == 02) || (ARCH == 03) || (ARCH == 04))
322 vpextrd %%dest, %%src, %%offset
324 pextrd %%dest, %%src, %%offset
331 %if ((ARCH == 02) || (ARCH == 03) || (ARCH == 04))
332 vpsrldq %%dest, %%offset
334 psrldq %%dest, %%offset
342 %if (ARCH == 02 || ARCH == 03 || ARCH == 04)
343 vpand %%dest, %%src1, %%src2
345 %ifnidn %%dest, %%src1
346 movdqa %%dest, %%src1
356 %if ((ARCH == 02) || (ARCH == 03) || (ARCH == 04))
357 vpcmpeqb %%dest, %%src1, %%src2
359 %ifnidn %%dest, %%src1
360 movdqa %%dest, %%src1
362 pcmpeqb %%dest, %%src2
369 %if ((ARCH == 02) || (ARCH == 03) || (ARCH == 04))
370 vpmovmskb %%dest, %%src
372 pmovmskb %%dest, %%src
380 %if ((ARCH == 02) || (ARCH == 03) || (ARCH == 04))
381 vpxor %%dest, %%src1, %%src2
383 %ifnidn %%dest, %%src1
384 movdqa %%dest, %%src1
389 %endif ;; ifndef STDMAC_ASM