@@ -206,212 +206,116 @@ mod f_to_i {
206
206
}
207
207
}
208
208
209
- macro_rules! conv {
210
- ( $fX: ident, $fD: ident, $fn: ident, $apfloatX: ident, $apfloatD: ident) => {
211
- fuzz_float( N , |x: $fX| {
212
- let tmp0: $apfloatD = $apfloatX:: from_bits( x. to_bits( ) . into( ) )
213
- . convert( & mut false )
214
- . value;
215
- let tmp0 = $fD:: from_bits( tmp0. to_bits( ) . try_into( ) . unwrap( ) ) ;
216
- let tmp1: $fD = $fn( x) ;
217
- if !Float :: eq_repr( tmp0, tmp1) {
218
- panic!(
219
- "{}({x:?}): apfloat: {tmp0:?}, builtins: {tmp1:?}" ,
220
- stringify!( $fn)
221
- ) ;
222
- }
223
- } )
224
- } ;
225
- }
226
-
227
- macro_rules! extend {
228
- ( $fX: ident, $fD: ident, $fn: ident) => {
209
+ macro_rules! f_to_f {
210
+ (
211
+ $mod: ident,
212
+ $(
213
+ $from_ty: ty => $to_ty: ty,
214
+ $from_ap_ty: ident => $to_ap_ty: ident,
215
+ $fn: ident, $sys_available: meta
216
+ ) ;+;
217
+ ) => { $(
229
218
#[ test]
230
219
fn $fn( ) {
231
- use compiler_builtins:: float:: extend:: $fn;
220
+ use compiler_builtins:: float:: { $mod:: $fn, Float } ;
221
+ use rustc_apfloat:: ieee:: { $from_ap_ty, $to_ap_ty} ;
222
+
223
+ fuzz_float( N , |x: $from_ty| {
224
+ let tmp0: $to_ty = apfloat_fallback!(
225
+ $from_ty,
226
+ $from_ap_ty,
227
+ $sys_available,
228
+ |x: $from_ty| x as $to_ty;
229
+ |x: $from_ty| {
230
+ let from_apf = FloatTy :: from_bits( x. to_bits( ) . into( ) ) ;
231
+ // Get `value` directly to ignore INVALID_OP
232
+ let to_apf: $to_ap_ty = from_apf. convert( & mut false ) . value;
233
+ <$to_ty>:: from_bits( to_apf. to_bits( ) . try_into( ) . unwrap( ) )
234
+ } ,
235
+ x
236
+ ) ;
237
+ let tmp1: $to_ty = $fn( x) ;
232
238
233
- fuzz_float( N , |x: $fX| {
234
- let tmp0 = x as $fD;
235
- let tmp1: $fD = $fn( x) ;
236
239
if !Float :: eq_repr( tmp0, tmp1) {
237
240
panic!(
238
- "{}({}): std: {}, builtins: {}" ,
241
+ "{}({:? }): std: {:? }, builtins: {:? }" ,
239
242
stringify!( $fn) ,
240
243
x,
241
244
tmp0,
242
245
tmp1
243
246
) ;
244
247
}
245
- } ) ;
248
+ } )
246
249
}
247
- } ;
250
+ ) + } ;
248
251
}
249
252
250
- // PowerPC tests are failing on LLVM 13: https://github.com/rust-lang/rust/issues/88520
251
- #[ cfg( not( target_arch = "powerpc64" ) ) ]
252
- mod float_extend {
253
+ mod extend {
253
254
use super :: * ;
254
255
255
- extend ! ( f32 , f64 , __extendsfdf2) ;
256
-
257
- #[ test]
258
- fn conv ( ) {
259
- use compiler_builtins:: float:: extend:: __extendsfdf2;
260
- use rustc_apfloat:: ieee:: { Double , Single } ;
261
-
262
- conv ! ( f32 , f64 , __extendsfdf2, Single , Double ) ;
256
+ f_to_f ! {
257
+ extend,
258
+ f32 => f64 , Single => Double , __extendsfdf2, all( ) ;
263
259
}
264
- }
265
-
266
- #[ cfg( not( feature = "no-f16-f128" ) ) ]
267
- #[ cfg( not( any( target_arch = "powerpc" , target_arch = "powerpc64" ) ) ) ]
268
- mod float_extend_f128 {
269
- use super :: * ;
270
-
271
- #[ test]
272
- fn conv ( ) {
273
- use compiler_builtins:: float:: extend:: {
274
- __extenddftf2, __extendhfsf2, __extendhftf2, __extendsftf2, __gnu_h2f_ieee,
275
- } ;
276
- use rustc_apfloat:: ieee:: { Double , Half , Quad , Single } ;
277
260
278
- // FIXME(f16_f128): Also do extend!() for `f16` and `f128` when builtins are in nightly
279
- conv ! ( f16, f32 , __extendhfsf2, Half , Single ) ;
280
- conv ! ( f16, f32 , __gnu_h2f_ieee, Half , Single ) ;
281
- conv ! ( f16, f128, __extendhftf2, Half , Quad ) ;
282
- conv ! ( f32 , f128, __extendsftf2, Single , Quad ) ;
283
- conv ! ( f64 , f128, __extenddftf2, Double , Quad ) ;
261
+ #[ cfg( target_arch = "arm" ) ]
262
+ f_to_f ! {
263
+ extend,
264
+ f32 => f64 , Single => Double , __extendsfdf2vfp, all( ) ;
284
265
}
285
- }
286
266
287
- #[ cfg( not( feature = "no-f16-f128" ) ) ]
288
- #[ cfg( any( target_arch = "powerpc" , target_arch = "powerpc64" ) ) ]
289
- mod float_extend_f128_ppc {
290
- use super :: * ;
291
-
292
- #[ test]
293
- fn conv ( ) {
294
- use compiler_builtins:: float:: extend:: {
295
- __extenddfkf2, __extendhfkf2, __extendhfsf2, __extendsfkf2, __gnu_h2f_ieee,
296
- } ;
297
- use rustc_apfloat:: ieee:: { Double , Half , Quad , Single } ;
298
-
299
- // FIXME(f16_f128): Also do extend!() for `f16` and `f128` when builtins are in nightly
300
- conv ! ( f16, f32 , __extendhfsf2, Half , Single ) ;
301
- conv ! ( f16, f32 , __gnu_h2f_ieee, Half , Single ) ;
302
- conv ! ( f16, f128, __extendhfkf2, Half , Quad ) ;
303
- conv ! ( f32 , f128, __extendsfkf2, Single , Quad ) ;
304
- conv ! ( f64 , f128, __extenddfkf2, Double , Quad ) ;
267
+ #[ cfg( not( feature = "no-f16-f128" ) ) ]
268
+ #[ cfg( not( any( target_arch = "powerpc" , target_arch = "powerpc64" ) ) ) ]
269
+ f_to_f ! {
270
+ extend,
271
+ f16 => f32 , Half => Single , __extendhfsf2, not( feature = "no-sys-f16" ) ;
272
+ f16 => f32 , Half => Single , __gnu_h2f_ieee, not( feature = "no-sys-f16" ) ;
273
+ f16 => f128, Half => Quad , __extendhftf2, not( feature = "no-sys-f16-f128-convert" ) ;
274
+ f32 => f128, Single => Quad , __extendsftf2, not( feature = "no-sys-f128" ) ;
275
+ f64 => f128, Double => Quad , __extenddftf2, not( feature = "no-sys-f128" ) ;
305
276
}
306
- }
307
-
308
- #[ cfg( target_arch = "arm" ) ]
309
- mod float_extend_arm {
310
- use super :: * ;
311
277
312
- extend ! ( f32 , f64 , __extendsfdf2vfp) ;
313
-
314
- #[ test]
315
- fn conv ( ) {
316
- use compiler_builtins:: float:: extend:: __extendsfdf2vfp;
317
- use rustc_apfloat:: ieee:: { Double , Single } ;
318
-
319
- conv ! ( f32 , f64 , __extendsfdf2vfp, Single , Double ) ;
278
+ #[ cfg( not( feature = "no-f16-f128" ) ) ]
279
+ #[ cfg( any( target_arch = "powerpc" , target_arch = "powerpc64" ) ) ]
280
+ f_to_f ! {
281
+ extend,
282
+ // FIXME(#655): `f16` tests disabled until we can bootstrap symbols
283
+ f32 => f128, Single => Quad , __extendsfkf2, not( feature = "no-sys-f128" ) ;
284
+ f64 => f128, Double => Quad , __extenddfkf2, not( feature = "no-sys-f128" ) ;
320
285
}
321
286
}
322
287
323
- macro_rules! trunc {
324
- ( $fX: ident, $fD: ident, $fn: ident) => {
325
- #[ test]
326
- fn $fn( ) {
327
- use compiler_builtins:: float:: trunc:: $fn;
328
-
329
- fuzz_float( N , |x: $fX| {
330
- let tmp0 = x as $fD;
331
- let tmp1: $fD = $fn( x) ;
332
- if !Float :: eq_repr( tmp0, tmp1) {
333
- panic!(
334
- "{}({}): std: {}, builtins: {}" ,
335
- stringify!( $fn) ,
336
- x,
337
- tmp0,
338
- tmp1
339
- ) ;
340
- }
341
- } ) ;
342
- }
343
- } ;
344
- }
345
-
346
- // PowerPC tests are failing on LLVM 13: https://github.com/rust-lang/rust/issues/88520
347
- #[ cfg( not( target_arch = "powerpc64" ) ) ]
348
- mod float_trunc {
288
+ mod trunc {
349
289
use super :: * ;
350
290
351
- trunc ! ( f64 , f32 , __truncdfsf2) ;
352
-
353
- #[ test]
354
- fn conv ( ) {
355
- use compiler_builtins:: float:: trunc:: __truncdfsf2;
356
- use rustc_apfloat:: ieee:: { Double , Single } ;
357
-
358
- conv ! ( f64 , f32 , __truncdfsf2, Double , Single ) ;
291
+ f_to_f ! {
292
+ trunc,
293
+ f64 => f32 , Double => Single , __truncdfsf2, all( ) ;
359
294
}
360
- }
361
295
362
- #[ cfg( not( feature = "no-f16-f128" ) ) ]
363
- #[ cfg( not( any( target_arch = "powerpc" , target_arch = "powerpc64" ) ) ) ]
364
- mod float_trunc_f128 {
365
- use super :: * ;
366
-
367
- #[ test]
368
- fn conv ( ) {
369
- use compiler_builtins:: float:: trunc:: { __gnu_f2h_ieee, __truncdfhf2, __truncsfhf2} ;
370
- use compiler_builtins:: float:: trunc:: { __trunctfdf2, __trunctfhf2, __trunctfsf2} ;
371
- use rustc_apfloat:: ieee:: { Double , Half , Quad , Single } ;
372
-
373
- // FIXME(f16_f128): Also do trunc!() for `f16` and `f128` when builtins are in nightly
374
- conv ! ( f32 , f16, __truncsfhf2, Single , Half ) ;
375
- conv ! ( f32 , f16, __gnu_f2h_ieee, Single , Half ) ;
376
- conv ! ( f64 , f16, __truncdfhf2, Double , Half ) ;
377
- conv ! ( f128, f16, __trunctfhf2, Quad , Half ) ;
378
- conv ! ( f128, f32 , __trunctfsf2, Quad , Single ) ;
379
- conv ! ( f128, f64 , __trunctfdf2, Quad , Double ) ;
296
+ #[ cfg( target_arch = "arm" ) ]
297
+ f_to_f ! {
298
+ trunc,
299
+ f64 => f32 , Double => Single , __truncdfsf2vfp, all( ) ;
380
300
}
381
- }
382
-
383
- #[ cfg( not( feature = "no-f16-f128" ) ) ]
384
- #[ cfg( any( target_arch = "powerpc" , target_arch = "powerpc64" ) ) ]
385
- mod float_trunc_f128_ppc {
386
- use super :: * ;
387
-
388
- #[ test]
389
- fn conv ( ) {
390
- use compiler_builtins:: float:: trunc:: { __gnu_f2h_ieee, __truncdfhf2, __truncsfhf2} ;
391
- use compiler_builtins:: float:: trunc:: { __trunckfdf2, __trunckfhf2, __trunckfsf2} ;
392
- use rustc_apfloat:: ieee:: { Double , Half , Quad , Single } ;
393
301
394
- // FIXME(f16_f128): Also do trunc!() for `f16` and `f128` when builtins are in nightly
395
- conv ! ( f32 , f16, __truncsfhf2, Single , Half ) ;
396
- conv ! ( f32 , f16, __gnu_f2h_ieee, Single , Half ) ;
397
- conv ! ( f64 , f16, __truncdfhf2, Double , Half ) ;
398
- conv ! ( f128, f16, __trunckfhf2, Quad , Half ) ;
399
- conv ! ( f128, f32 , __trunckfsf2, Quad , Single ) ;
400
- conv ! ( f128, f64 , __trunckfdf2, Quad , Double ) ;
302
+ #[ cfg( not( feature = "no-f16-f128" ) ) ]
303
+ #[ cfg( not( any( target_arch = "powerpc" , target_arch = "powerpc64" ) ) ) ]
304
+ f_to_f ! {
305
+ trunc,
306
+ f32 => f16, Single => Half , __truncsfhf2, not( feature = "no-sys-f16" ) ;
307
+ f32 => f16, Single => Half , __gnu_f2h_ieee, not( feature = "no-sys-f16" ) ;
308
+ f128 => f16, Quad => Half , __trunctfhf2, not( feature = "no-sys-f16-f128-convert" ) ;
309
+ f128 => f32 , Quad => Single , __trunctfsf2, not( feature = "no-sys-f128" ) ;
310
+ f128 => f64 , Quad => Double , __trunctfdf2, not( feature = "no-sys-f128" ) ;
401
311
}
402
- }
403
-
404
- #[ cfg( target_arch = "arm" ) ]
405
- mod float_trunc_arm {
406
- use super :: * ;
407
312
408
- trunc ! ( f64 , f32 , __truncdfsf2vfp) ;
409
-
410
- #[ test]
411
- fn conv ( ) {
412
- use compiler_builtins:: float:: trunc:: __truncdfsf2vfp;
413
- use rustc_apfloat:: ieee:: { Double , Single } ;
414
-
415
- conv ! ( f64 , f32 , __truncdfsf2vfp, Double , Single )
313
+ #[ cfg( not( feature = "no-f16-f128" ) ) ]
314
+ #[ cfg( any( target_arch = "powerpc" , target_arch = "powerpc64" ) ) ]
315
+ f_to_f ! {
316
+ trunc,
317
+ // FIXME(#655): `f16` tests disabled until we can bootstrap symbols
318
+ f128 => f32 , Quad => Single , __trunckfsf2, not( feature = "no-sys-f128" ) ;
319
+ f128 => f64 , Quad => Double , __trunckfdf2, not( feature = "no-sys-f128" ) ;
416
320
}
417
321
}
0 commit comments