Skip to content

Commit 9ddeafc

Browse files
authored
Use f16_enabled/f128_enabled in examples/intrinsics.rs (#724)
Enable conditional compilation for intrinsics with `f16_enabled` and `f128_enabled`
1 parent b1459f3 commit 9ddeafc

File tree

1 file changed

+106
-16
lines changed

1 file changed

+106
-16
lines changed

examples/intrinsics.rs

+106-16
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,28 @@ extern "C" {}
2828
mod intrinsics {
2929
/* f16 operations */
3030

31+
#[cfg(f16_enabled)]
3132
pub fn extendhfsf(x: f16) -> f32 {
3233
x as f32
3334
}
3435

36+
#[cfg(f16_enabled)]
3537
pub fn extendhfdf(x: f16) -> f64 {
3638
x as f64
3739
}
3840

39-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
41+
#[cfg(all(
42+
f16_enabled,
43+
f128_enabled,
44+
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
45+
))]
4046
pub fn extendhftf(x: f16) -> f128 {
4147
x as f128
4248
}
4349

4450
/* f32 operations */
4551

52+
#[cfg(f16_enabled)]
4653
pub fn truncsfhf(x: f32) -> f16 {
4754
x as f16
4855
}
@@ -52,6 +59,7 @@ mod intrinsics {
5259
x as f64
5360
}
5461

62+
#[cfg(f128_enabled)]
5563
pub fn extendsftf(x: f32) -> f128 {
5664
x as f128
5765
}
@@ -191,73 +199,104 @@ mod intrinsics {
191199

192200
/* f128 operations */
193201

194-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
202+
#[cfg(all(
203+
f16_enabled,
204+
f128_enabled,
205+
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
206+
))]
195207
pub fn trunctfhf(x: f128) -> f16 {
196208
x as f16
197209
}
198210

211+
#[cfg(f128_enabled)]
199212
pub fn trunctfsf(x: f128) -> f32 {
200213
x as f32
201214
}
202215

216+
#[cfg(f128_enabled)]
203217
pub fn trunctfdf(x: f128) -> f64 {
204218
x as f64
205219
}
206220

207-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
221+
#[cfg(all(
222+
f128_enabled,
223+
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
224+
))]
208225
pub fn fixtfsi(x: f128) -> i32 {
209226
x as i32
210227
}
211228

212-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
229+
#[cfg(all(
230+
f128_enabled,
231+
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
232+
))]
213233
pub fn fixtfdi(x: f128) -> i64 {
214234
x as i64
215235
}
216236

217-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
237+
#[cfg(all(
238+
f128_enabled,
239+
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
240+
))]
218241
pub fn fixtfti(x: f128) -> i128 {
219242
x as i128
220243
}
221244

222-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
245+
#[cfg(all(
246+
f128_enabled,
247+
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
248+
))]
223249
pub fn fixunstfsi(x: f128) -> u32 {
224250
x as u32
225251
}
226252

227-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
253+
#[cfg(all(
254+
f128_enabled,
255+
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
256+
))]
228257
pub fn fixunstfdi(x: f128) -> u64 {
229258
x as u64
230259
}
231260

232-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
261+
#[cfg(all(
262+
f128_enabled,
263+
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
264+
))]
233265
pub fn fixunstfti(x: f128) -> u128 {
234266
x as u128
235267
}
236268

269+
#[cfg(f128_enabled)]
237270
pub fn addtf(a: f128, b: f128) -> f128 {
238271
a + b
239272
}
240273

274+
#[cfg(f128_enabled)]
241275
pub fn eqtf(a: f128, b: f128) -> bool {
242276
a == b
243277
}
244278

279+
#[cfg(f128_enabled)]
245280
pub fn gttf(a: f128, b: f128) -> bool {
246281
a > b
247282
}
248283

284+
#[cfg(f128_enabled)]
249285
pub fn lttf(a: f128, b: f128) -> bool {
250286
a < b
251287
}
252288

289+
#[cfg(f128_enabled)]
253290
pub fn multf(a: f128, b: f128) -> f128 {
254291
a * b
255292
}
256293

294+
#[cfg(f128_enabled)]
257295
pub fn divtf(a: f128, b: f128) -> f128 {
258296
a / b
259297
}
260298

299+
#[cfg(f128_enabled)]
261300
pub fn subtf(a: f128, b: f128) -> f128 {
262301
a - b
263302
}
@@ -274,6 +313,7 @@ mod intrinsics {
274313
x as f64
275314
}
276315

316+
#[cfg(f128_enabled)]
277317
pub fn floatsitf(x: i32) -> f128 {
278318
x as f128
279319
}
@@ -298,6 +338,7 @@ mod intrinsics {
298338
x as f64
299339
}
300340

341+
#[cfg(f128_enabled)]
301342
pub fn floatditf(x: i64) -> f128 {
302343
x as f128
303344
}
@@ -330,6 +371,7 @@ mod intrinsics {
330371
x as f64
331372
}
332373

374+
#[cfg(f128_enabled)]
333375
pub fn floattitf(x: i128) -> f128 {
334376
x as f128
335377
}
@@ -358,6 +400,7 @@ mod intrinsics {
358400
x as f64
359401
}
360402

403+
#[cfg(f128_enabled)]
361404
pub fn floatunsitf(x: u32) -> f128 {
362405
x as f128
363406
}
@@ -382,6 +425,7 @@ mod intrinsics {
382425
x as f64
383426
}
384427

428+
#[cfg(f128_enabled)]
385429
pub fn floatunditf(x: u64) -> f128 {
386430
x as f128
387431
}
@@ -405,6 +449,7 @@ mod intrinsics {
405449
x as f64
406450
}
407451

452+
#[cfg(f128_enabled)]
408453
pub fn floatuntitf(x: u128) -> f128 {
409454
x as f128
410455
}
@@ -440,6 +485,7 @@ fn run() {
440485

441486
// FIXME(f16_f128): some PPC f128 <-> int conversion functions have the wrong names
442487

488+
#[cfg(f128_enabled)]
443489
bb(addtf(bb(2.), bb(2.)));
444490
bb(aeabi_d2f(bb(2.)));
445491
bb(aeabi_d2i(bb(2.)));
@@ -482,54 +528,98 @@ fn run() {
482528
bb(aeabi_uldivmod(bb(2), bb(3)));
483529
bb(ashlti3(bb(2), bb(2)));
484530
bb(ashrti3(bb(2), bb(2)));
531+
#[cfg(f128_enabled)]
485532
bb(divtf(bb(2.), bb(2.)));
486533
bb(divti3(bb(2), bb(2)));
534+
#[cfg(f128_enabled)]
487535
bb(eqtf(bb(2.), bb(2.)));
536+
#[cfg(f16_enabled)]
488537
bb(extendhfdf(bb(2.)));
538+
#[cfg(f16_enabled)]
489539
bb(extendhfsf(bb(2.)));
490-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
540+
#[cfg(all(
541+
f16_enabled,
542+
f128_enabled,
543+
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
544+
))]
491545
bb(extendhftf(bb(2.)));
546+
#[cfg(f128_enabled)]
492547
bb(extendsftf(bb(2.)));
493548
bb(fixdfti(bb(2.)));
494549
bb(fixsfti(bb(2.)));
495-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
550+
#[cfg(all(
551+
f128_enabled,
552+
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
553+
))]
496554
bb(fixtfdi(bb(2.)));
497-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
555+
#[cfg(all(
556+
f128_enabled,
557+
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
558+
))]
498559
bb(fixtfsi(bb(2.)));
499-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
560+
#[cfg(all(
561+
f128_enabled,
562+
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
563+
))]
500564
bb(fixtfti(bb(2.)));
501565
bb(fixunsdfti(bb(2.)));
502566
bb(fixunssfti(bb(2.)));
503-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
567+
#[cfg(all(
568+
f128_enabled,
569+
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
570+
))]
504571
bb(fixunstfdi(bb(2.)));
505-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
572+
#[cfg(all(
573+
f128_enabled,
574+
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
575+
))]
506576
bb(fixunstfsi(bb(2.)));
507-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
577+
#[cfg(all(
578+
f128_enabled,
579+
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
580+
))]
508581
bb(fixunstfti(bb(2.)));
582+
#[cfg(f128_enabled)]
509583
bb(floatditf(bb(2)));
584+
#[cfg(f128_enabled)]
510585
bb(floatsitf(bb(2)));
511586
bb(floattidf(bb(2)));
512587
bb(floattisf(bb(2)));
588+
#[cfg(f128_enabled)]
513589
bb(floattitf(bb(2)));
590+
#[cfg(f128_enabled)]
514591
bb(floatunditf(bb(2)));
592+
#[cfg(f128_enabled)]
515593
bb(floatunsitf(bb(2)));
516594
bb(floatuntidf(bb(2)));
517595
bb(floatuntisf(bb(2)));
596+
#[cfg(f128_enabled)]
518597
bb(floatuntitf(bb(2)));
598+
#[cfg(f128_enabled)]
519599
bb(gttf(bb(2.), bb(2.)));
520600
bb(lshrti3(bb(2), bb(2)));
601+
#[cfg(f128_enabled)]
521602
bb(lttf(bb(2.), bb(2.)));
522603
bb(moddi3(bb(2), bb(3)));
523604
bb(modti3(bb(2), bb(2)));
524605
bb(mulodi4(bb(2), bb(3)));
525606
bb(muloti4(bb(2), bb(2)));
607+
#[cfg(f128_enabled)]
526608
bb(multf(bb(2.), bb(2.)));
527609
bb(multi3(bb(2), bb(2)));
610+
#[cfg(f128_enabled)]
528611
bb(subtf(bb(2.), bb(2.)));
612+
#[cfg(f16_enabled)]
529613
bb(truncsfhf(bb(2.)));
614+
#[cfg(f128_enabled)]
530615
bb(trunctfdf(bb(2.)));
531-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
616+
#[cfg(all(
617+
f16_enabled,
618+
f128_enabled,
619+
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
620+
))]
532621
bb(trunctfhf(bb(2.)));
622+
#[cfg(f128_enabled)]
533623
bb(trunctfsf(bb(2.)));
534624
bb(udivti3(bb(2), bb(2)));
535625
bb(umoddi3(bb(2), bb(3)));

0 commit comments

Comments
 (0)