Skip to content

Commit 940398c

Browse files
authored
Restrict offsets to index type's range in validation (#79)
1 parent 04e1cf6 commit 940398c

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

document/core/syntax/instructions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ Instructions in this group are concerned with linear :ref:`memory <syntax-mem>`.
683683
\DATADROP~\dataidx \\
684684
\end{array}
685685
686-
Memory is accessed with |LOAD| and |STORE| instructions for the different :ref:`number types <syntax-numtype>` and `vector types <syntax-vectype>`.
686+
Memory is accessed with |LOAD| and |STORE| instructions for the different :ref:`number types <syntax-numtype>` and :ref:`vector types <syntax-vectype>`.
687687
They all take a :ref:`memory index <syntax-memidx>` and a *memory immediate* |memarg| that contains an address *offset* and the expected *alignment* (expressed as the exponent of a power of 2).
688688

689689
Integer loads and stores can optionally specify a *storage size* that is smaller than the :ref:`bit width <syntax-numtype>` of the respective value type.
@@ -692,7 +692,7 @@ In the case of loads, a sign extension mode |sx| is then required to select appr
692692
Vector loads can specify a shape that is half the :ref:`bit width <syntax-valtype>` of |V128|. Each lane is half its usual size, and the sign extension mode |sx| then specifies how the smaller lane is extended to the larger lane.
693693
Alternatively, vector loads can perform a *splat*, such that only a single lane of the specified storage size is loaded, and the result is duplicated to all lanes.
694694

695-
The static address offset is added to the dynamic address operand, yielding a 33 bit *effective address* that is the zero-based index at which the memory is accessed.
695+
The static address offset is added to the dynamic address operand, yielding a 33-bit or 65-bit *effective address* that is the zero-based index at which the memory is accessed.
696696
All values are read and written in |LittleEndian|_ byte order.
697697
A :ref:`trap <trap>` results if any of the accessed memory bytes lies outside the address range implied by the memory's current size.
698698

document/core/valid/instructions.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,8 @@ Memory Instructions
15091509

15101510
* Let :math:`\X{it}~\limits` be the :ref:`memory type <syntax-memtype>` :math:`C.\CMEMS[x]`.
15111511

1512+
* The offset :math:`\memarg.\OFFSET` must be less than :math:`2^{|\X{it}|}`.
1513+
15121514
* The alignment :math:`2^{\memarg.\ALIGN}` must not be larger than the :ref:`bit width <syntax-numtype>` of :math:`t` divided by :math:`8`.
15131515

15141516
* Then the instruction is valid with type :math:`[\X{it}] \to [t]`.
@@ -1517,6 +1519,8 @@ Memory Instructions
15171519
\frac{
15181520
C.\CMEMS[x] = \X{it}~\limits
15191521
\qquad
1522+
\memarg.\OFFSET < 2^{|\X{it}|}
1523+
\qquad
15201524
2^{\memarg.\ALIGN} \leq |t|/8
15211525
}{
15221526
C \vdashinstr t\K{.load}~x~\memarg : [\X{it}] \to [t]
@@ -1532,6 +1536,8 @@ Memory Instructions
15321536

15331537
* Let :math:`\X{it}~\limits` be the :ref:`memory type <syntax-memtype>` :math:`C.\CMEMS[x]`.
15341538

1539+
* The offset :math:`\memarg.\OFFSET` must be less than :math:`2^{|\X{it}|}`.
1540+
15351541
* The alignment :math:`2^{\memarg.\ALIGN}` must not be larger than :math:`N/8`.
15361542

15371543
* Then the instruction is valid with type :math:`[\X{it}] \to [t]`.
@@ -1540,6 +1546,8 @@ Memory Instructions
15401546
\frac{
15411547
C.\CMEMS[x] = \X{it}~\limits
15421548
\qquad
1549+
\memarg.\OFFSET < 2^{|\X{it}|}
1550+
\qquad
15431551
2^{\memarg.\ALIGN} \leq N/8
15441552
}{
15451553
C \vdashinstr t\K{.load}N\K{\_}\sx~x~\memarg : [\X{it}] \to [t]
@@ -1553,6 +1561,8 @@ Memory Instructions
15531561

15541562
* Let :math:`\X{it}~\limits` be the :ref:`memory type <syntax-memtype>` :math:`C.\CMEMS[x]`.
15551563

1564+
* The offset :math:`\memarg.\OFFSET` must be less than :math:`2^{|\X{it}|}`.
1565+
15561566
* The alignment :math:`2^{\memarg.\ALIGN}` must not be larger than the :ref:`bit width <syntax-numtype>` of :math:`t` divided by :math:`8`.
15571567

15581568
* Then the instruction is valid with type :math:`[\X{it}~t] \to []`.
@@ -1561,6 +1571,8 @@ Memory Instructions
15611571
\frac{
15621572
C.\CMEMS[x] = \X{it}~\limits
15631573
\qquad
1574+
\memarg.\OFFSET < 2^{|\X{it}|}
1575+
\qquad
15641576
2^{\memarg.\ALIGN} \leq |t|/8
15651577
}{
15661578
C \vdashinstr t\K{.store}~x~\memarg : [\X{it}~t] \to []
@@ -1574,6 +1586,10 @@ Memory Instructions
15741586

15751587
* The memory :math:`C.\CMEMS[x]` must be defined in the context.
15761588

1589+
* Let :math:`\X{it}~\limits` be the :ref:`memory type <syntax-memtype>` :math:`C.\CMEMS[x]`.
1590+
1591+
* The offset :math:`\memarg.\OFFSET` must be less than :math:`2^{|\X{it}|}`.
1592+
15771593
* The alignment :math:`2^{\memarg.\ALIGN}` must not be larger than :math:`N/8`.
15781594

15791595
* Then the instruction is valid with type :math:`[\X{it}~t] \to []`.
@@ -1582,6 +1598,8 @@ Memory Instructions
15821598
\frac{
15831599
C.\CMEMS[x] = \X{it}~\limits
15841600
\qquad
1601+
\memarg.\OFFSET < 2^{|\X{it}|}
1602+
\qquad
15851603
2^{\memarg.\ALIGN} \leq N/8
15861604
}{
15871605
C \vdashinstr t\K{.store}N~x~\memarg : [\X{it}~t] \to []
@@ -1597,6 +1615,8 @@ Memory Instructions
15971615

15981616
* Let :math:`\X{it}~\limits` be the :ref:`memory type <syntax-memtype>` :math:`C.\CMEMS[x]`.
15991617

1618+
* The offset :math:`\memarg.\OFFSET` must be less than :math:`2^{|\X{it}|}`.
1619+
16001620
* The alignment :math:`2^{\memarg.\ALIGN}` must not be larger than :math:`N/8 \cdot M`.
16011621

16021622
* Then the instruction is valid with type :math:`[\X{it}] \to [\V128]`.
@@ -1605,6 +1625,8 @@ Memory Instructions
16051625
\frac{
16061626
C.\CMEMS[x] = \X{it}~\limits
16071627
\qquad
1628+
\memarg.\OFFSET < 2^{|\X{it}|}
1629+
\qquad
16081630
2^{\memarg.\ALIGN} \leq N/8 \cdot M
16091631
}{
16101632
C \vdashinstr \K{v128.}\LOAD{N}\K{x}M\_\sx~x~\memarg : [\X{it}] \to [\V128]
@@ -1620,6 +1642,8 @@ Memory Instructions
16201642

16211643
* Let :math:`\X{it}~\limits` be the :ref:`memory type <syntax-memtype>` :math:`C.\CMEMS[x]`.
16221644

1645+
* The offset :math:`\memarg.\OFFSET` must be less than :math:`2^{|\X{it}|}`.
1646+
16231647
* The alignment :math:`2^{\memarg.\ALIGN}` must not be larger than :math:`N/8`.
16241648

16251649
* Then the instruction is valid with type :math:`[\X{it}] \to [\V128]`.
@@ -1628,6 +1652,8 @@ Memory Instructions
16281652
\frac{
16291653
C.\CMEMS[x] = \X{it}~\limits
16301654
\qquad
1655+
\memarg.\OFFSET < 2^{|\X{it}|}
1656+
\qquad
16311657
2^{\memarg.\ALIGN} \leq N/8
16321658
}{
16331659
C \vdashinstr \K{v128.}\LOAD{N}\K{\_splat}~x~\memarg : [\X{it}] \to [\V128]
@@ -1643,6 +1669,8 @@ Memory Instructions
16431669

16441670
* Let :math:`\X{it}~\limits` be the :ref:`memory type <syntax-memtype>` :math:`C.\CMEMS[x]`.
16451671

1672+
* The offset :math:`\memarg.\OFFSET` must be less than :math:`2^{|\X{it}|}`.
1673+
16461674
* The alignment :math:`2^{\memarg.\ALIGN}` must not be larger than :math:`N/8`.
16471675

16481676
* Then the instruction is valid with type :math:`[\X{it}] \to [\V128]`.
@@ -1651,6 +1679,8 @@ Memory Instructions
16511679
\frac{
16521680
C.\CMEMS[x] = \X{it}~\limits
16531681
\qquad
1682+
\memarg.\OFFSET < 2^{|\X{it}|}
1683+
\qquad
16541684
2^{\memarg.\ALIGN} \leq N/8
16551685
}{
16561686
C \vdashinstr \K{v128.}\LOAD{N}\K{\_zero}~x~\memarg : [\X{it}] \to [\V128]
@@ -1666,6 +1696,8 @@ Memory Instructions
16661696

16671697
* Let :math:`\X{it}~\limits` be the :ref:`memory type <syntax-memtype>` :math:`C.\CMEMS[x]`.
16681698

1699+
* The offset :math:`\memarg.\OFFSET` must be less than :math:`2^{|\X{it}|}`.
1700+
16691701
* The alignment :math:`2^{\memarg.\ALIGN}` must not be larger than :math:`N/8`.
16701702

16711703
* The lane index :math:`\laneidx` must be smaller than :math:`128/N`.
@@ -1676,6 +1708,8 @@ Memory Instructions
16761708
\frac{
16771709
C.\CMEMS[x] = \X{it}~\limits
16781710
\qquad
1711+
\memarg.\OFFSET < 2^{|\X{it}|}
1712+
\qquad
16791713
2^{\memarg.\ALIGN} \leq N/8
16801714
\qquad
16811715
\laneidx < 128/N
@@ -1692,6 +1726,9 @@ Memory Instructions
16921726
* The memory :math:`C.\CMEMS[x]` must be defined in the context.
16931727

16941728
* Let :math:`\X{it}~\limits` be the :ref:`memory type <syntax-memtype>` :math:`C.\CMEMS[x]`.
1729+
1730+
* The offset :math:`\memarg.\OFFSET` must be less than :math:`2^{|\X{it}|}`.
1731+
16951732
* The alignment :math:`2^{\memarg.\ALIGN}` must not be larger than :math:`N/8`.
16961733

16971734
* The lane index :math:`\laneidx` must be smaller than :math:`128/N`.
@@ -1702,6 +1739,8 @@ Memory Instructions
17021739
\frac{
17031740
C.\CMEMS[x] = \X{it}~\limits
17041741
\qquad
1742+
\memarg.\OFFSET < 2^{|\X{it}|}
1743+
\qquad
17051744
2^{\memarg.\ALIGN} \leq N/8
17061745
\qquad
17071746
\laneidx < 128/N

0 commit comments

Comments
 (0)