Skip to content

Commit 783430e

Browse files
committed
Replace {u,i}128_* lang items with __rust_{u,i}128_* unmangled functions
The -Zlower-128bit-ops feature is completely broken, as libcore needs those lang items to compile with this feature, but they are only provided by compiler_builtins, which itself depends on libcore. According to rust-lang/rust#58969 the feature never got finished. This commit removes the associated lang items and replaces them with normal unmangled functions, when there is no existing intrinsic. This makes it easier for alternative codegen backends to implement 128bit integer support.
1 parent 5e06435 commit 783430e

File tree

6 files changed

+31
-99
lines changed

6 files changed

+31
-99
lines changed

src/int/addsub.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,44 +90,43 @@ where
9090
impl Subo for i128 {}
9191
impl Subo for u128 {}
9292

93-
u128_lang_items! {
94-
#[lang = "i128_add"]
95-
pub fn rust_i128_add(a: i128, b: i128) -> i128 {
96-
rust_u128_add(a as _, b as _) as _
93+
intrinsics! {
94+
pub extern "C" fn __rust_i128_add(a: i128, b: i128) -> i128 {
95+
__rust_u128_add(a as _, b as _) as _
9796
}
98-
#[lang = "i128_addo"]
99-
pub fn rust_i128_addo(a: i128, b: i128) -> (i128, bool) {
97+
98+
pub extern "C" fn __rust_i128_addo(a: i128, b: i128) -> (i128, bool) {
10099
let mut oflow = 0;
101100
let r = a.addo(b, &mut oflow);
102101
(r, oflow != 0)
103102
}
104-
#[lang = "u128_add"]
105-
pub fn rust_u128_add(a: u128, b: u128) -> u128 {
103+
104+
pub extern "C" fn __rust_u128_add(a: u128, b: u128) -> u128 {
106105
a.add(b)
107106
}
108-
#[lang = "u128_addo"]
109-
pub fn rust_u128_addo(a: u128, b: u128) -> (u128, bool) {
107+
108+
pub extern "C" fn __rust_u128_addo(a: u128, b: u128) -> (u128, bool) {
110109
let mut oflow = 0;
111110
let r = a.addo(b, &mut oflow);
112111
(r, oflow != 0)
113112
}
114113

115-
#[lang = "i128_sub"]
116-
pub fn rust_i128_sub(a: i128, b: i128) -> i128 {
117-
rust_u128_sub(a as _, b as _) as _
114+
115+
pub extern "C" fn __rust_i128_sub(a: i128, b: i128) -> i128 {
116+
__rust_u128_sub(a as _, b as _) as _
118117
}
119-
#[lang = "i128_subo"]
120-
pub fn rust_i128_subo(a: i128, b: i128) -> (i128, bool) {
118+
119+
pub extern "C" fn __rust_i128_subo(a: i128, b: i128) -> (i128, bool) {
121120
let mut oflow = 0;
122121
let r = a.subo(b, &mut oflow);
123122
(r, oflow != 0)
124123
}
125-
#[lang = "u128_sub"]
126-
pub fn rust_u128_sub(a: u128, b: u128) -> u128 {
124+
125+
pub extern "C" fn __rust_u128_sub(a: u128, b: u128) -> u128 {
127126
a.sub(b)
128127
}
129-
#[lang = "u128_subo"]
130-
pub fn rust_u128_subo(a: u128, b: u128) -> (u128, bool) {
128+
129+
pub extern "C" fn __rust_u128_subo(a: u128, b: u128) -> (u128, bool) {
131130
let mut oflow = 0;
132131
let r = a.subo(b, &mut oflow);
133132
(r, oflow != 0)

src/int/mul.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,14 @@ intrinsics! {
107107
pub extern "C" fn __muloti4(a: i128, b: i128, oflow: &mut i32) -> i128 {
108108
a.mulo(b, oflow)
109109
}
110-
}
111110

112-
u128_lang_items! {
113-
#[lang = "i128_mul"]
114-
pub fn rust_i128_mul(a: i128, b: i128) -> i128 {
115-
__multi3(a, b)
116-
}
117-
#[lang = "i128_mulo"]
118-
pub fn rust_i128_mulo(a: i128, b: i128) -> (i128, bool) {
111+
pub extern "C" fn __rust_i128_mulo(a: i128, b: i128) -> (i128, bool) {
119112
let mut oflow = 0;
120113
let r = __muloti4(a, b, &mut oflow);
121114
(r, oflow != 0)
122115
}
123-
#[lang = "u128_mul"]
124-
pub fn rust_u128_mul(a: u128, b: u128) -> u128 {
125-
__multi3(a as _, b as _) as _
126-
}
127-
#[lang = "u128_mulo"]
128-
pub fn rust_u128_mulo(a: u128, b: u128) -> (u128, bool) {
116+
117+
pub extern "C" fn __rust_u128_mulo(a: u128, b: u128) -> (u128, bool) {
129118
let mut oflow = 0;
130119
let r = a.mulo(b, &mut oflow);
131120
(r, oflow != 0)

src/int/sdiv.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,3 @@ intrinsics! {
9999
a.divmod(b, rem, |a, b| __divdi3(a, b))
100100
}
101101
}
102-
103-
u128_lang_items! {
104-
#[lang = "i128_div"]
105-
pub fn rust_i128_div(a: i128, b: i128) -> i128 {
106-
__divti3(a, b)
107-
}
108-
#[lang = "i128_rem"]
109-
pub fn rust_i128_rem(a: i128, b: i128) -> i128 {
110-
__modti3(a, b)
111-
}
112-
}

src/int/shift.rs

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -103,40 +103,20 @@ intrinsics! {
103103
pub extern "C" fn __lshrti3(a: u128, b: u32) -> u128 {
104104
a.lshr(b)
105105
}
106-
}
107106

108-
u128_lang_items! {
109-
#[lang = "i128_shl"]
110-
pub fn rust_i128_shl(a: i128, b: u32) -> i128 {
111-
__ashlti3(a as _, b) as _
112-
}
113-
#[lang = "i128_shlo"]
114-
pub fn rust_i128_shlo(a: i128, b: u128) -> (i128, bool) {
115-
(rust_i128_shl(a, b as _), b >= 128)
116-
}
117-
#[lang = "u128_shl"]
118-
pub fn rust_u128_shl(a: u128, b: u32) -> u128 {
119-
__ashlti3(a, b)
120-
}
121-
#[lang = "u128_shlo"]
122-
pub fn rust_u128_shlo(a: u128, b: u128) -> (u128, bool) {
123-
(rust_u128_shl(a, b as _), b >= 128)
107+
pub extern "C" fn __rust_i128_shlo(a: i128, b: u128) -> (i128, bool) {
108+
(__ashlti3(a as _, b as _) as _, b >= 128)
124109
}
125110

126-
#[lang = "i128_shr"]
127-
pub fn rust_i128_shr(a: i128, b: u32) -> i128 {
128-
__ashrti3(a, b)
111+
pub extern "C" fn __rust_u128_shlo(a: u128, b: u128) -> (u128, bool) {
112+
(__ashlti3(a, b as _), b >= 128)
129113
}
130-
#[lang = "i128_shro"]
131-
pub fn rust_i128_shro(a: i128, b: u128) -> (i128, bool) {
132-
(rust_i128_shr(a, b as _), b >= 128)
133-
}
134-
#[lang = "u128_shr"]
135-
pub fn rust_u128_shr(a: u128, b: u32) -> u128 {
136-
__lshrti3(a, b)
114+
115+
pub extern "C" fn __rust_i128_shro(a: i128, b: u128) -> (i128, bool) {
116+
(__ashrti3(a, b as _), b >= 128)
137117
}
138-
#[lang = "u128_shro"]
139-
pub fn rust_u128_shro(a: u128, b: u128) -> (u128, bool) {
140-
(rust_u128_shr(a, b as _), b >= 128)
118+
119+
pub extern "C" fn __rust_u128_shro(a: u128, b: u128) -> (u128, bool) {
120+
(__lshrti3(a, b as _), b >= 128)
141121
}
142122
}

src/int/udiv.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,3 @@ intrinsics! {
268268
udivmod_inner!(n, d, rem, u128)
269269
}
270270
}
271-
272-
u128_lang_items! {
273-
#[lang = "u128_div"]
274-
pub fn rust_u128_div(a: u128, b: u128) -> u128 {
275-
__udivti3(a, b)
276-
}
277-
#[lang = "u128_rem"]
278-
pub fn rust_u128_rem(a: u128, b: u128) -> u128 {
279-
__umodti3(a, b)
280-
}
281-
}

src/macros.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -280,17 +280,3 @@ pub mod win64_128bit_abi_hack {
280280
}
281281
}
282282
}
283-
284-
macro_rules! u128_lang_items {
285-
($(
286-
#[lang = $lang:tt]
287-
pub fn $name:ident( $($argname:ident: $ty:ty),* ) -> $ret:ty {
288-
$($body:tt)*
289-
}
290-
)*) => ($(
291-
#[cfg_attr(not(any(stage0, feature = "no-lang-items")), lang = $lang)]
292-
pub fn $name( $($argname: $ty),* ) -> $ret {
293-
$($body)*
294-
}
295-
)*)
296-
}

0 commit comments

Comments
 (0)