902 lines · plain
1// RUN: mlir-opt %s -pass-pipeline="builtin.module(func.func(math-expand-ops),convert-vector-to-scf,convert-scf-to-cf,convert-vector-to-llvm,convert-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: -shared-libs=%mlir_float16_utils \7// RUN: | FileCheck %s8 9// -------------------------------------------------------------------------- //10// exp2f.11// -------------------------------------------------------------------------- //12func.func @func_exp2f(%a : f64) {13 %r = math.exp2 %a : f6414 vector.print %r : f6415 return16}17 18func.func @exp2f() {19 // CHECK: 220 %a = arith.constant 1.0 : f6421 call @func_exp2f(%a) : (f64) -> ()22 23 // CHECK-NEXT: 424 %b = arith.constant 2.0 : f6425 call @func_exp2f(%b) : (f64) -> ()26 27 // CHECK-NEXT: 5.6568528 %c = arith.constant 2.5 : f6429 call @func_exp2f(%c) : (f64) -> ()30 31 // CHECK-NEXT: 0.2973032 %d = arith.constant -1.75 : f6433 call @func_exp2f(%d) : (f64) -> ()34 35 // CHECK-NEXT: 1.0958136 %e = arith.constant 0.132 : f6437 call @func_exp2f(%e) : (f64) -> ()38 39 // CHECK-NEXT: inf40 %f1 = arith.constant 0.00 : f6441 %f2 = arith.constant 1.00 : f6442 %f = arith.divf %f2, %f1 : f6443 call @func_exp2f(%f) : (f64) -> ()44 45 // CHECK-NEXT: inf46 %g = arith.constant 5038939.0 : f6447 call @func_exp2f(%g) : (f64) -> ()48 49 // CHECK-NEXT: 050 %neg_inf = arith.constant 0xff80000000000000 : f6451 call @func_exp2f(%neg_inf) : (f64) -> ()52 53 // CHECK-NEXT: inf54 %i = arith.constant 0x7fc0000000000000 : f6455 call @func_exp2f(%i) : (f64) -> ()56 return57}58 59// -------------------------------------------------------------------------- //60// round.61// -------------------------------------------------------------------------- //62func.func @func_roundf(%a : f32) {63 %r = math.round %a : f3264 vector.print %r : f3265 return66}67 68func.func @func_roundf$bitcast_result_to_int(%a : f32) {69 %b = math.round %a : f3270 %c = arith.bitcast %b : f32 to i3271 vector.print %c : i3272 return73}74 75func.func @func_roundf$vector(%a : vector<1xf32>) {76 %b = math.round %a : vector<1xf32>77 vector.print %b : vector<1xf32>78 return79}80 81func.func @roundf() {82 // CHECK-NEXT: 483 %a = arith.constant 3.8 : f3284 call @func_roundf(%a) : (f32) -> ()85 86 // CHECK-NEXT: -487 %b = arith.constant -3.8 : f3288 call @func_roundf(%b) : (f32) -> ()89 90 // CHECK-NEXT: -491 %c = arith.constant -4.2 : f3292 call @func_roundf(%c) : (f32) -> ()93 94 // CHECK-NEXT: -49595 %d = arith.constant -495.0 : f3296 call @func_roundf(%d) : (f32) -> ()97 98 // CHECK-NEXT: 49599 %e = arith.constant 495.0 : f32100 call @func_roundf(%e) : (f32) -> ()101 102 // CHECK-NEXT: 9103 %f = arith.constant 8.5 : f32104 call @func_roundf(%f) : (f32) -> ()105 106 // CHECK-NEXT: -9107 %g = arith.constant -8.5 : f32108 call @func_roundf(%g) : (f32) -> ()109 110 // CHECK-NEXT: -0111 %h = arith.constant -0.4 : f32112 call @func_roundf(%h) : (f32) -> ()113 114 // Special values: 0, -0, inf, -inf, nan, -nan115 %cNeg0 = arith.constant -0.0 : f32116 %c0 = arith.constant 0.0 : f32117 %cInfInt = arith.constant 0x7f800000 : i32118 %cInf = arith.bitcast %cInfInt : i32 to f32119 %cNegInfInt = arith.constant 0xff800000 : i32120 %cNegInf = arith.bitcast %cNegInfInt : i32 to f32121 %cNanInt = arith.constant 0x7fc00000 : i32122 %cNan = arith.bitcast %cNanInt : i32 to f32123 %cNegNanInt = arith.constant 0xffc00000 : i32124 %cNegNan = arith.bitcast %cNegNanInt : i32 to f32125 126 // CHECK-NEXT: -0127 call @func_roundf(%cNeg0) : (f32) -> ()128 // CHECK-NEXT: 0129 call @func_roundf(%c0) : (f32) -> ()130 // CHECK-NEXT: inf131 call @func_roundf(%cInf) : (f32) -> ()132 // CHECK-NEXT: -inf133 call @func_roundf(%cNegInf) : (f32) -> ()134 // Per IEEE 754-2008, sign is not required when printing a negative NaN, so135 // print as an int to ensure input NaN is left unchanged.136 // CHECK-NEXT: 2143289344137 // CHECK-NEXT: 2143289344138 call @func_roundf$bitcast_result_to_int(%cNan) : (f32) -> ()139 vector.print %cNanInt : i32140 // CHECK-NEXT: -4194304141 // CHECK-NEXT: -4194304142 call @func_roundf$bitcast_result_to_int(%cNegNan) : (f32) -> ()143 vector.print %cNegNanInt : i32144 145 // Very large values (greater than INT_64_MAX)146 %c2To100 = arith.constant 1.268e30 : f32 // 2^100147 // CHECK-NEXT: 1.268e+30148 call @func_roundf(%c2To100) : (f32) -> ()149 150 // Values above and below 2^23 = 8388608151 %c8388606_5 = arith.constant 8388606.5 : f32152 %c8388607 = arith.constant 8388607.0 : f32153 %c8388607_5 = arith.constant 8388607.5 : f32154 %c8388608 = arith.constant 8388608.0 : f32155 %c8388609 = arith.constant 8388609.0 : f32156 157 // Bitcast result to int to avoid printing in scientific notation,158 // which does not display all significant digits.159 160 // CHECK-NEXT: 1258291198161 // hex: 0x4AFFFFFE162 call @func_roundf$bitcast_result_to_int(%c8388606_5) : (f32) -> ()163 // CHECK-NEXT: 1258291198164 // hex: 0x4AFFFFFE165 call @func_roundf$bitcast_result_to_int(%c8388607) : (f32) -> ()166 // CHECK-NEXT: 1258291200167 // hex: 0x4B000000168 call @func_roundf$bitcast_result_to_int(%c8388607_5) : (f32) -> ()169 // CHECK-NEXT: 1258291200170 // hex: 0x4B000000171 call @func_roundf$bitcast_result_to_int(%c8388608) : (f32) -> ()172 // CHECK-NEXT: 1258291201173 // hex: 0x4B000001174 call @func_roundf$bitcast_result_to_int(%c8388609) : (f32) -> ()175 176 // Check that vector type works177 %cVec = arith.constant dense<[0.5]> : vector<1xf32>178 // CHECK-NEXT: ( 1 )179 call @func_roundf$vector(%cVec) : (vector<1xf32>) -> ()180 181 return182}183 184// -------------------------------------------------------------------------- //185// pow.186// -------------------------------------------------------------------------- //187func.func @func_powff64(%a : f64, %b : f64) {188 %r = math.powf %a, %b : f64189 vector.print %r : f64190 return191}192 193func.func @func_powff32(%a : f32, %b : f32) {194 %r = math.powf %a, %b : f32195 vector.print %r : f32196 return197}198 199func.func @powf() {200 // CHECK-NEXT: 16201 %a = arith.constant 4.0 : f64202 %a_p = arith.constant 2.0 : f64203 call @func_powff64(%a, %a_p) : (f64, f64) -> ()204 205 // CHECK-NEXT: 2.343206 %b = arith.constant 2.343 : f64207 %b_p = arith.constant 1.000 : f64208 call @func_powff64(%b, %b_p) : (f64, f64) -> ()209 210 // CHECK-NEXT: 0.176171211 %c = arith.constant 4.25 : f64212 %c_p = arith.constant -1.2 : f64213 call @func_powff64(%c, %c_p) : (f64, f64) -> ()214 215 // CHECK-NEXT: 1216 %d = arith.constant 4.385 : f64217 %d_p = arith.constant 0.00 : f64218 call @func_powff64(%d, %d_p) : (f64, f64) -> ()219 220 // CHECK-NEXT: 6.62637221 %e = arith.constant 4.835 : f64222 %e_p = arith.constant 1.2 : f64223 call @func_powff64(%e, %e_p) : (f64, f64) -> ()224 225 // CHECK-NEXT: nan226 %f = arith.constant 1.0 : f64227 %f_p = arith.constant 0x7fffffffffffffff : f64228 call @func_powff64(%f, %f_p) : (f64, f64) -> ()229 230 // CHECK-NEXT: inf231 %g = arith.constant 29385.0 : f64232 %g_p = arith.constant 23598.0 : f64233 call @func_powff64(%g, %g_p) : (f64, f64) -> ()234 235 // CHECK-NEXT: -nan236 %h = arith.constant 1.0 : f64237 %h_p = arith.constant 0xfff0000001000000 : f64238 call @func_powff64(%h, %h_p) : (f64, f64) -> ()239 240 // CHECK-NEXT: -nan241 %i = arith.constant 1.0 : f32242 %i_p = arith.constant 0xffffffff : f32243 call @func_powff32(%i, %i_p) : (f32, f32) -> ()244 245 // CHECK-NEXT: 1246 %j = arith.constant 0.000 : f32247 %j_r = math.powf %j, %j : f32248 vector.print %j_r : f32249 250 // CHECK-NEXT: 4251 %k = arith.constant -2.0 : f32252 %k_p = arith.constant 2.0 : f32253 %k_r = math.powf %k, %k_p : f32254 vector.print %k_r : f32255 256 // CHECK-NEXT: 0.25257 %l = arith.constant -2.0 : f32258 %l_p = arith.constant -2.0 : f32259 %l_r = math.powf %k, %l_p : f32260 vector.print %l_r : f32261 return262}263 264// -------------------------------------------------------------------------- //265// roundeven.266// -------------------------------------------------------------------------- //267 268func.func @func_roundeven32(%a : f32) {269 %b = math.roundeven %a : f32270 vector.print %b : f32271 return272}273 274func.func @func_roundeven32$bitcast_result_to_int(%a : f32) {275 %b = math.roundeven %a : f32276 %c = arith.bitcast %b : f32 to i32277 vector.print %c : i32278 return279}280 281func.func @func_roundeven32$vector(%a : vector<1xf32>) {282 %b = math.roundeven %a : vector<1xf32>283 vector.print %b : vector<1xf32>284 return285}286 287func.func @roundeven32() {288 %c0_25 = arith.constant 0.25 : f32289 %c0_5 = arith.constant 0.5 : f32290 %c0_75 = arith.constant 0.75 : f32291 %c1 = arith.constant 1.0 : f32292 %c1_25 = arith.constant 1.25 : f32293 %c1_5 = arith.constant 1.5 : f32294 %c1_75 = arith.constant 1.75 : f32295 %c2 = arith.constant 2.0 : f32296 %c2_25 = arith.constant 2.25 : f32297 %c2_5 = arith.constant 2.5 : f32298 %c2_75 = arith.constant 2.75 : f32299 %c3 = arith.constant 3.0 : f32300 %c3_25 = arith.constant 3.25 : f32301 %c3_5 = arith.constant 3.5 : f32302 %c3_75 = arith.constant 3.75 : f32303 304 %cNeg0_25 = arith.constant -0.25 : f32305 %cNeg0_5 = arith.constant -0.5 : f32306 %cNeg0_75 = arith.constant -0.75 : f32307 %cNeg1 = arith.constant -1.0 : f32308 %cNeg1_25 = arith.constant -1.25 : f32309 %cNeg1_5 = arith.constant -1.5 : f32310 %cNeg1_75 = arith.constant -1.75 : f32311 %cNeg2 = arith.constant -2.0 : f32312 %cNeg2_25 = arith.constant -2.25 : f32313 %cNeg2_5 = arith.constant -2.5 : f32314 %cNeg2_75 = arith.constant -2.75 : f32315 %cNeg3 = arith.constant -3.0 : f32316 %cNeg3_25 = arith.constant -3.25 : f32317 %cNeg3_5 = arith.constant -3.5 : f32318 %cNeg3_75 = arith.constant -3.75 : f32319 320 // CHECK-NEXT: 0321 call @func_roundeven32(%c0_25) : (f32) -> ()322 // CHECK-NEXT: 0323 call @func_roundeven32(%c0_5) : (f32) -> ()324 // CHECK-NEXT: 1325 call @func_roundeven32(%c0_75) : (f32) -> ()326 // CHECK-NEXT: 1327 call @func_roundeven32(%c1) : (f32) -> ()328 // CHECK-NEXT: 1329 call @func_roundeven32(%c1_25) : (f32) -> ()330 // CHECK-NEXT: 2331 call @func_roundeven32(%c1_5) : (f32) -> ()332 // CHECK-NEXT: 2333 call @func_roundeven32(%c1_75) : (f32) -> ()334 // CHECK-NEXT: 2335 call @func_roundeven32(%c2) : (f32) -> ()336 // CHECK-NEXT: 2337 call @func_roundeven32(%c2_25) : (f32) -> ()338 // CHECK-NEXT: 2339 call @func_roundeven32(%c2_5) : (f32) -> ()340 // CHECK-NEXT: 3341 call @func_roundeven32(%c2_75) : (f32) -> ()342 // CHECK-NEXT: 3343 call @func_roundeven32(%c3) : (f32) -> ()344 // CHECK-NEXT: 3345 call @func_roundeven32(%c3_25) : (f32) -> ()346 // CHECK-NEXT: 4347 call @func_roundeven32(%c3_5) : (f32) -> ()348 // CHECK-NEXT: 4349 call @func_roundeven32(%c3_75) : (f32) -> ()350 351 // CHECK-NEXT: -0352 call @func_roundeven32(%cNeg0_25) : (f32) -> ()353 // CHECK-NEXT: -0354 call @func_roundeven32(%cNeg0_5) : (f32) -> ()355 // CHECK-NEXT: -1356 call @func_roundeven32(%cNeg0_75) : (f32) -> ()357 // CHECK-NEXT: -1358 call @func_roundeven32(%cNeg1) : (f32) -> ()359 // CHECK-NEXT: -1360 call @func_roundeven32(%cNeg1_25) : (f32) -> ()361 // CHECK-NEXT: -2362 call @func_roundeven32(%cNeg1_5) : (f32) -> ()363 // CHECK-NEXT: -2364 call @func_roundeven32(%cNeg1_75) : (f32) -> ()365 // CHECK-NEXT: -2366 call @func_roundeven32(%cNeg2) : (f32) -> ()367 // CHECK-NEXT: -2368 call @func_roundeven32(%cNeg2_25) : (f32) -> ()369 // CHECK-NEXT: -2370 call @func_roundeven32(%cNeg2_5) : (f32) -> ()371 // CHECK-NEXT: -3372 call @func_roundeven32(%cNeg2_75) : (f32) -> ()373 // CHECK-NEXT: -3374 call @func_roundeven32(%cNeg3) : (f32) -> ()375 // CHECK-NEXT: -3376 call @func_roundeven32(%cNeg3_25) : (f32) -> ()377 // CHECK-NEXT: -4378 call @func_roundeven32(%cNeg3_5) : (f32) -> ()379 // CHECK-NEXT: -4380 call @func_roundeven32(%cNeg3_75) : (f32) -> ()381 382 // Special values: 0, -0, inf, -inf, nan, -nan383 %cNeg0 = arith.constant -0.0 : f32384 %c0 = arith.constant 0.0 : f32385 %cInfInt = arith.constant 0x7f800000 : i32386 %cInf = arith.bitcast %cInfInt : i32 to f32387 %cNegInfInt = arith.constant 0xff800000 : i32388 %cNegInf = arith.bitcast %cNegInfInt : i32 to f32389 %cNanInt = arith.constant 0x7fc00000 : i32390 %cNan = arith.bitcast %cNanInt : i32 to f32391 %cNegNanInt = arith.constant 0xffc00000 : i32392 %cNegNan = arith.bitcast %cNegNanInt : i32 to f32393 394 // CHECK-NEXT: -0395 call @func_roundeven32(%cNeg0) : (f32) -> ()396 // CHECK-NEXT: 0397 call @func_roundeven32(%c0) : (f32) -> ()398 // CHECK-NEXT: inf399 call @func_roundeven32(%cInf) : (f32) -> ()400 // CHECK-NEXT: -inf401 call @func_roundeven32(%cNegInf) : (f32) -> ()402 // Per IEEE 754-2008, sign is not required when printing a negative NaN, so403 // print as an int to ensure input NaN is left unchanged.404 // CHECK-NEXT: 2143289344405 // CHECK-NEXT: 2143289344406 call @func_roundeven32$bitcast_result_to_int(%cNan) : (f32) -> ()407 vector.print %cNanInt : i32408 // CHECK-NEXT: -4194304409 // CHECK-NEXT: -4194304410 call @func_roundeven32$bitcast_result_to_int(%cNegNan) : (f32) -> ()411 vector.print %cNegNanInt : i32412 413 414 // Values above and below 2^23 = 8388608415 %c8388606_5 = arith.constant 8388606.5 : f32416 %c8388607 = arith.constant 8388607.0 : f32417 %c8388607_5 = arith.constant 8388607.5 : f32418 %c8388608 = arith.constant 8388608.0 : f32419 %c8388609 = arith.constant 8388609.0 : f32420 421 // Bitcast result to int to avoid printing in scientific notation,422 // which does not display all significant digits.423 424 // CHECK-NEXT: 1258291196425 // hex: 0x4AFFFFFC426 call @func_roundeven32$bitcast_result_to_int(%c8388606_5) : (f32) -> ()427 // CHECK-NEXT: 1258291198428 // hex: 0x4AFFFFFE429 call @func_roundeven32$bitcast_result_to_int(%c8388607) : (f32) -> ()430 // CHECK-NEXT: 1258291200431 // hex: 0x4B000000432 call @func_roundeven32$bitcast_result_to_int(%c8388607_5) : (f32) -> ()433 // CHECK-NEXT: 1258291200434 // hex: 0x4B000000435 call @func_roundeven32$bitcast_result_to_int(%c8388608) : (f32) -> ()436 // CHECK-NEXT: 1258291201437 // hex: 0x4B000001438 call @func_roundeven32$bitcast_result_to_int(%c8388609) : (f32) -> ()439 440 441 // Check that vector type works442 %cVec = arith.constant dense<[0.5]> : vector<1xf32>443 // CHECK-NEXT: ( 0 )444 call @func_roundeven32$vector(%cVec) : (vector<1xf32>) -> ()445 return446}447 448func.func @func_roundeven64(%a : f64) {449 %b = math.roundeven %a : f64450 vector.print %b : f64451 return452}453 454func.func @func_roundeven64$bitcast_result_to_int(%a : f64) {455 %b = math.roundeven %a : f64456 %c = arith.bitcast %b : f64 to i64457 vector.print %c : i64458 return459}460 461func.func @func_roundeven64$vector(%a : vector<1xf64>) {462 %b = math.roundeven %a : vector<1xf64>463 vector.print %b : vector<1xf64>464 return465}466 467func.func @roundeven64() {468 %c0_25 = arith.constant 0.25 : f64469 %c0_5 = arith.constant 0.5 : f64470 %c0_75 = arith.constant 0.75 : f64471 %c1 = arith.constant 1.0 : f64472 %c1_25 = arith.constant 1.25 : f64473 %c1_5 = arith.constant 1.5 : f64474 %c1_75 = arith.constant 1.75 : f64475 %c2 = arith.constant 2.0 : f64476 %c2_25 = arith.constant 2.25 : f64477 %c2_5 = arith.constant 2.5 : f64478 %c2_75 = arith.constant 2.75 : f64479 %c3 = arith.constant 3.0 : f64480 %c3_25 = arith.constant 3.25 : f64481 %c3_5 = arith.constant 3.5 : f64482 %c3_75 = arith.constant 3.75 : f64483 484 %cNeg0_25 = arith.constant -0.25 : f64485 %cNeg0_5 = arith.constant -0.5 : f64486 %cNeg0_75 = arith.constant -0.75 : f64487 %cNeg1 = arith.constant -1.0 : f64488 %cNeg1_25 = arith.constant -1.25 : f64489 %cNeg1_5 = arith.constant -1.5 : f64490 %cNeg1_75 = arith.constant -1.75 : f64491 %cNeg2 = arith.constant -2.0 : f64492 %cNeg2_25 = arith.constant -2.25 : f64493 %cNeg2_5 = arith.constant -2.5 : f64494 %cNeg2_75 = arith.constant -2.75 : f64495 %cNeg3 = arith.constant -3.0 : f64496 %cNeg3_25 = arith.constant -3.25 : f64497 %cNeg3_5 = arith.constant -3.5 : f64498 %cNeg3_75 = arith.constant -3.75 : f64499 500 // CHECK-NEXT: 0501 call @func_roundeven64(%c0_25) : (f64) -> ()502 // CHECK-NEXT: 0503 call @func_roundeven64(%c0_5) : (f64) -> ()504 // CHECK-NEXT: 1505 call @func_roundeven64(%c0_75) : (f64) -> ()506 // CHECK-NEXT: 1507 call @func_roundeven64(%c1) : (f64) -> ()508 // CHECK-NEXT: 1509 call @func_roundeven64(%c1_25) : (f64) -> ()510 // CHECK-NEXT: 2511 call @func_roundeven64(%c1_5) : (f64) -> ()512 // CHECK-NEXT: 2513 call @func_roundeven64(%c1_75) : (f64) -> ()514 // CHECK-NEXT: 2515 call @func_roundeven64(%c2) : (f64) -> ()516 // CHECK-NEXT: 2517 call @func_roundeven64(%c2_25) : (f64) -> ()518 // CHECK-NEXT: 2519 call @func_roundeven64(%c2_5) : (f64) -> ()520 // CHECK-NEXT: 3521 call @func_roundeven64(%c2_75) : (f64) -> ()522 // CHECK-NEXT: 3523 call @func_roundeven64(%c3) : (f64) -> ()524 // CHECK-NEXT: 3525 call @func_roundeven64(%c3_25) : (f64) -> ()526 // CHECK-NEXT: 4527 call @func_roundeven64(%c3_5) : (f64) -> ()528 // CHECK-NEXT: 4529 call @func_roundeven64(%c3_75) : (f64) -> ()530 531 // CHECK-NEXT: -0532 call @func_roundeven64(%cNeg0_25) : (f64) -> ()533 // CHECK-NEXT: -0534 call @func_roundeven64(%cNeg0_5) : (f64) -> ()535 // CHECK-NEXT: -1536 call @func_roundeven64(%cNeg0_75) : (f64) -> ()537 // CHECK-NEXT: -1538 call @func_roundeven64(%cNeg1) : (f64) -> ()539 // CHECK-NEXT: -1540 call @func_roundeven64(%cNeg1_25) : (f64) -> ()541 // CHECK-NEXT: -2542 call @func_roundeven64(%cNeg1_5) : (f64) -> ()543 // CHECK-NEXT: -2544 call @func_roundeven64(%cNeg1_75) : (f64) -> ()545 // CHECK-NEXT: -2546 call @func_roundeven64(%cNeg2) : (f64) -> ()547 // CHECK-NEXT: -2548 call @func_roundeven64(%cNeg2_25) : (f64) -> ()549 // CHECK-NEXT: -2550 call @func_roundeven64(%cNeg2_5) : (f64) -> ()551 // CHECK-NEXT: -3552 call @func_roundeven64(%cNeg2_75) : (f64) -> ()553 // CHECK-NEXT: -3554 call @func_roundeven64(%cNeg3) : (f64) -> ()555 // CHECK-NEXT: -3556 call @func_roundeven64(%cNeg3_25) : (f64) -> ()557 // CHECK-NEXT: -4558 call @func_roundeven64(%cNeg3_5) : (f64) -> ()559 // CHECK-NEXT: -4560 call @func_roundeven64(%cNeg3_75) : (f64) -> ()561 562 // Special values: 0, -0, inf, -inf, nan, -nan563 %cNeg0 = arith.constant -0.0 : f64564 %c0 = arith.constant 0.0 : f64565 %cInfInt = arith.constant 0x7FF0000000000000 : i64566 %cInf = arith.bitcast %cInfInt : i64 to f64567 %cNegInfInt = arith.constant 0xFFF0000000000000 : i64568 %cNegInf = arith.bitcast %cNegInfInt : i64 to f64569 %cNanInt = arith.constant 0x7FF0000000000001 : i64570 %cNan = arith.bitcast %cNanInt : i64 to f64571 %cNegNanInt = arith.constant 0xFFF0000000000001 : i64572 %cNegNan = arith.bitcast %cNegNanInt : i64 to f64573 574 // CHECK-NEXT: -0575 call @func_roundeven64(%cNeg0) : (f64) -> ()576 // CHECK-NEXT: 0577 call @func_roundeven64(%c0) : (f64) -> ()578 // CHECK-NEXT: inf579 call @func_roundeven64(%cInf) : (f64) -> ()580 // CHECK-NEXT: -inf581 call @func_roundeven64(%cNegInf) : (f64) -> ()582 583 // Values above and below 2^52 = 4503599627370496584 %c4503599627370494_5 = arith.constant 4503599627370494.5 : f64585 %c4503599627370495 = arith.constant 4503599627370495.0 : f64586 %c4503599627370495_5 = arith.constant 4503599627370495.5 : f64587 %c4503599627370496 = arith.constant 4503599627370496.0 : f64588 %c4503599627370497 = arith.constant 4503599627370497.0 : f64589 590 // Bitcast result to int to avoid printing in scientific notation,591 // which does not display all significant digits.592 593 // CHECK-NEXT: 4841369599423283196594 // hex: 0x432ffffffffffffc595 call @func_roundeven64$bitcast_result_to_int(%c4503599627370494_5) : (f64) -> ()596 // CHECK-NEXT: 4841369599423283198597 // hex: 0x432ffffffffffffe598 call @func_roundeven64$bitcast_result_to_int(%c4503599627370495) : (f64) -> ()599 // CHECK-NEXT: 4841369599423283200600 // hex: 0x4330000000000000601 call @func_roundeven64$bitcast_result_to_int(%c4503599627370495_5) : (f64) -> ()602 // CHECK-NEXT: 4841369599423283200603 // hex: 0x10000000000000604 call @func_roundeven64$bitcast_result_to_int(%c4503599627370496) : (f64) -> ()605 // CHECK-NEXT: 4841369599423283201606 // hex: 0x10000000000001607 call @func_roundeven64$bitcast_result_to_int(%c4503599627370497) : (f64) -> ()608 609 // Check that vector type works610 %cVec = arith.constant dense<[0.5]> : vector<1xf64>611 // CHECK-NEXT: ( 0 )612 call @func_roundeven64$vector(%cVec) : (vector<1xf64>) -> ()613 return614}615 616func.func @roundeven() {617 call @roundeven32() : () -> ()618 call @roundeven64() : () -> ()619 return620}621 622// -------------------------------------------------------------------------- //623// Sinh.624// -------------------------------------------------------------------------- //625 626func.func @sinh_f32(%a : f32) {627 %r = math.sinh %a : f32628 vector.print %r : f32629 return630}631 632func.func @sinh_4xf32(%a : vector<4xf32>) {633 %r = math.sinh %a : vector<4xf32>634 vector.print %r : vector<4xf32>635 return636}637 638func.func @sinh_8xf32(%a : vector<8xf32>) {639 %r = math.sinh %a : vector<8xf32>640 vector.print %r : vector<8xf32>641 return642}643 644func.func @sinh() {645 // CHECK: 1.60192646 %f0 = arith.constant 1.25 : f32647 call @sinh_f32(%f0) : (f32) -> ()648 649 // CHECK: 0.252612, 0.822317, 1.1752, 1.60192650 %v1 = arith.constant dense<[0.25, 0.75, 1.0, 1.25]> : vector<4xf32>651 call @sinh_4xf32(%v1) : (vector<4xf32>) -> ()652 653 // CHECK: 0.100167, 0.201336, 0.30452, 0.410752, 0.521095, 0.636654, 0.758584, 0.888106654 %v2 = arith.constant dense<[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]> : vector<8xf32>655 call @sinh_8xf32(%v2) : (vector<8xf32>) -> ()656 657 // CHECK: -0.100167, -0.201336, -0.30452, -0.410752, -0.521095, -0.636654, -0.758584, -0.888106658 %v3 = arith.constant dense<[-0.1, -0.2, -0.3, -0.4, -0.5, -0.6, -0.7, -0.8]> : vector<8xf32>659 call @sinh_8xf32(%v3) : (vector<8xf32>) -> ()660 661 // CHECK: nan662 %nan = arith.constant 0x7fc00000 : f32663 call @sinh_f32(%nan) : (f32) -> ()664 665 return666}667 668// -------------------------------------------------------------------------- //669// Cosh.670// -------------------------------------------------------------------------- //671 672func.func @cosh_f32(%a : f32) {673 %r = math.cosh %a : f32674 vector.print %r : f32675 return676}677 678func.func @cosh_4xf32(%a : vector<4xf32>) {679 %r = math.cosh %a : vector<4xf32>680 vector.print %r : vector<4xf32>681 return682}683 684func.func @cosh_8xf32(%a : vector<8xf32>) {685 %r = math.cosh %a : vector<8xf32>686 vector.print %r : vector<8xf32>687 return688}689 690func.func @cosh() {691 // CHECK: 1.88842692 %f0 = arith.constant 1.25 : f32693 call @cosh_f32(%f0) : (f32) -> ()694 695 // CHECK: 1.03141, 1.29468, 1.54308, 1.88842696 %v1 = arith.constant dense<[0.25, 0.75, 1.0, 1.25]> : vector<4xf32>697 call @cosh_4xf32(%v1) : (vector<4xf32>) -> ()698 699 // CHECK: 1.005, 1.02007, 1.04534, 1.08107, 1.12763, 1.18547, 1.25517, 1.33743700 %v2 = arith.constant dense<[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]> : vector<8xf32>701 call @cosh_8xf32(%v2) : (vector<8xf32>) -> ()702 703 // CHECK: 1.005, 1.02007, 1.04534, 1.08107, 1.12763, 1.18547, 1.25517, 1.33743704 %v3 = arith.constant dense<[-0.1, -0.2, -0.3, -0.4, -0.5, -0.6, -0.7, -0.8]> : vector<8xf32>705 call @cosh_8xf32(%v3) : (vector<8xf32>) -> ()706 707 // CHECK: nan708 %nan = arith.constant 0x7fc00000 : f32709 call @cosh_f32(%nan) : (f32) -> ()710 711 return712}713 714// -------------------------------------------------------------------------- //715// Tanh.716// -------------------------------------------------------------------------- //717 718func.func @tanh_8xf32(%a : vector<8xf32>) {719 %r = math.tanh %a : vector<8xf32>720 vector.print %r : vector<8xf32>721 return722}723 724func.func @tanh() {725 // CHECK: -1, -0.761594, -0.291313, 0, 0.291313, 0.761594, 1, 1726 %v3 = arith.constant dense<[0xff800000, -1.0, -0.3, 0.0, 0.3, 1.0, 10.0, 0x7f800000]> : vector<8xf32>727 call @tanh_8xf32(%v3) : (vector<8xf32>) -> ()728 729 return730}731 732// -------------------------------------------------------------------------- //733// Asinh.734// -------------------------------------------------------------------------- //735 736func.func @asinh_f32(%a : f32) {737 %r = math.asinh %a : f32738 vector.print %r : f32739 return740}741 742func.func @asinh_3xf32(%a : vector<3xf32>) {743 %r = math.asinh %a : vector<3xf32>744 vector.print %r : vector<3xf32>745 return746}747 748func.func @asinh() {749 // CHECK: 0750 %zero = arith.constant 0.0 : f32751 call @asinh_f32(%zero) : (f32) -> ()752 753 // CHECK: 0.881374754 %cst1 = arith.constant 1.0 : f32755 call @asinh_f32(%cst1) : (f32) -> ()756 757 // CHECK: -0.881374758 %cst2 = arith.constant -1.0 : f32759 call @asinh_f32(%cst2) : (f32) -> ()760 761 // CHECK: 1.81845762 %cst3 = arith.constant 3.0 : f32763 call @asinh_f32(%cst3) : (f32) -> ()764 765 // CHECK: 0.247466, 0.790169, 1.44364766 %vec_x = arith.constant dense<[0.25, 0.875, 2.0]> : vector<3xf32>767 call @asinh_3xf32(%vec_x) : (vector<3xf32>) -> ()768 769 return770}771 772// -------------------------------------------------------------------------- //773// Acosh.774// -------------------------------------------------------------------------- //775 776func.func @acosh_f32(%a : f32) {777 %r = math.acosh %a : f32778 vector.print %r : f32779 return780}781 782func.func @acosh_3xf32(%a : vector<3xf32>) {783 %r = math.acosh %a : vector<3xf32>784 vector.print %r : vector<3xf32>785 return786}787 788func.func @acosh() {789 // CHECK: 0790 %zero = arith.constant 1.0 : f32791 call @acosh_f32(%zero) : (f32) -> ()792 793 // CHECK: 1.31696794 %cst1 = arith.constant 2.0 : f32795 call @acosh_f32(%cst1) : (f32) -> ()796 797 // CHECK: 2.99322798 %cst2 = arith.constant 10.0 : f32799 call @acosh_f32(%cst2) : (f32) -> ()800 801 // CHECK: 0.962424, 1.76275, 2.47789802 %vec_x = arith.constant dense<[1.5, 3.0, 6.0]> : vector<3xf32>803 call @acosh_3xf32(%vec_x) : (vector<3xf32>) -> ()804 805 return806}807 808// -------------------------------------------------------------------------- //809// Atanh.810// -------------------------------------------------------------------------- //811 812func.func @atanh_f32(%a : f32) {813 %r = math.atanh %a : f32814 vector.print %r : f32815 return816}817 818func.func @atanh_3xf32(%a : vector<3xf32>) {819 %r = math.atanh %a : vector<3xf32>820 vector.print %r : vector<3xf32>821 return822}823 824func.func @atanh() {825 // CHECK: 0826 %zero = arith.constant 0.0 : f32827 call @atanh_f32(%zero) : (f32) -> ()828 829 // CHECK: 0.549306830 %cst1 = arith.constant 0.5 : f32831 call @atanh_f32(%cst1) : (f32) -> ()832 833 // CHECK: -0.549306834 %cst2 = arith.constant -0.5 : f32835 call @atanh_f32(%cst2) : (f32) -> ()836 837 // CHECK: inf838 %cst3 = arith.constant 1.0 : f32839 call @atanh_f32(%cst3) : (f32) -> ()840 841 // CHECK: 0.255413, 0.394229, 2.99448842 %vec_x = arith.constant dense<[0.25, 0.375, 0.995]> : vector<3xf32>843 call @atanh_3xf32(%vec_x) : (vector<3xf32>) -> ()844 845 return846}847 848// -------------------------------------------------------------------------- //849// Rsqrt.850// -------------------------------------------------------------------------- //851 852func.func @rsqrt_f32(%a : f32) {853 %r = math.rsqrt %a : f32854 vector.print %r : f32855 return856}857 858func.func @rsqrt_3xf32(%a : vector<3xf32>) {859 %r = math.rsqrt %a : vector<3xf32>860 vector.print %r : vector<3xf32>861 return862}863 864func.func @rsqrt() {865 // CHECK: 1866 %zero = arith.constant 1.0 : f32867 call @rsqrt_f32(%zero) : (f32) -> ()868 869 // CHECK: 0.707107870 %cst1 = arith.constant 2.0 : f32871 call @rsqrt_f32(%cst1) : (f32) -> ()872 873 // CHECK: inf874 %cst2 = arith.constant 0.0 : f32875 call @rsqrt_f32(%cst2) : (f32) -> ()876 877 // CHECK: nan878 %cst3 = arith.constant -1.0 : f32879 call @rsqrt_f32(%cst3) : (f32) -> ()880 881 // CHECK: 0.5, 1.41421, 0.57735882 %vec_x = arith.constant dense<[4.0, 0.5, 3.0]> : vector<3xf32>883 call @rsqrt_3xf32(%vec_x) : (vector<3xf32>) -> ()884 885 return886}887 888func.func @main() {889 call @exp2f() : () -> ()890 call @roundf() : () -> ()891 call @powf() : () -> ()892 call @roundeven() : () -> ()893 call @sinh() : () -> ()894 call @cosh() : () -> ()895 call @tanh() : () -> ()896 call @asinh() : () -> ()897 call @acosh() : () -> ()898 call @atanh() : () -> ()899 call @rsqrt() : () -> ()900 return901}902