tor-browser

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

Architecture-riscv64.cpp (2637B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 * vim: set ts=8 sts=2 et sw=2 tw=80:
      3 * This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "jit/riscv64/Architecture-riscv64.h"
      8 
      9 #include "jit/FlushICache.h"  // js::jit::FlushICache
     10 #include "jit/RegisterSets.h"
     11 #include "jit/riscv64/MacroAssembler-riscv64.h"
     12 #include "jit/Simulator.h"
     13 
     14 namespace js {
     15 namespace jit {
     16 Registers::Code Registers::FromName(const char* name) {
     17  for (size_t i = 0; i < Total; i++) {
     18    if (strcmp(GetName(i), name) == 0) {
     19      return Code(i);
     20    }
     21  }
     22 
     23  return Invalid;
     24 }
     25 
     26 FloatRegisters::Code FloatRegisters::FromName(const char* name) {
     27  for (size_t i = 0; i < Total; i++) {
     28    if (strcmp(GetName(i), name) == 0) {
     29      return Code(i);
     30    }
     31  }
     32 
     33  return Invalid;
     34 }
     35 
     36 FloatRegisterSet FloatRegister::ReduceSetForPush(const FloatRegisterSet& s) {
     37 #ifdef ENABLE_WASM_SIMD
     38 #  error "Needs more careful logic if SIMD is enabled"
     39 #endif
     40 
     41  LiveFloatRegisterSet mod;
     42  for (FloatRegisterIterator iter(s); iter.more(); ++iter) {
     43    if ((*iter).isSingle()) {
     44      // Even for single size registers save complete double register.
     45      mod.addUnchecked((*iter).doubleOverlay());
     46    } else {
     47      mod.addUnchecked(*iter);
     48    }
     49  }
     50  return mod.set();
     51 }
     52 
     53 FloatRegister FloatRegister::singleOverlay() const {
     54  MOZ_ASSERT(!isInvalid());
     55  if (kind_ == Codes::Double) {
     56    return FloatRegister(encoding_, Codes::Single);
     57  }
     58  return *this;
     59 }
     60 
     61 FloatRegister FloatRegister::doubleOverlay() const {
     62  MOZ_ASSERT(!isInvalid());
     63  if (kind_ != Codes::Double) {
     64    return FloatRegister(encoding_, Codes::Double);
     65  }
     66  return *this;
     67 }
     68 
     69 uint32_t FloatRegister::GetPushSizeInBytes(
     70    const TypedRegisterSet<FloatRegister>& s) {
     71 #ifdef ENABLE_WASM_SIMD
     72 #  error "Needs more careful logic if SIMD is enabled"
     73 #endif
     74 
     75  return s.size() * sizeof(double);
     76 }
     77 void FlushICache(void* code, size_t size) {
     78 #if defined(JS_SIMULATOR)
     79  js::jit::SimulatorProcess::FlushICache(code, size);
     80 
     81 #elif defined(__linux__) || defined(__OpenBSD__)
     82 #  if defined(__GNUC__)
     83  intptr_t end = reinterpret_cast<intptr_t>(code) + size;
     84  __builtin___clear_cache(reinterpret_cast<char*>(code),
     85                          reinterpret_cast<char*>(end));
     86 
     87 #  else
     88  _flush_cache(reinterpret_cast<char*>(code), size, BCACHE);
     89 #  endif
     90 #else
     91 #  error "Unsupported platform"
     92 #endif
     93 }
     94 
     95 bool CPUFlagsHaveBeenComputed() { return RVFlags::FlagsHaveBeenComputed(); }
     96 
     97 }  // namespace jit
     98 }  // namespace js