Botan 3.11.0
Crypto and TLS for C&
cpuid_wasm.cpp
Go to the documentation of this file.
1/*
2* (C) 2025 Jack Lloyd
3* (C) 2025 polarnis
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#include <botan/internal/cpuid.h>
9
10namespace Botan {
11
12uint32_t CPUID::CPUID_Data::detect_cpu_features(uint32_t allowed) {
13 // There's no cpuid equivalent for Wasm, but we can detect some VM capabilities (like SIMD128 or Relaxed SIMD)
14 // at compile time either way.
15 enum class Wasm_vmcap_bit : uint64_t {
16 SIMD128_bit = (1 << 0),
17 };
18
19 uint64_t flags = 0;
20#ifdef __wasm_simd128__
21 flags |= static_cast<std::underlying_type_t<Wasm_vmcap_bit>>(Wasm_vmcap_bit::SIMD128_bit);
22#endif
23
24 uint32_t feat = 0;
25 feat |= if_set(flags, Wasm_vmcap_bit::SIMD128_bit, CPUFeature::Bit::SIMD128, allowed);
26
27 return feat;
28}
29
30} // namespace Botan
static uint32_t if_set(uint64_t cpuid, T flag, CPUID::Feature bit, uint32_t allowed)
Definition cpuid.h:117
Flags flags(Flag flags)
Definition p11.h:1227