From 6321fd1f5f39917c21fa2ef0c696855c07fa7cdd Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Thu, 7 Jul 2016 18:12:01 -0700 Subject: [PATCH] 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. --- docs/langref.rst | 6 +++--- meta/cretonne/base.py | 47 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/docs/langref.rst b/docs/langref.rst index 0f49b8f6ed..881976a701 100644 --- a/docs/langref.rst +++ b/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 diff --git a/meta/cretonne/base.py b/meta/cretonne/base.py index 15f23b1abc..b560b9bb7a 100644 --- a/meta/cretonne/base.py +++ b/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()