Implement wasm saturating conversions;

This commit is contained in:
Benjamin Bouvier
2018-07-27 19:11:39 +02:00
committed by Dan Gohman
parent 9dbfbbde10
commit f7e481d9ac
5 changed files with 305 additions and 31 deletions

View File

@@ -1879,6 +1879,14 @@ fcvt_to_uint = Instruction(
""",
ins=x, outs=a, can_trap=True)
fcvt_to_uint_sat = Instruction(
'fcvt_to_uint_sat', r"""
Convert floating point to unsigned integer as fcvt_to_uint does, but
saturates the input instead of trapping. NaN and negative values are
converted to 0.
""",
ins=x, outs=a)
fcvt_to_sint = Instruction(
'fcvt_to_sint', r"""
Convert floating point to signed integer.
@@ -1891,6 +1899,13 @@ fcvt_to_sint = Instruction(
""",
ins=x, outs=a, can_trap=True)
fcvt_to_sint_sat = Instruction(
'fcvt_to_sint_sat', r"""
Convert floating point to signed integer as fcvt_to_sint does, but
saturates the input instead of trapping. NaN values are converted to 0.
""",
ins=x, outs=a)
x = Operand('x', Int)
a = Operand('a', FloatTo)

View File

@@ -94,9 +94,11 @@ x86_expand.custom_legalize(insts.fmax, 'expand_minmax')
# Conversions from unsigned need special handling.
x86_expand.custom_legalize(insts.fcvt_from_uint, 'expand_fcvt_from_uint')
# Conversions from float to int can trap.
# Conversions from float to int can trap and modify the control flow graph.
x86_expand.custom_legalize(insts.fcvt_to_sint, 'expand_fcvt_to_sint')
x86_expand.custom_legalize(insts.fcvt_to_uint, 'expand_fcvt_to_uint')
x86_expand.custom_legalize(insts.fcvt_to_sint_sat, 'expand_fcvt_to_sint_sat')
x86_expand.custom_legalize(insts.fcvt_to_uint_sat, 'expand_fcvt_to_uint_sat')
# Count leading and trailing zeroes, for baseline x86_64
c_minus_one = Var('c_minus_one')