From e46ddfe0878e599c1aac55226cd5e2ddc5ae7205 Mon Sep 17 00:00:00 2001 From: Stephen Canon Date: Thu, 14 Aug 2025 12:57:32 -0400 Subject: [PATCH] Merge pull request #325 from stephentyrone/enable-wasm-testing Enable workflows testing for wasm. --- .github/workflows/pull_request.yml | 3 +++ Sources/RealModule/Float16+Real.swift | 5 +++++ Sources/_NumericsShims/include/_NumericsShims.h | 2 ++ 3 files changed, 10 insertions(+) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index a92c6416..bf0ce917 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -8,6 +8,9 @@ jobs: tests: name: Test uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main + with: + enable_wasm_sdk_build: true + wasm_sdk_build_command: swift build --target Numerics soundness: name: Soundness uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main diff --git a/Sources/RealModule/Float16+Real.swift b/Sources/RealModule/Float16+Real.swift index 6781683e..98e97e89 100644 --- a/Sources/RealModule/Float16+Real.swift +++ b/Sources/RealModule/Float16+Real.swift @@ -173,6 +173,10 @@ extension Float16: Real { } #endif + #if !arch(wasm32) + // WASM doesn't have _Float16 on the C side, so we can't define the C hooks + // that these use. TODO: implement these as Swift builtins instead. + @_transparent public static func _relaxedAdd(_ a: Float16, _ b: Float16) -> Float16 { _numerics_relaxed_addf16(a, b) @@ -182,6 +186,7 @@ extension Float16: Real { public static func _relaxedMul(_ a: Float16, _ b: Float16) -> Float16 { _numerics_relaxed_mulf16(a, b) } + #endif } #endif diff --git a/Sources/_NumericsShims/include/_NumericsShims.h b/Sources/_NumericsShims/include/_NumericsShims.h index 0cf3c191..8b7bf995 100644 --- a/Sources/_NumericsShims/include/_NumericsShims.h +++ b/Sources/_NumericsShims/include/_NumericsShims.h @@ -389,6 +389,7 @@ HEADER_SHIM long double libm_lgammal(long double x, int *signp) { // MARK: - math inlines with relaxed semantics to support optimization. #define CLANG_RELAX_FP _Pragma("clang fp reassociate(on) contract(fast)") +#if !defined __wasm__ // No _Float16 on wasm /// a + b with the "allow reassociation" and "allow FMA formation" flags /// set in the IR. HEADER_SHIM _Float16 _numerics_relaxed_addf16(_Float16 a, _Float16 b) { @@ -402,6 +403,7 @@ HEADER_SHIM _Float16 _numerics_relaxed_mulf16(_Float16 a, _Float16 b) { CLANG_RELAX_FP return a * b; } +#endif /// a + b with the "allow reassociation" and "allow FMA formation" flags /// set in the IR.