-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrust_e2e_arith.rs
More file actions
83 lines (67 loc) · 1.46 KB
/
Copy pathrust_e2e_arith.rs
File metadata and controls
83 lines (67 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#![no_std]
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}
#[no_mangle]
pub extern "C" fn add_i32(a: i32, b: i32) -> i32 {
a.wrapping_add(b)
}
#[no_mangle]
pub extern "C" fn sum_recursive(n: i32) -> i32 {
if n <= 0 {
0
} else {
n + sum_recursive(n - 1)
}
}
include!("common/fibo.rs");
#[no_mangle]
pub extern "C" fn fibo(n: i32) -> i32 {
fibo_impl(n)
}
#[no_mangle]
pub extern "C" fn sub_i32(a: i32, b: i32) -> i32 {
a.wrapping_sub(b)
}
#[no_mangle]
pub extern "C" fn mul_i32(a: i32, b: i32) -> i32 {
a.wrapping_mul(b)
}
#[no_mangle]
pub extern "C" fn add_i64(a: i64, b: i64) -> i64 {
a.wrapping_add(b)
}
#[no_mangle]
pub extern "C" fn bitwise_and(a: i32, b: i32) -> i32 {
a & b
}
#[no_mangle]
pub extern "C" fn bitwise_or(a: i32, b: i32) -> i32 {
a | b
}
#[no_mangle]
pub extern "C" fn bitwise_xor(a: i32, b: i32) -> i32 {
a ^ b
}
#[no_mangle]
pub extern "C" fn shift_left(a: i32, b: i32) -> i32 {
a.wrapping_shl(b as u32)
}
#[no_mangle]
pub extern "C" fn shift_right_u(a: i32, b: i32) -> i32 {
((a as u32).wrapping_shr(b as u32)) as i32
}
#[no_mangle]
pub extern "C" fn negate(a: i32) -> i32 {
a.wrapping_neg()
}
#[no_mangle]
pub extern "C" fn const_42() -> i32 {
42
}
/// (a + b) * (a - b) — tests that LLVM composes multiple operations.
#[no_mangle]
pub extern "C" fn diff_of_squares(a: i32, b: i32) -> i32 {
a.wrapping_add(b).wrapping_mul(a.wrapping_sub(b))
}