You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1672 lines
48KB

  1. ;*****************************************************************************
  2. ;* x86inc.asm: x264asm abstraction layer
  3. ;*****************************************************************************
  4. ;* Copyright (C) 2005-2017 x264 project
  5. ;*
  6. ;* Authors: Loren Merritt <lorenm@u.washington.edu>
  7. ;* Anton Mitrofanov <BugMaster@narod.ru>
  8. ;* Fiona Glaser <fiona@x264.com>
  9. ;* Henrik Gramner <henrik@gramner.com>
  10. ;*
  11. ;* Permission to use, copy, modify, and/or distribute this software for any
  12. ;* purpose with or without fee is hereby granted, provided that the above
  13. ;* copyright notice and this permission notice appear in all copies.
  14. ;*
  15. ;* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  16. ;* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  17. ;* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  18. ;* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19. ;* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  20. ;* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  21. ;* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22. ;*****************************************************************************
  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.
  28. ; Unlike the rest of x264, this file is available under an ISC license, as it
  29. ; has significant usefulness outside of x264 and we want it to be available
  30. ; to the largest audience possible. Of course, if you modify it for your own
  31. ; purposes to add a new feature, we strongly encourage contributing a patch
  32. ; as this feature might be useful for others as well. Send patches or ideas
  33. ; to x264-devel@videolan.org .
  34. %ifndef private_prefix
  35. %define private_prefix x264
  36. %endif
  37. %ifndef public_prefix
  38. %define public_prefix private_prefix
  39. %endif
  40. %if HAVE_ALIGNED_STACK
  41. %define STACK_ALIGNMENT 16
  42. %endif
  43. %ifndef STACK_ALIGNMENT
  44. %if ARCH_X86_64
  45. %define STACK_ALIGNMENT 16
  46. %else
  47. %define STACK_ALIGNMENT 4
  48. %endif
  49. %endif
  50. %define WIN64 0
  51. %define UNIX64 0
  52. %if ARCH_X86_64
  53. %ifidn __OUTPUT_FORMAT__,win32
  54. %define WIN64 1
  55. %elifidn __OUTPUT_FORMAT__,win64
  56. %define WIN64 1
  57. %elifidn __OUTPUT_FORMAT__,x64
  58. %define WIN64 1
  59. %else
  60. %define UNIX64 1
  61. %endif
  62. %endif
  63. %define FORMAT_ELF 0
  64. %ifidn __OUTPUT_FORMAT__,elf
  65. %define FORMAT_ELF 1
  66. %elifidn __OUTPUT_FORMAT__,elf32
  67. %define FORMAT_ELF 1
  68. %elifidn __OUTPUT_FORMAT__,elf64
  69. %define FORMAT_ELF 1
  70. %endif
  71. %ifdef PREFIX
  72. %define mangle(x) _ %+ x
  73. %else
  74. %define mangle(x) x
  75. %endif
  76. ; aout does not support align=
  77. ; NOTE: This section is out of sync with x264, in order to
  78. ; keep supporting OS/2.
  79. %macro SECTION_RODATA 0-1 16
  80. %ifidn __OUTPUT_FORMAT__,aout
  81. SECTION .text
  82. %elifidn __OUTPUT_FORMAT__,coff
  83. SECTION .text
  84. %else
  85. SECTION .rodata align=%1
  86. %endif
  87. %endmacro
  88. %if WIN64
  89. %define PIC
  90. %elif ARCH_X86_64 == 0
  91. ; x86_32 doesn't require PIC.
  92. ; Some distros prefer shared objects to be PIC, but nothing breaks if
  93. ; the code contains a few textrels, so we'll skip that complexity.
  94. %undef PIC
  95. %endif
  96. %ifdef PIC
  97. default rel
  98. %endif
  99. %macro CPUNOP 1
  100. %if HAVE_CPUNOP
  101. CPU %1
  102. %endif
  103. %endmacro
  104. ; Macros to eliminate most code duplication between x86_32 and x86_64:
  105. ; Currently this works only for leaf functions which load all their arguments
  106. ; into registers at the start, and make no other use of the stack. Luckily that
  107. ; covers most of x264's asm.
  108. ; PROLOGUE:
  109. ; %1 = number of arguments. loads them from stack if needed.
  110. ; %2 = number of registers used. pushes callee-saved regs if needed.
  111. ; %3 = number of xmm registers used. pushes callee-saved xmm regs if needed.
  112. ; %4 = (optional) stack size to be allocated. The stack will be aligned before
  113. ; allocating the specified stack size. If the required stack alignment is
  114. ; larger than the known stack alignment the stack will be manually aligned
  115. ; and an extra register will be allocated to hold the original stack
  116. ; pointer (to not invalidate r0m etc.). To prevent the use of an extra
  117. ; register as stack pointer, request a negative stack size.
  118. ; %4+/%5+ = list of names to define to registers
  119. ; PROLOGUE can also be invoked by adding the same options to cglobal
  120. ; e.g.
  121. ; cglobal foo, 2,3,7,0x40, dst, src, tmp
  122. ; declares a function (foo) that automatically loads two arguments (dst and
  123. ; src) into registers, uses one additional register (tmp) plus 7 vector
  124. ; registers (m0-m6) and allocates 0x40 bytes of stack space.
  125. ; TODO Some functions can use some args directly from the stack. If they're the
  126. ; last args then you can just not declare them, but if they're in the middle
  127. ; we need more flexible macro.
  128. ; RET:
  129. ; Pops anything that was pushed by PROLOGUE, and returns.
  130. ; REP_RET:
  131. ; Use this instead of RET if it's a branch target.
  132. ; registers:
  133. ; rN and rNq are the native-size register holding function argument N
  134. ; rNd, rNw, rNb are dword, word, and byte size
  135. ; rNh is the high 8 bits of the word size
  136. ; rNm is the original location of arg N (a register or on the stack), dword
  137. ; rNmp is native size
  138. %macro DECLARE_REG 2-3
  139. %define r%1q %2
  140. %define r%1d %2d
  141. %define r%1w %2w
  142. %define r%1b %2b
  143. %define r%1h %2h
  144. %define %2q %2
  145. %if %0 == 2
  146. %define r%1m %2d
  147. %define r%1mp %2
  148. %elif ARCH_X86_64 ; memory
  149. %define r%1m [rstk + stack_offset + %3]
  150. %define r%1mp qword r %+ %1 %+ m
  151. %else
  152. %define r%1m [rstk + stack_offset + %3]
  153. %define r%1mp dword r %+ %1 %+ m
  154. %endif
  155. %define r%1 %2
  156. %endmacro
  157. %macro DECLARE_REG_SIZE 3
  158. %define r%1q r%1
  159. %define e%1q r%1
  160. %define r%1d e%1
  161. %define e%1d e%1
  162. %define r%1w %1
  163. %define e%1w %1
  164. %define r%1h %3
  165. %define e%1h %3
  166. %define r%1b %2
  167. %define e%1b %2
  168. %if ARCH_X86_64 == 0
  169. %define r%1 e%1
  170. %endif
  171. %endmacro
  172. DECLARE_REG_SIZE ax, al, ah
  173. DECLARE_REG_SIZE bx, bl, bh
  174. DECLARE_REG_SIZE cx, cl, ch
  175. DECLARE_REG_SIZE dx, dl, dh
  176. DECLARE_REG_SIZE si, sil, null
  177. DECLARE_REG_SIZE di, dil, null
  178. DECLARE_REG_SIZE bp, bpl, null
  179. ; t# defines for when per-arch register allocation is more complex than just function arguments
  180. %macro DECLARE_REG_TMP 1-*
  181. %assign %%i 0
  182. %rep %0
  183. CAT_XDEFINE t, %%i, r%1
  184. %assign %%i %%i+1
  185. %rotate 1
  186. %endrep
  187. %endmacro
  188. %macro DECLARE_REG_TMP_SIZE 0-*
  189. %rep %0
  190. %define t%1q t%1 %+ q
  191. %define t%1d t%1 %+ d
  192. %define t%1w t%1 %+ w
  193. %define t%1h t%1 %+ h
  194. %define t%1b t%1 %+ b
  195. %rotate 1
  196. %endrep
  197. %endmacro
  198. DECLARE_REG_TMP_SIZE 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14
  199. %if ARCH_X86_64
  200. %define gprsize 8
  201. %else
  202. %define gprsize 4
  203. %endif
  204. %macro PUSH 1
  205. push %1
  206. %ifidn rstk, rsp
  207. %assign stack_offset stack_offset+gprsize
  208. %endif
  209. %endmacro
  210. %macro POP 1
  211. pop %1
  212. %ifidn rstk, rsp
  213. %assign stack_offset stack_offset-gprsize
  214. %endif
  215. %endmacro
  216. %macro PUSH_IF_USED 1-*
  217. %rep %0
  218. %if %1 < regs_used
  219. PUSH r%1
  220. %endif
  221. %rotate 1
  222. %endrep
  223. %endmacro
  224. %macro POP_IF_USED 1-*
  225. %rep %0
  226. %if %1 < regs_used
  227. pop r%1
  228. %endif
  229. %rotate 1
  230. %endrep
  231. %endmacro
  232. %macro LOAD_IF_USED 1-*
  233. %rep %0
  234. %if %1 < num_args
  235. mov r%1, r %+ %1 %+ mp
  236. %endif
  237. %rotate 1
  238. %endrep
  239. %endmacro
  240. %macro SUB 2
  241. sub %1, %2
  242. %ifidn %1, rstk
  243. %assign stack_offset stack_offset+(%2)
  244. %endif
  245. %endmacro
  246. %macro ADD 2
  247. add %1, %2
  248. %ifidn %1, rstk
  249. %assign stack_offset stack_offset-(%2)
  250. %endif
  251. %endmacro
  252. %macro movifnidn 2
  253. %ifnidn %1, %2
  254. mov %1, %2
  255. %endif
  256. %endmacro
  257. %macro movsxdifnidn 2
  258. %ifnidn %1, %2
  259. movsxd %1, %2
  260. %endif
  261. %endmacro
  262. %macro ASSERT 1
  263. %if (%1) == 0
  264. %error assertion ``%1'' failed
  265. %endif
  266. %endmacro
  267. %macro DEFINE_ARGS 0-*
  268. %ifdef n_arg_names
  269. %assign %%i 0
  270. %rep n_arg_names
  271. CAT_UNDEF arg_name %+ %%i, q
  272. CAT_UNDEF arg_name %+ %%i, d
  273. CAT_UNDEF arg_name %+ %%i, w
  274. CAT_UNDEF arg_name %+ %%i, h
  275. CAT_UNDEF arg_name %+ %%i, b
  276. CAT_UNDEF arg_name %+ %%i, m
  277. CAT_UNDEF arg_name %+ %%i, mp
  278. CAT_UNDEF arg_name, %%i
  279. %assign %%i %%i+1
  280. %endrep
  281. %endif
  282. %xdefine %%stack_offset stack_offset
  283. %undef stack_offset ; so that the current value of stack_offset doesn't get baked in by xdefine
  284. %assign %%i 0
  285. %rep %0
  286. %xdefine %1q r %+ %%i %+ q
  287. %xdefine %1d r %+ %%i %+ d
  288. %xdefine %1w r %+ %%i %+ w
  289. %xdefine %1h r %+ %%i %+ h
  290. %xdefine %1b r %+ %%i %+ b
  291. %xdefine %1m r %+ %%i %+ m
  292. %xdefine %1mp r %+ %%i %+ mp
  293. CAT_XDEFINE arg_name, %%i, %1
  294. %assign %%i %%i+1
  295. %rotate 1
  296. %endrep
  297. %xdefine stack_offset %%stack_offset
  298. %assign n_arg_names %0
  299. %endmacro
  300. %define required_stack_alignment ((mmsize + 15) & ~15)
  301. %define vzeroupper_required (mmsize > 16 && (ARCH_X86_64 == 0 || xmm_regs_used > 16 || notcpuflag(avx512)))
  302. %define high_mm_regs (16*cpuflag(avx512))
  303. %macro ALLOC_STACK 1-2 0 ; stack_size, n_xmm_regs (for win64 only)
  304. %ifnum %1
  305. %if %1 != 0
  306. %assign %%pad 0
  307. %assign stack_size %1
  308. %if stack_size < 0
  309. %assign stack_size -stack_size
  310. %endif
  311. %if WIN64
  312. %assign %%pad %%pad + 32 ; shadow space
  313. %if mmsize != 8
  314. %assign xmm_regs_used %2
  315. %if xmm_regs_used > 8
  316. %assign %%pad %%pad + (xmm_regs_used-8)*16 ; callee-saved xmm registers
  317. %endif
  318. %endif
  319. %endif
  320. %if required_stack_alignment <= STACK_ALIGNMENT
  321. ; maintain the current stack alignment
  322. %assign stack_size_padded stack_size + %%pad + ((-%%pad-stack_offset-gprsize) & (STACK_ALIGNMENT-1))
  323. SUB rsp, stack_size_padded
  324. %else
  325. %assign %%reg_num (regs_used - 1)
  326. %xdefine rstk r %+ %%reg_num
  327. ; align stack, and save original stack location directly above
  328. ; it, i.e. in [rsp+stack_size_padded], so we can restore the
  329. ; stack in a single instruction (i.e. mov rsp, rstk or mov
  330. ; rsp, [rsp+stack_size_padded])
  331. %if %1 < 0 ; need to store rsp on stack
  332. %xdefine rstkm [rsp + stack_size + %%pad]
  333. %assign %%pad %%pad + gprsize
  334. %else ; can keep rsp in rstk during whole function
  335. %xdefine rstkm rstk
  336. %endif
  337. %assign stack_size_padded stack_size + ((%%pad + required_stack_alignment-1) & ~(required_stack_alignment-1))
  338. mov rstk, rsp
  339. and rsp, ~(required_stack_alignment-1)
  340. sub rsp, stack_size_padded
  341. movifnidn rstkm, rstk
  342. %endif
  343. WIN64_PUSH_XMM
  344. %endif
  345. %endif
  346. %endmacro
  347. %macro SETUP_STACK_POINTER 1
  348. %ifnum %1
  349. %if %1 != 0 && required_stack_alignment > STACK_ALIGNMENT
  350. %if %1 > 0
  351. ; Reserve an additional register for storing the original stack pointer, but avoid using
  352. ; eax/rax for this purpose since it can potentially get overwritten as a return value.
  353. %assign regs_used (regs_used + 1)
  354. %if ARCH_X86_64 && regs_used == 7
  355. %assign regs_used 8
  356. %elif ARCH_X86_64 == 0 && regs_used == 1
  357. %assign regs_used 2
  358. %endif
  359. %endif
  360. %if ARCH_X86_64 && regs_used < 5 + UNIX64 * 3
  361. ; Ensure that we don't clobber any registers containing arguments. For UNIX64 we also preserve r6 (rax)
  362. ; since it's used as a hidden argument in vararg functions to specify the number of vector registers used.
  363. %assign regs_used 5 + UNIX64 * 3
  364. %endif
  365. %endif
  366. %endif
  367. %endmacro
  368. %macro DEFINE_ARGS_INTERNAL 3+
  369. %ifnum %2
  370. DEFINE_ARGS %3
  371. %elif %1 == 4
  372. DEFINE_ARGS %2
  373. %elif %1 > 4
  374. DEFINE_ARGS %2, %3
  375. %endif
  376. %endmacro
  377. %if WIN64 ; Windows x64 ;=================================================
  378. DECLARE_REG 0, rcx
  379. DECLARE_REG 1, rdx
  380. DECLARE_REG 2, R8
  381. DECLARE_REG 3, R9
  382. DECLARE_REG 4, R10, 40
  383. DECLARE_REG 5, R11, 48
  384. DECLARE_REG 6, rax, 56
  385. DECLARE_REG 7, rdi, 64
  386. DECLARE_REG 8, rsi, 72
  387. DECLARE_REG 9, rbx, 80
  388. DECLARE_REG 10, rbp, 88
  389. DECLARE_REG 11, R14, 96
  390. DECLARE_REG 12, R15, 104
  391. DECLARE_REG 13, R12, 112
  392. DECLARE_REG 14, R13, 120
  393. %macro PROLOGUE 2-5+ 0 ; #args, #regs, #xmm_regs, [stack_size,] arg_names...
  394. %assign num_args %1
  395. %assign regs_used %2
  396. ASSERT regs_used >= num_args
  397. SETUP_STACK_POINTER %4
  398. ASSERT regs_used <= 15
  399. PUSH_IF_USED 7, 8, 9, 10, 11, 12, 13, 14
  400. ALLOC_STACK %4, %3
  401. %if mmsize != 8 && stack_size == 0
  402. WIN64_SPILL_XMM %3
  403. %endif
  404. LOAD_IF_USED 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
  405. DEFINE_ARGS_INTERNAL %0, %4, %5
  406. %endmacro
  407. %macro WIN64_PUSH_XMM 0
  408. ; Use the shadow space to store XMM6 and XMM7, the rest needs stack space allocated.
  409. %if xmm_regs_used > 6 + high_mm_regs
  410. movaps [rstk + stack_offset + 8], xmm6
  411. %endif
  412. %if xmm_regs_used > 7 + high_mm_regs
  413. movaps [rstk + stack_offset + 24], xmm7
  414. %endif
  415. %assign %%xmm_regs_on_stack xmm_regs_used - high_mm_regs - 8
  416. %if %%xmm_regs_on_stack > 0
  417. %assign %%i 8
  418. %rep %%xmm_regs_on_stack
  419. movaps [rsp + (%%i-8)*16 + stack_size + 32], xmm %+ %%i
  420. %assign %%i %%i+1
  421. %endrep
  422. %endif
  423. %endmacro
  424. %macro WIN64_SPILL_XMM 1
  425. %assign xmm_regs_used %1
  426. ASSERT xmm_regs_used <= 16 + high_mm_regs
  427. %assign %%xmm_regs_on_stack xmm_regs_used - high_mm_regs - 8
  428. %if %%xmm_regs_on_stack > 0
  429. ; Allocate stack space for callee-saved xmm registers plus shadow space and align the stack.
  430. %assign %%pad %%xmm_regs_on_stack*16 + 32
  431. %assign stack_size_padded %%pad + ((-%%pad-stack_offset-gprsize) & (STACK_ALIGNMENT-1))
  432. SUB rsp, stack_size_padded
  433. %endif
  434. WIN64_PUSH_XMM
  435. %endmacro
  436. %macro WIN64_RESTORE_XMM_INTERNAL 0
  437. %assign %%pad_size 0
  438. %assign %%xmm_regs_on_stack xmm_regs_used - high_mm_regs - 8
  439. %if %%xmm_regs_on_stack > 0
  440. %assign %%i xmm_regs_used - high_mm_regs
  441. %rep %%xmm_regs_on_stack
  442. %assign %%i %%i-1
  443. movaps xmm %+ %%i, [rsp + (%%i-8)*16 + stack_size + 32]
  444. %endrep
  445. %endif
  446. %if stack_size_padded > 0
  447. %if stack_size > 0 && required_stack_alignment > STACK_ALIGNMENT
  448. mov rsp, rstkm
  449. %else
  450. add rsp, stack_size_padded
  451. %assign %%pad_size stack_size_padded
  452. %endif
  453. %endif
  454. %if xmm_regs_used > 7 + high_mm_regs
  455. movaps xmm7, [rsp + stack_offset - %%pad_size + 24]
  456. %endif
  457. %if xmm_regs_used > 6 + high_mm_regs
  458. movaps xmm6, [rsp + stack_offset - %%pad_size + 8]
  459. %endif
  460. %endmacro
  461. %macro WIN64_RESTORE_XMM 0
  462. WIN64_RESTORE_XMM_INTERNAL
  463. %assign stack_offset (stack_offset-stack_size_padded)
  464. %assign stack_size_padded 0
  465. %assign xmm_regs_used 0
  466. %endmacro
  467. %define has_epilogue regs_used > 7 || stack_size > 0 || vzeroupper_required || xmm_regs_used > 6+high_mm_regs
  468. %macro RET 0
  469. WIN64_RESTORE_XMM_INTERNAL
  470. POP_IF_USED 14, 13, 12, 11, 10, 9, 8, 7
  471. %if vzeroupper_required
  472. vzeroupper
  473. %endif
  474. AUTO_REP_RET
  475. %endmacro
  476. %elif ARCH_X86_64 ; *nix x64 ;=============================================
  477. DECLARE_REG 0, rdi
  478. DECLARE_REG 1, rsi
  479. DECLARE_REG 2, rdx
  480. DECLARE_REG 3, rcx
  481. DECLARE_REG 4, R8
  482. DECLARE_REG 5, R9
  483. DECLARE_REG 6, rax, 8
  484. DECLARE_REG 7, R10, 16
  485. DECLARE_REG 8, R11, 24
  486. DECLARE_REG 9, rbx, 32
  487. DECLARE_REG 10, rbp, 40
  488. DECLARE_REG 11, R14, 48
  489. DECLARE_REG 12, R15, 56
  490. DECLARE_REG 13, R12, 64
  491. DECLARE_REG 14, R13, 72
  492. %macro PROLOGUE 2-5+ 0 ; #args, #regs, #xmm_regs, [stack_size,] arg_names...
  493. %assign num_args %1
  494. %assign regs_used %2
  495. %assign xmm_regs_used %3
  496. ASSERT regs_used >= num_args
  497. SETUP_STACK_POINTER %4
  498. ASSERT regs_used <= 15
  499. PUSH_IF_USED 9, 10, 11, 12, 13, 14
  500. ALLOC_STACK %4
  501. LOAD_IF_USED 6, 7, 8, 9, 10, 11, 12, 13, 14
  502. DEFINE_ARGS_INTERNAL %0, %4, %5
  503. %endmacro
  504. %define has_epilogue regs_used > 9 || stack_size > 0 || vzeroupper_required
  505. %macro RET 0
  506. %if stack_size_padded > 0
  507. %if required_stack_alignment > STACK_ALIGNMENT
  508. mov rsp, rstkm
  509. %else
  510. add rsp, stack_size_padded
  511. %endif
  512. %endif
  513. POP_IF_USED 14, 13, 12, 11, 10, 9
  514. %if vzeroupper_required
  515. vzeroupper
  516. %endif
  517. AUTO_REP_RET
  518. %endmacro
  519. %else ; X86_32 ;==============================================================
  520. DECLARE_REG 0, eax, 4
  521. DECLARE_REG 1, ecx, 8
  522. DECLARE_REG 2, edx, 12
  523. DECLARE_REG 3, ebx, 16
  524. DECLARE_REG 4, esi, 20
  525. DECLARE_REG 5, edi, 24
  526. DECLARE_REG 6, ebp, 28
  527. %define rsp esp
  528. %macro DECLARE_ARG 1-*
  529. %rep %0
  530. %define r%1m [rstk + stack_offset + 4*%1 + 4]
  531. %define r%1mp dword r%1m
  532. %rotate 1
  533. %endrep
  534. %endmacro
  535. DECLARE_ARG 7, 8, 9, 10, 11, 12, 13, 14
  536. %macro PROLOGUE 2-5+ ; #args, #regs, #xmm_regs, [stack_size,] arg_names...
  537. %assign num_args %1
  538. %assign regs_used %2
  539. ASSERT regs_used >= num_args
  540. %if num_args > 7
  541. %assign num_args 7
  542. %endif
  543. %if regs_used > 7
  544. %assign regs_used 7
  545. %endif
  546. SETUP_STACK_POINTER %4
  547. ASSERT regs_used <= 7
  548. PUSH_IF_USED 3, 4, 5, 6
  549. ALLOC_STACK %4
  550. LOAD_IF_USED 0, 1, 2, 3, 4, 5, 6
  551. DEFINE_ARGS_INTERNAL %0, %4, %5
  552. %endmacro
  553. %define has_epilogue regs_used > 3 || stack_size > 0 || vzeroupper_required
  554. %macro RET 0
  555. %if stack_size_padded > 0
  556. %if required_stack_alignment > STACK_ALIGNMENT
  557. mov rsp, rstkm
  558. %else
  559. add rsp, stack_size_padded
  560. %endif
  561. %endif
  562. POP_IF_USED 6, 5, 4, 3
  563. %if vzeroupper_required
  564. vzeroupper
  565. %endif
  566. AUTO_REP_RET
  567. %endmacro
  568. %endif ;======================================================================
  569. %if WIN64 == 0
  570. %macro WIN64_SPILL_XMM 1
  571. %endmacro
  572. %macro WIN64_RESTORE_XMM 0
  573. %endmacro
  574. %macro WIN64_PUSH_XMM 0
  575. %endmacro
  576. %endif
  577. ; On AMD cpus <=K10, an ordinary ret is slow if it immediately follows either
  578. ; a branch or a branch target. So switch to a 2-byte form of ret in that case.
  579. ; We can automatically detect "follows a branch", but not a branch target.
  580. ; (SSSE3 is a sufficient condition to know that your cpu doesn't have this problem.)
  581. %macro REP_RET 0
  582. %if has_epilogue || cpuflag(ssse3)
  583. RET
  584. %else
  585. rep ret
  586. %endif
  587. annotate_function_size
  588. %endmacro
  589. %define last_branch_adr $$
  590. %macro AUTO_REP_RET 0
  591. %if notcpuflag(ssse3)
  592. times ((last_branch_adr-$)>>31)+1 rep ; times 1 iff $ == last_branch_adr.
  593. %endif
  594. ret
  595. annotate_function_size
  596. %endmacro
  597. %macro BRANCH_INSTR 0-*
  598. %rep %0
  599. %macro %1 1-2 %1
  600. %2 %1
  601. %if notcpuflag(ssse3)
  602. %%branch_instr equ $
  603. %xdefine last_branch_adr %%branch_instr
  604. %endif
  605. %endmacro
  606. %rotate 1
  607. %endrep
  608. %endmacro
  609. BRANCH_INSTR jz, je, jnz, jne, jl, jle, jnl, jnle, jg, jge, jng, jnge, ja, jae, jna, jnae, jb, jbe, jnb, jnbe, jc, jnc, js, jns, jo, jno, jp, jnp
  610. %macro TAIL_CALL 2 ; callee, is_nonadjacent
  611. %if has_epilogue
  612. call %1
  613. RET
  614. %elif %2
  615. jmp %1
  616. %endif
  617. annotate_function_size
  618. %endmacro
  619. ;=============================================================================
  620. ; arch-independent part
  621. ;=============================================================================
  622. %assign function_align 16
  623. ; Begin a function.
  624. ; Applies any symbol mangling needed for C linkage, and sets up a define such that
  625. ; subsequent uses of the function name automatically refer to the mangled version.
  626. ; Appends cpuflags to the function name if cpuflags has been specified.
  627. ; The "" empty default parameter is a workaround for nasm, which fails if SUFFIX
  628. ; is empty and we call cglobal_internal with just %1 %+ SUFFIX (without %2).
  629. %macro cglobal 1-2+ "" ; name, [PROLOGUE args]
  630. cglobal_internal 1, %1 %+ SUFFIX, %2
  631. %endmacro
  632. %macro cvisible 1-2+ "" ; name, [PROLOGUE args]
  633. cglobal_internal 0, %1 %+ SUFFIX, %2
  634. %endmacro
  635. %macro cglobal_internal 2-3+
  636. annotate_function_size
  637. %if %1
  638. %xdefine %%FUNCTION_PREFIX private_prefix
  639. %xdefine %%VISIBILITY hidden
  640. %else
  641. %xdefine %%FUNCTION_PREFIX public_prefix
  642. %xdefine %%VISIBILITY
  643. %endif
  644. %ifndef cglobaled_%2
  645. %xdefine %2 mangle(%%FUNCTION_PREFIX %+ _ %+ %2)
  646. %xdefine %2.skip_prologue %2 %+ .skip_prologue
  647. CAT_XDEFINE cglobaled_, %2, 1
  648. %endif
  649. %xdefine current_function %2
  650. %xdefine current_function_section __SECT__
  651. %if FORMAT_ELF
  652. global %2:function %%VISIBILITY
  653. %else
  654. global %2
  655. %endif
  656. align function_align
  657. %2:
  658. RESET_MM_PERMUTATION ; needed for x86-64, also makes disassembly somewhat nicer
  659. %xdefine rstk rsp ; copy of the original stack pointer, used when greater alignment than the known stack alignment is required
  660. %assign stack_offset 0 ; stack pointer offset relative to the return address
  661. %assign stack_size 0 ; amount of stack space that can be freely used inside a function
  662. %assign stack_size_padded 0 ; total amount of allocated stack space, including space for callee-saved xmm registers on WIN64 and alignment padding
  663. %assign xmm_regs_used 0 ; number of XMM registers requested, used for dealing with callee-saved registers on WIN64 and vzeroupper
  664. %ifnidn %3, ""
  665. PROLOGUE %3
  666. %endif
  667. %endmacro
  668. %macro cextern 1
  669. %xdefine %1 mangle(private_prefix %+ _ %+ %1)
  670. CAT_XDEFINE cglobaled_, %1, 1
  671. extern %1
  672. %endmacro
  673. ; like cextern, but without the prefix
  674. %macro cextern_naked 1
  675. %ifdef PREFIX
  676. %xdefine %1 mangle(%1)
  677. %endif
  678. CAT_XDEFINE cglobaled_, %1, 1
  679. extern %1
  680. %endmacro
  681. %macro const 1-2+
  682. %xdefine %1 mangle(private_prefix %+ _ %+ %1)
  683. %if FORMAT_ELF
  684. global %1:data hidden
  685. %else
  686. global %1
  687. %endif
  688. %1: %2
  689. %endmacro
  690. ; This is needed for ELF, otherwise the GNU linker assumes the stack is executable by default.
  691. %if FORMAT_ELF
  692. [SECTION .note.GNU-stack noalloc noexec nowrite progbits]
  693. %endif
  694. ; Tell debuggers how large the function was.
  695. ; This may be invoked multiple times per function; we rely on later instances overriding earlier ones.
  696. ; This is invoked by RET and similar macros, and also cglobal does it for the previous function,
  697. ; but if the last function in a source file doesn't use any of the standard macros for its epilogue,
  698. ; then its size might be unspecified.
  699. %macro annotate_function_size 0
  700. %ifdef __YASM_VER__
  701. %ifdef current_function
  702. %if FORMAT_ELF
  703. current_function_section
  704. %%ecf equ $
  705. size current_function %%ecf - current_function
  706. __SECT__
  707. %endif
  708. %endif
  709. %endif
  710. %endmacro
  711. ; cpuflags
  712. %assign cpuflags_mmx (1<<0)
  713. %assign cpuflags_mmx2 (1<<1) | cpuflags_mmx
  714. %assign cpuflags_3dnow (1<<2) | cpuflags_mmx
  715. %assign cpuflags_3dnowext (1<<3) | cpuflags_3dnow
  716. %assign cpuflags_sse (1<<4) | cpuflags_mmx2
  717. %assign cpuflags_sse2 (1<<5) | cpuflags_sse
  718. %assign cpuflags_sse2slow (1<<6) | cpuflags_sse2
  719. %assign cpuflags_lzcnt (1<<7) | cpuflags_sse2
  720. %assign cpuflags_sse3 (1<<8) | cpuflags_sse2
  721. %assign cpuflags_ssse3 (1<<9) | cpuflags_sse3
  722. %assign cpuflags_sse4 (1<<10)| cpuflags_ssse3
  723. %assign cpuflags_sse42 (1<<11)| cpuflags_sse4
  724. %assign cpuflags_aesni (1<<12)| cpuflags_sse42
  725. %assign cpuflags_avx (1<<13)| cpuflags_sse42
  726. %assign cpuflags_xop (1<<14)| cpuflags_avx
  727. %assign cpuflags_fma4 (1<<15)| cpuflags_avx
  728. %assign cpuflags_fma3 (1<<16)| cpuflags_avx
  729. %assign cpuflags_bmi1 (1<<17)| cpuflags_avx|cpuflags_lzcnt
  730. %assign cpuflags_bmi2 (1<<18)| cpuflags_bmi1
  731. %assign cpuflags_avx2 (1<<19)| cpuflags_fma3|cpuflags_bmi2
  732. %assign cpuflags_avx512 (1<<20)| cpuflags_avx2 ; F, CD, BW, DQ, VL
  733. %assign cpuflags_cache32 (1<<21)
  734. %assign cpuflags_cache64 (1<<22)
  735. %assign cpuflags_slowctz (1<<23)
  736. %assign cpuflags_aligned (1<<24) ; not a cpu feature, but a function variant
  737. %assign cpuflags_atom (1<<25)
  738. ; Returns a boolean value expressing whether or not the specified cpuflag is enabled.
  739. %define cpuflag(x) (((((cpuflags & (cpuflags_ %+ x)) ^ (cpuflags_ %+ x)) - 1) >> 31) & 1)
  740. %define notcpuflag(x) (cpuflag(x) ^ 1)
  741. ; Takes an arbitrary number of cpuflags from the above list.
  742. ; All subsequent functions (up to the next INIT_CPUFLAGS) is built for the specified cpu.
  743. ; You shouldn't need to invoke this macro directly, it's a subroutine for INIT_MMX &co.
  744. %macro INIT_CPUFLAGS 0-*
  745. %xdefine SUFFIX
  746. %undef cpuname
  747. %assign cpuflags 0
  748. %if %0 >= 1
  749. %rep %0
  750. %ifdef cpuname
  751. %xdefine cpuname cpuname %+ _%1
  752. %else
  753. %xdefine cpuname %1
  754. %endif
  755. %assign cpuflags cpuflags | cpuflags_%1
  756. %rotate 1
  757. %endrep
  758. %xdefine SUFFIX _ %+ cpuname
  759. %if cpuflag(avx)
  760. %assign avx_enabled 1
  761. %endif
  762. %if (mmsize == 16 && notcpuflag(sse2)) || (mmsize == 32 && notcpuflag(avx2))
  763. %define mova movaps
  764. %define movu movups
  765. %define movnta movntps
  766. %endif
  767. %if cpuflag(aligned)
  768. %define movu mova
  769. %elif cpuflag(sse3) && notcpuflag(ssse3)
  770. %define movu lddqu
  771. %endif
  772. %endif
  773. %if ARCH_X86_64 || cpuflag(sse2)
  774. CPUNOP amdnop
  775. %else
  776. CPUNOP basicnop
  777. %endif
  778. %endmacro
  779. ; Merge mmx, sse*, and avx*
  780. ; m# is a simd register of the currently selected size
  781. ; xm# is the corresponding xmm register if mmsize >= 16, otherwise the same as m#
  782. ; ym# is the corresponding ymm register if mmsize >= 32, otherwise the same as m#
  783. ; zm# is the corresponding zmm register if mmsize >= 64, otherwise the same as m#
  784. ; (All 4 remain in sync through SWAP.)
  785. %macro CAT_XDEFINE 3
  786. %xdefine %1%2 %3
  787. %endmacro
  788. %macro CAT_UNDEF 2
  789. %undef %1%2
  790. %endmacro
  791. ; Prefer registers 16-31 over 0-15 to avoid having to use vzeroupper
  792. %macro AVX512_MM_PERMUTATION 0-1 0 ; start_reg
  793. %if ARCH_X86_64 && cpuflag(avx512)
  794. %assign %%i %1
  795. %rep 16-%1
  796. %assign %%i_high %%i+16
  797. SWAP %%i, %%i_high
  798. %assign %%i %%i+1
  799. %endrep
  800. %endif
  801. %endmacro
  802. %macro INIT_MMX 0-1+
  803. %assign avx_enabled 0
  804. %define RESET_MM_PERMUTATION INIT_MMX %1
  805. %define mmsize 8
  806. %define num_mmregs 8
  807. %define mova movq
  808. %define movu movq
  809. %define movh movd
  810. %define movnta movntq
  811. %assign %%i 0
  812. %rep 8
  813. CAT_XDEFINE m, %%i, mm %+ %%i
  814. CAT_XDEFINE nnmm, %%i, %%i
  815. %assign %%i %%i+1
  816. %endrep
  817. %rep 24
  818. CAT_UNDEF m, %%i
  819. CAT_UNDEF nnmm, %%i
  820. %assign %%i %%i+1
  821. %endrep
  822. INIT_CPUFLAGS %1
  823. %endmacro
  824. %macro INIT_XMM 0-1+
  825. %assign avx_enabled 0
  826. %define RESET_MM_PERMUTATION INIT_XMM %1
  827. %define mmsize 16
  828. %define mova movdqa
  829. %define movu movdqu
  830. %define movh movq
  831. %define movnta movntdq
  832. INIT_CPUFLAGS %1
  833. %define num_mmregs 8
  834. %if ARCH_X86_64
  835. %define num_mmregs 16
  836. %if cpuflag(avx512)
  837. %define num_mmregs 32
  838. %endif
  839. %endif
  840. %assign %%i 0
  841. %rep num_mmregs
  842. CAT_XDEFINE m, %%i, xmm %+ %%i
  843. CAT_XDEFINE nnxmm, %%i, %%i
  844. %assign %%i %%i+1
  845. %endrep
  846. %if WIN64
  847. ; Swap callee-saved registers with volatile registers
  848. AVX512_MM_PERMUTATION 6
  849. %endif
  850. %endmacro
  851. %macro INIT_YMM 0-1+
  852. %assign avx_enabled 1
  853. %define RESET_MM_PERMUTATION INIT_YMM %1
  854. %define mmsize 32
  855. %define mova movdqa
  856. %define movu movdqu
  857. %undef movh
  858. %define movnta movntdq
  859. INIT_CPUFLAGS %1
  860. %define num_mmregs 8
  861. %if ARCH_X86_64
  862. %define num_mmregs 16
  863. %if cpuflag(avx512)
  864. %define num_mmregs 32
  865. %endif
  866. %endif
  867. %assign %%i 0
  868. %rep num_mmregs
  869. CAT_XDEFINE m, %%i, ymm %+ %%i
  870. CAT_XDEFINE nnymm, %%i, %%i
  871. %assign %%i %%i+1
  872. %endrep
  873. AVX512_MM_PERMUTATION
  874. %endmacro
  875. %macro INIT_ZMM 0-1+
  876. %assign avx_enabled 1
  877. %define RESET_MM_PERMUTATION INIT_ZMM %1
  878. %define mmsize 64
  879. %define num_mmregs 8
  880. %if ARCH_X86_64
  881. %define num_mmregs 32
  882. %endif
  883. %define mova movdqa
  884. %define movu movdqu
  885. %undef movh
  886. %define movnta movntdq
  887. %assign %%i 0
  888. %rep num_mmregs
  889. CAT_XDEFINE m, %%i, zmm %+ %%i
  890. CAT_XDEFINE nnzmm, %%i, %%i
  891. %assign %%i %%i+1
  892. %endrep
  893. INIT_CPUFLAGS %1
  894. AVX512_MM_PERMUTATION
  895. %endmacro
  896. INIT_XMM
  897. %macro DECLARE_MMCAST 1
  898. %define mmmm%1 mm%1
  899. %define mmxmm%1 mm%1
  900. %define mmymm%1 mm%1
  901. %define mmzmm%1 mm%1
  902. %define xmmmm%1 mm%1
  903. %define xmmxmm%1 xmm%1
  904. %define xmmymm%1 xmm%1
  905. %define xmmzmm%1 xmm%1
  906. %define ymmmm%1 mm%1
  907. %define ymmxmm%1 xmm%1
  908. %define ymmymm%1 ymm%1
  909. %define ymmzmm%1 ymm%1
  910. %define zmmmm%1 mm%1
  911. %define zmmxmm%1 xmm%1
  912. %define zmmymm%1 ymm%1
  913. %define zmmzmm%1 zmm%1
  914. %define xm%1 xmm %+ m%1
  915. %define ym%1 ymm %+ m%1
  916. %define zm%1 zmm %+ m%1
  917. %endmacro
  918. %assign i 0
  919. %rep 32
  920. DECLARE_MMCAST i
  921. %assign i i+1
  922. %endrep
  923. ; I often want to use macros that permute their arguments. e.g. there's no
  924. ; efficient way to implement butterfly or transpose or dct without swapping some
  925. ; arguments.
  926. ;
  927. ; I would like to not have to manually keep track of the permutations:
  928. ; If I insert a permutation in the middle of a function, it should automatically
  929. ; change everything that follows. For more complex macros I may also have multiple
  930. ; implementations, e.g. the SSE2 and SSSE3 versions may have different permutations.
  931. ;
  932. ; Hence these macros. Insert a PERMUTE or some SWAPs at the end of a macro that
  933. ; permutes its arguments. It's equivalent to exchanging the contents of the
  934. ; registers, except that this way you exchange the register names instead, so it
  935. ; doesn't cost any cycles.
  936. %macro PERMUTE 2-* ; takes a list of pairs to swap
  937. %rep %0/2
  938. %xdefine %%tmp%2 m%2
  939. %rotate 2
  940. %endrep
  941. %rep %0/2
  942. %xdefine m%1 %%tmp%2
  943. CAT_XDEFINE nn, m%1, %1
  944. %rotate 2
  945. %endrep
  946. %endmacro
  947. %macro SWAP 2+ ; swaps a single chain (sometimes more concise than pairs)
  948. %ifnum %1 ; SWAP 0, 1, ...
  949. SWAP_INTERNAL_NUM %1, %2
  950. %else ; SWAP m0, m1, ...
  951. SWAP_INTERNAL_NAME %1, %2
  952. %endif
  953. %endmacro
  954. %macro SWAP_INTERNAL_NUM 2-*
  955. %rep %0-1
  956. %xdefine %%tmp m%1
  957. %xdefine m%1 m%2
  958. %xdefine m%2 %%tmp
  959. CAT_XDEFINE nn, m%1, %1
  960. CAT_XDEFINE nn, m%2, %2
  961. %rotate 1
  962. %endrep
  963. %endmacro
  964. %macro SWAP_INTERNAL_NAME 2-*
  965. %xdefine %%args nn %+ %1
  966. %rep %0-1
  967. %xdefine %%args %%args, nn %+ %2
  968. %rotate 1
  969. %endrep
  970. SWAP_INTERNAL_NUM %%args
  971. %endmacro
  972. ; If SAVE_MM_PERMUTATION is placed at the end of a function, then any later
  973. ; calls to that function will automatically load the permutation, so values can
  974. ; be returned in mmregs.
  975. %macro SAVE_MM_PERMUTATION 0-1
  976. %if %0
  977. %xdefine %%f %1_m
  978. %else
  979. %xdefine %%f current_function %+ _m
  980. %endif
  981. %assign %%i 0
  982. %rep num_mmregs
  983. CAT_XDEFINE %%f, %%i, m %+ %%i
  984. %assign %%i %%i+1
  985. %endrep
  986. %endmacro
  987. %macro LOAD_MM_PERMUTATION 1 ; name to load from
  988. %ifdef %1_m0
  989. %assign %%i 0
  990. %rep num_mmregs
  991. CAT_XDEFINE m, %%i, %1_m %+ %%i
  992. CAT_XDEFINE nn, m %+ %%i, %%i
  993. %assign %%i %%i+1
  994. %endrep
  995. %endif
  996. %endmacro
  997. ; Append cpuflags to the callee's name iff the appended name is known and the plain name isn't
  998. %macro call 1
  999. %ifid %1
  1000. call_internal %1 %+ SUFFIX, %1
  1001. %else
  1002. call %1
  1003. %endif
  1004. %endmacro
  1005. %macro call_internal 2
  1006. %xdefine %%i %2
  1007. %ifndef cglobaled_%2
  1008. %ifdef cglobaled_%1
  1009. %xdefine %%i %1
  1010. %endif
  1011. %endif
  1012. call %%i
  1013. LOAD_MM_PERMUTATION %%i
  1014. %endmacro
  1015. ; Substitutions that reduce instruction size but are functionally equivalent
  1016. %macro add 2
  1017. %ifnum %2
  1018. %if %2==128
  1019. sub %1, -128
  1020. %else
  1021. add %1, %2
  1022. %endif
  1023. %else
  1024. add %1, %2
  1025. %endif
  1026. %endmacro
  1027. %macro sub 2
  1028. %ifnum %2
  1029. %if %2==128
  1030. add %1, -128
  1031. %else
  1032. sub %1, %2
  1033. %endif
  1034. %else
  1035. sub %1, %2
  1036. %endif
  1037. %endmacro
  1038. ;=============================================================================
  1039. ; AVX abstraction layer
  1040. ;=============================================================================
  1041. %assign i 0
  1042. %rep 32
  1043. %if i < 8
  1044. CAT_XDEFINE sizeofmm, i, 8
  1045. CAT_XDEFINE regnumofmm, i, i
  1046. %endif
  1047. CAT_XDEFINE sizeofxmm, i, 16
  1048. CAT_XDEFINE sizeofymm, i, 32
  1049. CAT_XDEFINE sizeofzmm, i, 64
  1050. CAT_XDEFINE regnumofxmm, i, i
  1051. CAT_XDEFINE regnumofymm, i, i
  1052. CAT_XDEFINE regnumofzmm, i, i
  1053. %assign i i+1
  1054. %endrep
  1055. %undef i
  1056. %macro CHECK_AVX_INSTR_EMU 3-*
  1057. %xdefine %%opcode %1
  1058. %xdefine %%dst %2
  1059. %rep %0-2
  1060. %ifidn %%dst, %3
  1061. %error non-avx emulation of ``%%opcode'' is not supported
  1062. %endif
  1063. %rotate 1
  1064. %endrep
  1065. %endmacro
  1066. ;%1 == instruction
  1067. ;%2 == minimal instruction set
  1068. ;%3 == 1 if float, 0 if int
  1069. ;%4 == 1 if 4-operand emulation, 0 if 3-operand emulation, 255 otherwise (no emulation)
  1070. ;%5 == 1 if commutative (i.e. doesn't matter which src arg is which), 0 if not
  1071. ;%6+: operands
  1072. %macro RUN_AVX_INSTR 6-9+
  1073. %ifnum sizeof%7
  1074. %assign __sizeofreg sizeof%7
  1075. %elifnum sizeof%6
  1076. %assign __sizeofreg sizeof%6
  1077. %else
  1078. %assign __sizeofreg mmsize
  1079. %endif
  1080. %assign __emulate_avx 0
  1081. %if avx_enabled && __sizeofreg >= 16
  1082. %xdefine __instr v%1
  1083. %else
  1084. %xdefine __instr %1
  1085. %if %0 >= 8+%4
  1086. %assign __emulate_avx 1
  1087. %endif
  1088. %endif
  1089. %ifnidn %2, fnord
  1090. %ifdef cpuname
  1091. %if notcpuflag(%2)
  1092. %error use of ``%1'' %2 instruction in cpuname function: current_function
  1093. %elif cpuflags_%2 < cpuflags_sse && notcpuflag(sse2) && __sizeofreg > 8
  1094. %error use of ``%1'' sse2 instruction in cpuname function: current_function
  1095. %endif
  1096. %endif
  1097. %endif
  1098. %if __emulate_avx
  1099. %xdefine __src1 %7
  1100. %xdefine __src2 %8
  1101. %if %5 && %4 == 0
  1102. %ifnidn %6, %7
  1103. %ifidn %6, %8
  1104. %xdefine __src1 %8
  1105. %xdefine __src2 %7
  1106. %elifnnum sizeof%8
  1107. ; 3-operand AVX instructions with a memory arg can only have it in src2,
  1108. ; whereas SSE emulation prefers to have it in src1 (i.e. the mov).
  1109. ; So, if the instruction is commutative with a memory arg, swap them.
  1110. %xdefine __src1 %8
  1111. %xdefine __src2 %7
  1112. %endif
  1113. %endif
  1114. %endif
  1115. %ifnidn %6, __src1
  1116. %if %0 >= 9
  1117. CHECK_AVX_INSTR_EMU {%1 %6, %7, %8, %9}, %6, __src2, %9
  1118. %else
  1119. CHECK_AVX_INSTR_EMU {%1 %6, %7, %8}, %6, __src2
  1120. %endif
  1121. %if __sizeofreg == 8
  1122. MOVQ %6, __src1
  1123. %elif %3
  1124. MOVAPS %6, __src1
  1125. %else
  1126. MOVDQA %6, __src1
  1127. %endif
  1128. %endif
  1129. %if %0 >= 9
  1130. %1 %6, __src2, %9
  1131. %else
  1132. %1 %6, __src2
  1133. %endif
  1134. %elif %0 >= 9
  1135. __instr %6, %7, %8, %9
  1136. %elif %0 == 8
  1137. __instr %6, %7, %8
  1138. %elif %0 == 7
  1139. __instr %6, %7
  1140. %else
  1141. __instr %6
  1142. %endif
  1143. %endmacro
  1144. ;%1 == instruction
  1145. ;%2 == minimal instruction set
  1146. ;%3 == 1 if float, 0 if int
  1147. ;%4 == 1 if 4-operand emulation, 0 if 3-operand emulation, 255 otherwise (no emulation)
  1148. ;%5 == 1 if commutative (i.e. doesn't matter which src arg is which), 0 if not
  1149. %macro AVX_INSTR 1-5 fnord, 0, 255, 0
  1150. %macro %1 1-10 fnord, fnord, fnord, fnord, %1, %2, %3, %4, %5
  1151. %ifidn %2, fnord
  1152. RUN_AVX_INSTR %6, %7, %8, %9, %10, %1
  1153. %elifidn %3, fnord
  1154. RUN_AVX_INSTR %6, %7, %8, %9, %10, %1, %2
  1155. %elifidn %4, fnord
  1156. RUN_AVX_INSTR %6, %7, %8, %9, %10, %1, %2, %3
  1157. %elifidn %5, fnord
  1158. RUN_AVX_INSTR %6, %7, %8, %9, %10, %1, %2, %3, %4
  1159. %else
  1160. RUN_AVX_INSTR %6, %7, %8, %9, %10, %1, %2, %3, %4, %5
  1161. %endif
  1162. %endmacro
  1163. %endmacro
  1164. ; Instructions with both VEX/EVEX and legacy encodings
  1165. ; Non-destructive instructions are written without parameters
  1166. AVX_INSTR addpd, sse2, 1, 0, 1
  1167. AVX_INSTR addps, sse, 1, 0, 1
  1168. AVX_INSTR addsd, sse2, 1, 0, 0
  1169. AVX_INSTR addss, sse, 1, 0, 0
  1170. AVX_INSTR addsubpd, sse3, 1, 0, 0
  1171. AVX_INSTR addsubps, sse3, 1, 0, 0
  1172. AVX_INSTR aesdec, aesni, 0, 0, 0
  1173. AVX_INSTR aesdeclast, aesni, 0, 0, 0
  1174. AVX_INSTR aesenc, aesni, 0, 0, 0
  1175. AVX_INSTR aesenclast, aesni, 0, 0, 0
  1176. AVX_INSTR aesimc, aesni
  1177. AVX_INSTR aeskeygenassist, aesni
  1178. AVX_INSTR andnpd, sse2, 1, 0, 0
  1179. AVX_INSTR andnps, sse, 1, 0, 0
  1180. AVX_INSTR andpd, sse2, 1, 0, 1
  1181. AVX_INSTR andps, sse, 1, 0, 1
  1182. AVX_INSTR blendpd, sse4, 1, 1, 0
  1183. AVX_INSTR blendps, sse4, 1, 1, 0
  1184. AVX_INSTR blendvpd, sse4 ; can't be emulated
  1185. AVX_INSTR blendvps, sse4 ; can't be emulated
  1186. AVX_INSTR cmppd, sse2, 1, 1, 0
  1187. AVX_INSTR cmpps, sse, 1, 1, 0
  1188. AVX_INSTR cmpsd, sse2, 1, 1, 0
  1189. AVX_INSTR cmpss, sse, 1, 1, 0
  1190. AVX_INSTR comisd, sse2
  1191. AVX_INSTR comiss, sse
  1192. AVX_INSTR cvtdq2pd, sse2
  1193. AVX_INSTR cvtdq2ps, sse2
  1194. AVX_INSTR cvtpd2dq, sse2
  1195. AVX_INSTR cvtpd2ps, sse2
  1196. AVX_INSTR cvtps2dq, sse2
  1197. AVX_INSTR cvtps2pd, sse2
  1198. AVX_INSTR cvtsd2si, sse2
  1199. AVX_INSTR cvtsd2ss, sse2, 1, 0, 0
  1200. AVX_INSTR cvtsi2sd, sse2, 1, 0, 0
  1201. AVX_INSTR cvtsi2ss, sse, 1, 0, 0
  1202. AVX_INSTR cvtss2sd, sse2, 1, 0, 0
  1203. AVX_INSTR cvtss2si, sse
  1204. AVX_INSTR cvttpd2dq, sse2
  1205. AVX_INSTR cvttps2dq, sse2
  1206. AVX_INSTR cvttsd2si, sse2
  1207. AVX_INSTR cvttss2si, sse
  1208. AVX_INSTR divpd, sse2, 1, 0, 0
  1209. AVX_INSTR divps, sse, 1, 0, 0
  1210. AVX_INSTR divsd, sse2, 1, 0, 0
  1211. AVX_INSTR divss, sse, 1, 0, 0
  1212. AVX_INSTR dppd, sse4, 1, 1, 0
  1213. AVX_INSTR dpps, sse4, 1, 1, 0
  1214. AVX_INSTR extractps, sse4
  1215. AVX_INSTR haddpd, sse3, 1, 0, 0
  1216. AVX_INSTR haddps, sse3, 1, 0, 0
  1217. AVX_INSTR hsubpd, sse3, 1, 0, 0
  1218. AVX_INSTR hsubps, sse3, 1, 0, 0
  1219. AVX_INSTR insertps, sse4, 1, 1, 0
  1220. AVX_INSTR lddqu, sse3
  1221. AVX_INSTR ldmxcsr, sse
  1222. AVX_INSTR maskmovdqu, sse2
  1223. AVX_INSTR maxpd, sse2, 1, 0, 1
  1224. AVX_INSTR maxps, sse, 1, 0, 1
  1225. AVX_INSTR maxsd, sse2, 1, 0, 0
  1226. AVX_INSTR maxss, sse, 1, 0, 0
  1227. AVX_INSTR minpd, sse2, 1, 0, 1
  1228. AVX_INSTR minps, sse, 1, 0, 1
  1229. AVX_INSTR minsd, sse2, 1, 0, 0
  1230. AVX_INSTR minss, sse, 1, 0, 0
  1231. AVX_INSTR movapd, sse2
  1232. AVX_INSTR movaps, sse
  1233. AVX_INSTR movd, mmx
  1234. AVX_INSTR movddup, sse3
  1235. AVX_INSTR movdqa, sse2
  1236. AVX_INSTR movdqu, sse2
  1237. AVX_INSTR movhlps, sse, 1, 0, 0
  1238. AVX_INSTR movhpd, sse2, 1, 0, 0
  1239. AVX_INSTR movhps, sse, 1, 0, 0
  1240. AVX_INSTR movlhps, sse, 1, 0, 0
  1241. AVX_INSTR movlpd, sse2, 1, 0, 0
  1242. AVX_INSTR movlps, sse, 1, 0, 0
  1243. AVX_INSTR movmskpd, sse2
  1244. AVX_INSTR movmskps, sse
  1245. AVX_INSTR movntdq, sse2
  1246. AVX_INSTR movntdqa, sse4
  1247. AVX_INSTR movntpd, sse2
  1248. AVX_INSTR movntps, sse
  1249. AVX_INSTR movq, mmx
  1250. AVX_INSTR movsd, sse2, 1, 0, 0
  1251. AVX_INSTR movshdup, sse3
  1252. AVX_INSTR movsldup, sse3
  1253. AVX_INSTR movss, sse, 1, 0, 0
  1254. AVX_INSTR movupd, sse2
  1255. AVX_INSTR movups, sse
  1256. AVX_INSTR mpsadbw, sse4, 0, 1, 0
  1257. AVX_INSTR mulpd, sse2, 1, 0, 1
  1258. AVX_INSTR mulps, sse, 1, 0, 1
  1259. AVX_INSTR mulsd, sse2, 1, 0, 0
  1260. AVX_INSTR mulss, sse, 1, 0, 0
  1261. AVX_INSTR orpd, sse2, 1, 0, 1
  1262. AVX_INSTR orps, sse, 1, 0, 1
  1263. AVX_INSTR pabsb, ssse3
  1264. AVX_INSTR pabsd, ssse3
  1265. AVX_INSTR pabsw, ssse3
  1266. AVX_INSTR packsswb, mmx, 0, 0, 0
  1267. AVX_INSTR packssdw, mmx, 0, 0, 0
  1268. AVX_INSTR packuswb, mmx, 0, 0, 0
  1269. AVX_INSTR packusdw, sse4, 0, 0, 0
  1270. AVX_INSTR paddb, mmx, 0, 0, 1
  1271. AVX_INSTR paddw, mmx, 0, 0, 1
  1272. AVX_INSTR paddd, mmx, 0, 0, 1
  1273. AVX_INSTR paddq, sse2, 0, 0, 1
  1274. AVX_INSTR paddsb, mmx, 0, 0, 1
  1275. AVX_INSTR paddsw, mmx, 0, 0, 1
  1276. AVX_INSTR paddusb, mmx, 0, 0, 1
  1277. AVX_INSTR paddusw, mmx, 0, 0, 1
  1278. AVX_INSTR palignr, ssse3, 0, 1, 0
  1279. AVX_INSTR pand, mmx, 0, 0, 1
  1280. AVX_INSTR pandn, mmx, 0, 0, 0
  1281. AVX_INSTR pavgb, mmx2, 0, 0, 1
  1282. AVX_INSTR pavgw, mmx2, 0, 0, 1
  1283. AVX_INSTR pblendvb, sse4 ; can't be emulated
  1284. AVX_INSTR pblendw, sse4, 0, 1, 0
  1285. AVX_INSTR pclmulqdq, fnord, 0, 1, 0
  1286. AVX_INSTR pclmulhqhqdq, fnord, 0, 0, 0
  1287. AVX_INSTR pclmulhqlqdq, fnord, 0, 0, 0
  1288. AVX_INSTR pclmullqhqdq, fnord, 0, 0, 0
  1289. AVX_INSTR pclmullqlqdq, fnord, 0, 0, 0
  1290. AVX_INSTR pcmpestri, sse42
  1291. AVX_INSTR pcmpestrm, sse42
  1292. AVX_INSTR pcmpistri, sse42
  1293. AVX_INSTR pcmpistrm, sse42
  1294. AVX_INSTR pcmpeqb, mmx, 0, 0, 1
  1295. AVX_INSTR pcmpeqw, mmx, 0, 0, 1
  1296. AVX_INSTR pcmpeqd, mmx, 0, 0, 1
  1297. AVX_INSTR pcmpeqq, sse4, 0, 0, 1
  1298. AVX_INSTR pcmpgtb, mmx, 0, 0, 0
  1299. AVX_INSTR pcmpgtw, mmx, 0, 0, 0
  1300. AVX_INSTR pcmpgtd, mmx, 0, 0, 0
  1301. AVX_INSTR pcmpgtq, sse42, 0, 0, 0
  1302. AVX_INSTR pextrb, sse4
  1303. AVX_INSTR pextrd, sse4
  1304. AVX_INSTR pextrq, sse4
  1305. AVX_INSTR pextrw, mmx2
  1306. AVX_INSTR phaddw, ssse3, 0, 0, 0
  1307. AVX_INSTR phaddd, ssse3, 0, 0, 0
  1308. AVX_INSTR phaddsw, ssse3, 0, 0, 0
  1309. AVX_INSTR phminposuw, sse4
  1310. AVX_INSTR phsubw, ssse3, 0, 0, 0
  1311. AVX_INSTR phsubd, ssse3, 0, 0, 0
  1312. AVX_INSTR phsubsw, ssse3, 0, 0, 0
  1313. AVX_INSTR pinsrb, sse4, 0, 1, 0
  1314. AVX_INSTR pinsrd, sse4, 0, 1, 0
  1315. AVX_INSTR pinsrq, sse4, 0, 1, 0
  1316. AVX_INSTR pinsrw, mmx2, 0, 1, 0
  1317. AVX_INSTR pmaddwd, mmx, 0, 0, 1
  1318. AVX_INSTR pmaddubsw, ssse3, 0, 0, 0
  1319. AVX_INSTR pmaxsb, sse4, 0, 0, 1
  1320. AVX_INSTR pmaxsw, mmx2, 0, 0, 1
  1321. AVX_INSTR pmaxsd, sse4, 0, 0, 1
  1322. AVX_INSTR pmaxub, mmx2, 0, 0, 1
  1323. AVX_INSTR pmaxuw, sse4, 0, 0, 1
  1324. AVX_INSTR pmaxud, sse4, 0, 0, 1
  1325. AVX_INSTR pminsb, sse4, 0, 0, 1
  1326. AVX_INSTR pminsw, mmx2, 0, 0, 1
  1327. AVX_INSTR pminsd, sse4, 0, 0, 1
  1328. AVX_INSTR pminub, mmx2, 0, 0, 1
  1329. AVX_INSTR pminuw, sse4, 0, 0, 1
  1330. AVX_INSTR pminud, sse4, 0, 0, 1
  1331. AVX_INSTR pmovmskb, mmx2
  1332. AVX_INSTR pmovsxbw, sse4
  1333. AVX_INSTR pmovsxbd, sse4
  1334. AVX_INSTR pmovsxbq, sse4
  1335. AVX_INSTR pmovsxwd, sse4
  1336. AVX_INSTR pmovsxwq, sse4
  1337. AVX_INSTR pmovsxdq, sse4
  1338. AVX_INSTR pmovzxbw, sse4
  1339. AVX_INSTR pmovzxbd, sse4
  1340. AVX_INSTR pmovzxbq, sse4
  1341. AVX_INSTR pmovzxwd, sse4
  1342. AVX_INSTR pmovzxwq, sse4
  1343. AVX_INSTR pmovzxdq, sse4
  1344. AVX_INSTR pmuldq, sse4, 0, 0, 1
  1345. AVX_INSTR pmulhrsw, ssse3, 0, 0, 1
  1346. AVX_INSTR pmulhuw, mmx2, 0, 0, 1
  1347. AVX_INSTR pmulhw, mmx, 0, 0, 1
  1348. AVX_INSTR pmullw, mmx, 0, 0, 1
  1349. AVX_INSTR pmulld, sse4, 0, 0, 1
  1350. AVX_INSTR pmuludq, sse2, 0, 0, 1
  1351. AVX_INSTR por, mmx, 0, 0, 1
  1352. AVX_INSTR psadbw, mmx2, 0, 0, 1
  1353. AVX_INSTR pshufb, ssse3, 0, 0, 0
  1354. AVX_INSTR pshufd, sse2
  1355. AVX_INSTR pshufhw, sse2
  1356. AVX_INSTR pshuflw, sse2
  1357. AVX_INSTR psignb, ssse3, 0, 0, 0
  1358. AVX_INSTR psignw, ssse3, 0, 0, 0
  1359. AVX_INSTR psignd, ssse3, 0, 0, 0
  1360. AVX_INSTR psllw, mmx, 0, 0, 0
  1361. AVX_INSTR pslld, mmx, 0, 0, 0
  1362. AVX_INSTR psllq, mmx, 0, 0, 0
  1363. AVX_INSTR pslldq, sse2, 0, 0, 0
  1364. AVX_INSTR psraw, mmx, 0, 0, 0
  1365. AVX_INSTR psrad, mmx, 0, 0, 0
  1366. AVX_INSTR psrlw, mmx, 0, 0, 0
  1367. AVX_INSTR psrld, mmx, 0, 0, 0
  1368. AVX_INSTR psrlq, mmx, 0, 0, 0
  1369. AVX_INSTR psrldq, sse2, 0, 0, 0
  1370. AVX_INSTR psubb, mmx, 0, 0, 0
  1371. AVX_INSTR psubw, mmx, 0, 0, 0
  1372. AVX_INSTR psubd, mmx, 0, 0, 0
  1373. AVX_INSTR psubq, sse2, 0, 0, 0
  1374. AVX_INSTR psubsb, mmx, 0, 0, 0
  1375. AVX_INSTR psubsw, mmx, 0, 0, 0
  1376. AVX_INSTR psubusb, mmx, 0, 0, 0
  1377. AVX_INSTR psubusw, mmx, 0, 0, 0
  1378. AVX_INSTR ptest, sse4
  1379. AVX_INSTR punpckhbw, mmx, 0, 0, 0
  1380. AVX_INSTR punpckhwd, mmx, 0, 0, 0
  1381. AVX_INSTR punpckhdq, mmx, 0, 0, 0
  1382. AVX_INSTR punpckhqdq, sse2, 0, 0, 0
  1383. AVX_INSTR punpcklbw, mmx, 0, 0, 0
  1384. AVX_INSTR punpcklwd, mmx, 0, 0, 0
  1385. AVX_INSTR punpckldq, mmx, 0, 0, 0
  1386. AVX_INSTR punpcklqdq, sse2, 0, 0, 0
  1387. AVX_INSTR pxor, mmx, 0, 0, 1
  1388. AVX_INSTR rcpps, sse
  1389. AVX_INSTR rcpss, sse, 1, 0, 0
  1390. AVX_INSTR roundpd, sse4
  1391. AVX_INSTR roundps, sse4
  1392. AVX_INSTR roundsd, sse4, 1, 1, 0
  1393. AVX_INSTR roundss, sse4, 1, 1, 0
  1394. AVX_INSTR rsqrtps, sse
  1395. AVX_INSTR rsqrtss, sse, 1, 0, 0
  1396. AVX_INSTR shufpd, sse2, 1, 1, 0
  1397. AVX_INSTR shufps, sse, 1, 1, 0
  1398. AVX_INSTR sqrtpd, sse2
  1399. AVX_INSTR sqrtps, sse
  1400. AVX_INSTR sqrtsd, sse2, 1, 0, 0
  1401. AVX_INSTR sqrtss, sse, 1, 0, 0
  1402. AVX_INSTR stmxcsr, sse
  1403. AVX_INSTR subpd, sse2, 1, 0, 0
  1404. AVX_INSTR subps, sse, 1, 0, 0
  1405. AVX_INSTR subsd, sse2, 1, 0, 0
  1406. AVX_INSTR subss, sse, 1, 0, 0
  1407. AVX_INSTR ucomisd, sse2
  1408. AVX_INSTR ucomiss, sse
  1409. AVX_INSTR unpckhpd, sse2, 1, 0, 0
  1410. AVX_INSTR unpckhps, sse, 1, 0, 0
  1411. AVX_INSTR unpcklpd, sse2, 1, 0, 0
  1412. AVX_INSTR unpcklps, sse, 1, 0, 0
  1413. AVX_INSTR xorpd, sse2, 1, 0, 1
  1414. AVX_INSTR xorps, sse, 1, 0, 1
  1415. ; 3DNow instructions, for sharing code between AVX, SSE and 3DN
  1416. AVX_INSTR pfadd, 3dnow, 1, 0, 1
  1417. AVX_INSTR pfsub, 3dnow, 1, 0, 0
  1418. AVX_INSTR pfmul, 3dnow, 1, 0, 1
  1419. ; base-4 constants for shuffles
  1420. %assign i 0
  1421. %rep 256
  1422. %assign j ((i>>6)&3)*1000 + ((i>>4)&3)*100 + ((i>>2)&3)*10 + (i&3)
  1423. %if j < 10
  1424. CAT_XDEFINE q000, j, i
  1425. %elif j < 100
  1426. CAT_XDEFINE q00, j, i
  1427. %elif j < 1000
  1428. CAT_XDEFINE q0, j, i
  1429. %else
  1430. CAT_XDEFINE q, j, i
  1431. %endif
  1432. %assign i i+1
  1433. %endrep
  1434. %undef i
  1435. %undef j
  1436. %macro FMA_INSTR 3
  1437. %macro %1 4-7 %1, %2, %3
  1438. %if cpuflag(xop)
  1439. v%5 %1, %2, %3, %4
  1440. %elifnidn %1, %4
  1441. %6 %1, %2, %3
  1442. %7 %1, %4
  1443. %else
  1444. %error non-xop emulation of ``%5 %1, %2, %3, %4'' is not supported
  1445. %endif
  1446. %endmacro
  1447. %endmacro
  1448. FMA_INSTR pmacsww, pmullw, paddw
  1449. FMA_INSTR pmacsdd, pmulld, paddd ; sse4 emulation
  1450. FMA_INSTR pmacsdql, pmuldq, paddq ; sse4 emulation
  1451. FMA_INSTR pmadcswd, pmaddwd, paddd
  1452. ; tzcnt is equivalent to "rep bsf" and is backwards-compatible with bsf.
  1453. ; This lets us use tzcnt without bumping the yasm version requirement yet.
  1454. %define tzcnt rep bsf
  1455. ; Macros for consolidating FMA3 and FMA4 using 4-operand (dst, src1, src2, src3) syntax.
  1456. ; FMA3 is only possible if dst is the same as one of the src registers.
  1457. ; Either src2 or src3 can be a memory operand.
  1458. %macro FMA4_INSTR 2-*
  1459. %push fma4_instr
  1460. %xdefine %$prefix %1
  1461. %rep %0 - 1
  1462. %macro %$prefix%2 4-6 %$prefix, %2
  1463. %if notcpuflag(fma3) && notcpuflag(fma4)
  1464. %error use of ``%5%6'' fma instruction in cpuname function: current_function
  1465. %elif cpuflag(fma4)
  1466. v%5%6 %1, %2, %3, %4
  1467. %elifidn %1, %2
  1468. ; If %3 or %4 is a memory operand it needs to be encoded as the last operand.
  1469. %ifnum sizeof%3
  1470. v%{5}213%6 %2, %3, %4
  1471. %else
  1472. v%{5}132%6 %2, %4, %3
  1473. %endif
  1474. %elifidn %1, %3
  1475. v%{5}213%6 %3, %2, %4
  1476. %elifidn %1, %4
  1477. v%{5}231%6 %4, %2, %3
  1478. %else
  1479. %error fma3 emulation of ``%5%6 %1, %2, %3, %4'' is not supported
  1480. %endif
  1481. %endmacro
  1482. %rotate 1
  1483. %endrep
  1484. %pop
  1485. %endmacro
  1486. FMA4_INSTR fmadd, pd, ps, sd, ss
  1487. FMA4_INSTR fmaddsub, pd, ps
  1488. FMA4_INSTR fmsub, pd, ps, sd, ss
  1489. FMA4_INSTR fmsubadd, pd, ps
  1490. FMA4_INSTR fnmadd, pd, ps, sd, ss
  1491. FMA4_INSTR fnmsub, pd, ps, sd, ss
  1492. ; Macros for converting VEX instructions to equivalent EVEX ones.
  1493. %macro EVEX_INSTR 2-3 0 ; vex, evex, prefer_evex
  1494. %macro %1 2-7 fnord, fnord, %1, %2, %3
  1495. %ifidn %3, fnord
  1496. %define %%args %1, %2
  1497. %elifidn %4, fnord
  1498. %define %%args %1, %2, %3
  1499. %else
  1500. %define %%args %1, %2, %3, %4
  1501. %endif
  1502. %assign %%evex_required cpuflag(avx512) & %7
  1503. %ifnum regnumof%1
  1504. %if regnumof%1 >= 16 || sizeof%1 > 32
  1505. %assign %%evex_required 1
  1506. %endif
  1507. %endif
  1508. %ifnum regnumof%2
  1509. %if regnumof%2 >= 16 || sizeof%2 > 32
  1510. %assign %%evex_required 1
  1511. %endif
  1512. %endif
  1513. %if %%evex_required
  1514. %6 %%args
  1515. %else
  1516. %5 %%args ; Prefer VEX over EVEX due to shorter instruction length
  1517. %endif
  1518. %endmacro
  1519. %endmacro
  1520. EVEX_INSTR vbroadcastf128, vbroadcastf32x4
  1521. EVEX_INSTR vbroadcasti128, vbroadcasti32x4
  1522. EVEX_INSTR vextractf128, vextractf32x4
  1523. EVEX_INSTR vextracti128, vextracti32x4
  1524. EVEX_INSTR vinsertf128, vinsertf32x4
  1525. EVEX_INSTR vinserti128, vinserti32x4
  1526. EVEX_INSTR vmovdqa, vmovdqa32
  1527. EVEX_INSTR vmovdqu, vmovdqu32
  1528. EVEX_INSTR vpand, vpandd
  1529. EVEX_INSTR vpandn, vpandnd
  1530. EVEX_INSTR vpor, vpord
  1531. EVEX_INSTR vpxor, vpxord
  1532. EVEX_INSTR vrcpps, vrcp14ps, 1 ; EVEX versions have higher precision
  1533. EVEX_INSTR vrcpss, vrcp14ss, 1
  1534. EVEX_INSTR vrsqrtps, vrsqrt14ps, 1
  1535. EVEX_INSTR vrsqrtss, vrsqrt14ss, 1
  1536. ; workaround: vpbroadcastq is broken in x86_32 due to a yasm bug (fixed in 1.3.0)
  1537. %ifdef __YASM_VER__
  1538. %if __YASM_VERSION_ID__ < 0x01030000 && ARCH_X86_64 == 0
  1539. %macro vpbroadcastq 2
  1540. %if sizeof%1 == 16
  1541. movddup %1, %2
  1542. %else
  1543. vbroadcastsd %1, %2
  1544. %endif
  1545. %endmacro
  1546. %endif
  1547. %endif