tor-browser

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

WasmBCRegDefs-inl.h (3974B)


      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 *
      4 * Copyright 2016 Mozilla Foundation
      5 *
      6 * Licensed under the Apache License, Version 2.0 (the "License");
      7 * you may not use this file except in compliance with the License.
      8 * You may obtain a copy of the License at
      9 *
     10 *     http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 */
     18 
     19 // This is an INTERNAL header for Wasm baseline compiler: inline BaseCompiler
     20 // methods that don't fit in any other group in particular.
     21 
     22 #ifndef wasm_wasm_baseline_reg_defs_inl_h
     23 #define wasm_wasm_baseline_reg_defs_inl_h
     24 
     25 namespace js {
     26 namespace wasm {
     27 // TODO / OPTIMIZE (Bug 1316802): Do not sync everything on allocation
     28 // failure, only as much as we need.
     29 
     30 RegI32 BaseRegAlloc::needI32() {
     31  if (!hasGPR()) {
     32    bc->sync();
     33  }
     34  return RegI32(allocGPR());
     35 }
     36 
     37 void BaseRegAlloc::needI32(RegI32 specific) {
     38  if (!isAvailableI32(specific)) {
     39    bc->sync();
     40  }
     41  allocGPR(specific);
     42 }
     43 
     44 RegI64 BaseRegAlloc::needI64() {
     45  if (!hasGPR64()) {
     46    bc->sync();
     47  }
     48  return RegI64(allocInt64());
     49 }
     50 
     51 void BaseRegAlloc::needI64(RegI64 specific) {
     52  if (!isAvailableI64(specific)) {
     53    bc->sync();
     54  }
     55  allocInt64(specific);
     56 }
     57 
     58 RegRef BaseRegAlloc::needRef() {
     59  if (!hasGPR()) {
     60    bc->sync();
     61  }
     62  return RegRef(allocGPR());
     63 }
     64 
     65 void BaseRegAlloc::needRef(RegRef specific) {
     66  if (!isAvailableRef(specific)) {
     67    bc->sync();
     68  }
     69  allocGPR(specific);
     70 }
     71 
     72 RegPtr BaseRegAlloc::needPtr() {
     73  if (!hasGPR()) {
     74    bc->sync();
     75  }
     76  return RegPtr(allocGPR());
     77 }
     78 
     79 void BaseRegAlloc::needPtr(RegPtr specific) {
     80  if (!isAvailablePtr(specific)) {
     81    bc->sync();
     82  }
     83  allocGPR(specific);
     84 }
     85 
     86 RegPtr BaseRegAlloc::needTempPtr(RegPtr fallback, bool* saved) {
     87  if (hasGPR()) {
     88    *saved = false;
     89    return RegPtr(allocGPR());
     90  }
     91  *saved = true;
     92  bc->saveTempPtr(fallback);
     93  MOZ_ASSERT(isAvailablePtr(fallback));
     94  allocGPR(fallback);
     95  return RegPtr(fallback);
     96 }
     97 
     98 RegF32 BaseRegAlloc::needF32() {
     99  if (!hasFPU<MIRType::Float32>()) {
    100    bc->sync();
    101  }
    102  return RegF32(allocFPU<MIRType::Float32>());
    103 }
    104 
    105 void BaseRegAlloc::needF32(RegF32 specific) {
    106  if (!isAvailableF32(specific)) {
    107    bc->sync();
    108  }
    109  allocFPU(specific);
    110 }
    111 
    112 RegF64 BaseRegAlloc::needF64() {
    113  if (!hasFPU<MIRType::Double>()) {
    114    bc->sync();
    115  }
    116  return RegF64(allocFPU<MIRType::Double>());
    117 }
    118 
    119 void BaseRegAlloc::needF64(RegF64 specific) {
    120  if (!isAvailableF64(specific)) {
    121    bc->sync();
    122  }
    123  allocFPU(specific);
    124 }
    125 
    126 #ifdef ENABLE_WASM_SIMD
    127 RegV128 BaseRegAlloc::needV128() {
    128  if (!hasFPU<MIRType::Simd128>()) {
    129    bc->sync();
    130  }
    131  return RegV128(allocFPU<MIRType::Simd128>());
    132 }
    133 
    134 void BaseRegAlloc::needV128(RegV128 specific) {
    135  if (!isAvailableV128(specific)) {
    136    bc->sync();
    137  }
    138  allocFPU(specific);
    139 }
    140 #endif
    141 
    142 void BaseRegAlloc::freeI32(RegI32 r) { freeGPR(r); }
    143 
    144 void BaseRegAlloc::freeI64(RegI64 r) { freeInt64(r); }
    145 
    146 void BaseRegAlloc::freeRef(RegRef r) { freeGPR(r); }
    147 
    148 void BaseRegAlloc::freePtr(RegPtr r) { freeGPR(r); }
    149 
    150 void BaseRegAlloc::freeF64(RegF64 r) { freeFPU(r); }
    151 
    152 void BaseRegAlloc::freeF32(RegF32 r) { freeFPU(r); }
    153 
    154 #ifdef ENABLE_WASM_SIMD
    155 void BaseRegAlloc::freeV128(RegV128 r) { freeFPU(r); }
    156 #endif
    157 
    158 void BaseRegAlloc::freeTempPtr(RegPtr r, bool saved) {
    159  freePtr(r);
    160  if (saved) {
    161    bc->restoreTempPtr(r);
    162    MOZ_ASSERT(!isAvailablePtr(r));
    163  }
    164 }
    165 
    166 #ifdef JS_CODEGEN_ARM
    167 RegI64 BaseRegAlloc::needI64Pair() {
    168  if (!hasGPRPair()) {
    169    bc->sync();
    170  }
    171  Register low, high;
    172  allocGPRPair(&low, &high);
    173  return RegI64(Register64(high, low));
    174 }
    175 #endif
    176 
    177 }  // namespace wasm
    178 }  // namespace js
    179 
    180 #endif  // wasm_wasm_baseline_reg_defs_inl_h