Skip to content
This repository has been archived by the owner. It is now read-only.
Switch branches/tags
Go to file
Cannot retrieve contributors at this time

Non-trapping Float-to-int Conversions



The primary motivations are:

  • LLVM’s float-to-int conversion has an undefined result, rather than undefined behavior, and it seems LLVM does speculate it under certain conditions.
  • For the SIMD proposal, it’s more SIMD-hardware-like if no SIMD operations trap. This proposal would establish a convention for saturating operations which SIMD could share, to avoid introducing trapping.

This proposal is not motivated by performance data.

It's plausible that LLVM could be changed, to have something like an "nsw" flag for the "fptosi" instruction, especially with some of the recent proposals to modify the poison concept in LLVM. However, no one is currently working on this.


This issue has been discussed in several areas including here:

While performance concerns initially motivated the discussion, the performance effects were due to a particular implementation detail which has since been fixed.

Since then, no real-world performance problems related to this issue have been reported.

This topic was discussed at the CG-05 meeting:


which made decisions about which semantics to choose, and which encoding strategy.

These decisions were captured in a design repo PR:

At the CG-07-06 meeting it was decided that a full spec repo fork should be created to follow the new process for new features:

This led to the creation of the present repo:


This proposal introduces 8 new instructions:

  • i32.trunc_sat_f32_s
  • i32.trunc_sat_f32_u
  • i32.trunc_sat_f64_s
  • i32.trunc_sat_f64_u
  • i64.trunc_sat_f32_s
  • i64.trunc_sat_f32_u
  • i64.trunc_sat_f64_s
  • i64.trunc_sat_f64_u

The semantics are the same as the corresponding non-_sat instructions, except:

  • Instead of trapping on positive or negative overflow, they return the maximum or minimum integer value, respectively, and do not trap. (This behavior is also referred to as "saturating".)
  • Instead of trapping on NaN, they return 0 and do not trap.


This proposal introduces a new prefix byte:

Prefix Name Description
0xfc misc Miscellaneous operations 🎳

which is intended to be used as a prefix for other future miscellaneous operations as well.

The encodings for the new instructions use this new prefix and are as follows:

Name Opcode Immediate Description
i32.trunc_sat_f32_s 0xfc 0x00 🎳 saturating form of i32.trunc_f32_s
i32.trunc_sat_f32_u 0xfc 0x01 🎳 saturating form of i32.trunc_f32_u
i32.trunc_sat_f64_s 0xfc 0x02 🎳 saturating form of i32.trunc_f64_s
i32.trunc_sat_f64_u 0xfc 0x03 🎳 saturating form of i32.trunc_f64_u
i64.trunc_sat_f32_s 0xfc 0x04 🎳 saturating form of i64.trunc_f32_s
i64.trunc_sat_f32_u 0xfc 0x05 🎳 saturating form of i64.trunc_f32_u
i64.trunc_sat_f64_s 0xfc 0x06 🎳 saturating form of i64.trunc_f64_s
i64.trunc_sat_f64_u 0xfc 0x07 🎳 saturating form of i64.trunc_f64_u