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

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.8-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,388 kB
  • sloc: cpp: 7,438,767; ansic: 1,393,871; asm: 1,012,926; python: 241,728; f90: 86,635; objc: 75,411; lisp: 42,144; pascal: 17,286; sh: 10,027; ml: 5,082; perl: 4,730; awk: 3,523; makefile: 3,349; javascript: 2,251; xml: 892; fortran: 672
file content (85 lines) | stat: -rw-r--r-- 3,094 bytes parent folder | download | duplicates (5)
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
// Check that the wide integer multiplication emulation produces the same result as wide
// multiplication. 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-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-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_muli(%lhs : i16, %rhs : i16) -> (i16) {
  %res = arith.muli %lhs, %rhs : i16
  return %res : i16
}

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

func.func @entry() {
  %cst0 = arith.constant 0 : i16
  %cst1 = arith.constant 1 : i16
  %cst_n1 = arith.constant -1 : i16
  %cst_n3 = arith.constant -3 : i16

  %cst13 = arith.constant 13 : i16
  %cst37 = arith.constant 37 : i16
  %cst42 = arith.constant 42 : i16

  %cst256 = arith.constant 256 : i16
  %cst_i16_max = arith.constant 32767 : i16
  %cst_i16_min = arith.constant -32768 : i16

  // CHECK: 0
  func.call @check_muli(%cst0, %cst0) : (i16, i16) -> ()
  // CHECK-NEXT: 0
  func.call @check_muli(%cst0, %cst1) : (i16, i16) -> ()
  // CHECK-NEXT: 1
  func.call @check_muli(%cst1, %cst1) : (i16, i16) -> ()
  // CHECK-NEXT: -1
  func.call @check_muli(%cst1, %cst_n1) : (i16, i16) -> ()
  // CHECK-NEXT: 1
  func.call @check_muli(%cst_n1, %cst_n1) : (i16, i16) -> ()
  // CHECK-NEXT: -3
  func.call @check_muli(%cst1, %cst_n3) : (i16, i16) -> ()

  // CHECK-NEXT: 169
  func.call @check_muli(%cst13, %cst13) : (i16, i16) -> ()
  // CHECK-NEXT: 481
  func.call @check_muli(%cst13, %cst37) : (i16, i16) -> ()
  // CHECK-NEXT: 1554
  func.call @check_muli(%cst37, %cst42) : (i16, i16) -> ()

  // CHECK-NEXT: -256
  func.call @check_muli(%cst_n1, %cst256) : (i16, i16) -> ()
  // CHECK-NEXT: 3328
  func.call @check_muli(%cst256, %cst13) : (i16, i16) -> ()
  // CHECK-NEXT: 9472
  func.call @check_muli(%cst256, %cst37) : (i16, i16) -> ()
  // CHECK-NEXT: -768
  func.call @check_muli(%cst256, %cst_n3) : (i16, i16) -> ()

  // CHECK-NEXT: 32755
  func.call @check_muli(%cst13, %cst_i16_max) : (i16, i16) -> ()
  // CHECK-NEXT: -32768
  func.call @check_muli(%cst_i16_min, %cst37) : (i16, i16) -> ()

  // CHECK-NEXT: 1
  func.call @check_muli(%cst_i16_max, %cst_i16_max) : (i16, i16) -> ()
  // CHECK-NEXT: -32768
  func.call @check_muli(%cst_i16_min, %cst13) : (i16, i16) -> ()
  // CHECK-NEXT: 0
  func.call @check_muli(%cst_i16_min, %cst_i16_min) : (i16, i16) -> ()

  return
}