Skip to content

Commit ef03dc8

Browse files
committed
finish scattering the termination module and update references to it
1 parent de3ec22 commit ef03dc8

File tree

9 files changed

+51
-67
lines changed

9 files changed

+51
-67
lines changed

doc/ReadingGuide.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,7 @@ Vector (`V`) and cryptography (`Zk*`) extensions.
236236

237237
### Other modules
238238

239-
The `termination` module specifies
240-
[functions](../model/termination/termination.sail) that are used to prove
241-
loop termination for theorem prover backends of Sail. The
242-
`unit_tests` module collects Sail unit tests for the specification.
239+
The `unit_tests` module collects Sail unit tests for the specification.
243240
The `main` module provides a [`main()`](../model/main/main.sail)
244241
function that is used in other Sail backends.
245242

model/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ execute_process(
3232
${SAIL_BIN}
3333
${project_file}
3434
--require-version ${SAIL_REQUIRED_VER}
35-
# include termination.sail in the list of dependencies
36-
--variable "TERMINATION_FILE = true"
3735
--all-modules
3836
--list-files
3937
OUTPUT_VARIABLE sail_list_files
@@ -372,7 +370,6 @@ foreach (xlen IN ITEMS 32 64)
372370
--config ${config_file}
373371
# Input files.
374372
${SAIL_MODULES}
375-
--variable "TERMINATION_FILE = true"
376373
${project_file}
377374
)
378375
add_custom_command(
@@ -438,7 +435,6 @@ foreach (xlen IN ITEMS 32 64)
438435
${lean_sail_common}
439436
${lean_sail_default}
440437
${SAIL_MODULES}
441-
--variable "TERMINATION_FILE = true"
442438
${project_file}
443439
)
444440
add_custom_command(
@@ -457,7 +453,6 @@ foreach (xlen IN ITEMS 32 64)
457453
${lean_sail_common}
458454
${lean_sail_executable}
459455
${SAIL_MODULES}
460-
--variable "TERMINATION_FILE = true"
461456
${project_file}
462457
)
463458

model/core/extensions.sail

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,28 @@ scattered mapping extensionName
1919
val hartSupports : extension -> bool
2020
scattered function hartSupports
2121

22+
function hartSupports_measure(ext : extension) -> int =
23+
match ext {
24+
Ext_D => 1,
25+
Ext_V => 1,
26+
Ext_Zvkn => 1,
27+
Ext_Zvks => 1,
28+
Ext_C => 2,
29+
Ext_Zvknc => 2,
30+
Ext_Zvkng => 2,
31+
Ext_Zvksc => 2,
32+
Ext_Zvksg => 2,
33+
_ => 0,
34+
}
35+
36+
termination_measure hartSupports(ext) = hartSupports_measure(ext)
37+
2238
// Function used to determine if an extension is currently enabled in the model.
2339
// This means an extension is supported, *and* any necessary bits are set in the
2440
// relevant CSRs (misa, mstatus, etc.) to enable its use. It is possible for some
2541
// extensions to be supported in hardware, but temporarily disabled via a CSR, in
2642
// which case this function should return false.
27-
// Note: when adding a new extension, adjust the associated termination measure
28-
// in the file termination.sail, as explained in the comment in
29-
// that file.
43+
// Note: when adding a new extension, adjust the `currentlyEnabled_measure` below.
3044
val currentlyEnabled : extension -> bool
3145
scattered function currentlyEnabled
3246

@@ -473,9 +487,9 @@ function currentlyEnabled_measure(ext : extension) -> int =
473487
Ext_F => 1,
474488
Ext_M => 1,
475489
Ext_S => 1,
476-
Ext_V => 1,
477-
Ext_H => 4,
478490
Ext_Smcntrpmf => 3,
491+
Ext_Sscofpmf => 3,
492+
Ext_Sv39 => 3,
479493
Ext_Zabha => 3,
480494
Ext_Zacas => 3,
481495
Ext_Zcb => 3,
@@ -484,9 +498,20 @@ function currentlyEnabled_measure(ext : extension) -> int =
484498
Ext_Zcmop => 3,
485499
Ext_Zfhmin => 3,
486500
Ext_Zhinx => 3,
501+
Ext_Zicfilp => 3,
502+
Ext_Zve32x => 3,
487503
Ext_Zvkb => 3,
488-
Ext_Sscofpmf => 3,
504+
Ext_H => 4,
505+
Ext_Svrsw60t59b => 4,
489506
Ext_Zhinxmin => 4,
507+
Ext_Zve32f => 4,
508+
Ext_Zve64x => 4,
509+
Ext_Zve64f => 5,
510+
Ext_Zvfh => 5,
511+
Ext_Zve64d => 6,
512+
Ext_Zvfhmin => 6,
513+
Ext_Zvl128b => 6,
514+
Ext_V => 7,
490515
_ => 2
491516
}
492517

model/core/sys_regs.sail

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ function virtual_memory_supported() -> bool = {
144144
currentlyEnabled(Ext_Sv32) | currentlyEnabled(Ext_Sv39) | currentlyEnabled(Ext_Sv48) | currentlyEnabled(Ext_Sv57)
145145
}
146146

147+
termination_measure virtual_memory_supported(_) = 3
148+
147149
//
148150
// Illegal values legalized to least privileged mode supported.
149151
// Note: the only valid combinations of supported modes are M, M+U, M+S+U.

model/extensions/cfi/zicfilp_regs.sail

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ function get_xLPE(p : Privilege) -> bool =
3232
VirtualUser => internal_error(__FILE__, __LINE__, "Hypervisor extension not supported"),
3333
}
3434

35+
termination_measure get_xLPE(_) = 2
36+
3537
function clause currentlyEnabled(Ext_Zicfilp) =
3638
currentlyEnabled(Ext_Zicsr) & hartSupports(Ext_Zicfilp) & get_xLPE(cur_privilege)
3739

model/postlude/step.sail

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,13 @@ function loop () : unit -> unit = {
288288
}
289289
}
290290
}
291+
292+
// Termination measures for loops are not supported by the Lean backend, so they
293+
// should be guarded by this condition:
294+
$iftarget coq
295+
296+
// The top-level loop isn't terminating, but we put a limit so that it can still
297+
// be included in the Coq output
298+
termination_measure loop while 100
299+
300+
$endif

model/riscv.sail_project

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
variable TERMINATION_FILE = false
21
variable RMEM = false
32

43
core {
@@ -466,18 +465,8 @@ postlude {
466465
postlude/model.sail
467466
}
468467

469-
termination {
470-
after postlude
471-
requires core, sys, Zca, FD
472-
473-
files
474-
if $TERMINATION_FILE then
475-
termination/termination.sail
476-
else []
477-
}
478-
479468
unit_tests {
480-
after termination
469+
after postlude
481470
requires core, sys, exceptions, postlude
482471

483472
files

model/sys/vmem_utils.sail

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ function vmem_read_addr(vaddr, offset, width, acc, aq, rl, res) = {
172172
Ok(data)
173173
}
174174

175+
termination_measure vmem_read_addr repeat n
176+
175177
val vmem_write_addr : forall 'width, is_mem_width('width).
176178
(virtaddr, int('width), bits(8 * 'width), AccessType(ext_access_type), bool, bool, bool)
177179
-> result(bool, ExecutionResult)
@@ -227,6 +229,8 @@ function vmem_write_addr(vaddr, width, data, acc, aq, rl, res) = {
227229
Ok(write_success)
228230
}
229231

232+
termination_measure vmem_write_addr repeat n
233+
230234
val vmem_read : forall 'width, is_mem_width('width).
231235
(regidx, xlenbits, int('width), AccessType(ext_access_type), bool, bool, bool)
232236
-> result(bits(8 * 'width), ExecutionResult)

model/termination/termination.sail

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)