Skip to content

Commit 5ddc35b

Browse files
committed
scatter termination.sail and remove references to it
1 parent 91178c8 commit 5ddc35b

File tree

10 files changed

+106
-126
lines changed

10 files changed

+106
-126
lines changed

doc/ReadingGuide.md

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

241241
### Other modules
242242

243-
The `termination` module specifies
244-
[functions](../model/termination/termination.sail) that are used to prove
245-
loop termination for theorem prover backends of Sail. The
246-
`unit_tests` module collects Sail unit tests for the specification.
243+
The `unit_tests` module collects Sail unit tests for the specification.
247244
The `main` module provides a [`main()`](../model/main/main.sail)
248245
function that is used in other Sail backends.
249246

model/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ execute_process(
3535
${SAIL_BIN}
3636
${project_file}
3737
--require-version ${SAIL_REQUIRED_VER}
38-
# include termination.sail in the list of dependencies
39-
--variable "TERMINATION_FILE = true"
4038
--all-modules
4139
--list-files
4240
OUTPUT_VARIABLE sail_list_files
@@ -375,7 +373,6 @@ foreach (xlen IN ITEMS 32 64)
375373
--config ${config_file}
376374
# Input files.
377375
${SAIL_MODULES}
378-
--variable "TERMINATION_FILE = true"
379376
${project_file}
380377
)
381378
add_custom_command(
@@ -443,7 +440,6 @@ foreach (xlen IN ITEMS 32 64)
443440
${lean_sail_common}
444441
${lean_sail_default}
445442
${SAIL_MODULES}
446-
--variable "TERMINATION_FILE = true"
447443
${project_file}
448444
)
449445
add_custom_command(
@@ -462,7 +458,6 @@ foreach (xlen IN ITEMS 32 64)
462458
${lean_sail_common}
463459
${lean_sail_executable}
464460
${SAIL_MODULES}
465-
--variable "TERMINATION_FILE = true"
466461
${project_file}
467462
)
468463

model/core/extensions.sail

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,31 @@ 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, // > F
25+
Ext_Sstvecd => 1, // > S
26+
Ext_Ssu64xl => 1, // > S
27+
Ext_Zvkn => 1, // > Zvkned
28+
Ext_Zvks => 1, // > Zvksed
29+
30+
Ext_C => 2, // > D
31+
Ext_Zvknc => 2, // > Zvkn
32+
Ext_Zvkng => 2, // > Zvkn
33+
Ext_Zvksc => 2, // > Zvks
34+
Ext_Zvksg => 2, // > Zvks
35+
36+
_ => 0,
37+
}
38+
39+
termination_measure hartSupports(ext) = hartSupports_measure(ext)
40+
2241
// Function used to determine if an extension is currently enabled in the model.
2342
// This means an extension is supported, *and* any necessary bits are set in the
2443
// relevant CSRs (misa, mstatus, etc.) to enable its use. It is possible for some
2544
// extensions to be supported in hardware, but temporarily disabled via a CSR, in
2645
// 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.
46+
// Note: when adding a new extension, adjust the `currentlyEnabled_measure` below.
3047
val currentlyEnabled : extension -> bool
3148
scattered function currentlyEnabled
3249

@@ -474,6 +491,66 @@ enum clause extension = Ext_Smcntrpmf
474491
mapping clause extensionName = Ext_Smcntrpmf <-> "smcntrpmf"
475492
function clause hartSupports(Ext_Smcntrpmf) = config extensions.Smcntrpmf.supported
476493

494+
// When adding a new extension X, we need to make sure that if X being enabled
495+
// depends on Y being enabled, then the value associated to X is _greater_ than
496+
// the value associated to Y. The default value is 2, so that if it does not
497+
// depend on anything or only on extensions A, B, C, D, F, M, S, Zve32x, Zvl* or Zicsr,
498+
// nothing needs to be done.
499+
500+
function currentlyEnabled_measure(ext : extension) -> int =
501+
match ext {
502+
Ext_A => 0,
503+
Ext_B => 0,
504+
Ext_C => 0,
505+
Ext_M => 0,
506+
Ext_Zicsr => 0,
507+
Ext_Zvl128b => 0,
508+
Ext_Zvl32b => 0,
509+
Ext_Zvl64b => 0,
510+
511+
Ext_D => 1, // > Zicsr
512+
Ext_F => 1, // > Zicsr
513+
Ext_S => 1, // > Zicsr
514+
Ext_Zaamo => 1, // > A
515+
Ext_Zalrsc => 1, // > A
516+
Ext_Zca => 1, // > C
517+
Ext_Zfinx => 1, // > Zicsr
518+
Ext_Zicntr => 1, // > Zicsr
519+
Ext_Zihpm => 1, // > Zicsr
520+
Ext_Zve32x => 1, // > Zvl32b
521+
522+
// Note: even though these match the default case, making them explicit to
523+
// annotate the chain of dependencies
524+
Ext_Sv39 => 2, // > S
525+
Ext_Zfh => 2, // > F
526+
Ext_Zhinx => 2, // > Zfinx
527+
Ext_Zvbb => 2, // > Zve32x
528+
Ext_Zve32f => 2, // > Zve32x
529+
Ext_Zve64x => 2, // > Zve32x
530+
531+
Ext_Svrsw60t59b => 3, // > Sv39
532+
Ext_Zfhmin => 3, // > Zfh
533+
Ext_Zhinxmin => 3, // > Zhinx
534+
Ext_Zicfilp => 3, // > get_xLPE
535+
Ext_Zvbc => 3, // > Zve64x
536+
Ext_Zve64f => 3, // > Zve64x
537+
Ext_Zvfbfmin => 3, // > Zve32f
538+
Ext_Zvkb => 3, // > Zvbb
539+
Ext_Zvknhb => 3, // > Zve64x
540+
541+
Ext_H => 4, // > virtual_mem_supported
542+
Ext_Zve64d => 4, // > Zve64f
543+
Ext_Zvfbfwma => 4, // > Zvfbfmin
544+
Ext_Zvfh => 4, // > Zfhmin
545+
546+
Ext_V => 5, // > Zve64d
547+
Ext_Zvfhmin => 5, // > Zvfh
548+
549+
_ => 2
550+
}
551+
552+
termination_measure currentlyEnabled(ext) = currentlyEnabled_measure(ext)
553+
477554
let extensions_ordered_for_isa_string = [
478555
// Single letter extensions.
479556
Ext_M,

model/core/sys_regs.sail

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ function virtual_memory_supported() -> bool = {
146146
currentlyEnabled(Ext_Sv32) | currentlyEnabled(Ext_Sv39) | currentlyEnabled(Ext_Sv48) | currentlyEnabled(Ext_Sv57)
147147
}
148148

149+
// This measure needs to be > currentlyEnabled_measure(Ext_Sv{32,39,48,57}),
150+
// currently all equal to 2, see currentlyEnabled_measure in extensions.sail
151+
termination_measure virtual_memory_supported(_) = 3
152+
149153
//
150154
// Illegal values legalized to least privileged mode supported.
151155
// Note: the only valid combinations of supported modes are M, M+U, M+S+U.

model/extensions/cfi/zicfilp_regs.sail

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

35+
// This measure needs to be > currentlyEnabled_measure(Ext_S), currently equal
36+
// to 1, see currentlyEnabled_measure in extensions.sail
37+
termination_measure get_xLPE(_) = 2
38+
3539
function clause currentlyEnabled(Ext_Zicfilp) =
3640
currentlyEnabled(Ext_Zicsr) & hartSupports(Ext_Zicfilp) & get_xLPE(cur_privilege)
3741

model/postlude/step.sail

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,13 @@ function loop () : unit -> unit = {
296296
}
297297
}
298298
}
299+
300+
// Termination measures for loops are not supported by the Lean backend, so they
301+
// should be guarded by this condition:
302+
$iftarget coq
303+
304+
// The top-level loop isn't terminating, but we put a limit so that it can still
305+
// be included in the Coq output
306+
termination_measure loop while 100
307+
308+
$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, extensions
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.sail

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ function pt_walk(
156156
}
157157
}
158158

159+
termination_measure pt_walk(_,_,_,_,_,_,_,level,_, _) = level
160+
159161
// ****************************************************************
160162
// Architectural SATP CSR
161163

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), MemoryAccessType(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), MemoryAccessType(ext_access_type), bool, bool, bool)
232236
-> result(bits(8 * 'width), ExecutionResult)

model/termination/termination.sail

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

0 commit comments

Comments
 (0)