Skip to content

Commit a6903b1

Browse files
committed
Remove some unnecessary changes
1 parent 4397736 commit a6903b1

File tree

3 files changed

+67
-51
lines changed

3 files changed

+67
-51
lines changed

example/mini_core.rs

-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ pub mod intrinsics {
390390
pub fn needs_drop<T>() -> bool;
391391
pub fn bitreverse<T>(x: T) -> T;
392392
pub fn bswap<T>(x: T) -> T;
393-
pub fn unchecked_div<T>(lhs: T, rhs: T) -> T;
394393
}
395394
}
396395

example/std_example.rs

+59-17
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,65 @@
33
use std::io::Write;
44
use std::intrinsics;
55

6+
fn main() {
7+
let _ = ::std::iter::repeat('a' as u8).take(10).collect::<Vec<_>>();
8+
let stderr = ::std::io::stderr();
9+
let mut stderr = stderr.lock();
10+
11+
writeln!(stderr, "some {} text", "<unknown>").unwrap();
12+
13+
let _ = std::process::Command::new("true").env("c", "d").spawn();
14+
15+
println!("cargo:rustc-link-lib=z");
16+
17+
static ONCE: std::sync::Once = std::sync::ONCE_INIT;
18+
ONCE.call_once(|| {});
19+
20+
LoopState::Continue(()) == LoopState::Break(());
21+
22+
// Make sure ByValPair values with differently sized components are correctly passed
23+
map(None::<(u8, Box<Instruction>)>);
24+
25+
println!("{}", 2.3f32.exp());
26+
println!("{}", 2.3f32.exp2());
27+
println!("{}", 2.3f32.abs());
28+
println!("{}", 2.3f32.sqrt());
29+
println!("{}", 2.3f32.floor());
30+
println!("{}", 2.3f32.ceil());
31+
println!("{}", 2.3f32.min(1.0));
32+
println!("{}", 2.3f32.max(1.0));
33+
34+
assert_eq!(0b0000000000000000000000000010000010000000000000000000000000000000_0000000000100000000000000000000000001000000000000100000000000000u128.leading_zeros(), 26);
35+
assert_eq!(0b0000000000000000000000000010000000000000000000000000000000000000_0000000000000000000000000000000000001000000000000000000010000000u128.trailing_zeros(), 7);
36+
37+
checked_div_i128(0i128, 2i128);
38+
checked_div_u128(0u128, 2u128);
39+
assert_eq!(1u128 + 2, 3);
40+
41+
assert_eq!(0b100010000000000000000000000000000u128 >> 10, 0b10001000000000000000000u128);
42+
assert_eq!(0xFEDCBA987654321123456789ABCDEFu128 >> 64, 0xFEDCBA98765432u128);
43+
assert_eq!(0xFEDCBA987654321123456789ABCDEFu128 as i128 >> 64, 0xFEDCBA98765432i128);
44+
assert_eq!(353985398u128 * 932490u128, 330087843781020u128);
45+
}
46+
47+
#[derive(PartialEq)]
48+
enum LoopState {
49+
Continue(()),
50+
Break(())
51+
}
52+
53+
pub enum Instruction {
54+
Increment,
55+
Loop,
56+
}
57+
58+
fn map(a: Option<(u8, Box<Instruction>)>) -> Option<Box<Instruction>> {
59+
match a {
60+
None => None,
61+
Some((_, instr)) => Some(instr),
62+
}
63+
}
64+
665
fn checked_div_i128(lhs: i128, rhs: i128) -> Option<i128> {
766
if rhs == 0 || (lhs == -170141183460469231731687303715884105728 && rhs == -1) {
867
None
@@ -17,20 +76,3 @@ fn checked_div_u128(lhs: u128, rhs: u128) -> Option<u128> {
1776
rhs => Some(unsafe { intrinsics::unchecked_div(lhs, rhs) })
1877
}
1978
}
20-
21-
fn main() {
22-
assert_eq!(0b0000000000000000000000000010000010000000000000000000000000000000_0000000000100000000000000000000000001000000000000100000000000000u128.leading_zeros(), 26);
23-
assert_eq!(0b0000000000000000000000000010000000000000000000000000000000000000_0000000000000000000000000000000000001000000000000000000010000000u128.trailing_zeros(), 7);
24-
25-
checked_div_i128(0i128, 2i128);
26-
checked_div_u128(0u128, 2u128);
27-
assert_eq!(1u128 + 2, 3);
28-
29-
// overflow panic
30-
// 0xFEDCBA987654321123456789ABCDEFu128 + 0xFEDCBA987654321123456789ABCDEFu128;
31-
32-
println!("{}", 0b100010000000000000000000000000000u128 >> 10);
33-
println!("{}", 0xFEDCBA987654321123456789ABCDEFu128 >> 64);
34-
println!("{} >> 64 == {}", 0xFEDCBA987654321123456789ABCDEFu128 as i128, 0xFEDCBA987654321123456789ABCDEFu128 as i128 >> 64);
35-
println!("{}", 353985398u128 * 932490u128);
36-
}

src/value_and_place.rs

+8-33
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,6 @@ enum CValueInner {
3434
ByValPair(Value, Value),
3535
}
3636

37-
fn store_scalar<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx, impl Backend>, value: Value, addr: Value, offset: i32) {
38-
if fx.bcx.func.dfg.value_type(value) == types::I128 {
39-
let (a, b) = fx.bcx.ins().isplit(value);
40-
fx.bcx.ins().store(MemFlags::new(), a, addr, offset);
41-
fx.bcx.ins().store(MemFlags::new(), b, addr, offset + 8);
42-
} else {
43-
fx.bcx.ins().store(MemFlags::new(), value, addr, offset);
44-
}
45-
}
46-
47-
fn load_scalar<'a, 'tcx: 'a>(
48-
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
49-
clif_ty: Type,
50-
addr: Value,
51-
offset: i32,
52-
) -> Value {
53-
if clif_ty == types::I128 {
54-
let a = fx.bcx.ins().load(types::I64, MemFlags::new(), addr, offset);
55-
let b = fx.bcx.ins().load(types::I64, MemFlags::new(), addr, offset + 8);
56-
fx.bcx.ins().iconcat(a, b)
57-
} else {
58-
fx.bcx.ins().load(clif_ty, MemFlags::new(), addr, offset)
59-
}
60-
}
61-
6237
impl<'tcx> CValue<'tcx> {
6338
pub fn by_ref(value: Value, layout: TyLayout<'tcx>) -> CValue<'tcx> {
6439
CValue(CValueInner::ByRef(value), layout)
@@ -104,7 +79,7 @@ impl<'tcx> CValue<'tcx> {
10479
_ => unreachable!(),
10580
};
10681
let clif_ty = scalar_to_clif_type(fx.tcx, scalar);
107-
load_scalar(fx, clif_ty, addr, 0)
82+
fx.bcx.ins().load(clif_ty, MemFlags::new(), addr, 0)
10883
}
10984
CValueInner::ByVal(value) => value,
11085
CValueInner::ByValPair(_, _) => bug!("Please use load_scalar_pair for ByValPair"),
@@ -126,10 +101,10 @@ impl<'tcx> CValue<'tcx> {
126101
let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar);
127102
let clif_ty1 = scalar_to_clif_type(fx.tcx, a_scalar.clone());
128103
let clif_ty2 = scalar_to_clif_type(fx.tcx, b_scalar.clone());
129-
let val1 = load_scalar(fx, clif_ty1, addr, 0);
130-
let val2 = load_scalar(
131-
fx,
104+
let val1 = fx.bcx.ins().load(clif_ty1, MemFlags::new(), addr, 0);
105+
let val2 = fx.bcx.ins().load(
132106
clif_ty2,
107+
MemFlags::new(),
133108
addr,
134109
b_offset,
135110
);
@@ -389,15 +364,15 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
389364

390365
match from.0 {
391366
CValueInner::ByVal(val) => {
392-
store_scalar(fx, val, addr, 0);
367+
fx.bcx.ins().store(MemFlags::new(), val, addr, 0);
393368
}
394369
CValueInner::ByValPair(value, extra) => {
395370
match dst_layout.abi {
396371
Abi::ScalarPair(ref a_scalar, ref b_scalar) => {
397372
let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar);
398-
store_scalar(fx, value, addr, 0);
399-
store_scalar(
400-
fx,
373+
fx.bcx.ins().store(MemFlags::new(), value, addr, 0);
374+
fx.bcx.ins().store(
375+
MemFlags::new(),
401376
extra,
402377
addr,
403378
b_offset,

0 commit comments

Comments
 (0)