brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.4 KiB · e52225f Raw
86 lines · plain
1// RUN:   mlir-opt %s -pass-pipeline="builtin.module(func.func(arith-expand{include-bf16=true},convert-arith-to-llvm),convert-vector-to-llvm,convert-func-to-llvm,reconcile-unrealized-casts)" \2// RUN: | mlir-runner                                                      \3// RUN:     -e main -entry-point-result=void -O0                               \4// RUN:     -shared-libs=%mlir_c_runner_utils  \5// RUN:     -shared-libs=%mlir_runner_utils    \6// RUN: | FileCheck %s7 8func.func @trunc_bf16(%a : f32) {9  %b = arith.truncf %a : f32 to bf1610  %c = arith.extf %b : bf16 to f3211  vector.print %c : f3212  return13}14 15func.func @main() {16  // Note: this is a tie (low 16 bits are 0x8000). We expect the rounding behavior17  // to break ties "to nearest-even", which in this case means downwards,18  // since bit 16 is not set.19  // CHECK: 120  %value_1_00391_I = arith.constant 0x3f808000 : i3221  %value_1_00391_F = arith.bitcast %value_1_00391_I : i32 to f3222  call @trunc_bf16(%value_1_00391_F): (f32) -> ()23 24  // Note: this is a tie (low 16 bits are 0x8000). We expect the rounding behavior25  // to break ties "to nearest-even", which in this case means upwards,26  // since bit 16 is set.27  // CHECK-NEXT: 1.015628  %value_1_01172_I = arith.constant 0x3f818000 : i3229  %value_1_01172_F = arith.bitcast %value_1_01172_I : i32 to f3230  call @trunc_bf16(%value_1_01172_F): (f32) -> ()31 32  // CHECK-NEXT: -133  %noRoundNegOneI = arith.constant 0xbf808000 : i3234  %noRoundNegOneF = arith.bitcast %noRoundNegOneI : i32 to f3235  call @trunc_bf16(%noRoundNegOneF): (f32) -> ()36 37  // CHECK-NEXT: -1.0078138  %roundNegOneI = arith.constant 0xbf808001 : i3239  %roundNegOneF = arith.bitcast %roundNegOneI : i32 to f3240  call @trunc_bf16(%roundNegOneF): (f32) -> ()41 42  // CHECK-NEXT: inf43  %infi = arith.constant 0x7f800000 : i3244  %inff = arith.bitcast %infi : i32 to f3245  call @trunc_bf16(%inff): (f32) -> ()46 47  // CHECK-NEXT: -inf48  %neginfi = arith.constant 0xff800000 : i3249  %neginff = arith.bitcast %neginfi : i32 to f3250  call @trunc_bf16(%neginff): (f32) -> ()51 52  // Note: this rounds upwards. As the mantissa was already saturated, this rounding53  // causes the exponent to be incremented. As the exponent was already the54  // maximum exponent value for finite values, this increment of the exponent55  // causes this to overflow to +inf.56  // CHECK-NEXT: inf57  %big_overflowing_i = arith.constant 0x7f7fffff : i3258  %big_overflowing_f = arith.bitcast %big_overflowing_i : i32 to f3259  call @trunc_bf16(%big_overflowing_f): (f32) -> ()60 61  // Same as the previous testcase but negative.62  // CHECK-NEXT: -inf63  %negbig_overflowing_i = arith.constant 0xff7fffff : i3264  %negbig_overflowing_f = arith.bitcast %negbig_overflowing_i : i32 to f3265  call @trunc_bf16(%negbig_overflowing_f): (f32) -> ()66 67  // In contrast to the previous two testcases, the upwards-rounding here68  // does not cause overflow.69  // CHECK-NEXT: 3.38953e+3870  %big_nonoverflowing_i = arith.constant 0x7f7effff : i3271  %big_nonoverflowing_f = arith.bitcast %big_nonoverflowing_i : i32 to f3272  call @trunc_bf16(%big_nonoverflowing_f): (f32) -> ()73 74  // CHECK-NEXT: 1.62575  %exprolli = arith.constant 0x3fcfffff : i3276  %exprollf = arith.bitcast %exprolli : i32 to f3277  call @trunc_bf16(%exprollf): (f32) -> ()78 79  // CHECK-NEXT: -1.62580  %exprollnegi = arith.constant 0xbfcfffff : i3281  %exprollnegf = arith.bitcast %exprollnegi : i32 to f3282  call @trunc_bf16(%exprollnegf): (f32) -> ()83 84  return85}86