tor-browser

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

pixman-riscv.c (2134B)


      1 /*
      2 * Copyright © 2024 Filip Wasil, Samsung Electronics
      3 *
      4 * Permission to use, copy, modify, distribute, and sell this software and its
      5 * documentation for any purpose is hereby granted without fee, provided that
      6 * the above copyright notice appear in all copies and that both that
      7 * copyright notice and this permission notice appear in supporting
      8 * documentation, and that the name of Keith Packard not be used in
      9 * advertising or publicity pertaining to distribution of the software without
     10 * specific, written prior permission.  Keith Packard makes no
     11 * representations about the suitability of this software for any purpose.  It
     12 * is provided "as is" without express or implied warranty.
     13 *
     14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
     15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
     16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
     17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
     19 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
     20 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
     21 * SOFTWARE.
     22 */
     23 
     24 #ifdef HAVE_CONFIG_H
     25 #include <pixman-config.h>
     26 #endif
     27 
     28 #include "pixman-private.h"
     29 
     30 #ifdef USE_RVV
     31 
     32 #if defined(__linux__)
     33 #include <asm/hwcap.h>
     34 #include <sys/auxv.h>
     35 #endif
     36 
     37 typedef enum
     38 {
     39    RVV = (1 << 0),
     40 } riscv_cpu_features_t;
     41 
     42 static riscv_cpu_features_t
     43 detect_cpu_features (void)
     44 {
     45    riscv_cpu_features_t features = 0;
     46 
     47 #if defined(__linux__)
     48    if (getauxval (AT_HWCAP) & COMPAT_HWCAP_ISA_V)
     49    {
     50 features |= RVV;
     51    }
     52 #else
     53 #pragma message(                                                               \
     54    "warning: RISC-V Vector Extension runtime check not implemented for this platform. RVV will be disabled")
     55 #endif
     56    return features;
     57 }
     58 
     59 #endif
     60 
     61 pixman_implementation_t *
     62 _pixman_riscv_get_implementations (pixman_implementation_t *imp)
     63 {
     64 #ifdef USE_RVV
     65    if (!_pixman_disabled ("rvv") && (detect_cpu_features () & RVV))
     66    {
     67 imp = _pixman_implementation_create_rvv (imp);
     68    }
     69 #endif
     70    return imp;
     71 }