cc16cf0e5a391b94f562b52ef10df353c2b0a225
[power-instruction-analyzer.git] / src / main.rs
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 // See Notices.txt for copyright information
3
4 use power_instruction_analyzer::{DivInput, DivInstr, TestDivCase, WholeTest};
5
6 const TEST_VALUES: &[u64] = &[
7 0x0,
8 0x1,
9 0x2,
10 0xFFFF_FFFF_FFFF_FFFF,
11 0xFFFF_FFFF_FFFF_FFFE,
12 0x7FFF_FFFF_FFFF_FFFF,
13 0x8000_0000_0000_0000,
14 0x1234_5678_0000_0000,
15 0x1234_5678_8000_0000,
16 0x1234_5678_FFFF_FFFF,
17 0x1234_5678_7FFF_FFFF,
18 ];
19
20 fn main() {
21 let mut test_div_cases = Vec::new();
22 let mut any_model_mismatch = false;
23 for &instr in DivInstr::VALUES {
24 for &dividend in TEST_VALUES {
25 for &divisor in TEST_VALUES {
26 let inputs = DivInput {
27 dividend,
28 divisor,
29 result_prev: 0xFECD_BA98_7654_3210,
30 };
31 let model_outputs = instr.get_model_fn()(inputs);
32 #[cfg(feature = "native_instrs")]
33 let native_outputs = Some(instr.get_native_fn()(inputs));
34 #[cfg(not(feature = "native_instrs"))]
35 let native_outputs = None;
36 let model_mismatch = match native_outputs {
37 Some(native_outputs) if native_outputs != model_outputs => true,
38 _ => false,
39 };
40 any_model_mismatch |= model_mismatch;
41 test_div_cases.push(TestDivCase {
42 instr,
43 inputs,
44 native_outputs,
45 model_outputs,
46 model_mismatch,
47 });
48 }
49 }
50 }
51 let whole_test = WholeTest {
52 test_div_cases,
53 any_model_mismatch,
54 };
55 serde_json::to_writer_pretty(std::io::stdout().lock(), &whole_test).unwrap();
56 println!();
57 }