Browse Source

Metadefs for integer reduce and extend operations.

Naming is interesting here. Since 'truncate' refers to removing the least
significant digits, use 'ireduce' instead. The 'extend' use is fairly
established. Don't abbreviate, avoid unfortunate modern vernacular.
pull/1019/head
Jakob Stoklund Olesen 8 years ago
parent
commit
62e96f4d3e
  1. 6
      cranelift/docs/langref.rst
  2. 47
      meta/cretonne/base.py

6
cranelift/docs/langref.rst

@ -818,9 +818,9 @@ Conversion operations
---------------------
.. autoinst:: bitcast
.. inst:: a = itrunc x
.. inst:: a = uext x
.. inst:: a = sext x
.. autoinst:: ireduce
.. autoinst:: uextend
.. autoinst:: sextend
.. inst:: a = ftrunc x
.. inst:: a = fext x
.. inst:: a = cvt_ftou x

47
meta/cretonne/base.py

@ -786,4 +786,51 @@ 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)
x = Operand('x', Int)
a = Operand('a', IntTo)
ireduce = Instruction(
'ireduce', r"""
Convert `x` to a smaller integer type by dropping high bits.
Each lane in `x` is converted to a smaller integer type by discarding
the most significant bits. This is the same as reducing modulo
: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.
""",
ins=x, outs=a)
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.
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.
""",
ins=x, outs=a)
sextend = Instruction(
'sextend', r"""
Convert `x` to a larger integer type by sign-extending.
Each lane in `x` is converted to a larger integer type by replicating
the sign bit. The result has the same numerical value as `x` when both
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.
""",
ins=x, outs=a)
instructions.close()

Loading…
Cancel
Save