Files
spl/stage2/sys/time.spl
T

50 lines
1.1 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Expect retcode = 0
// 时间/参考量接口(原生 vm_timestamp,case 探测风格,不假设一定可用)。
// available() -> 1 = 时间可用;0 = 不可用(其余 time 相关返回值恒为 0)
// sec() -> 当前秒
// ns() -> 当前纳秒部分
// steps() -> VM 已执行指令数(参考量)
// now_ns() -> 完整纳秒时间戳(单次调用;纪元纳秒 < 2^64,无需 i128)
#extern(vm) fn vm_timestamp(kind: usize): usize;
fn available(): usize {
ret vm_timestamp(0);
}
fn sec(): usize {
ret vm_timestamp(1);
}
fn ns(): usize {
ret vm_timestamp(2);
}
fn steps(): usize {
ret vm_timestamp(3);
}
fn calls(): usize {
ret vm_timestamp(5);
}
fn now_ns(): usize {
ret vm_timestamp(4);
}
fn main(): void {
var has = available();
if has != 0 {
var a = now_ns();
var b = now_ns();
@assert(b >= a, "now monotonic");
}
var s0 = steps();
var i: usize = 0;
while i < 1000 { i = i + 1; }
var s1 = steps();
@assert(s1 >= s0, "steps monotonic");
}