1 ;*****************************************************************************
2 ;* x86inc.asm: x264asm abstraction layer
3 ;*****************************************************************************
4 ;* Copyright (C) 2005-2011 x264 project
6 ;* Authors: Loren Merritt <lorenm@u.washington.edu>
7 ;* Anton Mitrofanov <BugMaster@narod.ru>
8 ;* Jason Garrett-Glaser <darkshikari@gmail.com>
10 ;* Permission to use, copy, modify, and/or distribute this software for any
11 ;* purpose with or without fee is hereby granted, provided that the above
12 ;* copyright notice and this permission notice appear in all copies.
14 ;* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15 ;* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 ;* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17 ;* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 ;* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 ;* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20 ;* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 ;*****************************************************************************
23 ; This is a header file for the x264ASM assembly language, which uses
24 ; NASM/YASM syntax combined with a large number of macros to provide easy
25 ; abstraction between different calling conventions (x86_32, win64, linux64).
26 ; It also has various other useful features to simplify writing the kind of
27 ; DSP functions that are most often used in x264.
29 ; Unlike the rest of x264, this file is available under an ISC license, as it
30 ; has significant usefulness outside of x264 and we want it to be available
31 ; to the largest audience possible. Of course, if you modify it for your own
32 ; purposes to add a new feature, we strongly encourage contributing a patch
33 ; as this feature might be useful for others as well. Send patches or ideas
34 ; to x264-devel@videolan.org .
36 %define program_name ff
41 %ifidn __OUTPUT_FORMAT__,win32
43 %elifidn __OUTPUT_FORMAT__,win64
51 %define mangle(x) _ %+ x
56 ; FIXME: All of the 64bit asm functions that take a stride as an argument
57 ; via register, assume that the high dword of that register is filled with 0.
58 ; This is true in practice (since we never do any 64bit arithmetic on strides,
59 ; and x264's strides are all positive), but is not guaranteed by the ABI.
61 ; Name of the .rodata section.
62 ; Kludge: Something on OS X fails to align .rodata even given an align attribute,
63 ; so use a different read-only section.
64 %macro SECTION_RODATA 0-1 16
65 %ifidn __OUTPUT_FORMAT__,macho64
66 SECTION .text align=%1
67 %elifidn __OUTPUT_FORMAT__,macho
68 SECTION .text align=%1
70 %elifidn __OUTPUT_FORMAT__,aout
73 SECTION .rodata align=%1
77 ; aout does not support align=
78 %macro SECTION_TEXT 0-1 16
79 %ifidn __OUTPUT_FORMAT__,aout
82 SECTION .text align=%1
88 %elif ARCH_X86_64 == 0
89 ; x86_32 doesn't require PIC.
90 ; Some distros prefer shared objects to be PIC, but nothing breaks if
91 ; the code contains a few textrels, so we'll skip that complexity.
98 ; Macros to eliminate most code duplication between x86_32 and x86_64:
99 ; Currently this works only for leaf functions which load all their arguments
100 ; into registers at the start, and make no other use of the stack. Luckily that
101 ; covers most of x264's asm.
104 ; %1 = number of arguments. loads them from stack if needed.
105 ; %2 = number of registers used. pushes callee-saved regs if needed.
106 ; %3 = number of xmm registers used. pushes callee-saved xmm regs if needed.
107 ; %4 = list of names to define to registers
108 ; PROLOGUE can also be invoked by adding the same options to cglobal
111 ; cglobal foo, 2,3,0, dst, src, tmp
112 ; declares a function (foo), taking two args (dst and src) and one local variable (tmp)
114 ; TODO Some functions can use some args directly from the stack. If they're the
115 ; last args then you can just not declare them, but if they're in the middle
116 ; we need more flexible macro.
119 ; Pops anything that was pushed by PROLOGUE, and returns.
122 ; Same, but if it doesn't pop anything it becomes a 2-byte ret, for athlons
123 ; which are slow when a normal ret follows a branch.
126 ; rN and rNq are the native-size register holding function argument N
127 ; rNd, rNw, rNb are dword, word, and byte size
128 ; rNm is the original location of arg N (a register or on the stack), dword
129 ; rNmp is native size
137 %ifid %6 ; i.e. it's a register
139 %elif ARCH_X86_64 ; memory
140 %define r%1mp qword %6
142 %define r%1mp dword %6
147 %macro DECLARE_REG_SIZE 2
161 DECLARE_REG_SIZE ax, al
162 DECLARE_REG_SIZE bx, bl
163 DECLARE_REG_SIZE cx, cl
164 DECLARE_REG_SIZE dx, dl
165 DECLARE_REG_SIZE si, sil
166 DECLARE_REG_SIZE di, dil
167 DECLARE_REG_SIZE bp, bpl
169 ; t# defines for when per-arch register allocation is more complex than just function arguments
171 %macro DECLARE_REG_TMP 1-*
174 CAT_XDEFINE t, %%i, r%1
180 %macro DECLARE_REG_TMP_SIZE 0-*
182 %define t%1q t%1 %+ q
183 %define t%1d t%1 %+ d
184 %define t%1w t%1 %+ w
185 %define t%1b t%1 %+ b
190 DECLARE_REG_TMP_SIZE 0,1,2,3,4,5,6,7,8,9
200 %assign stack_offset stack_offset+gprsize
205 %assign stack_offset stack_offset-gprsize
211 %assign stack_offset stack_offset+(%2)
218 %assign stack_offset stack_offset-(%2)
228 %macro movsxdifnidn 2
240 %macro DEFINE_ARGS 0-*
244 CAT_UNDEF arg_name %+ %%i, q
245 CAT_UNDEF arg_name %+ %%i, d
246 CAT_UNDEF arg_name %+ %%i, w
247 CAT_UNDEF arg_name %+ %%i, b
248 CAT_UNDEF arg_name %+ %%i, m
249 CAT_UNDEF arg_name, %%i
254 %xdefine %%stack_offset stack_offset
255 %undef stack_offset ; so that the current value of stack_offset doesn't get baked in by xdefine
258 %xdefine %1q r %+ %%i %+ q
259 %xdefine %1d r %+ %%i %+ d
260 %xdefine %1w r %+ %%i %+ w
261 %xdefine %1b r %+ %%i %+ b
262 %xdefine %1m r %+ %%i %+ m
263 CAT_XDEFINE arg_name, %%i, %1
267 %xdefine stack_offset %%stack_offset
268 %assign n_arg_names %0
271 %if WIN64 ; Windows x64 ;=================================================
273 DECLARE_REG 0, rcx, ecx, cx, cl, ecx
274 DECLARE_REG 1, rdx, edx, dx, dl, edx
275 DECLARE_REG 2, r8, r8d, r8w, r8b, r8d
276 DECLARE_REG 3, r9, r9d, r9w, r9b, r9d
277 DECLARE_REG 4, rdi, edi, di, dil, [rsp + stack_offset + 40]
278 DECLARE_REG 5, rsi, esi, si, sil, [rsp + stack_offset + 48]
279 DECLARE_REG 6, rax, eax, ax, al, [rsp + stack_offset + 56]
280 %define r7m [rsp + stack_offset + 64]
281 %define r8m [rsp + stack_offset + 72]
283 %macro LOAD_IF_USED 2 ; reg_id, number_of_args
285 mov r%1, [rsp + stack_offset + 8 + %1*8]
289 %macro PROLOGUE 2-4+ 0 ; #args, #regs, #xmm_regs, arg_names...
292 ASSERT regs_used <= 7
296 %assign stack_offset stack_offset+16
299 %assign xmm_regs_used 0
309 %macro WIN64_SPILL_XMM 1
310 %assign xmm_regs_used %1
311 ASSERT xmm_regs_used <= 16
312 %if xmm_regs_used > 6
313 sub rsp, (xmm_regs_used-6)*16+16
314 %assign stack_offset stack_offset+(xmm_regs_used-6)*16+16
315 %assign %%i xmm_regs_used
316 %rep (xmm_regs_used-6)
318 movdqa [rsp + (%%i-6)*16+8], xmm %+ %%i
323 %macro WIN64_RESTORE_XMM_INTERNAL 1
324 %if xmm_regs_used > 6
325 %assign %%i xmm_regs_used
326 %rep (xmm_regs_used-6)
328 movdqa xmm %+ %%i, [%1 + (%%i-6)*16+8]
330 add %1, (xmm_regs_used-6)*16+16
334 %macro WIN64_RESTORE_XMM 1
335 WIN64_RESTORE_XMM_INTERNAL %1
336 %assign stack_offset stack_offset-(xmm_regs_used-6)*16+16
337 %assign xmm_regs_used 0
341 WIN64_RESTORE_XMM_INTERNAL rsp
350 %if regs_used > 4 || xmm_regs_used > 6
357 %elif ARCH_X86_64 ; *nix x64 ;=============================================
359 DECLARE_REG 0, rdi, edi, di, dil, edi
360 DECLARE_REG 1, rsi, esi, si, sil, esi
361 DECLARE_REG 2, rdx, edx, dx, dl, edx
362 DECLARE_REG 3, rcx, ecx, cx, cl, ecx
363 DECLARE_REG 4, r8, r8d, r8w, r8b, r8d
364 DECLARE_REG 5, r9, r9d, r9w, r9b, r9d
365 DECLARE_REG 6, rax, eax, ax, al, [rsp + stack_offset + 8]
366 %define r7m [rsp + stack_offset + 16]
367 %define r8m [rsp + stack_offset + 24]
369 %macro LOAD_IF_USED 2 ; reg_id, number_of_args
371 mov r%1, [rsp - 40 + %1*8]
375 %macro PROLOGUE 2-4+ ; #args, #regs, #xmm_regs, arg_names...
390 %else ; X86_32 ;==============================================================
392 DECLARE_REG 0, eax, eax, ax, al, [esp + stack_offset + 4]
393 DECLARE_REG 1, ecx, ecx, cx, cl, [esp + stack_offset + 8]
394 DECLARE_REG 2, edx, edx, dx, dl, [esp + stack_offset + 12]
395 DECLARE_REG 3, ebx, ebx, bx, bl, [esp + stack_offset + 16]
396 DECLARE_REG 4, esi, esi, si, null, [esp + stack_offset + 20]
397 DECLARE_REG 5, edi, edi, di, null, [esp + stack_offset + 24]
398 DECLARE_REG 6, ebp, ebp, bp, null, [esp + stack_offset + 28]
399 %define r7m [esp + stack_offset + 32]
400 %define r8m [esp + stack_offset + 36]
403 %macro PUSH_IF_USED 1 ; reg_id
406 %assign stack_offset stack_offset+4
410 %macro POP_IF_USED 1 ; reg_id
416 %macro LOAD_IF_USED 2 ; reg_id, number_of_args
418 mov r%1, [esp + stack_offset + 4 + %1*4]
422 %macro PROLOGUE 2-4+ ; #args, #regs, #xmm_regs, arg_names...
425 ASSERT regs_used <= 7
456 %endif ;======================================================================
459 %macro WIN64_SPILL_XMM 1
461 %macro WIN64_RESTORE_XMM 1
467 ;=============================================================================
468 ; arch-independent part
469 ;=============================================================================
471 %assign function_align 16
474 ; Applies any symbol mangling needed for C linkage, and sets up a define such that
475 ; subsequent uses of the function name automatically refer to the mangled version.
476 ; Appends cpuflags to the function name if cpuflags has been specified.
477 %macro cglobal 1-2+ ; name, [PROLOGUE args]
479 ; HACK: work around %+ broken with empty SUFFIX for nasm 2.09.10
483 cglobal_internal %1 %+ SUFFIX
486 ; HACK: work around %+ broken with empty SUFFIX for nasm 2.09.10
488 cglobal_internal %1, %2
490 cglobal_internal %1 %+ SUFFIX, %2
494 %macro cglobal_internal 1-2+
496 %xdefine %1 mangle(program_name %+ _ %+ %1)
497 %xdefine %1.skip_prologue %1 %+ .skip_prologue
498 CAT_XDEFINE cglobaled_, %1, 1
500 %xdefine current_function %1
501 %ifidn __OUTPUT_FORMAT__,elf
502 global %1:function hidden
508 RESET_MM_PERMUTATION ; not really needed, but makes disassembly somewhat nicer
509 %assign stack_offset 0
516 %xdefine %1 mangle(program_name %+ _ %+ %1)
517 CAT_XDEFINE cglobaled_, %1, 1
521 ; like cextern, but without the prefix
522 %macro cextern_naked 1
523 %xdefine %1 mangle(%1)
524 CAT_XDEFINE cglobaled_, %1, 1
529 %xdefine %1 mangle(program_name %+ _ %+ %1)
534 ; This is needed for ELF, otherwise the GNU linker assumes the stack is
535 ; executable by default.
536 %ifidn __OUTPUT_FORMAT__,elf
537 SECTION .note.GNU-stack noalloc noexec nowrite progbits
542 %assign cpuflags_mmx (1<<0)
543 %assign cpuflags_mmx2 (1<<1) | cpuflags_mmx
544 %assign cpuflags_3dnow (1<<2) | cpuflags_mmx
545 %assign cpuflags_3dnow2 (1<<3) | cpuflags_3dnow
546 %assign cpuflags_sse (1<<4) | cpuflags_mmx2
547 %assign cpuflags_sse2 (1<<5) | cpuflags_sse
548 %assign cpuflags_sse2slow (1<<6) | cpuflags_sse2
549 %assign cpuflags_sse3 (1<<7) | cpuflags_sse2
550 %assign cpuflags_ssse3 (1<<8) | cpuflags_sse3
551 %assign cpuflags_sse4 (1<<9) | cpuflags_ssse3
552 %assign cpuflags_sse42 (1<<10)| cpuflags_sse4
553 %assign cpuflags_avx (1<<11)| cpuflags_sse42
554 %assign cpuflags_xop (1<<12)| cpuflags_avx
555 %assign cpuflags_fma4 (1<<13)| cpuflags_avx
557 %assign cpuflags_cache32 (1<<16)
558 %assign cpuflags_cache64 (1<<17)
559 %assign cpuflags_slowctz (1<<18)
560 %assign cpuflags_lzcnt (1<<19)
561 %assign cpuflags_misalign (1<<20)
562 %assign cpuflags_aligned (1<<21) ; not a cpu feature, but a function variant
563 %assign cpuflags_atom (1<<22)
565 %define cpuflag(x) ((cpuflags & (cpuflags_ %+ x)) == (cpuflags_ %+ x))
566 %define notcpuflag(x) ((cpuflags & (cpuflags_ %+ x)) != (cpuflags_ %+ x))
568 ; Takes up to 2 cpuflags from the above list.
569 ; All subsequent functions (up to the next INIT_CPUFLAGS) is built for the specified cpu.
570 ; You shouldn't need to invoke this macro directly, it's a subroutine for INIT_MMX &co.
571 %macro INIT_CPUFLAGS 0-2
574 %assign cpuflags cpuflags_%1
576 %xdefine cpuname %1_%2
577 %assign cpuflags cpuflags | cpuflags_%2
579 %xdefine SUFFIX _ %+ cpuname
581 %assign avx_enabled 1
583 %if mmsize == 16 && notcpuflag(sse2)
586 %define movnta movntps
611 %assign avx_enabled 0
612 %define RESET_MM_PERMUTATION INIT_MMX %1
618 %define movnta movntq
621 CAT_XDEFINE m, %%i, mm %+ %%i
622 CAT_XDEFINE nmm, %%i, %%i
634 %assign avx_enabled 0
635 %define RESET_MM_PERMUTATION INIT_XMM %1
639 %define num_mmregs 16
644 %define movnta movntdq
647 CAT_XDEFINE m, %%i, xmm %+ %%i
648 CAT_XDEFINE nxmm, %%i, %%i
654 ; FIXME: INIT_AVX can be replaced by INIT_XMM avx
657 %assign avx_enabled 1
658 %define PALIGNR PALIGNR_SSSE3
659 %define RESET_MM_PERMUTATION INIT_AVX
663 %assign avx_enabled 1
664 %define RESET_MM_PERMUTATION INIT_YMM %1
668 %define num_mmregs 16
673 %define movnta vmovntps
676 CAT_XDEFINE m, %%i, ymm %+ %%i
677 CAT_XDEFINE nymm, %%i, %%i
685 ; I often want to use macros that permute their arguments. e.g. there's no
686 ; efficient way to implement butterfly or transpose or dct without swapping some
689 ; I would like to not have to manually keep track of the permutations:
690 ; If I insert a permutation in the middle of a function, it should automatically
691 ; change everything that follows. For more complex macros I may also have multiple
692 ; implementations, e.g. the SSE2 and SSSE3 versions may have different permutations.
694 ; Hence these macros. Insert a PERMUTE or some SWAPs at the end of a macro that
695 ; permutes its arguments. It's equivalent to exchanging the contents of the
696 ; registers, except that this way you exchange the register names instead, so it
697 ; doesn't cost any cycles.
699 %macro PERMUTE 2-* ; takes a list of pairs to swap
714 %macro SWAP 2-* ; swaps a single chain (sometimes more concise than pairs)
720 CAT_XDEFINE n, m%1, %1
721 CAT_XDEFINE n, m%2, %2
723 ; If we were called as "SWAP m0,m1" rather than "SWAP 0,1" infer the original numbers here.
724 ; Be careful using this mode in nested macros though, as in some cases there may be
725 ; other copies of m# that have already been dereferenced and don't get updated correctly.
726 %xdefine %%n1 n %+ %1
727 %xdefine %%n2 n %+ %2
728 %xdefine tmp m %+ %%n1
729 CAT_XDEFINE m, %%n1, m %+ %%n2
730 CAT_XDEFINE m, %%n2, tmp
731 CAT_XDEFINE n, m %+ %%n1, %%n1
732 CAT_XDEFINE n, m %+ %%n2, %%n2
739 ; If SAVE_MM_PERMUTATION is placed at the end of a function, then any later
740 ; calls to that function will automatically load the permutation, so values can
741 ; be returned in mmregs.
742 %macro SAVE_MM_PERMUTATION 0-1
746 %xdefine %%f current_function %+ _m
750 CAT_XDEFINE %%f, %%i, m %+ %%i
755 %macro LOAD_MM_PERMUTATION 1 ; name to load from
759 CAT_XDEFINE m, %%i, %1_m %+ %%i
760 CAT_XDEFINE n, m %+ %%i, %%i
766 ; Append cpuflags to the callee's name iff the appended name is known and the plain name isn't
768 ; HACK: work around %+ broken with empty SUFFIX for nasm 2.09.10
772 call_internal %1, %1 %+ SUFFIX
775 %macro call_internal 2
783 LOAD_MM_PERMUTATION %%i
786 ; Substitutions that reduce instruction size but are functionally equivalent
811 ;=============================================================================
812 ; AVX abstraction layer
813 ;=============================================================================
818 CAT_XDEFINE sizeofmm, i, 8
820 CAT_XDEFINE sizeofxmm, i, 16
821 CAT_XDEFINE sizeofymm, i, 32
827 ;%2 == 1 if float, 0 if int
828 ;%3 == 1 if 4-operand (xmm, xmm, xmm, imm), 0 if 3-operand (xmm, xmm, xmm)
829 ;%4 == number of operands given
831 %macro RUN_AVX_INSTR 6-7+
833 %define %%size sizeof%5
835 %define %%size mmsize
841 %define %%regmov movq
843 %define %%regmov movaps
845 %define %%regmov movdqa
850 %if avx_enabled && sizeof%5==16
867 ; 3arg AVX ops with a memory arg can only have it in src2,
868 ; whereas SSE emulation of 3arg prefers to have it in src1 (i.e. the mov).
869 ; So, if the op is symmetric and the wrong one is memory, swap them.
870 %macro RUN_AVX_INSTR1 8
881 %if %%swap && %3 == 0 && %8 == 1
882 RUN_AVX_INSTR %1, %2, %3, %4, %5, %7, %6
884 RUN_AVX_INSTR %1, %2, %3, %4, %5, %6, %7
889 ;%2 == 1 if float, 0 if int
890 ;%3 == 1 if 4-operand (xmm, xmm, xmm, imm), 0 if 3-operand (xmm, xmm, xmm)
891 ;%4 == 1 if symmetric (i.e. doesn't matter which src arg is which), 0 if not
893 %macro %1 2-9 fnord, fnord, fnord, %1, %2, %3, %4
895 RUN_AVX_INSTR %6, %7, %8, 2, %1, %2
897 RUN_AVX_INSTR1 %6, %7, %8, 3, %1, %2, %3, %9
899 RUN_AVX_INSTR %6, %7, %8, 4, %1, %2, %3, %4
901 RUN_AVX_INSTR %6, %7, %8, 5, %1, %2, %3, %4, %5
906 AVX_INSTR addpd, 1, 0, 1
907 AVX_INSTR addps, 1, 0, 1
908 AVX_INSTR addsd, 1, 0, 1
909 AVX_INSTR addss, 1, 0, 1
910 AVX_INSTR addsubpd, 1, 0, 0
911 AVX_INSTR addsubps, 1, 0, 0
912 AVX_INSTR andpd, 1, 0, 1
913 AVX_INSTR andps, 1, 0, 1
914 AVX_INSTR andnpd, 1, 0, 0
915 AVX_INSTR andnps, 1, 0, 0
916 AVX_INSTR blendpd, 1, 0, 0
917 AVX_INSTR blendps, 1, 0, 0
918 AVX_INSTR blendvpd, 1, 0, 0
919 AVX_INSTR blendvps, 1, 0, 0
920 AVX_INSTR cmppd, 1, 0, 0
921 AVX_INSTR cmpps, 1, 0, 0
922 AVX_INSTR cmpsd, 1, 0, 0
923 AVX_INSTR cmpss, 1, 0, 0
924 AVX_INSTR divpd, 1, 0, 0
925 AVX_INSTR divps, 1, 0, 0
926 AVX_INSTR divsd, 1, 0, 0
927 AVX_INSTR divss, 1, 0, 0
928 AVX_INSTR dppd, 1, 1, 0
929 AVX_INSTR dpps, 1, 1, 0
930 AVX_INSTR haddpd, 1, 0, 0
931 AVX_INSTR haddps, 1, 0, 0
932 AVX_INSTR hsubpd, 1, 0, 0
933 AVX_INSTR hsubps, 1, 0, 0
934 AVX_INSTR maxpd, 1, 0, 1
935 AVX_INSTR maxps, 1, 0, 1
936 AVX_INSTR maxsd, 1, 0, 1
937 AVX_INSTR maxss, 1, 0, 1
938 AVX_INSTR minpd, 1, 0, 1
939 AVX_INSTR minps, 1, 0, 1
940 AVX_INSTR minsd, 1, 0, 1
941 AVX_INSTR minss, 1, 0, 1
942 AVX_INSTR movhlps, 1, 0, 0
943 AVX_INSTR movlhps, 1, 0, 0
944 AVX_INSTR movsd, 1, 0, 0
945 AVX_INSTR movss, 1, 0, 0
946 AVX_INSTR mpsadbw, 0, 1, 0
947 AVX_INSTR mulpd, 1, 0, 1
948 AVX_INSTR mulps, 1, 0, 1
949 AVX_INSTR mulsd, 1, 0, 1
950 AVX_INSTR mulss, 1, 0, 1
951 AVX_INSTR orpd, 1, 0, 1
952 AVX_INSTR orps, 1, 0, 1
953 AVX_INSTR packsswb, 0, 0, 0
954 AVX_INSTR packssdw, 0, 0, 0
955 AVX_INSTR packuswb, 0, 0, 0
956 AVX_INSTR packusdw, 0, 0, 0
957 AVX_INSTR paddb, 0, 0, 1
958 AVX_INSTR paddw, 0, 0, 1
959 AVX_INSTR paddd, 0, 0, 1
960 AVX_INSTR paddq, 0, 0, 1
961 AVX_INSTR paddsb, 0, 0, 1
962 AVX_INSTR paddsw, 0, 0, 1
963 AVX_INSTR paddusb, 0, 0, 1
964 AVX_INSTR paddusw, 0, 0, 1
965 AVX_INSTR palignr, 0, 1, 0
966 AVX_INSTR pand, 0, 0, 1
967 AVX_INSTR pandn, 0, 0, 0
968 AVX_INSTR pavgb, 0, 0, 1
969 AVX_INSTR pavgw, 0, 0, 1
970 AVX_INSTR pblendvb, 0, 0, 0
971 AVX_INSTR pblendw, 0, 1, 0
972 AVX_INSTR pcmpestri, 0, 0, 0
973 AVX_INSTR pcmpestrm, 0, 0, 0
974 AVX_INSTR pcmpistri, 0, 0, 0
975 AVX_INSTR pcmpistrm, 0, 0, 0
976 AVX_INSTR pcmpeqb, 0, 0, 1
977 AVX_INSTR pcmpeqw, 0, 0, 1
978 AVX_INSTR pcmpeqd, 0, 0, 1
979 AVX_INSTR pcmpeqq, 0, 0, 1
980 AVX_INSTR pcmpgtb, 0, 0, 0
981 AVX_INSTR pcmpgtw, 0, 0, 0
982 AVX_INSTR pcmpgtd, 0, 0, 0
983 AVX_INSTR pcmpgtq, 0, 0, 0
984 AVX_INSTR phaddw, 0, 0, 0
985 AVX_INSTR phaddd, 0, 0, 0
986 AVX_INSTR phaddsw, 0, 0, 0
987 AVX_INSTR phsubw, 0, 0, 0
988 AVX_INSTR phsubd, 0, 0, 0
989 AVX_INSTR phsubsw, 0, 0, 0
990 AVX_INSTR pmaddwd, 0, 0, 1
991 AVX_INSTR pmaddubsw, 0, 0, 0
992 AVX_INSTR pmaxsb, 0, 0, 1
993 AVX_INSTR pmaxsw, 0, 0, 1
994 AVX_INSTR pmaxsd, 0, 0, 1
995 AVX_INSTR pmaxub, 0, 0, 1
996 AVX_INSTR pmaxuw, 0, 0, 1
997 AVX_INSTR pmaxud, 0, 0, 1
998 AVX_INSTR pminsb, 0, 0, 1
999 AVX_INSTR pminsw, 0, 0, 1
1000 AVX_INSTR pminsd, 0, 0, 1
1001 AVX_INSTR pminub, 0, 0, 1
1002 AVX_INSTR pminuw, 0, 0, 1
1003 AVX_INSTR pminud, 0, 0, 1
1004 AVX_INSTR pmulhuw, 0, 0, 1
1005 AVX_INSTR pmulhrsw, 0, 0, 1
1006 AVX_INSTR pmulhw, 0, 0, 1
1007 AVX_INSTR pmullw, 0, 0, 1
1008 AVX_INSTR pmulld, 0, 0, 1
1009 AVX_INSTR pmuludq, 0, 0, 1
1010 AVX_INSTR pmuldq, 0, 0, 1
1011 AVX_INSTR por, 0, 0, 1
1012 AVX_INSTR psadbw, 0, 0, 1
1013 AVX_INSTR pshufb, 0, 0, 0
1014 AVX_INSTR psignb, 0, 0, 0
1015 AVX_INSTR psignw, 0, 0, 0
1016 AVX_INSTR psignd, 0, 0, 0
1017 AVX_INSTR psllw, 0, 0, 0
1018 AVX_INSTR pslld, 0, 0, 0
1019 AVX_INSTR psllq, 0, 0, 0
1020 AVX_INSTR pslldq, 0, 0, 0
1021 AVX_INSTR psraw, 0, 0, 0
1022 AVX_INSTR psrad, 0, 0, 0
1023 AVX_INSTR psrlw, 0, 0, 0
1024 AVX_INSTR psrld, 0, 0, 0
1025 AVX_INSTR psrlq, 0, 0, 0
1026 AVX_INSTR psrldq, 0, 0, 0
1027 AVX_INSTR psubb, 0, 0, 0
1028 AVX_INSTR psubw, 0, 0, 0
1029 AVX_INSTR psubd, 0, 0, 0
1030 AVX_INSTR psubq, 0, 0, 0
1031 AVX_INSTR psubsb, 0, 0, 0
1032 AVX_INSTR psubsw, 0, 0, 0
1033 AVX_INSTR psubusb, 0, 0, 0
1034 AVX_INSTR psubusw, 0, 0, 0
1035 AVX_INSTR punpckhbw, 0, 0, 0
1036 AVX_INSTR punpckhwd, 0, 0, 0
1037 AVX_INSTR punpckhdq, 0, 0, 0
1038 AVX_INSTR punpckhqdq, 0, 0, 0
1039 AVX_INSTR punpcklbw, 0, 0, 0
1040 AVX_INSTR punpcklwd, 0, 0, 0
1041 AVX_INSTR punpckldq, 0, 0, 0
1042 AVX_INSTR punpcklqdq, 0, 0, 0
1043 AVX_INSTR pxor, 0, 0, 1
1044 AVX_INSTR shufps, 1, 1, 0
1045 AVX_INSTR subpd, 1, 0, 0
1046 AVX_INSTR subps, 1, 0, 0
1047 AVX_INSTR subsd, 1, 0, 0
1048 AVX_INSTR subss, 1, 0, 0
1049 AVX_INSTR unpckhpd, 1, 0, 0
1050 AVX_INSTR unpckhps, 1, 0, 0
1051 AVX_INSTR unpcklpd, 1, 0, 0
1052 AVX_INSTR unpcklps, 1, 0, 0
1053 AVX_INSTR xorpd, 1, 0, 1
1054 AVX_INSTR xorps, 1, 0, 1
1056 ; 3DNow instructions, for sharing code between AVX, SSE and 3DN
1057 AVX_INSTR pfadd, 1, 0, 1
1058 AVX_INSTR pfsub, 1, 0, 0
1059 AVX_INSTR pfmul, 1, 0, 1
1061 ; base-4 constants for shuffles
1064 %assign j ((i>>6)&3)*1000 + ((i>>4)&3)*100 + ((i>>2)&3)*10 + (i&3)
1066 CAT_XDEFINE q000, j, i
1068 CAT_XDEFINE q00, j, i
1070 CAT_XDEFINE q0, j, i
1080 %macro %1 4-7 %1, %2, %3
1090 FMA_INSTR pmacsdd, pmulld, paddd
1091 FMA_INSTR pmacsww, pmullw, paddw
1092 FMA_INSTR pmadcswd, pmaddwd, paddd