Spaces:
Runtime error
Runtime error
/* | |
* Copyright (c) 2015 James Almer | |
* | |
* This file is part of FFmpeg. | |
* | |
* FFmpeg is free software; you can redistribute it and/or | |
* modify it under the terms of the GNU Lesser General Public | |
* License as published by the Free Software Foundation; either | |
* version 2.1 of the License, or (at your option) any later version. | |
* | |
* FFmpeg is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
* Lesser General Public License for more details. | |
* | |
* You should have received a copy of the GNU Lesser General Public | |
* License along with FFmpeg; if not, write to the Free Software | |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
*/ | |
static av_always_inline av_const int ff_log2_x86(unsigned int v) | |
{ | |
unsigned long n; | |
_BitScanReverse(&n, v|1); | |
return n; | |
} | |
static av_always_inline av_const int ff_ctzll_x86(long long v) | |
{ | |
return ((uint32_t)v == 0) ? _tzcnt_u32((uint32_t)(v >> 32)) + 32 : _tzcnt_u32((uint32_t)v); | |
} | |
/* Our generic version of av_popcount is faster than GCC's built-in on | |
* CPUs that don't support the popcnt instruction. | |
*/ | |
/* GCC releases before 5.1.0 have a broken bzhi builtin, so for those we | |
* implement it using inline assembly | |
*/ | |
static av_always_inline av_const unsigned av_mod_uintp2_bmi2(unsigned a, unsigned p) | |
{ | |
if (av_builtin_constant_p(p)) | |
return a & ((1 << p) - 1); | |
else { | |
unsigned x; | |
__asm__ ("bzhi %2, %1, %0 \n\t" : "=r"(x) : "rm"(a), "r"(p)); | |
return x; | |
} | |
} | |
static av_always_inline av_const double av_clipd_sse2(double a, double amin, double amax) | |
{ | |
if (amin > amax) abort(); | |
__asm__ ("maxsd %1, %0 \n\t" | |
"minsd %2, %0 \n\t" | |
: "+&x"(a) : "xm"(amin), "xm"(amax)); | |
return a; | |
} | |
static av_always_inline av_const float av_clipf_sse(float a, float amin, float amax) | |
{ | |
if (amin > amax) abort(); | |
__asm__ ("maxss %1, %0 \n\t" | |
"minss %2, %0 \n\t" | |
: "+&x"(a) : "xm"(amin), "xm"(amax)); | |
return a; | |
} | |
static av_always_inline av_const double av_clipd_avx(double a, double amin, double amax) | |
{ | |
if (amin > amax) abort(); | |
__asm__ ("vmaxsd %1, %0, %0 \n\t" | |
"vminsd %2, %0, %0 \n\t" | |
: "+&x"(a) : "xm"(amin), "xm"(amax)); | |
return a; | |
} | |
static av_always_inline av_const float av_clipf_avx(float a, float amin, float amax) | |
{ | |
if (amin > amax) abort(); | |
__asm__ ("vmaxss %1, %0, %0 \n\t" | |
"vminss %2, %0, %0 \n\t" | |
: "+&x"(a) : "xm"(amin), "xm"(amax)); | |
return a; | |
} | |