Skip to content

Commit 857ad00

Browse files
authored
Merge pull request rust-lang#620 from tgross35/ppc-alias
Add `ppc_alias` to the `intrinsics!` macro
2 parents 1f701b0 + aa2ed5f commit 857ad00

File tree

9 files changed

+70
-102
lines changed

9 files changed

+70
-102
lines changed

src/float/add.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,12 @@ intrinsics! {
203203
add(a, b)
204204
}
205205

206-
#[cfg(not(any(feature = "no-f16-f128", target_arch = "powerpc", target_arch = "powerpc64")))]
206+
#[ppc_alias = __addkf3]
207+
#[cfg(not(feature = "no-f16-f128"))]
207208
pub extern "C" fn __addtf3(a: f128, b: f128) -> f128 {
208209
add(a, b)
209210
}
210211

211-
#[cfg(all(not(feature = "no-f16-f128"), any(target_arch = "powerpc", target_arch = "powerpc64")))]
212-
pub extern "C" fn __addkf3(a: f128, b: f128) -> f128 {
213-
add(a, b)
214-
}
215-
216212
#[cfg(target_arch = "arm")]
217213
pub extern "C" fn __addsf3vfp(a: f32, b: f32) -> f32 {
218214
a + b

src/float/cmp.rs

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -172,89 +172,51 @@ intrinsics! {
172172
}
173173
}
174174

175-
#[cfg(not(any(
176-
feature = "no-f16-f128",
177-
target_arch = "powerpc",
178-
target_arch = "powerpc64"
179-
)))]
175+
#[cfg(not(feature = "no-f16-f128",))]
180176
intrinsics! {
181177
#[avr_skip]
178+
#[ppc_alias = __lekf2]
182179
pub extern "C" fn __letf2(a: f128, b: f128) -> i32 {
183180
cmp(a, b).to_le_abi()
184181
}
185182

186183
#[avr_skip]
184+
#[ppc_alias = __gekf2]
187185
pub extern "C" fn __getf2(a: f128, b: f128) -> i32 {
188186
cmp(a, b).to_ge_abi()
189187
}
190188

191189
#[avr_skip]
190+
#[ppc_alias = __unordkf2]
192191
pub extern "C" fn __unordtf2(a: f128, b: f128) -> i32 {
193192
unord(a, b) as i32
194193
}
195194

196195
#[avr_skip]
196+
#[ppc_alias = __eqkf2]
197197
pub extern "C" fn __eqtf2(a: f128, b: f128) -> i32 {
198198
cmp(a, b).to_le_abi()
199199
}
200200

201201
#[avr_skip]
202+
#[ppc_alias = __ltkf2]
202203
pub extern "C" fn __lttf2(a: f128, b: f128) -> i32 {
203204
cmp(a, b).to_le_abi()
204205
}
205206

206207
#[avr_skip]
208+
#[ppc_alias = __nekf2]
207209
pub extern "C" fn __netf2(a: f128, b: f128) -> i32 {
208210
cmp(a, b).to_le_abi()
209211
}
210212

211213
#[avr_skip]
214+
#[ppc_alias = __gtkf2]
212215
pub extern "C" fn __gttf2(a: f128, b: f128) -> i32 {
213216
cmp(a, b).to_ge_abi()
214217
}
215218
}
216219

217-
#[cfg(all(
218-
not(feature = "no-f16-f128"),
219-
any(target_arch = "powerpc", target_arch = "powerpc64")
220-
))]
221-
intrinsics! {
222-
#[avr_skip]
223-
pub extern "C" fn __lekf2(a: f128, b: f128) -> i32 {
224-
cmp(a, b).to_le_abi()
225-
}
226-
227-
#[avr_skip]
228-
pub extern "C" fn __gekf2(a: f128, b: f128) -> i32 {
229-
cmp(a, b).to_ge_abi()
230-
}
231-
232-
#[avr_skip]
233-
pub extern "C" fn __unordkf2(a: f128, b: f128) -> i32 {
234-
unord(a, b) as i32
235-
}
236-
237-
#[avr_skip]
238-
pub extern "C" fn __eqkf2(a: f128, b: f128) -> i32 {
239-
cmp(a, b).to_le_abi()
240-
}
241-
242-
#[avr_skip]
243-
pub extern "C" fn __ltkf2(a: f128, b: f128) -> i32 {
244-
cmp(a, b).to_le_abi()
245-
}
246-
247-
#[avr_skip]
248-
pub extern "C" fn __nekf2(a: f128, b: f128) -> i32 {
249-
cmp(a, b).to_le_abi()
250-
}
251-
252-
#[avr_skip]
253-
pub extern "C" fn __gtkf2(a: f128, b: f128) -> i32 {
254-
cmp(a, b).to_ge_abi()
255-
}
256-
}
257-
258220
#[cfg(target_arch = "arm")]
259221
intrinsics! {
260222
pub extern "aapcs" fn __aeabi_fcmple(a: f32, b: f32) -> i32 {

src/float/conv.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,19 @@ intrinsics! {
262262
float_to_unsigned_int(f)
263263
}
264264

265+
#[ppc_alias = __fixunskfsi]
265266
#[cfg(not(feature = "no-f16-f128"))]
266267
pub extern "C" fn __fixunstfsi(f: f128) -> u32 {
267268
float_to_unsigned_int(f)
268269
}
269270

271+
#[ppc_alias = __fixunskfdi]
270272
#[cfg(not(feature = "no-f16-f128"))]
271273
pub extern "C" fn __fixunstfdi(f: f128) -> u64 {
272274
float_to_unsigned_int(f)
273275
}
274276

277+
#[ppc_alias = __fixunskfti]
275278
#[cfg(not(feature = "no-f16-f128"))]
276279
pub extern "C" fn __fixunstfti(f: f128) -> u128 {
277280
float_to_unsigned_int(f)
@@ -310,16 +313,19 @@ intrinsics! {
310313
float_to_signed_int(f)
311314
}
312315

316+
#[ppc_alias = __fixkfsi]
313317
#[cfg(not(feature = "no-f16-f128"))]
314318
pub extern "C" fn __fixtfsi(f: f128) -> i32 {
315319
float_to_signed_int(f)
316320
}
317321

322+
#[ppc_alias = __fixkfdi]
318323
#[cfg(not(feature = "no-f16-f128"))]
319324
pub extern "C" fn __fixtfdi(f: f128) -> i64 {
320325
float_to_signed_int(f)
321326
}
322327

328+
#[ppc_alias = __fixkfti]
323329
#[cfg(not(feature = "no-f16-f128"))]
324330
pub extern "C" fn __fixtfti(f: f128) -> i128 {
325331
float_to_signed_int(f)

src/float/extend.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,37 +100,22 @@ intrinsics! {
100100

101101
#[avr_skip]
102102
#[aapcs_on_arm]
103-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
103+
#[ppc_alias = __extendhfkf2]
104104
pub extern "C" fn __extendhftf2(a: f16) -> f128 {
105105
extend(a)
106106
}
107107

108-
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
109-
pub extern "C" fn __extendhfkf2(a: f16) -> f128 {
110-
extend(a)
111-
}
112-
113108
#[avr_skip]
114109
#[aapcs_on_arm]
115-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
110+
#[ppc_alias = __extendsfkf2]
116111
pub extern "C" fn __extendsftf2(a: f32) -> f128 {
117112
extend(a)
118113
}
119114

120-
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
121-
pub extern "C" fn __extendsfkf2(a: f32) -> f128 {
122-
extend(a)
123-
}
124-
125115
#[avr_skip]
126116
#[aapcs_on_arm]
127-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
117+
#[ppc_alias = __extenddfkf2]
128118
pub extern "C" fn __extenddftf2(a: f64) -> f128 {
129119
extend(a)
130120
}
131-
132-
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
133-
pub extern "C" fn __extenddfkf2(a: f64) -> f128 {
134-
extend(a)
135-
}
136121
}

src/float/mul.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,17 +199,12 @@ intrinsics! {
199199
mul(a, b)
200200
}
201201

202-
#[cfg(not(any(feature = "no-f16-f128", target_arch = "powerpc", target_arch = "powerpc64")))]
202+
#[ppc_alias = __mulkf3]
203+
#[cfg(not(feature = "no-f16-f128"))]
203204
pub extern "C" fn __multf3(a: f128, b: f128) -> f128 {
204205
mul(a, b)
205206
}
206207

207-
208-
#[cfg(all(not(feature = "no-f16-f128"), any(target_arch = "powerpc", target_arch = "powerpc64")))]
209-
pub extern "C" fn __mulkf3(a: f128, b: f128) -> f128 {
210-
mul(a, b)
211-
}
212-
213208
#[cfg(target_arch = "arm")]
214209
pub extern "C" fn __mulsf3vfp(a: f32, b: f32) -> f32 {
215210
a * b

src/float/sub.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@ intrinsics! {
1515
__adddf3(a, f64::from_repr(b.repr() ^ f64::SIGN_MASK))
1616
}
1717

18-
#[cfg(not(any(feature = "no-f16-f128", target_arch = "powerpc", target_arch = "powerpc64")))]
18+
#[ppc_alias = __subkf3]
19+
#[cfg(not(feature = "no-f16-f128"))]
1920
pub extern "C" fn __subtf3(a: f128, b: f128) -> f128 {
21+
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
22+
use crate::float::add::__addkf3 as __addtf3;
23+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
2024
use crate::float::add::__addtf3;
21-
__addtf3(a, f128::from_repr(b.repr() ^ f128::SIGN_MASK))
22-
}
2325

24-
#[cfg(all(not(feature = "no-f16-f128"), any(target_arch = "powerpc", target_arch = "powerpc64")))]
25-
pub extern "C" fn __subkf3(a: f128, b: f128) -> f128 {
26-
use crate::float::add::__addkf3;
27-
__addkf3(a, f128::from_repr(b.repr() ^ f128::SIGN_MASK))
26+
__addtf3(a, f128::from_repr(b.repr() ^ f128::SIGN_MASK))
2827
}
2928

3029
#[cfg(target_arch = "arm")]

src/float/trunc.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -155,37 +155,22 @@ intrinsics! {
155155

156156
#[avr_skip]
157157
#[aapcs_on_arm]
158-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
158+
#[ppc_alias = __trunckfhf2]
159159
pub extern "C" fn __trunctfhf2(a: f128) -> f16 {
160160
trunc(a)
161161
}
162162

163-
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
164-
pub extern "C" fn __trunckfhf2(a: f128) -> f16 {
165-
trunc(a)
166-
}
167-
168163
#[avr_skip]
169164
#[aapcs_on_arm]
170-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
165+
#[ppc_alias = __trunckfsf2]
171166
pub extern "C" fn __trunctfsf2(a: f128) -> f32 {
172167
trunc(a)
173168
}
174169

175-
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
176-
pub extern "C" fn __trunckfsf2(a: f128) -> f32 {
177-
trunc(a)
178-
}
179-
180170
#[avr_skip]
181171
#[aapcs_on_arm]
182-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
172+
#[ppc_alias = __trunckfdf2]
183173
pub extern "C" fn __trunctfdf2(a: f128) -> f64 {
184174
trunc(a)
185175
}
186-
187-
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
188-
pub extern "C" fn __trunckfdf2(a: f128) -> f64 {
189-
trunc(a)
190-
}
191176
}

src/macros.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ macro_rules! public_test_dep {
6565
/// it's a normal ABI elsewhere for returning a 128 bit integer.
6666
/// * `arm_aeabi_alias` - handles the "aliasing" of various intrinsics on ARM
6767
/// their otherwise typical names to other prefixed ones.
68+
/// * `ppc_alias` - changes the name of the symbol on PowerPC platforms without
69+
/// changing any other behavior. This is mostly for `f128`, which is `tf` on
70+
/// most platforms but `kf` on PowerPC.
6871
macro_rules! intrinsics {
6972
() => ();
7073

@@ -320,6 +323,36 @@ macro_rules! intrinsics {
320323
intrinsics!($($rest)*);
321324
);
322325

326+
// PowerPC usually uses `kf` rather than `tf` for `f128`. This is just an easy
327+
// way to add an alias on those targets.
328+
(
329+
#[ppc_alias = $alias:ident]
330+
$(#[$($attr:tt)*])*
331+
pub extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? {
332+
$($body:tt)*
333+
}
334+
335+
$($rest:tt)*
336+
) => (
337+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
338+
intrinsics! {
339+
$(#[$($attr)*])*
340+
pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
341+
$($body)*
342+
}
343+
}
344+
345+
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
346+
intrinsics! {
347+
$(#[$($attr)*])*
348+
pub extern $abi fn $alias( $($argname: $ty),* ) $(-> $ret)? {
349+
$($body)*
350+
}
351+
}
352+
353+
intrinsics!($($rest)*);
354+
);
355+
323356
// C mem* functions are only generated when the "mem" feature is enabled.
324357
(
325358
#[mem_builtin]

testcrate/tests/conv.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,13 @@ mod f_to_i {
178178
#[test]
179179
#[cfg(not(feature = "no-f16-f128"))]
180180
fn f128_to_int() {
181+
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
182+
use compiler_builtins::float::conv::{
183+
__fixkfdi as __fixtfdi, __fixkfsi as __fixtfsi, __fixkfti as __fixtfti,
184+
__fixunskfdi as __fixunstfdi, __fixunskfsi as __fixunstfsi,
185+
__fixunskfti as __fixunstfti,
186+
};
187+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
181188
use compiler_builtins::float::conv::{
182189
__fixtfdi, __fixtfsi, __fixtfti, __fixunstfdi, __fixunstfsi, __fixunstfti,
183190
};

0 commit comments

Comments
 (0)