@@ -279,32 +279,6 @@ pub trait BuilderMethods<'a, 'tcx>:
279
279
assert ! ( rounded_max. value. is_finite( ) ) ;
280
280
( rounded_min. value . to_bits ( ) , rounded_max. value . to_bits ( ) )
281
281
} ;
282
-
283
- let maybe_splat = |bx : & mut Self , val| {
284
- if bx. cx ( ) . type_kind ( dest_ty) == TypeKind :: Vector {
285
- bx. vector_splat ( bx. vector_length ( dest_ty) , val)
286
- } else {
287
- val
288
- }
289
- } ;
290
-
291
- let float_bits_to_llval = |bx : & mut Self , bits| {
292
- let bits_llval = match float_width {
293
- 32 => bx. cx ( ) . const_u32 ( bits as u32 ) ,
294
- 64 => bx. cx ( ) . const_u64 ( bits as u64 ) ,
295
- n => bug ! ( "unsupported float width {}" , n) ,
296
- } ;
297
- bx. bitcast ( bits_llval, float_ty)
298
- } ;
299
- let ( f_min, f_max) = match float_width {
300
- 32 => compute_clamp_bounds_single ( signed, int_width) ,
301
- 64 => compute_clamp_bounds_double ( signed, int_width) ,
302
- n => bug ! ( "unsupported float width {}" , n) ,
303
- } ;
304
- let f_min = float_bits_to_llval ( self , f_min) ;
305
- let f_max = float_bits_to_llval ( self , f_max) ;
306
- let f_min = maybe_splat ( self , f_min) ;
307
- let f_max = maybe_splat ( self , f_max) ;
308
282
// To implement saturation, we perform the following steps:
309
283
//
310
284
// 1. Cast x to an integer with fpto[su]i. This may result in undef.
@@ -332,9 +306,37 @@ pub trait BuilderMethods<'a, 'tcx>:
332
306
// int_ty::MIN and therefore the return value of int_ty::MIN is correct.
333
307
// QED.
334
308
309
+ let float_bits_to_llval = |bx : & mut Self , bits| {
310
+ let bits_llval = match float_width {
311
+ 32 => bx. cx ( ) . const_u32 ( bits as u32 ) ,
312
+ 64 => bx. cx ( ) . const_u64 ( bits as u64 ) ,
313
+ n => bug ! ( "unsupported float width {}" , n) ,
314
+ } ;
315
+ bx. bitcast ( bits_llval, float_ty)
316
+ } ;
317
+ let ( f_min, f_max) = match float_width {
318
+ 32 => compute_clamp_bounds_single ( signed, int_width) ,
319
+ 64 => compute_clamp_bounds_double ( signed, int_width) ,
320
+ n => bug ! ( "unsupported float width {}" , n) ,
321
+ } ;
322
+ let f_min = float_bits_to_llval ( self , f_min) ;
323
+ let f_max = float_bits_to_llval ( self , f_max) ;
335
324
let int_max = self . cx ( ) . const_uint_big ( int_ty, int_max ( signed, int_width) ) ;
336
325
let int_min = self . cx ( ) . const_uint_big ( int_ty, int_min ( signed, int_width) as u128 ) ;
337
326
let zero = self . cx ( ) . const_uint ( int_ty, 0 ) ;
327
+
328
+ // If we're working with vectors, constants must be "splatted": the constant is duplicated
329
+ // into each lane of the vector. The algorithm stays the same, we are just using the
330
+ // same constant across all lanes.
331
+ let maybe_splat = |bx : & mut Self , val| {
332
+ if bx. cx ( ) . type_kind ( dest_ty) == TypeKind :: Vector {
333
+ bx. vector_splat ( bx. vector_length ( dest_ty) , val)
334
+ } else {
335
+ val
336
+ }
337
+ } ;
338
+ let f_min = maybe_splat ( self , f_min) ;
339
+ let f_max = maybe_splat ( self , f_max) ;
338
340
let int_max = maybe_splat ( self , int_max) ;
339
341
let int_min = maybe_splat ( self , int_min) ;
340
342
let zero = maybe_splat ( self , zero) ;
0 commit comments