Skip to content

Commit 6fae6e5

Browse files
committed
Add a bunch of rustc_nounwind for c_unwind
1 parent 351d48e commit 6fae6e5

File tree

9 files changed

+61
-9
lines changed

9 files changed

+61
-9
lines changed

src/float/conv.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
///
66
/// The algorithm is explained here: <https://blog.m-ou.se/floats/>
77
mod int_to_float {
8+
#[rustc_nounwind]
89
pub fn u32_to_f32_bits(i: u32) -> u32 {
910
if i == 0 {
1011
return 0;
@@ -17,6 +18,7 @@ mod int_to_float {
1718
(e << 23) + m // + not |, so the mantissa can overflow into the exponent.
1819
}
1920

21+
#[rustc_nounwind]
2022
pub fn u32_to_f64_bits(i: u32) -> u64 {
2123
if i == 0 {
2224
return 0;
@@ -27,6 +29,7 @@ mod int_to_float {
2729
(e << 52) + m // Bit 53 of m will overflow into e.
2830
}
2931

32+
#[rustc_nounwind]
3033
pub fn u64_to_f32_bits(i: u64) -> u32 {
3134
let n = i.leading_zeros();
3235
let y = i.wrapping_shl(n);
@@ -37,6 +40,7 @@ mod int_to_float {
3740
(e << 23) + m // + not |, so the mantissa can overflow into the exponent.
3841
}
3942

43+
#[rustc_nounwind]
4044
pub fn u64_to_f64_bits(i: u64) -> u64 {
4145
if i == 0 {
4246
return 0;
@@ -49,6 +53,7 @@ mod int_to_float {
4953
(e << 52) + m // + not |, so the mantissa can overflow into the exponent.
5054
}
5155

56+
#[rustc_nounwind]
5257
pub fn u128_to_f32_bits(i: u128) -> u32 {
5358
let n = i.leading_zeros();
5459
let y = i.wrapping_shl(n);
@@ -59,6 +64,7 @@ mod int_to_float {
5964
(e << 23) + m // + not |, so the mantissa can overflow into the exponent.
6065
}
6166

67+
#[rustc_nounwind]
6268
pub fn u128_to_f64_bits(i: u128) -> u64 {
6369
let n = i.leading_zeros();
6470
let y = i.wrapping_shl(n);

src/float/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,41 +120,51 @@ macro_rules! float_impl {
120120
const IMPLICIT_BIT: Self::Int = 1 << Self::SIGNIFICAND_BITS;
121121
const EXPONENT_MASK: Self::Int = !(Self::SIGN_MASK | Self::SIGNIFICAND_MASK);
122122

123+
#[rustc_nounwind]
123124
fn repr(self) -> Self::Int {
124125
self.to_bits()
125126
}
127+
#[rustc_nounwind]
126128
fn signed_repr(self) -> Self::SignedInt {
127129
self.to_bits() as Self::SignedInt
128130
}
131+
#[rustc_nounwind]
129132
fn eq_repr(self, rhs: Self) -> bool {
130133
if self.is_nan() && rhs.is_nan() {
131134
true
132135
} else {
133136
self.repr() == rhs.repr()
134137
}
135138
}
139+
#[rustc_nounwind]
136140
fn sign(self) -> bool {
137141
self.signed_repr() < Self::SignedInt::ZERO
138142
}
143+
#[rustc_nounwind]
139144
fn exp(self) -> Self::ExpInt {
140145
((self.to_bits() & Self::EXPONENT_MASK) >> Self::SIGNIFICAND_BITS) as Self::ExpInt
141146
}
147+
#[rustc_nounwind]
142148
fn frac(self) -> Self::Int {
143149
self.to_bits() & Self::SIGNIFICAND_MASK
144150
}
151+
#[rustc_nounwind]
145152
fn imp_frac(self) -> Self::Int {
146153
self.frac() | Self::IMPLICIT_BIT
147154
}
155+
#[rustc_nounwind]
148156
fn from_repr(a: Self::Int) -> Self {
149157
Self::from_bits(a)
150158
}
159+
#[rustc_nounwind]
151160
fn from_parts(sign: bool, exponent: Self::Int, significand: Self::Int) -> Self {
152161
Self::from_repr(
153162
((sign as Self::Int) << (Self::BITS - 1))
154163
| ((exponent << Self::SIGNIFICAND_BITS) & Self::EXPONENT_MASK)
155164
| (significand & Self::SIGNIFICAND_MASK),
156165
)
157166
}
167+
#[rustc_nounwind]
158168
fn normalize(significand: Self::Int) -> (i32, Self::Int) {
159169
let shift = significand
160170
.leading_zeros()
@@ -164,6 +174,7 @@ macro_rules! float_impl {
164174
significand << shift as Self::Int,
165175
)
166176
}
177+
#[rustc_nounwind]
167178
fn is_subnormal(self) -> bool {
168179
(self.repr() & Self::EXPONENT_MASK) == Self::Int::ZERO
169180
}

src/int/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,50 +151,62 @@ macro_rules! int_impl_common {
151151
}
152152
};
153153

154+
#[rustc_nounwind]
154155
fn from_bool(b: bool) -> Self {
155156
b as $ty
156157
}
157158

159+
#[rustc_nounwind]
158160
fn logical_shr(self, other: u32) -> Self {
159161
Self::from_unsigned(self.unsigned().wrapping_shr(other))
160162
}
161163

164+
#[rustc_nounwind]
162165
fn is_zero(self) -> bool {
163166
self == Self::ZERO
164167
}
165168

169+
#[rustc_nounwind]
166170
fn wrapping_neg(self) -> Self {
167171
<Self>::wrapping_neg(self)
168172
}
169173

174+
#[rustc_nounwind]
170175
fn wrapping_add(self, other: Self) -> Self {
171176
<Self>::wrapping_add(self, other)
172177
}
173178

179+
#[rustc_nounwind]
174180
fn wrapping_mul(self, other: Self) -> Self {
175181
<Self>::wrapping_mul(self, other)
176182
}
177183

184+
#[rustc_nounwind]
178185
fn wrapping_sub(self, other: Self) -> Self {
179186
<Self>::wrapping_sub(self, other)
180187
}
181188

189+
#[rustc_nounwind]
182190
fn wrapping_shl(self, other: u32) -> Self {
183191
<Self>::wrapping_shl(self, other)
184192
}
185193

194+
#[rustc_nounwind]
186195
fn wrapping_shr(self, other: u32) -> Self {
187196
<Self>::wrapping_shr(self, other)
188197
}
189198

199+
#[rustc_nounwind]
190200
fn rotate_left(self, other: u32) -> Self {
191201
<Self>::rotate_left(self, other)
192202
}
193203

204+
#[rustc_nounwind]
194205
fn overflowing_add(self, other: Self) -> (Self, bool) {
195206
<Self>::overflowing_add(self, other)
196207
}
197208

209+
#[rustc_nounwind]
198210
fn leading_zeros(self) -> u32 {
199211
<Self>::leading_zeros(self)
200212
}

src/int/specialized_div_rem/asymmetric.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ macro_rules! impl_asymmetric {
1414
$uH:ident, // unsigned integer with half the bit width of $uX
1515
$uX:ident, // unsigned integer with half the bit width of $uD
1616
$uD:ident // unsigned integer type for the inputs and outputs of `$fn`
17+
$(, $fun_attr:meta)* // attributes for the function
1718
) => {
1819
/// Computes the quotient and remainder of `duo` divided by `div` and returns them as a
1920
/// tuple.
21+
$(
22+
#[$fun_attr]
23+
)*
2024
pub fn $fn(duo: $uD, div: $uD) -> ($uD, $uD) {
2125
let n: u32 = $n_h * 2;
2226

src/int/specialized_div_rem/delegate.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ macro_rules! impl_delegate {
1414
$uX:ident, // unsigned integer with half the bit width of $uD.
1515
$uD:ident, // unsigned integer type for the inputs and outputs of `$fn`
1616
$iD:ident // signed integer type with the same bitwidth as `$uD`
17+
$(, $fun_attr:meta)* // attributes for the function
1718
) => {
1819
/// Computes the quotient and remainder of `duo` divided by `div` and returns them as a
1920
/// tuple.
21+
$(
22+
#[$fun_attr]
23+
)*
2024
pub fn $fn(duo: $uD, div: $uD) -> ($uD, $uD) {
2125
// The two possibility algorithm, undersubtracting long division algorithm, or any kind
2226
// of reciprocal based algorithm will not be fastest, because they involve large

src/int/specialized_div_rem/mod.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,17 @@ impl_normalization_shift!(
110110
32,
111111
u32,
112112
i32,
113-
allow(dead_code)
113+
allow(dead_code),
114+
rustc_nounwind
114115
);
115116
impl_normalization_shift!(
116117
u64_normalization_shift,
117118
USE_LZ,
118119
64,
119120
u64,
120121
i64,
121-
allow(dead_code)
122+
allow(dead_code),
123+
rustc_nounwind
122124
);
123125

124126
/// Divides `duo` by `div` and returns a tuple of the quotient and the remainder.
@@ -149,7 +151,8 @@ impl_trifecta!(
149151
32,
150152
u32,
151153
u64,
152-
u128
154+
u128,
155+
rustc_nounwind
153156
);
154157

155158
// If the pointer width less than 64, then the target architecture almost certainly does not have
@@ -168,7 +171,8 @@ impl_delegate!(
168171
u32,
169172
u64,
170173
u128,
171-
i128
174+
i128,
175+
rustc_nounwind
172176
);
173177

174178
/// Divides `duo` by `div` and returns a tuple of the quotient and the remainder.
@@ -209,7 +213,8 @@ impl_asymmetric!(
209213
32,
210214
u32,
211215
u64,
212-
u128
216+
u128,
217+
rustc_nounwind
213218
);
214219

215220
/// Divides `duo` by `div` and returns a tuple of the quotient and the remainder.
@@ -241,7 +246,8 @@ impl_delegate!(
241246
u16,
242247
u32,
243248
u64,
244-
i64
249+
i64,
250+
rustc_nounwind
245251
);
246252

247253
// When not on x86 and the pointer width is 64, use `binary_long`.
@@ -255,7 +261,8 @@ impl_binary_long!(
255261
u64_normalization_shift,
256262
64,
257263
u64,
258-
i64
264+
i64,
265+
rustc_nounwind
259266
);
260267

261268
/// Divides `duo` by `div` and returns a tuple of the quotient and the remainder.
@@ -296,7 +303,8 @@ impl_asymmetric!(
296303
16,
297304
u16,
298305
u32,
299-
u64
306+
u64,
307+
rustc_nounwind
300308
);
301309

302310
// 32 bits is the smallest division used by `compiler-builtins`, so we end with binary long division
@@ -307,5 +315,6 @@ impl_binary_long!(
307315
32,
308316
u32,
309317
i32,
310-
allow(dead_code)
318+
allow(dead_code),
319+
rustc_nounwind
311320
);

src/int/specialized_div_rem/trifecta.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ macro_rules! impl_trifecta {
1212
$uH:ident, // unsigned integer with half the bit width of $uX
1313
$uX:ident, // unsigned integer with half the bit width of $uD
1414
$uD:ident // unsigned integer type for the inputs and outputs of `$unsigned_name`
15+
$(, $fun_attr:meta)* // attributes for the function
1516
) => {
1617
/// Computes the quotient and remainder of `duo` divided by `div` and returns them as a
1718
/// tuple.
19+
$(
20+
#[$fun_attr]
21+
)*
1822
pub fn $fn(duo: $uD, div: $uD) -> ($uD, $uD) {
1923
// This is called the trifecta algorithm because it uses three main algorithms: short
2024
// division for small divisors, the two possibility algorithm for large divisors, and an

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#![feature(linkage)]
1313
#![feature(naked_functions)]
1414
#![feature(repr_simd)]
15+
#![feature(rustc_attrs)]
1516
#![no_builtins]
1617
#![no_std]
1718
#![allow(unused_features)]

src/mem/x86_64.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ pub unsafe fn c_string_length(mut s: *const core::ffi::c_char) -> usize {
304304
}
305305

306306
/// Determine optimal parameters for a `rep` instruction.
307+
#[rustc_nounwind]
307308
fn rep_param(dest: *mut u8, mut count: usize) -> (usize, usize, usize) {
308309
// Unaligned writes are still slow on modern processors, so align the destination address.
309310
let pre_byte_count = ((8 - (dest as usize & 0b111)) & 0b111).min(count);

0 commit comments

Comments
 (0)