File: expand-arith-ops.mlir

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (62 lines) | stat: -rw-r--r-- 2,150 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// 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)" \
// RUN: | mlir-cpu-runner                                                      \
// RUN:     -e main -entry-point-result=void -O0                               \
// RUN:     -shared-libs=%mlir_c_runner_utils  \
// RUN:     -shared-libs=%mlir_runner_utils    \
// RUN: | FileCheck %s

func.func @trunc_bf16(%a : f32) {
  %b = arith.truncf %a : f32 to bf16
  %c = arith.extf %b : bf16 to f32
  vector.print %c : f32
  return
}

func.func @main() {
  // CHECK: 1.00781
  %roundOneI = arith.constant 0x3f808000 : i32
  %roundOneF = arith.bitcast %roundOneI : i32 to f32
  call @trunc_bf16(%roundOneF): (f32) -> ()

  // CHECK-NEXT: -1
  %noRoundNegOneI = arith.constant 0xbf808000 : i32
  %noRoundNegOneF = arith.bitcast %noRoundNegOneI : i32 to f32
  call @trunc_bf16(%noRoundNegOneF): (f32) -> ()

  // CHECK-NEXT: -1.00781
  %roundNegOneI = arith.constant 0xbf808001 : i32
  %roundNegOneF = arith.bitcast %roundNegOneI : i32 to f32
  call @trunc_bf16(%roundNegOneF): (f32) -> ()

  // CHECK-NEXT: inf
  %infi = arith.constant 0x7f800000 : i32
  %inff = arith.bitcast %infi : i32 to f32
  call @trunc_bf16(%inff): (f32) -> ()

  // CHECK-NEXT: -inf
  %neginfi = arith.constant 0xff800000 : i32
  %neginff = arith.bitcast %neginfi : i32 to f32
  call @trunc_bf16(%neginff): (f32) -> ()

  // CHECK-NEXT: 3.38953e+38
  %bigi = arith.constant 0x7f7fffff : i32
  %bigf = arith.bitcast %bigi : i32 to f32
  call @trunc_bf16(%bigf): (f32) -> ()

  // CHECK-NEXT: -3.38953e+38
  %negbigi = arith.constant 0xff7fffff : i32
  %negbigf = arith.bitcast %negbigi : i32 to f32
  call @trunc_bf16(%negbigf): (f32) -> ()

  // CHECK-NEXT: 1.625
  %exprolli = arith.constant 0x3fcfffff : i32
  %exprollf = arith.bitcast %exprolli : i32 to f32
  call @trunc_bf16(%exprollf): (f32) -> ()

  // CHECK-NEXT: -1.625
  %exprollnegi = arith.constant 0xbfcfffff : i32
  %exprollnegf = arith.bitcast %exprollnegi : i32 to f32
  call @trunc_bf16(%exprollnegf): (f32) -> ()

  return
}