From fd9f08c30f54d89d20b571b1654a2cc284bc957f Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Fri, 8 Jul 2016 11:20:19 -0700 Subject: [PATCH] Define floating point conversion instructions. --- docs/langref.rst | 13 +++-- meta/cretonne/base.py | 119 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 115 insertions(+), 17 deletions(-) diff --git a/docs/langref.rst b/docs/langref.rst index 881976a701..9181f10e26 100644 --- a/docs/langref.rst +++ b/docs/langref.rst @@ -821,13 +821,12 @@ Conversion operations .. autoinst:: ireduce .. autoinst:: uextend .. autoinst:: sextend -.. inst:: a = ftrunc x -.. inst:: a = fext x -.. inst:: a = cvt_ftou x -.. inst:: a = cvt_ftos x -.. inst:: a = cvt_utof x -.. inst:: a = cvt_stof x - +.. autoinst:: fpromote +.. autoinst:: fdemote +.. autoinst:: fcvt_to_uint +.. autoinst:: fcvt_to_sint +.. autoinst:: fcvt_from_uint +.. autoinst:: fcvt_from_sint Glossary ======== diff --git a/meta/cretonne/base.py b/meta/cretonne/base.py index b560b9bb7a..894ac2f505 100644 --- a/meta/cretonne/base.py +++ b/meta/cretonne/base.py @@ -787,7 +787,9 @@ bitcast = Instruction( ins=x, outs=a) Int = TypeVar('Int', 'A scalar or vector integer type', ints=True, simd=True) -IntTo = TypeVar('IntTo', 'A smaller integer type with the same number of lanes', ints=True, simd=True) +IntTo = TypeVar( + 'IntTo', 'A smaller integer type with the same number of lanes', + ints=True, simd=True) x = Operand('x', Int) a = Operand('a', IntTo) @@ -801,22 +803,30 @@ ireduce = Instruction( :math:`2^n`. The result type must have the same number of vector lanes as the input, - and each lane must not have more bits that the input lanes. If the input - and output types are the same, this is a no-op. + and each lane must not have more bits that the input lanes. If the + input and output types are the same, this is a no-op. """, ins=x, outs=a) + +IntTo = TypeVar( + 'IntTo', 'A larger integer type with the same number of lanes', + ints=True, simd=True) + +x = Operand('x', Int) +a = Operand('a', IntTo) + uextend = Instruction( 'uextend', r""" Convert `x` to a larger integer type by zero-extending. - Each lane in `x` is converted to a larger integer type by adding zeroes. - The result has the same numerical value as `x` when both are interpreted - as unsigned integers. + Each lane in `x` is converted to a larger integer type by adding + zeroes. The result has the same numerical value as `x` when both are + interpreted as unsigned integers. The result type must have the same number of vector lanes as the input, - and each lane must not have fewer bits that the input lanes. If the input - and output types are the same, this is a no-op. + and each lane must not have fewer bits that the input lanes. If the + input and output types are the same, this is a no-op. """, ins=x, outs=a) @@ -829,8 +839,97 @@ sextend = Instruction( are interpreted as signed integers. The result type must have the same number of vector lanes as the input, - and each lane must not have fewer bits that the input lanes. If the input - and output types are the same, this is a no-op. + and each lane must not have fewer bits that the input lanes. If the + input and output types are the same, this is a no-op. + """, + ins=x, outs=a) + +FloatTo = TypeVar( + 'FloatTo', 'A scalar or vector floating point number', + floats=True, simd=True) + +x = Operand('x', Float) +a = Operand('a', FloatTo) + +fpromote = Instruction( + 'fcvt_ftof', r""" + Convert `x` to a larger floating point format. + + Each lane in `x` is converted to the destination floating point format. + This is an exact operation. + + Since Cretonne currently only supports two floating point formats, this + instruction always converts :type:`f32` to :type:`f64`. This may change + in the future. + + The result type must have the same number of vector lanes as the input, + and the result lanes must be larger than the input lanes. + """, + ins=x, outs=a) + +fdemote = Instruction( + 'fdemote', r""" + Convert `x` to a smaller floating point format. + + Each lane in `x` is converted to the destination floating point format + by rounding to nearest, ties to even. + + Since Cretonne currently only supports two floating point formats, this + instruction always converts :type:`f64` to :type:`f32`. This may change + in the future. + + The result type must have the same number of vector lanes as the input, + and the result lanes must be smaller than the input lanes. """, ins=x, outs=a) + +x = Operand('x', Float) +a = Operand('a', Int) + +fcvt_to_uint = Instruction( + 'fcvt_to_uint', r""" + Convert floating point to unsigned integer. + + Each lane in `x` is converted to an unsigned integer by rounding + towards zero. If `x` is NaN or if the unsigned integral value cannot be + represented in the result type, this instruction traps. + + The result type must have the same number of vector lanes as the input. + """, + ins=x, outs=a) + +fcvt_to_sint = Instruction( + 'fcvt_to_sint', r""" + Convert floating point to signed integer. + + Each lane in `x` is converted to a signed integer by rounding towards + zero. If `x` is NaN or if the signed integral value cannot be + represented in the result type, this instruction traps. + + The result type must have the same number of vector lanes as the input. + """, + ins=x, outs=a) + +fcvt_from_uint = Instruction( + 'fcvt_from_uint', r""" + Convert unsigned integer to floating point. + + Each lane in `x` is interpreted as an unsigned integer and converted to + floating point using round to nearest, ties to even. + + The result type must have the same number of vector lanes as the input. + """, + ins=x, outs=a) + +fcvt_from_sint = Instruction( + 'fcvt_from_sint', r""" + Convert signed integer to floating point. + + Each lane in `x` is interpreted as a signed integer and converted to + floating point using round to nearest, ties to even. + + The result type must have the same number of vector lanes as the input. + """, + ins=x, outs=a) + instructions.close()