GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — WavPack/src/pack_x64.asm at master · dbry/WavPack Expand file tree/ Copy pathpack_x64.asmMore file actions 1852 lines (1616 loc) · 63.8 KB / Copy pathpack_x64.asmFile metadata and controls1852 lines (1616 loc) · 63.8 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; **** WAVPACK **** ;; ;; Hybrid Lossless Wavefile Compressor ;; ;; Copyright (c) 1998 - 2015 Conifer Software. ;; ;; All Rights Reserved. ;; ;; Distributed under the BSD Software License (see license.txt) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; include <ksamd64.inc> public pack_decorr_stereo_pass_cont_rev_x64win public pack_decorr_stereo_pass_cont_x64win asmcode segment page 'CODE' ; This module contains X64 assembly optimized versions of functions required ; to encode WavPack files. ; This is an assembly optimized version of the following WavPack function: ; ; void pack_decorr_stereo_pass ( ; struct decorr_pass *dpp, ; int32_t *buffer, ; int32_t sample_count); ; ; It performs a single pass of stereo decorrelation, in place, as specified ; by the decorr_pass structure. Note that this function does NOT return the ; dpp->samples_X[] values in the "normalized" positions for terms 1-8, so if ; the number of samples is not a multiple of MAX_TERM, these must be moved if ; they are to be used somewhere else. ; ; This is written to work on an X86-64 processor (also called the AMD64) ; running in 64-bit mode and uses the MMX extensions to improve the ; performance by processing both stereo channels together. It is based on ; the original MMX code written by Joachim Henke that used MMX intrinsics ; called from C. Many thanks to Joachim for that! ; ; An issue with using MMX for this is that the sample history array in the ; decorr_pass structure contains separate arrays for each channel while the ; MMX code wants there to be a single array of dual samples. The fix for ; this is to convert the data in the arrays on entry and exit, and this is ; made easy by the fact that the 8 MMX registers hold exactly the required ; amount of data (64 bytes)! ; ; This is written to work on an X86-64 processor (also called the AMD64) ; running in 64-bit mode. This version is for the 64-bit Windows ABI and ; provides appropriate prologs and epilogs for stack unwinding. The ; arguments are passed in registers: ; ; struct decorr_pass *dpp rcx ; int32_t *buffer rdx ; int32_t sample_count r8d ; ; During the processing loops, the following registers are used: ; ; rdi buffer pointer ; rsi termination buffer pointer ; rax,rbx,rdx used in default term to reduce calculation ; rbp decorr_pass pointer ; mm0, mm1 scratch ; mm2 original sample values ; mm3 correlation samples ; mm4 0 (for pcmpeqd) ; mm5 weights ; mm6 delta ; mm7 512 (for rounding) ; pack_decorr_stereo_pass_x64win proc frame push_reg rbp ; save non-volatile registers on stack push_reg rbx ; (alphabetically) push_reg rdi push_reg rsi alloc_stack 8 ; allocate 8 bytes on stack & align to 16 bytes end_prologue mov rdi, rcx ; copy params from win regs to Linux regs mov rsi, rdx ; so we can leave following code similar mov rdx, r8 mov rcx, r9 mov rbp, rdi ; rbp = *dpp mov rdi, rsi ; rdi = inbuffer mov esi, edx sal esi, 3 jz bdone add rsi, rdi ; rsi = termination buffer pointer ; convert samples_A and samples_B array into samples_AB array for MMX ; (the MMX registers provide exactly enough storage to do this easily) movq mm0, [rbp+16] punpckldq mm0, [rbp+48] movq mm1, [rbp+16] punpckhdq mm1, [rbp+48] movq mm2, [rbp+24] punpckldq mm2, [rbp+56] movq mm3, [rbp+24] punpckhdq mm3, [rbp+56] movq mm4, [rbp+32] punpckldq mm4, [rbp+64] movq mm5, [rbp+32] punpckhdq mm5, [rbp+64] movq mm6, [rbp+40] punpckldq mm6, [rbp+72] movq mm7, [rbp+40] punpckhdq mm7, [rbp+72] movq [rbp+16], mm0 movq [rbp+24], mm1 movq [rbp+32], mm2 movq [rbp+40], mm3 movq [rbp+48], mm4 movq [rbp+56], mm5 movq [rbp+64], mm6 movq [rbp+72], mm7 mov eax, 512 movd mm7, eax punpckldq mm7, mm7 ; mm7 = round (512) mov eax, [rbp+4] movd mm6, eax punpckldq mm6, mm6 ; mm6 = delta (0-7) mov eax, 0FFFFh ; mask high weights to zero for PMADDWD movd mm5, eax punpckldq mm5, mm5 ; mm5 = weight mask 0x0000FFFF0000FFFF pand mm5, [rbp+8] ; mm5 = weight_AB masked to 16-bit movq mm4, [rbp+16] ; preload samples_AB[0] mov al, [rbp] ; get term and vector to correct loop cmp al, 17 je buff_term_17_loop cmp al, 18 je buff_term_18_loop cmp al, -1 je buff_term_minus_1_loop cmp al, -2 je buff_term_minus_2_loop cmp al, -3 je buff_term_minus_3_loop pxor mm4, mm4 ; mm4 = 0 (for pcmpeqd) xor eax, eax xor ebx, ebx add bl, [rbp] mov ecx, 7 and ebx, ecx jmp buff_default_term_loop align 64 buff_default_term_loop: movq mm2, [rdi] ; mm2 = left_right movq mm3, [rbp+16+rax*8] inc eax and eax, ecx movq [rbp+16+rbx*8], mm2 inc ebx and ebx, ecx movq mm1, mm3 paddd mm1, mm1 psrlw mm1, 1 pmaddwd mm1, mm5 movq mm0, mm3 psrld mm0, 15 pmaddwd mm0, mm5 pslld mm0, 5 paddd mm1, mm7 ; add 512 for rounding psrad mm1, 10 psubd mm2, mm0 psubd mm2, mm1 ; add shifted sums movq mm0, mm3 movq [rdi], mm2 ; store result pxor mm0, mm2 psrad mm0, 31 ; mm0 = sign (sam_AB ^ left_right) add rdi, 8 pcmpeqd mm2, mm4 ; mm2 = 1s if left_right was zero pcmpeqd mm3, mm4 ; mm3 = 1s if sam_AB was zero por mm2, mm3 ; mm2 = 1s if either was zero pandn mm2, mm6 ; mask delta with zeros check pxor mm5, mm0 paddw mm5, mm2 ; and add to weight_AB pxor mm5, mm0 cmp rdi, rsi jnz buff_default_term_loop jmp bdone align 64 buff_term_17_loop: movq mm3, mm4 ; get previous calculated value paddd mm3, mm4 psubd mm3, [rbp+24] movq [rbp+24], mm4 movq mm1, mm3 paddd mm1, mm1 psrlw mm1, 1 pmaddwd mm1, mm5 movq mm0, mm3 psrld mm0, 15 pmaddwd mm0, mm5 movq mm2, [rdi] ; mm2 = left_right movq mm4, mm2 pslld mm0, 5 paddd mm1, mm7 ; add 512 for rounding psrad mm1, 10 psubd mm2, mm0 psubd mm2, mm1 ; add shifted sums movq mm0, mm3 movq [rdi], mm2 ; store result pxor mm1, mm1 pxor mm0, mm2 psrad mm0, 31 ; mm0 = sign (sam_AB ^ left_right) add rdi, 8 pcmpeqd mm2, mm1 ; mm2 = 1s if left_right was zero pcmpeqd mm3, mm1 ; mm3 = 1s if sam_AB was zero por mm2, mm3 ; mm2 = 1s if either was zero pandn mm2, mm6 ; mask delta with zeros check pxor mm5, mm0 paddw mm5, mm2 ; and add to weight_AB pxor mm5, mm0 cmp rdi, rsi jnz buff_term_17_loop movq [rbp+16], mm4 ; post-store samples_AB[0] jmp bdone align 64 buff_term_18_loop: movq mm3, mm4 ; get previous calculated value psubd mm3, [rbp+24] psrad mm3, 1 paddd mm3, mm4 ; mm3 = sam_AB movq [rbp+24], mm4 movq mm1, mm3 paddd mm1, mm1 psrlw mm1, 1 pmaddwd mm1, mm5 movq mm0, mm3 psrld mm0, 15 pmaddwd mm0, mm5 movq mm2, [rdi] ; mm2 = left_right movq mm4, mm2 pslld mm0, 5 paddd mm1, mm7 ; add 512 for rounding psrad mm1, 10 psubd mm2, mm0 psubd mm2, mm1 ; add shifted sums movq mm0, mm3 movq [rdi], mm2 ; store result pxor mm1, mm1 pxor mm0, mm2 psrad mm0, 31 ; mm0 = sign (sam_AB ^ left_right) add rdi, 8 pcmpeqd mm2, mm1 ; mm2 = 1s if left_right was zero pcmpeqd mm3, mm1 ; mm3 = 1s if sam_AB was zero por mm2, mm3 ; mm2 = 1s if either was zero pandn mm2, mm6 ; mask delta with zeros check pxor mm5, mm0 paddw mm5, mm2 ; and add to weight_AB pxor mm5, mm0 cmp rdi, rsi jnz buff_term_18_loop movq [rbp+16], mm4 ; post-store samples_AB[0] jmp bdone align 64 buff_term_minus_1_loop: movq mm3, mm4 ; mm3 = previous calculated value movq mm2, [rdi] ; mm2 = left_right movq mm4, mm2 psrlq mm4, 32 punpckldq mm3, mm2 ; mm3 = sam_AB movq mm1, mm3 paddd mm1, mm1 psrlw mm1, 1 pmaddwd mm1, mm5 movq mm0, mm3 psrld mm0, 15 pmaddwd mm0, mm5 pslld mm0, 5 paddd mm1, mm7 ; add 512 for rounding psrad mm1, 10 psubd mm2, mm0 psubd mm2, mm1 ; add shifted sums movq mm0, mm3 movq [rdi], mm2 ; store result pxor mm1, mm1 pxor mm0, mm2 psrad mm0, 31 ; mm0 = sign (sam_AB ^ left_right) add rdi, 8 pcmpeqd mm2, mm1 ; mm2 = 1s if left_right was zero pcmpeqd mm3, mm1 ; mm3 = 1s if sam_AB was zero por mm2, mm3 ; mm2 = 1s if either was zero pandn mm2, mm6 ; mask delta with zeros check pcmpeqd mm1, mm1 psubd mm1, mm7 psubd mm1, mm7 psubd mm1, mm0 pxor mm5, mm0 paddw mm5, mm1 paddusw mm5, mm2 ; and add to weight_AB psubw mm5, mm1 pxor mm5, mm0 cmp rdi, rsi jnz buff_term_minus_1_loop movq [rbp+16], mm4 ; post-store samples_AB[0] jmp bdone align 64 buff_term_minus_2_loop: movq mm2, [rdi] ; mm2 = left_right movq mm3, mm2 psrlq mm3, 32 por mm3, mm4 punpckldq mm4, mm2 movq mm1, mm3 paddd mm1, mm1 psrlw mm1, 1 pmaddwd mm1, mm5 movq mm0, mm3 psrld mm0, 15 pmaddwd mm0, mm5 pslld mm0, 5 paddd mm1, mm7 ; add 512 for rounding psrad mm1, 10 psubd mm2, mm0 psubd mm2, mm1 ; add shifted sums movq mm0, mm3 movq [rdi], mm2 ; store result pxor mm1, mm1 pxor mm0, mm2 psrad mm0, 31 ; mm0 = sign (sam_AB ^ left_right) add rdi, 8 pcmpeqd mm2, mm1 ; mm2 = 1s if left_right was zero pcmpeqd mm3, mm1 ; mm3 = 1s if sam_AB was zero por mm2, mm3 ; mm2 = 1s if either was zero pandn mm2, mm6 ; mask delta with zeros check pcmpeqd mm1, mm1 psubd mm1, mm7 psubd mm1, mm7 psubd mm1, mm0 pxor mm5, mm0 paddw mm5, mm1 paddusw mm5, mm2 ; and add to weight_AB psubw mm5, mm1 pxor mm5, mm0 cmp rdi, rsi jnz buff_term_minus_2_loop movq [rbp+16], mm4 ; post-store samples_AB[0] jmp bdone align 64 buff_term_minus_3_loop: movq mm2, [rdi] ; mm2 = left_right movq mm3, mm4 ; mm3 = previous calculated value movq mm4, mm2 ; mm0 = swap dwords of new data psrlq mm4, 32 punpckldq mm4, mm2 ; mm3 = sam_AB movq mm1, mm3 paddd mm1, mm1 psrlw mm1, 1 pmaddwd mm1, mm5 movq mm0, mm3 psrld mm0, 15 pmaddwd mm0, mm5 pslld mm0, 5 paddd mm1, mm7 ; add 512 for rounding psrad mm1, 10 psubd mm2, mm0 psubd mm2, mm1 ; add shifted sums movq mm0, mm3 movq [rdi], mm2 ; store result pxor mm1, mm1 pxor mm0, mm2 psrad mm0, 31 ; mm0 = sign (sam_AB ^ left_right) add rdi, 8 pcmpeqd mm2, mm1 ; mm2 = 1s if left_right was zero pcmpeqd mm3, mm1 ; mm3 = 1s if sam_AB was zero por mm2, mm3 ; mm2 = 1s if either was zero pandn mm2, mm6 ; mask delta with zeros check pcmpeqd mm1, mm1 psubd mm1, mm7 psubd mm1, mm7 psubd mm1, mm0 pxor mm5, mm0 paddw mm5, mm1 paddusw mm5, mm2 ; and add to weight_AB psubw mm5, mm1 pxor mm5, mm0 cmp rdi, rsi jnz buff_term_minus_3_loop movq [rbp+16], mm4 ; post-store samples_AB[0] bdone: pslld mm5, 16 ; sign-extend 16-bit weights back to dwords psrad mm5, 16 movq [rbp+8], mm5 ; put weight_AB back ; convert samples_AB array back into samples_A and samples_B movq mm0, [rbp+16] movq mm1, [rbp+24] movq mm2, [rbp+32] movq mm3, [rbp+40] movq mm4, [rbp+48] movq mm5, [rbp+56] movq mm6, [rbp+64] movq mm7, [rbp+72] movd DWORD PTR [rbp+16], mm0 movd DWORD PTR [rbp+20], mm1 movd DWORD PTR [rbp+24], mm2 movd DWORD PTR [rbp+28], mm3 movd DWORD PTR [rbp+32], mm4 movd DWORD PTR [rbp+36], mm5 movd DWORD PTR [rbp+40], mm6 movd DWORD PTR [rbp+44], mm7 punpckhdq mm0, mm0 punpckhdq mm1, mm1 punpckhdq mm2, mm2 punpckhdq mm3, mm3 punpckhdq mm4, mm4 punpckhdq mm5, mm5 punpckhdq mm6, mm6 punpckhdq mm7, mm7 movd DWORD PTR [rbp+48], mm0 movd DWORD PTR [rbp+52], mm1 movd DWORD PTR [rbp+56], mm2 movd DWORD PTR [rbp+60], mm3 movd DWORD PTR [rbp+64], mm4 movd DWORD PTR [rbp+68], mm5 movd DWORD PTR [rbp+72], mm6 movd DWORD PTR [rbp+76], mm7 emms add rsp, 8 pop rsi pop rdi pop rbx pop rbp ret pack_decorr_stereo_pass_x64win endp ; These are assembly optimized version of the following WavPack functions: ; ; void pack_decorr_stereo_pass_cont ( ; struct decorr_pass *dpp, ; int32_t *in_buffer, ; int32_t *out_buffer, ; int32_t sample_count); ; ; void pack_decorr_stereo_pass_cont_rev ( ; struct decorr_pass *dpp, ; int32_t *in_buffer, ; int32_t *out_buffer, ; int32_t sample_count); ; ; It performs a single pass of stereo decorrelation, transferring from the ; input buffer to the output buffer. Note that this version of the function ; requires that the up to 8 previous (depending on dpp->term) stereo samples ; are visible and correct. In other words, it ignores the "samples_*" ; fields in the decorr_pass structure and gets the history data directly ; from the source buffer. It does, however, return the appropriate history ; samples to the decorr_pass structure before returning. ; ; This is written to work on an X86-64 processor (also called the AMD64) ; running in 64-bit mode and uses the MMX extensions to improve the ; performance by processing both stereo channels together. It is based on ; the original MMX code written by Joachim Henke that used MMX intrinsics ; called from C. Many thanks to Joachim for that! ; ; This version is for 64-bit Windows. Note that the two public functions ; are "leaf" functions that simply load rax with the direction and jump ; into the private common "frame" function. The arguments are passed in ; registers: ; ; struct decorr_pass *dpp rcx ; int32_t *in_buffer rdx ; int32_t *out_buffer r8 ; int32_t sample_count r9d ; ; During the processing loops, the following registers are used: ; ; rdi input buffer pointer ; rsi direction (-8 forward, +8 reverse) ; rbx delta from input to output buffer ; ecx sample count ; rdx sign (dir) * term * -8 (terms 1-8 only) ; mm0, mm1 scratch ; mm2 original sample values ; mm3 correlation samples ; mm4 weight sums ; mm5 weights ; mm6 delta ; mm7 512 (for rounding) ; ; stack usage: ; ; [rsp+0] = *dpp ; pack_decorr_stereo_pass_cont_rev_x64win: mov rax, 8 ; get value for reverse direction & jump jmp pack_decorr_stereo_pass_cont_common pack_decorr_stereo_pass_cont_x64win: mov rax, -8 ; get value for forward direction & jump jmp pack_decorr_stereo_pass_cont_common pack_decorr_stereo_pass_cont_common proc frame push_reg rbp ; save non-volatile registers on stack push_reg rbx ; (alphabetically) push_reg rdi push_reg rsi alloc_stack 8 ; allocate 8 bytes on stack & align to 16 bytes end_prologue mov [rsp], rcx ; [rsp] = *dpp mov rdi, rcx ; copy params from win regs to Linux regs mov rsi, rdx ; so we can leave following code similar mov rdx, r8 mov rcx, r9 mov rdi, rsi ; rdi = inbuffer mov rsi, rax ; rsi = -direction mov eax, 512 movd mm7, eax punpckldq mm7, mm7 ; mm7 = round (512) mov rax, [rsp] ; access dpp mov eax, [rax+4] movd mm6, eax punpckldq mm6, mm6 ; mm6 = delta (0-7) mov rax, [rsp] ; access dpp movq mm5, [rax+8] ; mm5 = weight_AB movq mm4, [rax+88] ; mm4 = sum_AB mov rbx, rdx ; rbx = out_buffer (rdx) - in_buffer (rdi) sub rbx, rdi mov rax, [rsp] ; *eax = dpp movsxd rax, DWORD PTR [rax] ; get term and vector to correct loop cmp al, 17 je term_17_loop cmp al, 18 je term_18_loop cmp al, -1 je term_minus_1_loop cmp al, -2 je term_minus_2_loop cmp al, -3 je term_minus_3_loop sal rax, 3 mov rdx, rax ; rdx = term * 8 to index correlation sample test rsi, rsi ; test direction jns default_term_loop neg rdx jmp default_term_loop align 64 default_term_loop: movq mm3, [rdi+rdx] ; mm3 = sam_AB movq mm1, mm3 pslld mm1, 17 psrld mm1, 17 pmaddwd mm1, mm5 movq mm0, mm3 pslld mm0, 1 psrld mm0, 16 pmaddwd mm0, mm5 movq mm2, [rdi] ; mm2 = left_right pslld mm0, 5 paddd mm1, mm7 ; add 512 for rounding psrad mm1, 10 psubd mm2, mm0 psubd mm2, mm1 ; add shifted sums movq mm0, mm3 movq [rdi+rbx], mm2 ; store result pxor mm0, mm2 psrad mm0, 31 ; mm0 = sign (sam_AB ^ left_right) sub rdi, rsi pxor mm1, mm1 ; mm1 = zero pcmpeqd mm2, mm1 ; mm2 = 1s if left_right was zero pcmpeqd mm3, mm1 ; mm3 = 1s if sam_AB was zero por mm2, mm3 ; mm2 = 1s if either was zero pandn mm2, mm6 ; mask delta with zeros check pxor mm5, mm0 paddd mm5, mm2 ; and add to weight_AB pxor mm5, mm0 paddd mm4, mm5 ; add weights to sum dec ecx jnz default_term_loop mov rax, [rsp] ; access dpp movq [rax+8], mm5 ; put weight_AB back movq [rax+88], mm4 ; put sum_AB back emms mov rdx, [rsp] ; access dpp with rdx movsxd rcx, DWORD PTR [rdx] ; rcx = dpp->term default_store_samples: dec rcx add rdi, rsi ; back up one full sample mov eax, [rdi+4] mov [rdx+rcx*4+48], eax ; store samples_B [ecx] mov eax, [rdi] mov [rdx+rcx*4+16], eax ; store samples_A [ecx] test rcx, rcx jnz default_store_samples jmp done align 64 term_17_loop: movq mm3, [rdi+rsi] ; get previous calculated value paddd mm3, mm3 psubd mm3, [rdi+rsi*2] movq mm1, mm3 pslld mm1, 17 psrld mm1, 17 pmaddwd mm1, mm5 movq mm0, mm3 pslld mm0, 1 psrld mm0, 16 pmaddwd mm0, mm5 movq mm2, [rdi] ; mm2 = left_right pslld mm0, 5 paddd mm1, mm7 ; add 512 for rounding psrad mm1, 10 psubd mm2, mm0 psubd mm2, mm1 ; add shifted sums movq mm0, mm3 movq [rdi+rbx], mm2 ; store result pxor mm0, mm2 psrad mm0, 31 ; mm0 = sign (sam_AB ^ left_right) sub rdi, rsi pxor mm1, mm1 ; mm1 = zero pcmpeqd mm2, mm1 ; mm2 = 1s if left_right was zero pcmpeqd mm3, mm1 ; mm3 = 1s if sam_AB was zero por mm2, mm3 ; mm2 = 1s if either was zero pandn mm2, mm6 ; mask delta with zeros check pxor mm5, mm0 paddd mm5, mm2 ; and add to weight_AB pxor mm5, mm0 paddd mm4, mm5 ; add weights to sum dec ecx jnz term_17_loop mov rax, [rsp] ; access dpp movq [rax+8], mm5 ; put weight_AB back movq [rax+88], mm4 ; put sum_AB back emms jmp term_1718_common_store align 64 term_18_loop: movq mm3, [rdi+rsi] ; get previous calculated value movq mm0, mm3 psubd mm3, [rdi+rsi*2] psrad mm3, 1 paddd mm3, mm0 ; mm3 = sam_AB movq mm1, mm3 pslld mm1, 17 psrld mm1, 17 pmaddwd mm1, mm5 movq mm0, mm3 pslld mm0, 1 psrld mm0, 16 pmaddwd mm0, mm5 movq mm2, [rdi] ; mm2 = left_right pslld mm0, 5 paddd mm1, mm7 ; add 512 for rounding psrad mm1, 10 psubd mm2, mm0 psubd mm2, mm1 ; add shifted sums movq mm0, mm3 movq [rdi+rbx], mm2 ; store result pxor mm0, mm2 psrad mm0, 31 ; mm0 = sign (sam_AB ^ left_right) sub rdi, rsi pxor mm1, mm1 ; mm1 = zero pcmpeqd mm2, mm1 ; mm2 = 1s if left_right was zero pcmpeqd mm3, mm1 ; mm3 = 1s if sam_AB was zero por mm2, mm3 ; mm2 = 1s if either was zero pandn mm2, mm6 ; mask delta with zeros check pxor mm5, mm0 paddd mm5, mm2 ; and add to weight_AB pxor mm5, mm0 dec ecx paddd mm4, mm5 ; add weights to sum jnz term_18_loop mov rax, [rsp] ; access dpp movq [rax+8], mm5 ; put weight_AB back movq [rax+88], mm4 ; put sum_AB back emms term_1718_common_store: mov rax, [rsp] ; access dpp add rdi, rsi ; back up a full sample mov edx, [rdi+4] ; dpp->samples_B [0] = iptr [-1]; mov [rax+48], edx mov edx, [rdi] ; dpp->samples_A [0] = iptr [-2]; mov [rax+16], edx add rdi, rsi ; back up another sample mov edx, [rdi+4] ; dpp->samples_B [1] = iptr [-3]; mov [rax+52], edx mov edx, [rdi] ; dpp->samples_A [1] = iptr [-4]; mov [rax+20], edx jmp done align 64 term_minus_1_loop: movq mm3, [rdi+rsi] ; mm3 = previous calculated value movq mm2, [rdi] ; mm2 = left_right psrlq mm3, 32 punpckldq mm3, mm2 ; mm3 = sam_AB movq mm1, mm3 pslld mm1, 17 psrld mm1, 17 pmaddwd mm1, mm5 movq mm0, mm3 pslld mm0, 1 psrld mm0, 16 pmaddwd mm0, mm5 pslld mm0, 5 paddd mm1, mm7 ; add 512 for rounding psrad mm1, 10 psubd mm2, mm0 psubd mm2, mm1 ; add shifted sums movq mm0, mm3 movq [rdi+rbx], mm2 ; store result pxor mm0, mm2 psrad mm0, 31 ; mm0 = sign (sam_AB ^ left_right) sub rdi, rsi pxor mm1, mm1 ; mm1 = zero pcmpeqd mm2, mm1 ; mm2 = 1s if left_right was zero pcmpeqd mm3, mm1 ; mm3 = 1s if sam_AB was zero por mm2, mm3 ; mm2 = 1s if either was zero pandn mm2, mm6 ; mask delta with zeros check pcmpeqd mm1, mm1 psubd mm1, mm7 psubd mm1, mm7 psubd mm1, mm0 pxor mm5, mm0 paddd mm5, mm1 paddusw mm5, mm2 ; and add to weight_AB psubd mm5, mm1 pxor mm5, mm0 paddd mm4, mm5 ; add weights to sum dec ecx jnz term_minus_1_loop mov rax, [rsp] ; access dpp movq [rax+8], mm5 ; put weight_AB back movq [rax+88], mm4 ; put sum_AB back emms add rdi, rsi ; back up a full sample mov edx, [rdi+4] ; dpp->samples_A [0] = iptr [-1]; mov rax, [rsp] mov [rax+16], edx jmp done align 64 term_minus_2_loop: movq mm2, [rdi] ; mm2 = left_right movq mm3, mm2 ; mm3 = swap dwords psrlq mm3, 32 punpckldq mm3, [rdi+rsi] ; mm3 = sam_AB movq mm1, mm3 pslld mm1, 17 psrld mm1, 17 pmaddwd mm1, mm5 movq mm0, mm3 pslld mm0, 1 psrld mm0, 16 pmaddwd mm0, mm5 pslld mm0, 5 paddd mm1, mm7 ; add 512 for rounding psrad mm1, 10 psubd mm2, mm0 psubd mm2, mm1 ; add shifted sums movq mm0, mm3 movq [rdi+rbx], mm2 ; store result pxor mm0, mm2 psrad mm0, 31 ; mm0 = sign (sam_AB ^ left_right) sub rdi, rsi pxor mm1, mm1 ; mm1 = zero pcmpeqd mm2, mm1 ; mm2 = 1s if left_right was zero pcmpeqd mm3, mm1 ; mm3 = 1s if sam_AB was zero por mm2, mm3 ; mm2 = 1s if either was zero pandn mm2, mm6 ; mask delta with zeros check pcmpeqd mm1, mm1 psubd mm1, mm7 psubd mm1, mm7 psubd mm1, mm0 pxor mm5, mm0 paddd mm5, mm1 paddusw mm5, mm2 ; and add to weight_AB psubd mm5, mm1 pxor mm5, mm0 paddd mm4, mm5 ; add weights to sum dec ecx jnz term_minus_2_loop mov rax, [rsp] ; access dpp movq [rax+8], mm5 ; put weight_AB back movq [rax+88], mm4 ; put sum_AB back emms add rdi, rsi ; back up a full sample mov edx, [rdi] ; dpp->samples_B [0] = iptr [-2]; mov rax, [rsp] mov [rax+48], edx jmp done align 64 term_minus_3_loop: movq mm0, [rdi+rsi] ; mm0 = previous calculated value movq mm3, mm0 ; mm3 = swap dwords psrlq mm3, 32 punpckldq mm3, mm0 ; mm3 = sam_AB movq mm1, mm3 pslld mm1, 17 psrld mm1, 17 pmaddwd mm1, mm5 movq mm0, mm3 pslld mm0, 1 psrld mm0, 16 pmaddwd mm0, mm5 movq mm2, [rdi] ; mm2 = left_right pslld mm0, 5 paddd mm1, mm7 ; add 512 for rounding psrad mm1, 10 psubd mm2, mm0 psubd mm2, mm1 ; add shifted sums movq mm0, mm3 movq [rdi+rbx], mm2 ; store result pxor mm0, mm2 psrad mm0, 31 ; mm0 = sign (sam_AB ^ left_right) sub rdi, rsi pxor mm1, mm1 ; mm1 = zero pcmpeqd mm2, mm1 ; mm2 = 1s if left_right was zero pcmpeqd mm3, mm1 ; mm3 = 1s if sam_AB was zero por mm2, mm3 ; mm2 = 1s if either was zero pandn mm2, mm6 ; mask delta with zeros check pcmpeqd mm1, mm1 psubd mm1, mm7 psubd mm1, mm7 psubd mm1, mm0 pxor mm5, mm0 paddd mm5, mm1 paddusw mm5, mm2 ; and add to weight_AB psubd mm5, mm1 pxor mm5, mm0 paddd mm4, mm5 ; add weights to sum dec ecx jnz term_minus_3_loop mov rax, [rsp] ; access dpp movq [rax+8], mm5 ; put weight_AB back movq [rax+88], mm4 ; put sum_AB back emms add rdi, rsi ; back up a full sample mov edx, [rdi+4] ; dpp->samples_A [0] = iptr [-1]; mov rax, [rsp] mov [rax+16], edx mov edx, [rdi] ; dpp->samples_B [0] = iptr [-2]; mov [rax+48], edx done: add rsp, 8 ; begin epilog by deallocating stack pop rsi ; restore non-volatile registers & return pop rdi pop rbx pop rbp ret pack_decorr_stereo_pass_cont_common endp ; This is an assembly optimized version of the following WavPack function: ; ; uint32_t decorr_mono_buffer (int32_t *buffer, ; struct decorr_pass *decorr_passes, ; int32_t num_terms, ; int32_t sample_count) ; ; Decorrelate a buffer of mono samples, in place, as specified by the array ; of decorr_pass structures. Note that this function does NOT return the ; dpp->samples_X[] values in the "normalized" positions for terms 1-8, so if ; the number of samples is not a multiple of MAX_TERM, these must be moved if ; they are to be used somewhere else. The magnitude of the output samples is ; accumulated and returned (see scan_max_magnitude() for more details). By ; using the overflow detection of the multiply instruction, this detects ; when the "long_math" variant is required. ; ; For the fastest possible operation with the four "common" decorrelation ; filters (i.e, fast, normal, high and very high) this function can be ; configured to include hardcoded versions of these filters that are created ; using macros. In that case, the passed filter is checked to make sure that ; it matches one of the four. If it doesn't, or if the hardcoded flters are ; not enabled, a "general" version of the decorrelation loop is used. This ; variable enables the hardcoded filters and can be disabled if there are ; problems with the code or macros: HARDCODED_FILTERS = 1 ; This is written to work on an X86-64 processor (also called the AMD64) ; running in 64-bit mode. This version is for the 64-bit Windows ABI and ; provides appropriate prologs and epilogs for stack unwinding. The ; arguments are passed in registers: ; ; int32_t *buffer rcx ; struct decorr_pass *dpp rdx ; int32_t num_terms r8 ; int32_t sample_count r9 ; ; stack usage: ; ; [rsp+8] = sample_count ; [rsp+0] = decorr_passes (unused in hardcoded filter case) ; ; register usage: ; ; ecx = sample being decorrelated ; esi = sample up counter ; rdi = *buffer ; rbp = *dpp ; r8 = magnitude accumulator ; r9 = dpp end ptr (unused in hardcoded filter case) ; if HARDCODED_FILTERS ; ; This macro is used for checking the decorr_passes array to make sure that the terms match ; the hardcoded terms. The terms of these filters are the first element in the tables defined ; in decorr_tables.h (with the negative terms replaced with 1). ; |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |