Ignore:
Timestamp:
Nov 21, 2017 9:25:11 AM (6 years ago)
Author:
riza
Message:

Close #2065: Update libyuv to fix linker error when building libyuv as dll on Visual Studio 2015.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/third_party/yuv/source/compare_gcc.cc

    r5633 r5699  
    2323    (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER))) 
    2424 
    25 uint32 HammingDistance_X86(const uint8* src_a, const uint8* src_b, int count) { 
     25#if defined(__x86_64__) 
     26uint32 HammingDistance_SSE42(const uint8* src_a, 
     27                             const uint8* src_b, 
     28                             int count) { 
     29  uint64 diff = 0u; 
     30 
     31  asm volatile( 
     32      "xor        %3,%3                          \n" 
     33      "xor        %%r8,%%r8                      \n" 
     34      "xor        %%r9,%%r9                      \n" 
     35      "xor        %%r10,%%r10                    \n" 
     36 
     37      // Process 32 bytes per loop. 
     38      LABELALIGN 
     39      "1:                                        \n" 
     40      "mov        (%0),%%rcx                     \n" 
     41      "mov        0x8(%0),%%rdx                  \n" 
     42      "xor        (%1),%%rcx                     \n" 
     43      "xor        0x8(%1),%%rdx                  \n" 
     44      "popcnt     %%rcx,%%rcx                    \n" 
     45      "popcnt     %%rdx,%%rdx                    \n" 
     46      "mov        0x10(%0),%%rsi                 \n" 
     47      "mov        0x18(%0),%%rdi                 \n" 
     48      "xor        0x10(%1),%%rsi                 \n" 
     49      "xor        0x18(%1),%%rdi                 \n" 
     50      "popcnt     %%rsi,%%rsi                    \n" 
     51      "popcnt     %%rdi,%%rdi                    \n" 
     52      "add        $0x20,%0                       \n" 
     53      "add        $0x20,%1                       \n" 
     54      "add        %%rcx,%3                       \n" 
     55      "add        %%rdx,%%r8                     \n" 
     56      "add        %%rsi,%%r9                     \n" 
     57      "add        %%rdi,%%r10                    \n" 
     58      "sub        $0x20,%2                       \n" 
     59      "jg         1b                             \n" 
     60 
     61      "add        %%r8, %3                       \n" 
     62      "add        %%r9, %3                       \n" 
     63      "add        %%r10, %3                      \n" 
     64      : "+r"(src_a),  // %0 
     65        "+r"(src_b),  // %1 
     66        "+r"(count),  // %2 
     67        "=r"(diff)    // %3 
     68      : 
     69      : "memory", "cc", "rcx", "rdx", "rsi", "rdi", "r8", "r9", "r10"); 
     70 
     71  return static_cast<uint32>(diff); 
     72} 
     73#else 
     74uint32 HammingDistance_SSE42(const uint8* src_a, 
     75                             const uint8* src_b, 
     76                             int count) { 
    2677  uint32 diff = 0u; 
    2778 
    28   int i; 
    29   for (i = 0; i < count - 7; i += 8) { 
    30     uint64 x = *((uint64*)src_a) ^ *((uint64*)src_b); 
    31     src_a += 8; 
    32     src_b += 8; 
    33     diff += __builtin_popcountll(x); 
    34   } 
     79  asm volatile( 
     80      // Process 16 bytes per loop. 
     81      LABELALIGN 
     82      "1:                                        \n" 
     83      "mov        (%0),%%ecx                     \n" 
     84      "mov        0x4(%0),%%edx                  \n" 
     85      "xor        (%1),%%ecx                     \n" 
     86      "xor        0x4(%1),%%edx                  \n" 
     87      "popcnt     %%ecx,%%ecx                    \n" 
     88      "add        %%ecx,%3                       \n" 
     89      "popcnt     %%edx,%%edx                    \n" 
     90      "add        %%edx,%3                       \n" 
     91      "mov        0x8(%0),%%ecx                  \n" 
     92      "mov        0xc(%0),%%edx                  \n" 
     93      "xor        0x8(%1),%%ecx                  \n" 
     94      "xor        0xc(%1),%%edx                  \n" 
     95      "popcnt     %%ecx,%%ecx                    \n" 
     96      "add        %%ecx,%3                       \n" 
     97      "popcnt     %%edx,%%edx                    \n" 
     98      "add        %%edx,%3                       \n" 
     99      "add        $0x10,%0                       \n" 
     100      "add        $0x10,%1                       \n" 
     101      "sub        $0x10,%2                       \n" 
     102      "jg         1b                             \n" 
     103      : "+r"(src_a),  // %0 
     104        "+r"(src_b),  // %1 
     105        "+r"(count),  // %2 
     106        "+r"(diff)    // %3 
     107      : 
     108      : "memory", "cc", "ecx", "edx"); 
     109 
    35110  return diff; 
    36111} 
     112#endif 
     113 
     114static vec8 kNibbleMask = {15, 15, 15, 15, 15, 15, 15, 15, 
     115                           15, 15, 15, 15, 15, 15, 15, 15}; 
     116static vec8 kBitCount = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4}; 
     117 
     118uint32 HammingDistance_SSSE3(const uint8* src_a, 
     119                             const uint8* src_b, 
     120                             int count) { 
     121  uint32 diff = 0u; 
     122 
     123  asm volatile( 
     124      "movdqa     %4,%%xmm2                      \n" 
     125      "movdqa     %5,%%xmm3                      \n" 
     126      "pxor       %%xmm0,%%xmm0                  \n" 
     127      "pxor       %%xmm1,%%xmm1                  \n" 
     128      "sub        %0,%1                          \n" 
     129 
     130      LABELALIGN 
     131      "1:                                        \n" 
     132      "movdqa     (%0),%%xmm4                    \n" 
     133      "movdqa     0x10(%0), %%xmm5               \n" 
     134      "pxor       (%0,%1), %%xmm4                \n" 
     135      "movdqa     %%xmm4,%%xmm6                  \n" 
     136      "pand       %%xmm2,%%xmm6                  \n" 
     137      "psrlw      $0x4,%%xmm4                    \n" 
     138      "movdqa     %%xmm3,%%xmm7                  \n" 
     139      "pshufb     %%xmm6,%%xmm7                  \n" 
     140      "pand       %%xmm2,%%xmm4                  \n" 
     141      "movdqa     %%xmm3,%%xmm6                  \n" 
     142      "pshufb     %%xmm4,%%xmm6                  \n" 
     143      "paddb      %%xmm7,%%xmm6                  \n" 
     144      "pxor       0x10(%0,%1),%%xmm5             \n" 
     145      "add        $0x20,%0                       \n" 
     146      "movdqa     %%xmm5,%%xmm4                  \n" 
     147      "pand       %%xmm2,%%xmm5                  \n" 
     148      "psrlw      $0x4,%%xmm4                    \n" 
     149      "movdqa     %%xmm3,%%xmm7                  \n" 
     150      "pshufb     %%xmm5,%%xmm7                  \n" 
     151      "pand       %%xmm2,%%xmm4                  \n" 
     152      "movdqa     %%xmm3,%%xmm5                  \n" 
     153      "pshufb     %%xmm4,%%xmm5                  \n" 
     154      "paddb      %%xmm7,%%xmm5                  \n" 
     155      "paddb      %%xmm5,%%xmm6                  \n" 
     156      "psadbw     %%xmm1,%%xmm6                  \n" 
     157      "paddd      %%xmm6,%%xmm0                  \n" 
     158      "sub        $0x20,%2                       \n" 
     159      "jg         1b                             \n" 
     160 
     161      "pshufd     $0xaa,%%xmm0,%%xmm1            \n" 
     162      "paddd      %%xmm1,%%xmm0                  \n" 
     163      "movd       %%xmm0, %3                     \n" 
     164      : "+r"(src_a),       // %0 
     165        "+r"(src_b),       // %1 
     166        "+r"(count),       // %2 
     167        "=r"(diff)         // %3 
     168      : "m"(kNibbleMask),  // %4 
     169        "m"(kBitCount)     // %5 
     170      : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", 
     171        "xmm7"); 
     172 
     173  return diff; 
     174} 
     175 
     176#ifdef HAS_HAMMINGDISTANCE_AVX2 
     177uint32 HammingDistance_AVX2(const uint8* src_a, const uint8* src_b, int count) { 
     178  uint32 diff = 0u; 
     179 
     180  asm volatile( 
     181      "vbroadcastf128 %4,%%ymm2                  \n" 
     182      "vbroadcastf128 %5,%%ymm3                  \n" 
     183      "vpxor      %%ymm0,%%ymm0,%%ymm0           \n" 
     184      "vpxor      %%ymm1,%%ymm1,%%ymm1           \n" 
     185      "sub        %0,%1                          \n" 
     186 
     187      LABELALIGN 
     188      "1:                                        \n" 
     189      "vmovdqa    (%0),%%ymm4                    \n" 
     190      "vmovdqa    0x20(%0), %%ymm5               \n" 
     191      "vpxor      (%0,%1), %%ymm4, %%ymm4        \n" 
     192      "vpand      %%ymm2,%%ymm4,%%ymm6           \n" 
     193      "vpsrlw     $0x4,%%ymm4,%%ymm4             \n" 
     194      "vpshufb    %%ymm6,%%ymm3,%%ymm6           \n" 
     195      "vpand      %%ymm2,%%ymm4,%%ymm4           \n" 
     196      "vpshufb    %%ymm4,%%ymm3,%%ymm4           \n" 
     197      "vpaddb     %%ymm4,%%ymm6,%%ymm6           \n" 
     198      "vpxor      0x20(%0,%1),%%ymm5,%%ymm4      \n" 
     199      "add        $0x40,%0                       \n" 
     200      "vpand      %%ymm2,%%ymm4,%%ymm5           \n" 
     201      "vpsrlw     $0x4,%%ymm4,%%ymm4             \n" 
     202      "vpshufb    %%ymm5,%%ymm3,%%ymm5           \n" 
     203      "vpand      %%ymm2,%%ymm4,%%ymm4           \n" 
     204      "vpshufb    %%ymm4,%%ymm3,%%ymm4           \n" 
     205      "vpaddb     %%ymm5,%%ymm4,%%ymm4           \n" 
     206      "vpaddb     %%ymm6,%%ymm4,%%ymm4           \n" 
     207      "vpsadbw    %%ymm1,%%ymm4,%%ymm4           \n" 
     208      "vpaddd     %%ymm0,%%ymm4,%%ymm0           \n" 
     209      "sub        $0x40,%2                       \n" 
     210      "jg         1b                             \n" 
     211 
     212      "vpermq     $0xb1,%%ymm0,%%ymm1            \n" 
     213      "vpaddd     %%ymm1,%%ymm0,%%ymm0           \n" 
     214      "vpermq     $0xaa,%%ymm0,%%ymm1            \n" 
     215      "vpaddd     %%ymm1,%%ymm0,%%ymm0           \n" 
     216      "vmovd      %%xmm0, %3                     \n" 
     217      "vzeroupper                                \n" 
     218      : "+r"(src_a),       // %0 
     219        "+r"(src_b),       // %1 
     220        "+r"(count),       // %2 
     221        "=r"(diff)         // %3 
     222      : "m"(kNibbleMask),  // %4 
     223        "m"(kBitCount)     // %5 
     224      : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); 
     225 
     226  return diff; 
     227} 
     228#endif  // HAS_HAMMINGDISTANCE_AVX2 
    37229 
    38230uint32 SumSquareError_SSE2(const uint8* src_a, const uint8* src_b, int count) { 
Note: See TracChangeset for help on using the changeset viewer.