Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Onwasm32,half operation results aren't correctly rounded between each operation #96437

@beetrees

Description

@beetrees

The following IR (compiler explorer):

targettriple ="wasm32-unknown-wasi"definehalf@f(half%x) {start:%y =fmulhalf%x, 0xH4000; 0xH4000 == 2.0%z =fdivhalf%y, 0xH4000; 0xH4000 == 2.0rethalf%z}definehalf@callf() {%res =callhalf@f(half 0xH7BFF); 0xH7BFF = maximum finite `f16`rethalf%res}

Is compiled into the following WASM:

f:                                      # @flocal.get0call    __truncsfhf2call    __extendhfsf2local.tee0local.get0f32.addf32.const0x1p-1f32.mul         end_functioncallf:                                  # @callff32.const0x1.ffcp15call    f        end_function

callf should return positive infinity (0xH7C00), but on WASM it will return0xH7BFF due to the extra range of thef32 used to store the intermediate result.

This Rust program, when compiled withrustc 1.81.0-nightly (3cb521a43 2024-06-22) withrustc --target wasm32-wasip1 code.rs and run withwasmtime, demonstrates the issue.

#![feature(f16)]fnf(x:f16) ->f16{x*2.0 /2.0}fnmain(){assert_eq!(f(f16::MAX),1.0 /0.0);}

The assertion should succeed, but on WASM it fails.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp