tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

x86cpu.h (4247B)


      1 /* Copyright (c) 2014, Cisco Systems, INC
      2   Written by XiangMingZhu WeiZhou MinPeng YanWang
      3 
      4   Redistribution and use in source and binary forms, with or without
      5   modification, are permitted provided that the following conditions
      6   are met:
      7 
      8   - Redistributions of source code must retain the above copyright
      9   notice, this list of conditions and the following disclaimer.
     10 
     11   - Redistributions in binary form must reproduce the above copyright
     12   notice, this list of conditions and the following disclaimer in the
     13   documentation and/or other materials provided with the distribution.
     14 
     15   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     16   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     17   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     18   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
     19   OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     20   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     21   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     22   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     23   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     24   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     25   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26 */
     27 
     28 #if !defined(X86CPU_H)
     29 # define X86CPU_H
     30 
     31 # if defined(OPUS_X86_MAY_HAVE_SSE)
     32 #  define MAY_HAVE_SSE(name) name ## _sse
     33 # else
     34 #  define MAY_HAVE_SSE(name) name ## _c
     35 # endif
     36 
     37 # if defined(OPUS_X86_MAY_HAVE_SSE2)
     38 #  define MAY_HAVE_SSE2(name) name ## _sse2
     39 # else
     40 #  define MAY_HAVE_SSE2(name) name ## _c
     41 # endif
     42 
     43 # if defined(OPUS_X86_MAY_HAVE_SSE4_1)
     44 #  define MAY_HAVE_SSE4_1(name) name ## _sse4_1
     45 # else
     46 #  define MAY_HAVE_SSE4_1(name) name ## _c
     47 # endif
     48 
     49 # if defined(OPUS_X86_MAY_HAVE_AVX2)
     50 #  define MAY_HAVE_AVX2(name) name ## _avx2
     51 # else
     52 #  define MAY_HAVE_AVX2(name) name ## _c
     53 # endif
     54 
     55 # if defined(OPUS_HAVE_RTCD) && \
     56  ((defined(OPUS_X86_MAY_HAVE_SSE) && !defined(OPUS_X86_PRESUME_SSE)) || \
     57  (defined(OPUS_X86_MAY_HAVE_SSE2) && !defined(OPUS_X86_PRESUME_SSE2)) || \
     58  (defined(OPUS_X86_MAY_HAVE_SSE4_1) && !defined(OPUS_X86_PRESUME_SSE4_1)) || \
     59  (defined(OPUS_X86_MAY_HAVE_AVX2) && !defined(OPUS_X86_PRESUME_AVX2)))
     60 int opus_select_arch(void);
     61 # endif
     62 
     63 # if defined(OPUS_X86_MAY_HAVE_SSE2)
     64 #  include "opus_defines.h"
     65 
     66 /*MOVD should not impose any alignment restrictions, but the C standard does,
     67   and UBSan will report errors if we actually make unaligned accesses.
     68  Use this to work around those restrictions (which should hopefully all get
     69   optimized to a single MOVD instruction).
     70  GCC implemented _mm_loadu_si32() since GCC 11; HOWEVER, there is a bug!
     71  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99754
     72  LLVM implemented _mm_loadu_si32() since Clang 8.0, however the
     73   __clang_major__ version number macro is unreliable, as vendors
     74   (specifically, Apple) will use different numbering schemes than upstream.
     75  Clang's advice is "use feature detection", but they do not provide feature
     76   detection support for specific SIMD functions.
     77  We follow the approach from the SIMDe project and instead detect unrelated
     78   features that should be available in the version we want (see
     79   <https://github.com/simd-everywhere/simde/blob/master/simde/simde-detect-clang.h>).*/
     80 #  if defined(__clang__)
     81 #   if __has_warning("-Wextra-semi-stmt") || \
     82 __has_builtin(__builtin_rotateleft32)
     83 #    define OPUS_CLANG_8 (1)
     84 #   endif
     85 #  endif
     86 #  if !defined(_MSC_VER) && !OPUS_GNUC_PREREQ(11,3) && !defined(OPUS_CLANG_8)
     87 #   include <string.h>
     88 #   include <emmintrin.h>
     89 
     90 #   ifdef _mm_loadu_si32
     91 #    undef _mm_loadu_si32
     92 #   endif
     93 #   define _mm_loadu_si32 WORKAROUND_mm_loadu_si32
     94 static inline __m128i WORKAROUND_mm_loadu_si32(void const* mem_addr) {
     95  int val;
     96  memcpy(&val, mem_addr, sizeof(val));
     97  return _mm_cvtsi32_si128(val);
     98 }
     99 #  elif defined(_MSC_VER)
    100    /* MSVC needs this for _mm_loadu_si32 */
    101 #   include <immintrin.h>
    102 #  endif
    103 
    104 #  define OP_CVTEPI8_EPI32_M32(x) \
    105 (_mm_cvtepi8_epi32(_mm_loadu_si32(x)))
    106 
    107 #  define OP_CVTEPI16_EPI32_M64(x) \
    108 (_mm_cvtepi16_epi32(_mm_loadl_epi64((__m128i *)(void*)(x))))
    109 
    110 # endif
    111 
    112 #endif