feat(vm): add deterministic gameplay math and domain coverage gates
Intrepid/Prometeu/Runtime/pipeline/pr-master There was a failure building this commit
Intrepid/Prometeu/Runtime/pipeline/pr-master There was a failure building this commit
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
fn main() {
|
||||
if std::env::args().nth(1).as_deref() == Some("constants") {
|
||||
print!("{}", prometeu_vm::builtin_constant_catalog_csv());
|
||||
} else {
|
||||
print!("{}", prometeu_vm::intrinsic_catalog_csv());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
//! Local host timing only; these measurements never define guest cycles.
|
||||
use prometeu_bytecode::Value;
|
||||
use prometeu_vm::{HostContext, lookup_intrinsic_by_id};
|
||||
use std::hint::black_box;
|
||||
use std::time::Instant;
|
||||
fn main() {
|
||||
let iterations: u32 =
|
||||
std::env::args().nth(1).unwrap_or_else(|| "20000".into()).parse().unwrap();
|
||||
for (id, args) in [
|
||||
(0x3010, vec![Value::Float(2.)]),
|
||||
(0x3011, vec![Value::Float(f64::from_bits(0x6974e718d7d7625a))]),
|
||||
(0x3012, vec![Value::Float(f64::from_bits(0x7fefffffffffffff))]),
|
||||
(0x3013, vec![Value::Float(1.), Value::Float(3.)]),
|
||||
(0x1000, vec![Value::Float(1.), Value::Float(2.), Value::Float(3.), Value::Float(4.)]),
|
||||
(0x1001, vec![Value::Float(1e200), Value::Float(1e200)]),
|
||||
] {
|
||||
let m = lookup_intrinsic_by_id(id).unwrap();
|
||||
let mut ctx = HostContext::new(None);
|
||||
for _ in 0..100 {
|
||||
black_box((m.implementation)(black_box(&args), &mut ctx).unwrap());
|
||||
}
|
||||
let start = Instant::now();
|
||||
for _ in 0..iterations {
|
||||
black_box((m.implementation)(black_box(&args), &mut ctx).unwrap());
|
||||
}
|
||||
let elapsed = start.elapsed().as_nanos();
|
||||
println!(
|
||||
"{}.{} iterations={} total_ns={} ns_per_call={:.2} virtual_cycles={}",
|
||||
m.owner,
|
||||
m.name,
|
||||
iterations,
|
||||
elapsed,
|
||||
elapsed as f64 / f64::from(iterations),
|
||||
m.cost_cycles
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
//! Reproducible bit-level probe for independent tooling; not a cartridge dependency.
|
||||
//! stdin: intrinsic hex ID followed by f:bits / i:decimal / l:decimal.
|
||||
//! Arithmetic opcode names ADD/SUB/MUL/DIV execute a validated PBX program.
|
||||
use prometeu_bytecode::{Value, assemble};
|
||||
use prometeu_hal::vm_fault::VmFault;
|
||||
use prometeu_vm::{
|
||||
HostContext, HostReturn, LogicalFrameEndingReason, NativeInterface, VirtualMachine,
|
||||
lookup_intrinsic_by_id,
|
||||
};
|
||||
use std::io::{self, BufRead};
|
||||
struct NoNative;
|
||||
impl NativeInterface for NoNative {
|
||||
fn syscall(
|
||||
&mut self,
|
||||
_: u32,
|
||||
_: &[Value],
|
||||
_: &mut HostReturn,
|
||||
_: &mut HostContext,
|
||||
) -> Result<(), VmFault> {
|
||||
panic!("no native call in numeric probe")
|
||||
}
|
||||
}
|
||||
fn text(value: &Value) -> String {
|
||||
match value {
|
||||
Value::Float(x) => format!("f:{:016x}", x.to_bits()),
|
||||
Value::Int32(x) => format!("i:{x}"),
|
||||
Value::Int64(x) => format!("l:{x}"),
|
||||
_ => panic!("numeric output"),
|
||||
}
|
||||
}
|
||||
fn main() {
|
||||
for line in io::stdin().lock().lines() {
|
||||
let line = line.unwrap();
|
||||
let mut words = line.split_whitespace();
|
||||
let op = words.next().unwrap();
|
||||
let args: Vec<_> = words
|
||||
.map(|s| {
|
||||
let (kind, v) = s.split_once(':').unwrap();
|
||||
match kind {
|
||||
"f" => Value::Float(f64::from_bits(u64::from_str_radix(v, 16).unwrap())),
|
||||
"i" => Value::Int32(v.parse().unwrap()),
|
||||
"l" => Value::Int64(v.parse().unwrap()),
|
||||
_ => panic!("carrier"),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
if !matches!(op, "ADD" | "SUB" | "MUL" | "DIV") {
|
||||
let id = u32::from_str_radix(op, 16).unwrap();
|
||||
let m = lookup_intrinsic_by_id(id).unwrap();
|
||||
match (m.implementation)(&args, &mut HostContext::new(None)) {
|
||||
Ok(v) => println!("{} {}", text(&v[0]), m.cost_cycles),
|
||||
Err(prometeu_vm::IntrinsicExecutionError::Numeric(e)) => {
|
||||
println!("trap:{:x} {}", e.code, m.cost_cycles)
|
||||
}
|
||||
Err(e) => panic!("{e:?}"),
|
||||
}
|
||||
} else {
|
||||
let mut source = String::new();
|
||||
for v in args {
|
||||
source.push_str(&match v {
|
||||
Value::Float(x) => format!("PUSH_F64 f64:0x{:016x}\n", x.to_bits()),
|
||||
Value::Int32(x) => format!("PUSH_I32 {x}\n"),
|
||||
Value::Int64(x) => format!("PUSH_I64 {x}\n"),
|
||||
_ => unreachable!(),
|
||||
});
|
||||
}
|
||||
source.push_str(op);
|
||||
source.push_str("\nHALT");
|
||||
let bytes = prometeu_test_support::program::TestProgram::single(
|
||||
assemble(&source).unwrap(),
|
||||
Default::default(),
|
||||
0,
|
||||
8,
|
||||
)
|
||||
.serialize();
|
||||
let mut vm = VirtualMachine::default();
|
||||
vm.initialize(bytes).unwrap();
|
||||
vm.prepare_call("0").unwrap();
|
||||
let r = vm.run_budget(100, &mut NoNative, &mut HostContext::new(None)).unwrap();
|
||||
match r.reason {
|
||||
LogicalFrameEndingReason::Halted => {
|
||||
println!("{} {}", text(&vm.operand_stack_top(1)[0]), r.cycles_used)
|
||||
}
|
||||
LogicalFrameEndingReason::Trap(e) => {
|
||||
println!("trap:{:x} {}", e.code, r.cycles_used)
|
||||
}
|
||||
e => panic!("{e:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user