tor-browser

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

mathops_arm.h (3884B)


      1 /* Copyright (c) 2024 Arm Limited */
      2 /*
      3   Redistribution and use in source and binary forms, with or without
      4   modification, are permitted provided that the following conditions
      5   are met:
      6 
      7   - Redistributions of source code must retain the above copyright
      8   notice, this list of conditions and the following disclaimer.
      9 
     10   - Redistributions in binary form must reproduce the above copyright
     11   notice, this list of conditions and the following disclaimer in the
     12   documentation and/or other materials provided with the distribution.
     13 
     14   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     15   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     16   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     17   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
     18   OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     19   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     20   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     21   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     22   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     23   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     24   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25 */
     26 
     27 #if !defined(MATHOPS_ARM_H)
     28 # define MATHOPS_ARM_H
     29 
     30 #include "armcpu.h"
     31 #include "cpu_support.h"
     32 #include "opus_defines.h"
     33 
     34 # if !defined(DISABLE_FLOAT_API) && defined(OPUS_ARM_MAY_HAVE_NEON_INTR)
     35 
     36 #include <arm_neon.h>
     37 
     38 static inline int32x4_t vroundf(float32x4_t x)
     39 {
     40 #  if defined(__aarch64__) || (defined(__ARM_ARCH) && __ARM_ARCH >= 8)
     41    return vcvtaq_s32_f32(x);
     42 #  else
     43    uint32x4_t sign = vandq_u32(vreinterpretq_u32_f32(x), vdupq_n_u32(0x80000000));
     44    uint32x4_t bias = vdupq_n_u32(0x3F000000);
     45    return vcvtq_s32_f32(vaddq_f32(x, vreinterpretq_f32_u32(vorrq_u32(bias, sign))));
     46 #  endif
     47 }
     48 
     49 static inline float vminvf(float32x4_t a)
     50 {
     51 #if defined(__aarch64__)
     52   return vminvq_f32(a);
     53 #else
     54    float32x2_t xy = vmin_f32(vget_low_f32(a), vget_high_f32(a));
     55    float x = vget_lane_f32(xy, 0);
     56    float y = vget_lane_f32(xy, 1);
     57    return x < y ? x : y;
     58 #endif
     59 }
     60 
     61 static inline float vmaxvf(float32x4_t a)
     62 {
     63 #if defined(__aarch64__)
     64   return vmaxvq_f32(a);
     65 #else
     66    float32x2_t xy = vmax_f32(vget_low_f32(a), vget_high_f32(a));
     67    float x = vget_lane_f32(xy, 0);
     68    float y = vget_lane_f32(xy, 1);
     69    return x > y ? x : y;
     70 #endif
     71 }
     72 
     73 void celt_float2int16_neon(const float * OPUS_RESTRICT in, short * OPUS_RESTRICT out, int cnt);
     74 #  if defined(OPUS_HAVE_RTCD) && \
     75    (defined(OPUS_ARM_MAY_HAVE_NEON_INTR) && !defined(OPUS_ARM_PRESUME_NEON_INTR))
     76 extern void
     77 (*const CELT_FLOAT2INT16_IMPL[OPUS_ARCHMASK+1])(const float * OPUS_RESTRICT in, short * OPUS_RESTRICT out, int cnt);
     78 
     79 #   define OVERRIDE_FLOAT2INT16 (1)
     80 #   define celt_float2int16(in, out, cnt, arch) \
     81      ((*CELT_FLOAT2INT16_IMPL[(arch)&OPUS_ARCHMASK])(in, out, cnt))
     82 
     83 #  elif defined(OPUS_ARM_PRESUME_NEON_INTR)
     84 #   define OVERRIDE_FLOAT2INT16 (1)
     85 #   define celt_float2int16(in, out, cnt, arch) ((void)(arch), celt_float2int16_neon(in, out, cnt))
     86 #  endif
     87 
     88 int opus_limit2_checkwithin1_neon(float * samples, int cnt);
     89 #  if defined(OPUS_HAVE_RTCD) && \
     90      (defined(OPUS_ARM_MAY_HAVE_NEON_INTR) && !defined(OPUS_ARM_PRESUME_NEON_INTR))
     91 extern int (*const OPUS_LIMIT2_CHECKWITHIN1_IMPL[OPUS_ARCHMASK+1])(float * samples, int cnt);
     92 
     93 #   define OVERRIDE_LIMIT2_CHECKWITHIN1 (1)
     94 #   define opus_limit2_checkwithin1(samples, cnt, arch) \
     95   ((*OPUS_LIMIT2_CHECKWITHIN1_IMPL[(arch)&OPUS_ARCHMASK])(samples, cnt))
     96 
     97 #  elif defined(OPUS_ARM_PRESUME_NEON_INTR)
     98 #   define OVERRIDE_LIMIT2_CHECKWITHIN1 (1)
     99 #   define opus_limit2_checkwithin1(samples, cnt, arch) ((void)(arch), opus_limit2_checkwithin1_neon(samples, cnt))
    100 #  endif
    101 # endif
    102 
    103 #endif /* MATHOPS_ARM_H */