Skip to content

Commit 71cf398

Browse files
committed
refman import, shift and rotate [CI SKIP]
1 parent db7e938 commit 71cf398

File tree

3 files changed

+58
-31
lines changed

3 files changed

+58
-31
lines changed

doc/aarch32.vadl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
instruction set architecture AArch32 = {
22

3-
register file R: Bits<4> -> Bits<32>
3+
using Word = Bits<32>
4+
5+
register file R: Bits<4> -> Word
46
format Status: Bits<1> = {Z : Bits<1>}
57
register APSR: Status
68

79
enumeration cond: Bits<4> =
8-
{ EQ // equal Z == 1
9-
, NE // not equal Z == 0
10+
{ EQ // equal Z == 1
11+
, NE // not equal Z == 0
1012
//...
1113
, AL // always
1214
}
1315

14-
format ArLoImm: Bits<32> = // arithmetic/logic immediate format
15-
{ cc [31..28] // condition
16-
, op [27..21] // opcode
17-
, flags [20] // set status register
18-
, rn [19..16] // source register
19-
, rd [15..12] // destination register
20-
, imm12 [11..0] // 12 bit immediate
16+
format ArLoImm: Word = // arithmetic/logic immediate format
17+
{ cc [31..28] // condition
18+
, op [27..21] // opcode
19+
, flags [20] // set status register
20+
, rn [19..16] // source register
21+
, rd [15..12] // destination register
22+
, imm12 [11..0] // 12 bit immediate
2123
}
2224

2325
record Instr (id: Id, ass: Str, op: BinOp, opcode: Bin)
@@ -26,7 +28,7 @@ record Cond (str: Str, code: Id, ex: Ex)
2628
model ALImmCondInstr (cond: Cond, instr: Instr) : IsaDefs = {
2729
instruction ExtendId ($instr.id, $cond.str) : ArLoImm =
2830
if ($cond.ex) then
29-
R(rd) := R(rn) $instr.op imm12 as Bits<32>
31+
R(rd) := R(rn) $instr.op imm12 as Word
3032
encoding ExtendId ($instr.id, $cond.str) =
3133
{cc = cond::$cond.code, op = $instr.opcode, flags = 0}
3234
assembly ExtendId ($instr.id, $cond.str) =

doc/refmanual.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,22 @@ function ugeq ( a : UInt<N>, b : UInt<N> ) -> Bool // <=> a >= b
355355
~~~
356356
\endlisting
357357

358-
## Shifting Operations
358+
## Shift and Rotate Operations
359+
360+
Listing \r{basic_math_shifting} lists the primitives for shift and rotate operations.
361+
Shift and rotate operations move the bits of operand `a` left or right by the number of bits specified by operand `b % N` of type `UInt<M>`.
362+
Shift operations to the left fill the low bit positions with zeros and operand `a` and the result are of type `Bits<N>`.
363+
Shift operations to the right fill the high bit positions with the sign bit for arithmetic shifts (`SInt`) and with zeros for logical shifts (`UInt`).
364+
`M` has to be smaller or equal to `N`.
365+
366+
For instructions which set the status register (`*s`, `*c`, `rrx`) the carry flag is set to the last bit shifted out.
367+
The carry flag is unchanged if the shift/rotate amount is `0`.
368+
369+
Rotate left (right) provides the operand `a` rotated by a variable number of bits.
370+
The bits that are rotated off the left (right) end are inserted into the vacated bit positions on the right (left).
371+
Rotate right with extend ( `rrx`) moves the bits of a register to the right by one bit.
372+
It copies the carry flag into the highest bit position of the result and sets the carry flag to lowest bit position of operand `a`.
373+
359374
\listing{basic_math_shifting, VADL Shifting Operations}
360375
~~~{.vadl}
361376
M <= N
@@ -377,7 +392,7 @@ function rolc( a : Bits<N>, b : UInt<M>, c : Bool ) -> ( Bits<N>, Status )
377392
function ror ( a : Bits<N>, b : UInt<M> ) -> Bits<N> // <=> a <>> b
378393
function rors( a : Bits<N>, b : UInt<M> ) -> ( Bits<N>, Status )
379394
function rorc( a : Bits<N>, b : UInt<M>, c : Bool ) -> ( Bits<N>, Status )
380-
function rrx ( a : Bits<N>, b : UInt<M>, c : Bool ) -> Bits<N>
395+
function rrx ( a : Bits<N>, c : Bool ) -> Bits<N>
381396
~~~
382397
\endlisting
383398

doc/tutorial.md

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ The reference is of a valid type because the result type `Defs` is a subtype of
392392
\listing{model_type_parameters, Valid types in model references}
393393
~~~{.vadl}
394394
instruction set architecture ISA = {
395-
constant Word = 32
395+
constant wordSize = 32
396396
397397
model-type IsaDefsFactory = (Id) -> IsaDefs
398398
@@ -405,7 +405,7 @@ instruction set architecture ISA = {
405405
$factory($size)
406406
}
407407
408-
$BitDefs(Constants ; Word)
408+
$BitDefs(Constants ; wordSize)
409409
}
410410
~~~
411411
\endlisting
@@ -422,24 +422,26 @@ Arithmetic/logic instructions, which have an immediate value as second source op
422422
~~~{.vadl}
423423
instruction set architecture AArch32 = {
424424
425-
register file R: Bits<4> -> Bits<32>
425+
using Word = Bits<32>
426+
427+
register file R: Bits<4> -> Word
426428
format Status: Bits<1> = {Z : Bits<1>}
427429
register APSR: Status
428430
429431
enumeration cond: Bits<4> =
430-
{ EQ // equal Z == 1
431-
, NE // not equal Z == 0
432+
{ EQ // equal Z == 1
433+
, NE // not equal Z == 0
432434
//...
433435
, AL // always
434436
}
435437
436-
format ArLoImm: Bits<32> = // arithmetic/logic immediate format
437-
{ cc [31..28] // condition
438-
, op [27..21] // opcode
439-
, flags [20] // set status register
440-
, rn [19..16] // source register
441-
, rd [15..12] // destination register
442-
, imm12 [11..0] // 12 bit immediate
438+
format ArLoImm: Word = // arithmetic/logic immediate format
439+
{ cc [31..28] // condition
440+
, op [27..21] // opcode
441+
, flags [20] // set status register
442+
, rn [19..16] // source register
443+
, rd [15..12] // destination register
444+
, imm12 [11..0] // 12 bit immediate
443445
}
444446
445447
record Instr (id: Id, ass: Str, op: BinOp, opcode: Bin)
@@ -448,7 +450,7 @@ record Cond (str: Str, code: Id, ex: Ex)
448450
model ALImmCondInstr (cond: Cond, instr: Instr) : IsaDefs = {
449451
instruction ExtendId ($instr.id, $cond.str) : ArLoImm =
450452
if ($cond.ex) then
451-
R(rd) := R(rn) $instr.op imm12 as Bits<32>
453+
R(rd) := R(rn) $instr.op imm12 as Word
452454
encoding ExtendId ($instr.id, $cond.str) =
453455
{cc = cond::$cond.code, op = $instr.opcode, flags = 0}
454456
assembly ExtendId ($instr.id, $cond.str) =
@@ -493,14 +495,22 @@ This leads to a specification with multiple higher-order macro arguments.
493495
VADL provides the possibility of passing configuration information to the macro system using the command line.
494496
Currently, this mechanism is kept very simple and is restricted to elements of type `Id`.
495497
To prepare a configurable macro variable a default model of type `Id` has to be defined.
496-
Listing \r{macro_configuration} shows such a variable of name `Arch`, with the default setting `Aarch32`.
497-
Without any passed configurations the instantiation of `Arch` results in the identifier `Aarch32`.
498-
If VADL receives the command line option `-m` or `--model` followed by the string `"Arch=Aarch64"`, the value of `Arch` is overridden.
499-
If `Arch` is instantiated given the previous command line option, it would result in `Aarch64`.
498+
Listing \r{macro_configuration} shows such a variable of name `Size`, with the default setting `Arch32`.
499+
Without any passed configurations the instantiation of `Size` results in the identifier `Arch32`.
500+
If VADL receives the command line option `-m` or `--model` followed by the string `"Size=Arch64"`, the value of `Arch` is overridden.
501+
If `Arch` is instantiated given the previous command line option, it would result in `Arch64`.
500502
In combination with conditional expansion, see Section \r{macro_match} and Listing \r{match_macro}, this simple mechanism already provides powerful configuration capabilities.
501503

502504
\listing{macro_configuration, Macro Configuration Variable}
503505
~~~{.vadl}
504-
model Arch() : Id = { Aarch32 }
506+
model Size() : Id = { Arch32 }
507+
~~~
508+
\endlisting
509+
510+
Similarly to model passing in the command line it is possible to pass models as an argument to import declarations as demonstrated in Listing \r{macro_import}.
511+
512+
\listing{macro_import, Import with Macro Argument}
513+
~~~{.vadl}
514+
import rv3264im::RV3264I with ("Size=Arch64")
505515
~~~
506516
\endlisting

0 commit comments

Comments
 (0)