Skip to content

Commit c03e824

Browse files
committed
Patch 128bit usage away
1 parent d363ab2 commit c03e824

File tree

4 files changed

+225
-7
lines changed

4 files changed

+225
-7
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
From 449b92a496a239dbadb5137dac77e34d726ddec4 Mon Sep 17 00:00:00 2001
2+
From: bjorn3 <[email protected]>
3+
Date: Tue, 14 Apr 2020 14:53:34 +0200
4+
Subject: [PATCH] Patch 128bit usage away
5+
6+
---
7+
src/libcore/convert/num.rs | 28 ++++++++++++++--------------
8+
src/libcore/num/mod.rs | 8 ++++----
9+
src/libcore/sync/atomic.rs | 4 ++--
10+
3 files changed, 20 insertions(+), 20 deletions(-)
11+
12+
diff --git a/src/libcore/convert/num.rs b/src/libcore/convert/num.rs
13+
index 66ae760..3913060 100644
14+
--- a/src/libcore/convert/num.rs
15+
+++ b/src/libcore/convert/num.rs
16+
@@ -373,13 +373,13 @@ mod ptr_try_from_impls {
17+
}
18+
19+
// Conversion traits for non-zero integer types
20+
-use crate::num::NonZeroI128;
21+
+//use crate::num::NonZeroI128;
22+
use crate::num::NonZeroI16;
23+
use crate::num::NonZeroI32;
24+
use crate::num::NonZeroI64;
25+
use crate::num::NonZeroI8;
26+
use crate::num::NonZeroIsize;
27+
-use crate::num::NonZeroU128;
28+
+//use crate::num::NonZeroU128;
29+
use crate::num::NonZeroU16;
30+
use crate::num::NonZeroU32;
31+
use crate::num::NonZeroU64;
32+
@@ -416,39 +416,39 @@ macro_rules! nzint_impl_from {
33+
nzint_impl_from! { NonZeroU8, NonZeroU16, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
34+
nzint_impl_from! { NonZeroU8, NonZeroU32, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
35+
nzint_impl_from! { NonZeroU8, NonZeroU64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
36+
-nzint_impl_from! { NonZeroU8, NonZeroU128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
37+
+//nzint_impl_from! { NonZeroU8, NonZeroU128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
38+
nzint_impl_from! { NonZeroU8, NonZeroUsize, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
39+
nzint_impl_from! { NonZeroU16, NonZeroU32, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
40+
nzint_impl_from! { NonZeroU16, NonZeroU64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
41+
-nzint_impl_from! { NonZeroU16, NonZeroU128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
42+
+//nzint_impl_from! { NonZeroU16, NonZeroU128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
43+
nzint_impl_from! { NonZeroU16, NonZeroUsize, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
44+
nzint_impl_from! { NonZeroU32, NonZeroU64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
45+
-nzint_impl_from! { NonZeroU32, NonZeroU128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
46+
-nzint_impl_from! { NonZeroU64, NonZeroU128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
47+
+//nzint_impl_from! { NonZeroU32, NonZeroU128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
48+
+//nzint_impl_from! { NonZeroU64, NonZeroU128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
49+
50+
// Non-zero Signed -> Non-zero Signed
51+
nzint_impl_from! { NonZeroI8, NonZeroI16, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
52+
nzint_impl_from! { NonZeroI8, NonZeroI32, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
53+
nzint_impl_from! { NonZeroI8, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
54+
-nzint_impl_from! { NonZeroI8, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
55+
+//nzint_impl_from! { NonZeroI8, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
56+
nzint_impl_from! { NonZeroI8, NonZeroIsize, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
57+
nzint_impl_from! { NonZeroI16, NonZeroI32, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
58+
nzint_impl_from! { NonZeroI16, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
59+
-nzint_impl_from! { NonZeroI16, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
60+
+//nzint_impl_from! { NonZeroI16, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
61+
nzint_impl_from! { NonZeroI16, NonZeroIsize, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
62+
nzint_impl_from! { NonZeroI32, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
63+
-nzint_impl_from! { NonZeroI32, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
64+
-nzint_impl_from! { NonZeroI64, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
65+
+//nzint_impl_from! { NonZeroI32, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
66+
+//nzint_impl_from! { NonZeroI64, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
67+
68+
// NonZero UnSigned -> Non-zero Signed
69+
nzint_impl_from! { NonZeroU8, NonZeroI16, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
70+
nzint_impl_from! { NonZeroU8, NonZeroI32, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
71+
nzint_impl_from! { NonZeroU8, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
72+
-nzint_impl_from! { NonZeroU8, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
73+
+//nzint_impl_from! { NonZeroU8, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
74+
nzint_impl_from! { NonZeroU8, NonZeroIsize, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
75+
nzint_impl_from! { NonZeroU16, NonZeroI32, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
76+
nzint_impl_from! { NonZeroU16, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
77+
-nzint_impl_from! { NonZeroU16, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
78+
+//nzint_impl_from! { NonZeroU16, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
79+
nzint_impl_from! { NonZeroU32, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
80+
-nzint_impl_from! { NonZeroU32, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
81+
-nzint_impl_from! { NonZeroU64, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
82+
+//nzint_impl_from! { NonZeroU32, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
83+
+//nzint_impl_from! { NonZeroU64, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
84+
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs
85+
index 7ba4004..560ea38 100644
86+
--- a/src/libcore/num/mod.rs
87+
+++ b/src/libcore/num/mod.rs
88+
@@ -122,13 +122,13 @@ nonzero_integers! {
89+
#[stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16);
90+
#[stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32);
91+
#[stable(feature = "nonzero", since = "1.28.0")] NonZeroU64(u64);
92+
- #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU128(u128);
93+
+ //#[stable(feature = "nonzero", since = "1.28.0")] NonZeroU128(u128);
94+
#[stable(feature = "nonzero", since = "1.28.0")] NonZeroUsize(usize);
95+
#[stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI8(i8);
96+
#[stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI16(i16);
97+
#[stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI32(i32);
98+
#[stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI64(i64);
99+
- #[stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI128(i128);
100+
+ //#[stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI128(i128);
101+
#[stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroIsize(isize);
102+
}
103+
104+
@@ -147,8 +147,8 @@ macro_rules! from_str_radix_nzint_impl {
105+
)*}
106+
}
107+
108+
-from_str_radix_nzint_impl! { NonZeroU8 NonZeroU16 NonZeroU32 NonZeroU64 NonZeroU128 NonZeroUsize
109+
-NonZeroI8 NonZeroI16 NonZeroI32 NonZeroI64 NonZeroI128 NonZeroIsize }
110+
+from_str_radix_nzint_impl! { NonZeroU8 NonZeroU16 NonZeroU32 NonZeroU64 NonZeroUsize
111+
+NonZeroI8 NonZeroI16 NonZeroI32 NonZeroI64 NonZeroIsize }
112+
113+
/// Provides intentionally-wrapped arithmetic on `T`.
114+
///
115+
diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs
116+
index 220f221..134d8b1 100644
117+
--- a/src/libcore/sync/atomic.rs
118+
+++ b/src/libcore/sync/atomic.rs
119+
@@ -2152,7 +2152,7 @@ atomic_int! {
120+
"AtomicU64::new(0)",
121+
u64 AtomicU64 ATOMIC_U64_INIT
122+
}
123+
-#[cfg(target_has_atomic_load_store = "128")]
124+
+/*#[cfg(target_has_atomic_load_store = "128")]
125+
atomic_int! {
126+
cfg(target_has_atomic = "128"),
127+
unstable(feature = "integer_atomics", issue = "32976"),
128+
@@ -2187,7 +2187,7 @@ atomic_int! {
129+
16,
130+
"AtomicU128::new(0)",
131+
u128 AtomicU128 ATOMIC_U128_INIT
132+
-}
133+
+}*/
134+
#[cfg(target_has_atomic_load_store = "ptr")]
135+
#[cfg(target_pointer_width = "16")]
136+
macro_rules! ptr_width {
137+
--
138+
2.20.1
139+

src/base.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,85 @@ pub(crate) fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
1212

1313
let mir = *tcx.instance_mir(instance.def);
1414

15+
// Check fn sig for u128 and i128 and replace those functions with a trap.
16+
{
17+
// FIXME implement u128 and i128 support
18+
19+
// Check sig for u128 and i128
20+
let fn_sig = tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &crate::abi::fn_sig_for_fn_abi(tcx, instance));
21+
22+
struct UI128Visitor<'tcx>(TyCtxt<'tcx>, bool);
23+
24+
impl<'tcx> rustc_middle::ty::fold::TypeVisitor<'tcx> for UI128Visitor<'tcx> {
25+
fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {
26+
if t.kind == self.0.types.u128.kind || t.kind == self.0.types.i128.kind {
27+
self.1 = true;
28+
return false; // stop visiting
29+
}
30+
31+
t.super_visit_with(self)
32+
}
33+
}
34+
35+
let mut visitor = UI128Visitor(tcx, false);
36+
fn_sig.visit_with(&mut visitor);
37+
38+
//If found replace function with a trap.
39+
if visitor.1 {
40+
tcx.sess.warn("u128 and i128 are not yet supported. \
41+
Functions using these as args will be replaced with a trap.");
42+
43+
// Declare function with fake signature
44+
let sig = Signature {
45+
params: vec![],
46+
returns: vec![],
47+
call_conv: CallConv::Fast,
48+
};
49+
let name = tcx.symbol_name(instance).name.as_str();
50+
let func_id = cx.module.declare_function(&*name, linkage, &sig).unwrap();
51+
52+
// Create trapping function
53+
let mut func = Function::with_name_signature(ExternalName::user(0, 0), sig);
54+
let mut func_ctx = FunctionBuilderContext::new();
55+
let mut bcx = FunctionBuilder::new(&mut func, &mut func_ctx);
56+
let start_ebb = bcx.create_block();
57+
bcx.append_block_params_for_function_params(start_ebb);
58+
bcx.switch_to_block(start_ebb);
59+
60+
let mut fx = FunctionCx {
61+
tcx,
62+
module: cx.module,
63+
pointer_type: pointer_ty(tcx),
64+
65+
instance,
66+
mir,
67+
68+
bcx,
69+
block_map: IndexVec::default(),
70+
local_map: FxHashMap::default(),
71+
72+
clif_comments: crate::pretty_clif::CommentWriter::new(tcx, instance),
73+
source_info_set: indexmap::IndexSet::new(),
74+
caller_location: None,
75+
cold_blocks: EntitySet::new(),
76+
constants_cx: &mut cx.constants_cx,
77+
vtables: &mut cx.vtables,
78+
};
79+
80+
crate::trap::trap_unreachable(&mut fx, "[unimplemented] Called function with u128 or i128 as argument.");
81+
fx.bcx.seal_all_blocks();
82+
fx.bcx.finalize();
83+
84+
// Define function
85+
cx.cached_context.func = func;
86+
cx.module
87+
.define_function(func_id, &mut cx.cached_context, &mut cranelift_codegen::binemit::NullTrapSink {})
88+
.unwrap();
89+
cx.cached_context.clear();
90+
return;
91+
}
92+
}
93+
1594
// Declare function
1695
let (name, sig) = get_function_name_and_sig(tcx, cx.module.isa().triple(), instance, false);
1796
let func_id = cx.module.declare_function(&name, linkage, &sig).unwrap();

src/common.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(crate) fn scalar_to_clif_type(tcx: TyCtxt<'_>, scalar: Scalar) -> Type {
2626
Integer::I16 => types::I16,
2727
Integer::I32 => types::I32,
2828
Integer::I64 => types::I64,
29-
Integer::I128 => types::I128,
29+
Integer::I128 => todo!(),
3030
},
3131
Primitive::F32 => types::F32,
3232
Primitive::F64 => types::F64,
@@ -42,15 +42,15 @@ fn clif_type_from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<types::Typ
4242
UintTy::U16 => types::I16,
4343
UintTy::U32 => types::I32,
4444
UintTy::U64 => types::I64,
45-
UintTy::U128 => types::I128,
45+
UintTy::U128 => todo!(),
4646
UintTy::Usize => pointer_ty(tcx),
4747
},
4848
ty::Int(size) => match size {
4949
IntTy::I8 => types::I8,
5050
IntTy::I16 => types::I16,
5151
IntTy::I32 => types::I32,
5252
IntTy::I64 => types::I64,
53-
IntTy::I128 => types::I128,
53+
IntTy::I128 => todo!(),
5454
IntTy::Isize => pointer_ty(tcx),
5555
},
5656
ty::Char => types::I32,

src/driver/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ fn codegen_mono_items<'tcx>(
4141
for &(mono_item, (linkage, visibility)) in &mono_items {
4242
match mono_item {
4343
MonoItem::Fn(instance) => {
44-
let (name, sig) =
45-
get_function_name_and_sig(tcx, cx.module.isa().triple(), instance, false);
46-
let linkage = crate::linkage::get_clif_linkage(mono_item, linkage, visibility);
47-
cx.module.declare_function(&name, linkage, &sig).unwrap();
44+
//let (name, sig) =
45+
// get_function_name_and_sig(tcx, cx.module.isa().triple(), instance, false);
46+
//let linkage = crate::linkage::get_clif_linkage(mono_item, linkage, visibility);
47+
//cx.module.declare_function(&name, linkage, &sig).unwrap();
4848
}
4949
MonoItem::Static(_) | MonoItem::GlobalAsm(_) => {}
5050
}

0 commit comments

Comments
 (0)