Switch SIMD type spelling to i32x4.

Add support for 'type variables' in type directives.
This commit is contained in:
Jakob Stoklund Olesen
2016-01-21 16:39:45 -08:00
parent 401afdc48c
commit a3f97e4d1f
3 changed files with 79 additions and 40 deletions

View File

@@ -57,6 +57,33 @@ class CtonObject(ObjectDescription):
self.indexnode['entries'].append(('single', indextext, self.indexnode['entries'].append(('single', indextext,
targetname, '')) targetname, ''))
# Type variables are indicated as %T.
typevar = re.compile('(\%[A-Z])')
def parse_type(name, signode):
"""
Parse a type with embedded type vars and append to signode.
Return a a string that can be compiled into a regular expression matching
the type.
"""
re_str = ''
for part in typevar.split(name):
if part == '':
continue
if len(part) == 2 and part[0] == '%':
# This is a type parameter. Don't display the %, use emphasis
# instead.
part = part[1]
signode += nodes.emphasis(part, part)
re_str += r'\w+'
else:
signode += addnodes.desc_name(part, part)
re_str += re.escape(part)
return re_str
class CtonType(CtonObject): class CtonType(CtonObject):
"""A Cretonne IL type description.""" """A Cretonne IL type description."""
@@ -68,7 +95,7 @@ class CtonType(CtonObject):
""" """
name = sig.strip() name = sig.strip()
signode += addnodes.desc_name(name, name) re_str = parse_type(name, signode)
return name return name
def get_index_text(self, name): def get_index_text(self, name):

View File

@@ -15,10 +15,14 @@ class CretonneLexer(RegexLexer):
(r';.*?$', Comment.Single), (r';.*?$', Comment.Single),
(r'\b(function|entry)\b', Keyword), (r'\b(function|entry)\b', Keyword),
(r'\b(align)\b', Name.Attribute), (r'\b(align)\b', Name.Attribute),
(r'\b(v\d+)?(bool|i\d+|f32|f64)\b', Keyword.Type), # Well known value types.
(r'\b(bool|i\d+|f32|f64)(x\d+)?\b', Keyword.Type),
(r'\d+', Number.Integer), (r'\d+', Number.Integer),
(r'0[xX][0-9a-fA-F]+', Number.Hex), (r'0[xX][0-9a-fA-F]+', Number.Hex),
(r'(v|ss|ebb)\d+', Name.Variable), # v<nn> = value
# ss<nn> = stack slot
(r'(v|ss)\d+', Name.Variable),
# ebb<nn> = extended basic block
(r'(ebb)\d+', Name.Label), (r'(ebb)\d+', Name.Label),
(r'(=)( *)([a-z]\w*)', bygroups(Operator, Whitespace, Name.Function)), (r'(=)( *)([a-z]\w*)', bygroups(Operator, Whitespace, Name.Function)),
(r'^( +)([a-z]\w*\b)(?! *[,=])', bygroups(Whitespace, Name.Function)), (r'^( +)([a-z]\w*\b)(?! *[,=])', bygroups(Whitespace, Name.Function)),

View File

@@ -109,13 +109,13 @@ double-double formats.
.. type:: f32 .. type:: f32
A 32-bit floating point type represented in the IEEE 754 *Single precision* A 32-bit floating point type represented in the IEEE 754 *single precision*
format. This corresponds to the :c:type:`float` type in most C format. This corresponds to the :c:type:`float` type in most C
implementations. implementations.
.. type:: f64 .. type:: f64
A 64-bit floating point type represented in the IEEE 754 *Double precision* A 64-bit floating point type represented in the IEEE 754 *double precision*
format. This corresponds to the :c:type:`double` type in most C format. This corresponds to the :c:type:`double` type in most C
implementations. implementations.
@@ -126,40 +126,42 @@ A SIMD vector type represents a vector of values from one of the scalar types
(:type:`bool`, integer, and floating point). Each scalar value in a SIMD type is (:type:`bool`, integer, and floating point). Each scalar value in a SIMD type is
called a *lane*. The number of lanes must be a power of two in the range 2-256. called a *lane*. The number of lanes must be a power of two in the range 2-256.
.. type:: vNiB .. type:: i%Bx%N
A SIMD vector of integers. The lane type :type:`iB` must be one of the A SIMD vector of integers. The lane type :type:`iB` is one of the integer
integer types :type:`i8` ... :type:`i64`. types :type:`i8` ... :type:`i64`.
Some concrete integer vector types are :type:`v4i32`, :type:`v8i64`, and Some concrete integer vector types are :type:`i32x4`, :type:`i64x8`, and
:type:`v4i16`. :type:`i16x4`.
The size of a SIMD integer vector in memory is :math:`N B\over 8` bytes. The size of a SIMD integer vector in memory is :math:`N B\over 8` bytes.
.. type:: vNf32 .. type:: f32x%N
A SIMD vector of single precision floating point numbers. A SIMD vector of single precision floating point numbers.
Some concrete :type:`f32` vector types are: :type:`v2f32`, :type:`v4f32`, Some concrete :type:`f32` vector types are: :type:`f32x2`, :type:`f32x4`,
and :type:`v8f32`. and :type:`f32x8`.
The size of a :type:`f32` vector in memory is :math:`4N` bytes. The size of a :type:`f32` vector in memory is :math:`4N` bytes.
.. type:: vNf64 .. type:: f64x%N
A SIMD vector of double precision floating point numbers. A SIMD vector of double precision floating point numbers.
Some concrete :type:`f64` vector types are: :type:`v2f64`, :type:`v4f64`, Some concrete :type:`f64` vector types are: :type:`f64x2`, :type:`f64x4`,
and :type:`v8f64`. and :type:`f64x8`.
The size of a :type:`f64` vector in memory is :math:`8N` bytes. The size of a :type:`f64` vector in memory is :math:`8N` bytes.
.. type:: vNbool .. type:: boolx%N
A boolean SIMD vector. A boolean SIMD vector.
Like the :type:`bool` type, a boolean vector cannot be stored in memory. It Boolean vectors are used when comparing SIMD vectors. For example,
can only be used for ephemeral SSA values. comparing two :type:`i32x4` values would produce a :type:`boolx4` result.
Like the :type:`bool` type, a boolean vector cannot be stored in memory.
Instructions Instructions
============ ============
@@ -175,6 +177,9 @@ Control flow instructions
EBB arguments. The number and types of arguments must match the destination EBB arguments. The number and types of arguments must match the destination
EBB. EBB.
:arg EBB: Destination extended basic block.
:result: None. This is a terminator instruction.
.. inst:: brz x, EBB(args...) .. inst:: brz x, EBB(args...)
Branch when zero. Branch when zero.
@@ -182,8 +187,9 @@ Control flow instructions
If ``x`` is a :type:`bool` value, take the branch when ``x`` is false. If If ``x`` is a :type:`bool` value, take the branch when ``x`` is false. If
``x`` is an integer value, take the branch when ``x = 0``. ``x`` is an integer value, take the branch when ``x = 0``.
:param iN/bool x: Value to test. :arg iN / bool x: Value to test.
:param EBB: Destination extended basic block. :arg EBB: Destination extended basic block.
:result: None.
.. inst:: brnz x, EBB(args...) .. inst:: brnz x, EBB(args...)
@@ -192,15 +198,13 @@ Control flow instructions
If ``x`` is a :type:`bool` value, take the branch when ``x`` is true. If If ``x`` is a :type:`bool` value, take the branch when ``x`` is true. If
``x`` is an integer value, take the branch when ``x != 0``. ``x`` is an integer value, take the branch when ``x != 0``.
:param iN/bool x: Value to test. :arg iN / bool x: Value to test.
:param EBB: Destination extended basic block. :arg EBB: Destination extended basic block.
:result: None.
Special operations Special operations
================== ==================
Most operations are easily classified as arithmetic or control flow. These
instructions are not so easily classified.
.. inst:: a = iconst n .. inst:: a = iconst n
Integer constant. Integer constant.
@@ -217,13 +221,13 @@ instructions are not so easily classified.
Conditional select. Conditional select.
:param c bool: Controlling flag. :arg bool c: Controlling flag.
:param x: Value to return when ``c`` is true. :arg T x: Value to return when ``c`` is true.
:param y: Value to return when ``c`` is false. Must be same type as ``x``. :arg T y: Value to return when ``c`` is false. Must be same type as ``x``.
:rtype: Same type as ``x`` and ``y``. :rtype: T. Same type as ``x`` and ``y``.
This instruction selects whole values. Use :inst:`vselect` for This instruction selects whole values. Use :inst:`vselect` for lane-wise
lane-wise selection. selection.
Vector operations Vector operations
================= =================
@@ -235,7 +239,7 @@ Vector operations
Select lanes from ``x`` or ``y`` controlled by the lanes of the boolean Select lanes from ``x`` or ``y`` controlled by the lanes of the boolean
vector ``c``. vector ``c``.
:arg vNbool c: Controlling flag vector. :arg boolx%N c: Controlling flag vector.
:arg x: Vector with lanes selected by the true lanes of ``c``. :arg x: Vector with lanes selected by the true lanes of ``c``.
Must be a vector type with the same number of lanes as ``c``. Must be a vector type with the same number of lanes as ``c``.
:arg y: Vector with lanes selected by the false lanes of ``c``. :arg y: Vector with lanes selected by the false lanes of ``c``.
@@ -277,7 +281,7 @@ Integer operations
:param cond: Condition code determining how ``x`` and ``y`` are compared. :param cond: Condition code determining how ``x`` and ``y`` are compared.
:param x, y: Integer scalar or vector values of the same type. :param x, y: Integer scalar or vector values of the same type.
:rtype: :type:`bool` or :type:`vNbool` with the same number of lanes as :rtype: :type:`bool` or :type:`boolxN` with the same number of lanes as
``x`` and ``y``. ``x`` and ``y``.
The condition code determines if the operands are interpreted as signed or The condition code determines if the operands are interpreted as signed or
@@ -385,25 +389,25 @@ Bitwise operations
Bitwise and. Bitwise and.
:rtype: bool, iB, vNiB, vNfB? :rtype: bool, iB, iBxN, fBxN?
.. inst:: a = or x, y .. inst:: a = or x, y
Bitwise or. Bitwise or.
:rtype: bool, iB, vNiB, vNfB? :rtype: bool, iB, iBxN, fBxN?
.. inst:: a = xor x, y .. inst:: a = xor x, y
Bitwise xor. Bitwise xor.
:rtype: bool, iB, vNiB, vNfB? :rtype: bool, iB, iBxN, fBxN?
.. inst:: a = not x .. inst:: a = not x
Bitwise not. Bitwise not.
:rtype: bool, iB, vNiB, vNfB? :rtype: bool, iB, iBxN, fBxN?
.. todo:: Redundant bitwise operators. .. todo:: Redundant bitwise operators.
@@ -538,7 +542,7 @@ Floating point operations
:param cond: Condition code determining how ``x`` and ``y`` are compared. :param cond: Condition code determining how ``x`` and ``y`` are compared.
:param x, y: Floating point scalar or vector values of the same type. :param x, y: Floating point scalar or vector values of the same type.
:rtype: :type:`bool` or :type:`vNbool` with the same number of lanes as :rtype: :type:`bool` or :type:`boolxN` with the same number of lanes as
``x`` and ``y``. ``x`` and ``y``.
An 'ordered' condition code yields ``false`` if either operand is Nan. An 'ordered' condition code yields ``false`` if either operand is Nan.
@@ -672,6 +676,10 @@ Glossary
- Function signatures for indirect function calls. - Function signatures for indirect function calls.
- Function flags and attributes that are not part of the signature. - Function flags and attributes that are not part of the signature.
function body
The extended basic blocks which contain all the executable code in a
function. The function body follows the function preample.
basic block basic block
A maximal sequence of instructions that can only be entered from the A maximal sequence of instructions that can only be entered from the
top, and that contains no branch or terminator instructions except for top, and that contains no branch or terminator instructions except for
@@ -680,7 +688,7 @@ Glossary
extended basic block extended basic block
EBB EBB
A maximal sequence of instructions that can only be entered from the A maximal sequence of instructions that can only be entered from the
top, and that contains no :term:`terminator instruction`s except for top, and that contains no :term:`terminator instruction`\s except for
the last one. An EBB can contain conditional branches that can fall the last one. An EBB can contain conditional branches that can fall
through to the following instructions in the block, but only the first through to the following instructions in the block, but only the first
instruction in the EBB can be a branch target. instruction in the EBB can be a branch target.