tor-browser

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

WasmFeatures.h (7370B)


      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 #ifndef js_WasmFeatures_h
      8 #define js_WasmFeatures_h
      9 
     10 // [SMDOC] WebAssembly feature gating
     11 //
     12 // Declarative listing of WebAssembly optional features. This macro is used to
     13 // generate most of the feature gating code in a centralized manner. See
     14 // 'Adding a feature' below for the exact steps needed to add a new feature.
     15 //
     16 // # Adding a feature
     17 //
     18 // 1. Add a configure switch for the feature in js/moz.configure
     19 // 2. Add a WASM_FEATURE_ENABLED #define below
     20 // 3. Add the feature to JS_FOR_WASM_FEATURES
     21 //   a. capitalized name: Used for naming of feature functions, including
     22 //      wasmFeatureEnabled shell function.
     23 //   b. lower case name: Used for naming of feature flag variables, including
     24 //      in wasm::FeatureArgs.
     25 //   c. compile predicate: Set to WASM_FEATURE_ENABLED
     26 //   d. compiler predicate: Expression of compilers that this feature depends
     27 //      on.
     28 //   e. flag predicate: Expression used to predicate enablement of feature
     29 //      flag. Useful for disabling a feature when dependent feature is not
     30 //      enabled or if we are fuzzing.
     31 //   f. preference name: The stem of the browser preference. Will be expanded
     32 //      to `javascript.options.wasm-FEATURE`.
     33 // 4. Add the preference to module/libpref/init/StaticPrefList.yaml
     34 //   a. Set `set_spidermonkey_pref: startup`
     35 //   b. Set value to 'true' for default features, @IS_NIGHTLY_BUILD@ for
     36 //      tentative features, and 'false' for experimental features.
     37 // 5. [fuzzing] Add the feature to gluesmith/src/lib.rs, if wasm-smith has
     38 //    support for it.
     39 
     40 #ifdef ENABLE_WASM_RELAXED_SIMD
     41 #  define WASM_RELAXED_SIMD_ENABLED 1
     42 #else
     43 #  define WASM_RELAXED_SIMD_ENABLED 0
     44 #endif
     45 #ifdef ENABLE_WASM_MEMORY_CONTROL
     46 #  define WASM_MEMORY_CONTROL_ENABLED 1
     47 #else
     48 #  define WASM_MEMORY_CONTROL_ENABLED 0
     49 #endif
     50 #ifdef ENABLE_WASM_JSPI
     51 #  define WASM_JSPI_ENABLED 1
     52 #else
     53 #  define WASM_JSPI_ENABLED 0
     54 #endif
     55 #ifdef ENABLE_WASM_MOZ_INTGEMM
     56 #  define WASM_MOZ_INTGEMM_ENABLED 1
     57 #else
     58 #  define WASM_MOZ_INTGEMM_ENABLED 0
     59 #endif
     60 #ifdef ENABLE_WASM_BRANCH_HINTING
     61 #  define WASM_BRANCH_HINTING_ENABLED 1
     62 #else
     63 #  define WASM_BRANCH_HINTING_ENABLED 0
     64 #endif
     65 #ifdef ENABLE_WASM_CUSTOM_PAGE_SIZES
     66 #  define WASM_CUSTOM_PAGE_SIZES_ENABLED 1
     67 #else
     68 #  define WASM_CUSTOM_PAGE_SIZES_ENABLED 0
     69 #endif
     70 
     71 // clang-format off
     72 #define JS_FOR_WASM_FEATURES(FEATURE)                                   \
     73  FEATURE(                                                              \
     74    /* capitalized name   */ RelaxedSimd,                               \
     75    /* lower case name    */ v128Relaxed,                               \
     76    /* compile predicate  */ WASM_RELAXED_SIMD_ENABLED,                 \
     77    /* compiler predicate */ AnyCompilerAvailable(cx),                  \
     78    /* flag predicate     */ js::jit::JitSupportsWasmSimd(),            \
     79    /* flag force enable  */ false,                                     \
     80    /* flag fuzz enable   */ true,                                      \
     81    /* preference name    */ relaxed_simd)                              \
     82  FEATURE(                                                              \
     83    /* capitalized name   */ MemoryControl,                             \
     84    /* lower case name    */ memoryControl,                             \
     85    /* compile predicate  */ WASM_MEMORY_CONTROL_ENABLED,               \
     86    /* compiler predicate */ AnyCompilerAvailable(cx),                  \
     87    /* flag predicate     */ true,                                      \
     88    /* flag force enable  */ false,                                     \
     89    /* flag fuzz enable   */ false,                                     \
     90    /* preference name    */ memory_control)                            \
     91  FEATURE(                                                              \
     92    /* capitalized name   */ JSPromiseIntegration,                      \
     93    /* lower case name    */ jsPromiseIntegration,                      \
     94    /* compile predicate  */ WASM_JSPI_ENABLED,                         \
     95    /* compiler predicate */ IonPlatformSupport(),                      \
     96    /* flag predicate     */ true,                                      \
     97    /* flag force enable  */ false,                                     \
     98    /* flag fuzz enable   */ true,                                      \
     99    /* preference name    */ js_promise_integration)                    \
    100  FEATURE(                                                              \
    101    /* capitalized name   */ MozIntGemm,                                \
    102    /* lower case name    */ mozIntGemm,                                \
    103    /* compile predicate  */ WASM_MOZ_INTGEMM_ENABLED,                  \
    104    /* compiler predicate */ AnyCompilerAvailable(cx),                  \
    105    /* flag predicate     */ IsPrivilegedContext(cx),                   \
    106    /* flag force enable  */ false,                                     \
    107    /* flag fuzz enable   */ false,                                     \
    108    /* preference name    */ moz_intgemm)                               \
    109  FEATURE(                                                              \
    110    /* capitalized name   */ TestSerialization,                         \
    111    /* lower case name    */ testSerialization,                         \
    112    /* compile predicate  */ 1,                                         \
    113    /* compiler predicate */ IonAvailable(cx),                          \
    114    /* flag predicate     */ true,                                      \
    115    /* flag force enable  */ false,                                     \
    116    /* flag fuzz enable   */ false,                                     \
    117    /* preference name    */ test_serialization)                        \
    118  FEATURE(                                                              \
    119    /* capitalized name   */ BranchHinting,                             \
    120    /* lower case name    */ branchHinting,                             \
    121    /* compile predicate  */ WASM_BRANCH_HINTING_ENABLED,               \
    122    /* compiler predicate */ true,                                      \
    123    /* flag predicate     */ true,                                      \
    124    /* flag force enable  */ false,                                     \
    125    /* flag fuzz enable   */ true,                                      \
    126    /* preference name    */ branch_hinting)                            \
    127  FEATURE(                                                              \
    128    /* capitalized name   */ CustomPageSizes,                           \
    129    /* lower case name    */ customPageSizes,                           \
    130    /* compile predicate  */ WASM_CUSTOM_PAGE_SIZES_ENABLED,            \
    131    /* compiler predicate */ BaselineAvailable(cx),                     \
    132    /* flag predicate     */ !IsFuzzingIon(cx),                         \
    133    /* flag force enable  */ false,                                     \
    134    /* flag fuzz enable   */ true,                                      \
    135    /* preference name    */ custom_page_sizes)
    136 
    137 // clang-format on
    138 
    139 #endif  // js_WasmFeatures_h