initial commit
[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 #![feature(llvm_asm)]
5
6 #[derive(Copy, Clone, Debug)]
7 struct TestDivResult {
8 result: u64,
9 overflow: bool,
10 overflow32: bool,
11 }
12
13 impl TestDivResult {
14 fn from_result_xer(result: u64, xer: u64) -> Self {
15 TestDivResult {
16 result,
17 overflow: (xer & 0x4000_0000) != 0,
18 overflow32: (xer & 0x8_0000) != 0,
19 }
20 }
21 }
22
23 #[derive(Copy, Clone, Debug)]
24 struct TestDivInput {
25 divisor: u64,
26 dividend: u64,
27 result_prev: u64,
28 }
29
30 macro_rules! make_div_fn {
31 ($name:ident) => {
32 impl TestDivInput {
33 fn $name(self) -> TestDivResult {
34 let Self {
35 divisor,
36 dividend,
37 result_prev,
38 } = self;
39 let result: u64;
40 let xer: u64;
41 unsafe {
42 llvm_asm!(
43 concat!(
44 stringify!($name),
45 " $0, $3, $4\n",
46 "mfxer $1"
47 )
48 : "=&r"(result), "=&r"(xer)
49 : "0"(result_prev), "r"(dividend), "r"(divisor)
50 : "xer");
51 }
52 TestDivResult::from_result_xer(result, xer)
53 }
54 }
55 };
56 }
57
58 make_div_fn!(divdo);
59
60 fn main() {
61 let inputs = TestDivInput {
62 divisor: 0,
63 dividend: 0,
64 result_prev: 0x123456789ABCDEF,
65 };
66 dbg!(inputs);
67 let outputs = inputs.divdo();
68 dbg!(outputs);
69 }