@@ -284,6 +284,7 @@ impl IntrinsicType {
284
284
kind : TypeKind :: Vector ,
285
285
bit_len : Some ( bit_len @ ( 128 | 256 | 512 ) ) ,
286
286
simd_len,
287
+ vec_len,
287
288
..
288
289
} => {
289
290
let ( prefix, suffix) = match language {
@@ -292,14 +293,27 @@ impl IntrinsicType {
292
293
} ;
293
294
let body_indentation = indentation. nested ( ) ;
294
295
let effective_bit_len = 32 ;
295
- let effective_vec_len = bit_len / effective_bit_len;
296
296
format ! (
297
297
"{prefix}\n {body}\n {indentation}{suffix}" ,
298
- body = ( 0 ..( simd_len . unwrap_or( 1 ) * effective_vec_len + loads - 1 ) )
298
+ body = ( 0 ..( vec_len . unwrap_or( 1 ) * simd_len . unwrap_or ( 1 ) + loads - 1 ) )
299
299
. format_with( ",\n " , |i, fmt| {
300
300
let src = value_for_array( effective_bit_len, i) ;
301
- assert!( src == 0 || src. ilog2( ) < * bit_len) ;
302
- fmt( & format_args!( "{body_indentation}{src:#x}" ) )
301
+ assert!( src == 0 || src. ilog2( ) < effective_bit_len) ;
302
+ if ( src >> ( effective_bit_len - 1 ) ) != 0 {
303
+ // `src` is a two's complement representation of a negative value.
304
+ let mask = !0u64 >> ( 64 - effective_bit_len) ;
305
+ let ones_compl = src ^ mask;
306
+ let twos_compl = ones_compl + 1 ;
307
+ if ( twos_compl == src) && ( language == & Language :: C ) {
308
+ // `src` is INT*_MIN. C requires `-0x7fffffff - 1` to avoid
309
+ // undefined literal overflow behaviour.
310
+ fmt( & format_args!( "{body_indentation}-{ones_compl:#x} - 1" ) )
311
+ } else {
312
+ fmt( & format_args!( "{body_indentation}-{twos_compl:#x}" ) )
313
+ }
314
+ } else {
315
+ fmt( & format_args!( "{body_indentation}{src:#x}" ) )
316
+ }
303
317
} )
304
318
)
305
319
}
0 commit comments