native 0.0.1
Vectors, masks and wide register packs for C++26
Loading...
Searching...
No Matches
features.h
1// SPDX-FileCopyrightText: 2026 Edward Kmett <ekmett@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR Apache-2.0
3#pragma once
4#include "native/isa.h"
5#include <span>
6#include <optional>
7
8namespace native {
12
13 namespace detail {
14 // Complete import-free modules; v128.const and i8x16.relaxed_swizzle.
15 // The JS bridge carries the same bytes, checked by the consumer tests.
16 inline constexpr std::uint8_t wasm_simd128_probe[]{
17 0,97,115,109,1,0,0,0, 1,5,1,0x60,0,1,0x7b, 3,2,1,0,
18 10,22,1,20,0, 0xfd,0x0c,
19 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0x0b
20 };
21 inline constexpr std::uint8_t wasm_relaxed_simd_probe[]{
22 0,97,115,109,1,0,0,0, 1,7,1,0x60,2,0x7b,0x7b,1,0x7b, 3,2,1,0,
23 10,11,1,9,0, 0x20,0,0x20,1,0xfd,0x80,0x02,0x0b
24 };
25 }
26
31 constexpr std::span<std::uint8_t const> wasm_feature_probe(wasm_feature feature) noexcept {
32 switch(feature) {
33 case wasm_feature::simd128: return detail::wasm_simd128_probe;
34 case wasm_feature::relaxed_simd: return detail::wasm_relaxed_simd_probe;
35 }
36 return {};
37 }
38
61
66 wasm_capabilities result;
67 result.raw=raw;
68 result.observed.set(wasm_feature::simd128,raw.simd128_observed);
69 result.present.set(wasm_feature::simd128,raw.simd128_observed && raw.simd128);
70 result.observed.set(wasm_feature::relaxed_simd,raw.relaxed_simd_observed);
71 result.present.set(wasm_feature::relaxed_simd,raw.relaxed_simd_observed && raw.relaxed_simd);
72 return result;
73 }
74
81 template<class V> requires requires(V & validate,std::span<std::uint8_t const> bytes) {
82 { validate(bytes) } noexcept -> std::same_as<std::optional<bool>>;
83 }
84 constexpr wasm_capabilities observe_wasm_capabilities(V && validate) noexcept {
85 auto baseline=validate(wasm_feature_probe(wasm_feature::simd128).first(8));
86 if(!baseline || !*baseline) return {};
87 auto simd128=validate(wasm_feature_probe(wasm_feature::simd128));
88 auto relaxed_simd=validate(wasm_feature_probe(wasm_feature::relaxed_simd));
89 return decode_wasm_capabilities({simd128.has_value(),simd128.value_or(false),
90 relaxed_simd.has_value(),relaxed_simd.value_or(false)});
91 }
92
97 constexpr wasm_capabilities observe_wasm_capabilities() noexcept { return {}; }
98}
constexpr wasm_capabilities observe_wasm_capabilities(V &&validate) noexcept
Definition features.h:84
constexpr std::span< std::uint8_t const > wasm_feature_probe(wasm_feature feature) noexcept
Definition features.h:31
constexpr wasm_capabilities decode_wasm_capabilities(wasm_capabilities::raw_observations raw) noexcept
Definition features.h:65
Architecture-tagged vectors, register packs and supporting value types. Native arithmetic follows its...
wasm_feature
WebAssembly validation capabilities, using local bit indices.
Definition isa.h:30
constexpr void set(feature_type f, bool value) noexcept
Definition isa.h:300
A structural set of one family's features, without prerequisite closure.
Definition isa.h:58
Embedder-supplied query results; an unobserved positive never authorizes code.
Definition features.h:48
bool simd128
The runtime accepts standard SIMD128 instructions.
Definition features.h:52
bool relaxed_simd_observed
True only after a relaxed-SIMD query completes with a boolean answer.
Definition features.h:54
bool relaxed_simd
The runtime accepts the finalized relaxed-SIMD instruction set.
Definition features.h:56
bool simd128_observed
True only after a SIMD128 query completes with a boolean answer.
Definition features.h:50
isa< wasm > observed
Features whose observations completed, including negative answers.
Definition features.h:46
isa< wasm > present
Features successfully observed as supported.
Definition features.h:44
raw_observations raw
Diagnostic snapshot; editing it does not update present/observed.
Definition features.h:59