Skip to content

Commit 5e6c568

Browse files
authored
Merge pull request #297 from ShashankVM/main
Update IDL doc
2 parents e5d97e4 + 2896168 commit 5e6c568

File tree

2 files changed

+90
-42
lines changed

2 files changed

+90
-42
lines changed

arch/isa/fp.idl

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -416,27 +416,6 @@ function softfloat_normSubnormalF16Sig {
416416
}
417417
}
418418

419-
function softfloat_normRoundPackToF32 {
420-
returns Bits<32>
421-
arguments
422-
Bits<1> sign,
423-
Bits<8> exp,
424-
Bits<23> sig,
425-
RoundingMode mode
426-
description {
427-
Normalize, round, and pack into a 32-bit floating point value
428-
}
429-
body {
430-
Bits<8> shiftDist = count_leading_zeros<32>(sig) - 1;
431-
exp = exp - shiftDist;
432-
if ((7 <= shiftDist) && (exp < 0xFD)) {
433-
return packToF32UI(sign, (sig != 0) ? exp : 0, sig << (shiftDist - 7));
434-
} else {
435-
return softfloat_roundPackToF32(sign, exp, sig << shiftDist, mode);
436-
}
437-
}
438-
}
439-
440419
function softfloat_roundPackToF32 {
441420
returns Bits<32> # single precision value
442421
arguments
@@ -485,3 +464,24 @@ function softfloat_roundPackToF32 {
485464
return packToF32UI(sign, exp, sig);
486465
}
487466
}
467+
468+
function softfloat_normRoundPackToF32 {
469+
returns Bits<32>
470+
arguments
471+
Bits<1> sign,
472+
Bits<8> exp,
473+
Bits<23> sig,
474+
RoundingMode mode
475+
description {
476+
Normalize, round, and pack into a 32-bit floating point value
477+
}
478+
body {
479+
Bits<8> shiftDist = count_leading_zeros<32>(sig) - 1;
480+
exp = exp - shiftDist;
481+
if ((7 <= shiftDist) && (exp < 0xFD)) {
482+
return packToF32UI(sign, (sig != 0) ? exp : 0, sig << (shiftDist - 7));
483+
} else {
484+
return softfloat_roundPackToF32(sign, exp, sig << shiftDist, mode);
485+
}
486+
}
487+
}

arch/prose/idl.adoc

Lines changed: 69 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ All strings must be compile-time-known values.
161161

162162
=== Composite Types
163163

164-
IDL also supports three composite types: enumerations, bitfields, and arrays.
164+
IDL also supports four composite types: enumerations, bitfields, structs, and arrays.
165165

166166
==== Enumerations
167167

@@ -240,6 +240,24 @@ Sv39PageTableEntry pte = pte_data;
240240
Bits<2> pbmt = pte.PBMT;
241241
----
242242

243+
==== Structs
244+
245+
A struct is a collection of unrelated types, similar to a `struct` in C/C++ or Verilog. Structs are declared using the `struct` keyword. Struct names must begin with a capital letter. Struct members can begin with either lowercase or uppercase; in the former, the member is mutable and in the former the member is const. Struct members may be any type, including other structs.
246+
247+
Struct declarations do _not_ need to be followed by a semicolon (as they are in C/C++).
248+
249+
.example Struct
250+
[source,idl]
251+
----
252+
struct TranslationResult {
253+
Bits<PHYS_ADDR_WIDTH> paddr; # a bit vector
254+
Pbmt pbmt; # an enum
255+
PteFlags pte_flags; # another enum
256+
}
257+
----
258+
259+
Structs can be the return value of a function. Structs, like every other variable in IDL, are always passed-by-value.
260+
243261
==== Arrays
244262

245263
Fixed-size arrays of other data types may also be created in IDL. The size of the array must be known at compile time (_i.e._, there are no unbounded arrays like in C/C++).
@@ -592,7 +610,7 @@ Bitfields can be converted to a `Bits<N>` type, where N is the width of the bitf
592610

593611
== Casting
594612

595-
There are two explicit cast operators in IDL: `$isigned` and `$bits`.
613+
There are four explicit cast operators in IDL: `$signed`, `$bits`, `$enum`, and `$enum_to_a`.
596614

597615
Unsigned Bits<N> values may be cast to signed values using the `$signed` cast operator.
598616

@@ -630,6 +648,55 @@ $bits(CSR[mstatus]) # => XLEN'd??
630648
$bits(Sv39PageTableEntry) # => 64'd??
631649
----
632650

651+
The `$enum` cast will convert a `Bits<N>` type into an enum.
652+
653+
[source,idl]
654+
----
655+
$enum(RoundingMode, 1'b1) # => RoundingMode::RTZ
656+
----
657+
658+
The `$enum_to_a` cast will convert an enumeration type into an array of the enumeration values. The values will in the declaration order of the enum members.
659+
660+
[source,idl]
661+
----
662+
$enum_to_a(RoundingMode) # => [0, 1, 2, 3, 4]
663+
----
664+
665+
== Builtins
666+
667+
IDL provides a several builtins to access implicit machine state or query data structure properties.
668+
669+
=== Implicit Machine State
670+
671+
The current program counter (virtual address of the instruction being executed) is available in `$pc` in Instruction and CSR scope. `$pc` is not available in function scope or global scope.
672+
673+
The current instruction encoding (of the instruction being executed) is available in `$encoding` in Instruction and CSR scope. `$encoding` is not available in function scope or global scope.
674+
675+
=== Data Type Queries
676+
677+
The size (number of members) of an enum can be found with `$enum_size`.
678+
679+
[source,idl]
680+
----
681+
$enum_size(RoundingMode) # => 5
682+
----
683+
684+
The size of an enum element (the number of bits needed to represent the largest enum value) can be
685+
found with `$enum_element_size`.
686+
687+
[source,idl]
688+
----
689+
$enum_element_size(RoundingMode) # => 3
690+
----
691+
692+
The size (number of elements) of an array can be found with `$array_size`.
693+
694+
[source,idl]
695+
----
696+
Bits<32> array [13];
697+
$array_size(array) # => 13
698+
----
699+
633700
== Control flow
634701

635702
IDL provides if/else and for loops for control flow.
@@ -926,22 +993,3 @@ mstatus:
926993
reset_value(): |
927994
return (M_MODE_ENDIANESS == "big") ? 1 : 0;
928995
----
929-
930-
== Compilation order
931-
932-
The order of declaration is important in IDL (like C/C++, unlike Verilog). A variable, constant, or function must be declared *before* it is used.
933-
934-
.Compilation order
935-
[source,idl]
936-
----
937-
function mod {
938-
...
939-
body {
940-
# (-, remainder) = divmod(value); # compilation error: divmod not defined
941-
# return remainder;
942-
}
943-
}
944-
945-
function divmod { ... }
946-
947-
----

0 commit comments

Comments
 (0)