File: test-wide-int-emulation-shrui-i16.mlir

package info (click to toggle)
swiftlang 6.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,604 kB
  • sloc: cpp: 9,901,740; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (98 lines) | stat: -rw-r--r-- 3,634 bytes parent folder | download | duplicates (9)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Check that the wide integer `arith.shrui` emulation produces the same result as wide
// `arith.shrui`. Emulate i16 ops with i8 ops.

// RUN: mlir-opt %s --convert-scf-to-cf --convert-cf-to-llvm --convert-vector-to-llvm \
// RUN:             --convert-func-to-llvm --convert-arith-to-llvm | \
// RUN:   mlir-cpu-runner -e entry -entry-point-result=void \
// RUN:                   --shared-libs=%mlir_c_runner_utils | \
// RUN:   FileCheck %s --match-full-lines

// RUN: mlir-opt %s --test-arith-emulate-wide-int="widest-int-supported=8" \
// RUN:             --convert-scf-to-cf --convert-cf-to-llvm --convert-vector-to-llvm \
// RUN:             --convert-func-to-llvm --convert-arith-to-llvm | \
// RUN:   mlir-cpu-runner -e entry -entry-point-result=void \
// RUN:                   --shared-libs=%mlir_c_runner_utils | \
// RUN:   FileCheck %s --match-full-lines

// Ops in this function *only* will be emulated using i8 types.
func.func @emulate_shrui(%lhs : i16, %rhs : i16) -> (i16) {
  %res = arith.shrui %lhs, %rhs : i16
  return %res : i16
}

func.func @check_shrui(%lhs : i16, %rhs : i16) -> () {
  %res = func.call @emulate_shrui(%lhs, %rhs) : (i16, i16) -> (i16)
  vector.print %res : i16
  return
}

func.func @entry() {
  %cst0 = arith.constant 0 : i16
  %cst1 = arith.constant 1 : i16
  %cst2 = arith.constant 2 : i16
  %cst7 = arith.constant 7 : i16
  %cst8 = arith.constant 8 : i16
  %cst9 = arith.constant 9 : i16
  %cst15 = arith.constant 15 : i16

  %cst_n1 = arith.constant -1 : i16

  %cst1337 = arith.constant 1337 : i16
  %cst_n1337 = arith.constant -1337 : i16

  %cst_i16_min = arith.constant -32768 : i16

  // CHECK:      0
  // CHECK-NEXT: 0
  // CHECK-NEXT: 0
  // CHECK-NEXT: 1
  // CHECK-NEXT: 32767
  // CHECK-NEXT: 1
  func.call @check_shrui(%cst0, %cst0) : (i16, i16) -> ()
  func.call @check_shrui(%cst0, %cst1) : (i16, i16) -> ()
  func.call @check_shrui(%cst1, %cst1) : (i16, i16) -> ()
  func.call @check_shrui(%cst1, %cst0) : (i16, i16) -> ()
  func.call @check_shrui(%cst_n1, %cst1) : (i16, i16) -> ()
  func.call @check_shrui(%cst_n1, %cst15) : (i16, i16) -> ()

  // CHECK-NEXT: 1337
  // CHECK-NEXT: 334
  // CHECK-NEXT: 10
  // CHECK-NEXT: 5
  // CHECK-NEXT: 2
  // CHECK-NEXT: 0
  func.call @check_shrui(%cst1337, %cst0) : (i16, i16) -> ()
  func.call @check_shrui(%cst1337, %cst2) : (i16, i16) -> ()
  func.call @check_shrui(%cst1337, %cst7) : (i16, i16) -> ()
  func.call @check_shrui(%cst1337, %cst8) : (i16, i16) -> ()
  func.call @check_shrui(%cst1337, %cst9) : (i16, i16) -> ()
  func.call @check_shrui(%cst1337, %cst15) : (i16, i16) -> ()

  // CHECK-NEXT: -1337
  // CHECK-NEXT: 16049
  // CHECK-NEXT: 501
  // CHECK-NEXT: 250
  // CHECK-NEXT: 125
  // CHECK-NEXT: 1
  func.call @check_shrui(%cst_n1337, %cst0) : (i16, i16) -> ()
  func.call @check_shrui(%cst_n1337, %cst2) : (i16, i16) -> ()
  func.call @check_shrui(%cst_n1337, %cst7) : (i16, i16) -> ()
  func.call @check_shrui(%cst_n1337, %cst8) : (i16, i16) -> ()
  func.call @check_shrui(%cst_n1337, %cst9) : (i16, i16) -> ()
  func.call @check_shrui(%cst_n1337, %cst15) : (i16, i16) -> ()

  // CHECK-NEXT: 16384
  // CHECK-NEXT: 8192
  // CHECK-NEXT: 256
  // CHECK-NEXT: 128
  // CHECK-NEXT: 64
  // CHECK-NEXT: 1
  func.call @check_shrui(%cst_i16_min, %cst1) : (i16, i16) -> ()
  func.call @check_shrui(%cst_i16_min, %cst2) : (i16, i16) -> ()
  func.call @check_shrui(%cst_i16_min, %cst7) : (i16, i16) -> ()
  func.call @check_shrui(%cst_i16_min, %cst8) : (i16, i16) -> ()
  func.call @check_shrui(%cst_i16_min, %cst9) : (i16, i16) -> ()
  func.call @check_shrui(%cst_i16_min, %cst15) : (i16, i16) -> ()

  return
}