1// RUN: mlir-opt %s -pass-pipeline="builtin.module(func.func(test-expand-math),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 %s 8 9// -------------------------------------------------------------------------- // 10// exp2f. 11// -------------------------------------------------------------------------- // 12func.func @func_exp2f(%a : f64) { 13 %r = math.exp2 %a : f64 14 vector.print %r : f64 15 return 16} 17 18func.func @exp2f() { 19 // CHECK: 2 20 %a = arith.constant 1.0 : f64 21 call @func_exp2f(%a) : (f64) -> () 22 23 // CHECK-NEXT: 4 24 %b = arith.constant 2.0 : f64 25 call @func_exp2f(%b) : (f64) -> () 26 27 // CHECK-NEXT: 5.65685 28 %c = arith.constant 2.5 : f64 29 call @func_exp2f(%c) : (f64) -> () 30 31 // CHECK-NEXT: 0.29730 32 %d = arith.constant -1.75 : f64 33 call @func_exp2f(%d) : (f64) -> () 34 35 // CHECK-NEXT: 1.09581 36 %e = arith.constant 0.132 : f64 37 call @func_exp2f(%e) : (f64) -> () 38 39 // CHECK-NEXT: inf 40 %f1 = arith.constant 0.00 : f64 41 %f2 = arith.constant 1.00 : f64 42 %f = arith.divf %f2, %f1 : f64 43 call @func_exp2f(%f) : (f64) -> () 44 45 // CHECK-NEXT: inf 46 %g = arith.constant 5038939.0 : f64 47 call @func_exp2f(%g) : (f64) -> () 48 49 // CHECK-NEXT: 0 50 %neg_inf = arith.constant 0xff80000000000000 : f64 51 call @func_exp2f(%neg_inf) : (f64) -> () 52 53 // CHECK-NEXT: inf 54 %i = arith.constant 0x7fc0000000000000 : f64 55 call @func_exp2f(%i) : (f64) -> () 56 return 57} 58 59// -------------------------------------------------------------------------- // 60// round. 61// -------------------------------------------------------------------------- // 62func.func @func_roundf(%a : f32) { 63 %r = math.round %a : f32 64 vector.print %r : f32 65 return 66} 67 68func.func @func_roundf$bitcast_result_to_int(%a : f32) { 69 %b = math.round %a : f32 70 %c = arith.bitcast %b : f32 to i32 71 vector.print %c : i32 72 return 73} 74 75func.func @func_roundf$vector(%a : vector<1xf32>) { 76 %b = math.round %a : vector<1xf32> 77 vector.print %b : vector<1xf32> 78 return 79} 80 81func.func @roundf() { 82 // CHECK-NEXT: 4 83 %a = arith.constant 3.8 : f32 84 call @func_roundf(%a) : (f32) -> () 85 86 // CHECK-NEXT: -4 87 %b = arith.constant -3.8 : f32 88 call @func_roundf(%b) : (f32) -> () 89 90 // CHECK-NEXT: -4 91 %c = arith.constant -4.2 : f32 92 call @func_roundf(%c) : (f32) -> () 93 94 // CHECK-NEXT: -495 95 %d = arith.constant -495.0 : f32 96 call @func_roundf(%d) : (f32) -> () 97 98 // CHECK-NEXT: 495 99 %e = arith.constant 495.0 : f32 100 call @func_roundf(%e) : (f32) -> () 101 102 // CHECK-NEXT: 9 103 %f = arith.constant 8.5 : f32 104 call @func_roundf(%f) : (f32) -> () 105 106 // CHECK-NEXT: -9 107 %g = arith.constant -8.5 : f32 108 call @func_roundf(%g) : (f32) -> () 109 110 // CHECK-NEXT: -0 111 %h = arith.constant -0.4 : f32 112 call @func_roundf(%h) : (f32) -> () 113 114 // Special values: 0, -0, inf, -inf, nan, -nan 115 %cNeg0 = arith.constant -0.0 : f32 116 %c0 = arith.constant 0.0 : f32 117 %cInfInt = arith.constant 0x7f800000 : i32 118 %cInf = arith.bitcast %cInfInt : i32 to f32 119 %cNegInfInt = arith.constant 0xff800000 : i32 120 %cNegInf = arith.bitcast %cNegInfInt : i32 to f32 121 %cNanInt = arith.constant 0x7fc00000 : i32 122 %cNan = arith.bitcast %cNanInt : i32 to f32 123 %cNegNanInt = arith.constant 0xffc00000 : i32 124 %cNegNan = arith.bitcast %cNegNanInt : i32 to f32 125 126 // CHECK-NEXT: -0 127 call @func_roundf(%cNeg0) : (f32) -> () 128 // CHECK-NEXT: 0 129 call @func_roundf(%c0) : (f32) -> () 130 // CHECK-NEXT: inf 131 call @func_roundf(%cInf) : (f32) -> () 132 // CHECK-NEXT: -inf 133 call @func_roundf(%cNegInf) : (f32) -> () 134 // Per IEEE 754-2008, sign is not required when printing a negative NaN, so 135 // print as an int to ensure input NaN is left unchanged. 136 // CHECK-NEXT: 2143289344 137 // CHECK-NEXT: 2143289344 138 call @func_roundf$bitcast_result_to_int(%cNan) : (f32) -> () 139 vector.print %cNanInt : i32 140 // CHECK-NEXT: -4194304 141 // CHECK-NEXT: -4194304 142 call @func_roundf$bitcast_result_to_int(%cNegNan) : (f32) -> () 143 vector.print %cNegNanInt : i32 144 145 // Very large values (greater than INT_64_MAX) 146 %c2To100 = arith.constant 1.268e30 : f32 // 2^100 147 // CHECK-NEXT: 1.268e+30 148 call @func_roundf(%c2To100) : (f32) -> () 149 150 // Values above and below 2^23 = 8388608 151 %c8388606_5 = arith.constant 8388606.5 : f32 152 %c8388607 = arith.constant 8388607.0 : f32 153 %c8388607_5 = arith.constant 8388607.5 : f32 154 %c8388608 = arith.constant 8388608.0 : f32 155 %c8388609 = arith.constant 8388609.0 : f32 156 157 // Bitcast result to int to avoid printing in scientific notation, 158 // which does not display all significant digits. 159 160 // CHECK-NEXT: 1258291198 161 // hex: 0x4AFFFFFE 162 call @func_roundf$bitcast_result_to_int(%c8388606_5) : (f32) -> () 163 // CHECK-NEXT: 1258291198 164 // hex: 0x4AFFFFFE 165 call @func_roundf$bitcast_result_to_int(%c8388607) : (f32) -> () 166 // CHECK-NEXT: 1258291200 167 // hex: 0x4B000000 168 call @func_roundf$bitcast_result_to_int(%c8388607_5) : (f32) -> () 169 // CHECK-NEXT: 1258291200 170 // hex: 0x4B000000 171 call @func_roundf$bitcast_result_to_int(%c8388608) : (f32) -> () 172 // CHECK-NEXT: 1258291201 173 // hex: 0x4B000001 174 call @func_roundf$bitcast_result_to_int(%c8388609) : (f32) -> () 175 176 // Check that vector type works 177 %cVec = arith.constant dense<[0.5]> : vector<1xf32> 178 // CHECK-NEXT: ( 1 ) 179 call @func_roundf$vector(%cVec) : (vector<1xf32>) -> () 180 181 return 182} 183 184// -------------------------------------------------------------------------- // 185// pow. 186// -------------------------------------------------------------------------- // 187func.func @func_powff64(%a : f64, %b : f64) { 188 %r = math.powf %a, %b : f64 189 vector.print %r : f64 190 return 191} 192 193func.func @func_powff32(%a : f32, %b : f32) { 194 %r = math.powf %a, %b : f32 195 vector.print %r : f32 196 return 197} 198 199func.func @powf() { 200 // CHECK-NEXT: 16 201 %a = arith.constant 4.0 : f64 202 %a_p = arith.constant 2.0 : f64 203 call @func_powff64(%a, %a_p) : (f64, f64) -> () 204 205 // CHECK-NEXT: 2.343 206 %c = arith.constant 2.343 : f64 207 %c_p = arith.constant 1.000 : f64 208 call @func_powff64(%c, %c_p) : (f64, f64) -> () 209 210 // CHECK-NEXT: 0.176171 211 %d = arith.constant 4.25 : f64 212 %d_p = arith.constant -1.2 : f64 213 call @func_powff64(%d, %d_p) : (f64, f64) -> () 214 215 // CHECK-NEXT: 1 216 %e = arith.constant 4.385 : f64 217 %e_p = arith.constant 0.00 : f64 218 call @func_powff64(%e, %e_p) : (f64, f64) -> () 219 220 // CHECK-NEXT: 6.62637 221 %f = arith.constant 4.835 : f64 222 %f_p = arith.constant 1.2 : f64 223 call @func_powff64(%f, %f_p) : (f64, f64) -> () 224 225 // CHECK-NEXT: nan 226 %i = arith.constant 1.0 : f64 227 %h = arith.constant 0x7fffffffffffffff : f64 228 call @func_powff64(%i, %h) : (f64, f64) -> () 229 230 // CHECK-NEXT: inf 231 %j = arith.constant 29385.0 : f64 232 %j_p = arith.constant 23598.0 : f64 233 call @func_powff64(%j, %j_p) : (f64, f64) -> () 234 235 // CHECK-NEXT: -nan 236 %k = arith.constant 1.0 : f64 237 %k_p = arith.constant 0xfff0000001000000 : f64 238 call @func_powff64(%k, %k_p) : (f64, f64) -> () 239 240 // CHECK-NEXT: -nan 241 %l = arith.constant 1.0 : f32 242 %l_p = arith.constant 0xffffffff : f32 243 call @func_powff32(%l, %l_p) : (f32, f32) -> () 244 245 // CHECK-NEXT: 1 246 %zero = arith.constant 0.0 : f32 247 call @func_powff32(%zero, %zero) : (f32, f32) -> () 248 249 return 250} 251 252// -------------------------------------------------------------------------- // 253// roundeven. 254// -------------------------------------------------------------------------- // 255 256func.func @func_roundeven32(%a : f32) { 257 %b = math.roundeven %a : f32 258 vector.print %b : f32 259 return 260} 261 262func.func @func_roundeven32$bitcast_result_to_int(%a : f32) { 263 %b = math.roundeven %a : f32 264 %c = arith.bitcast %b : f32 to i32 265 vector.print %c : i32 266 return 267} 268 269func.func @func_roundeven32$vector(%a : vector<1xf32>) { 270 %b = math.roundeven %a : vector<1xf32> 271 vector.print %b : vector<1xf32> 272 return 273} 274 275func.func @roundeven32() { 276 %c0_25 = arith.constant 0.25 : f32 277 %c0_5 = arith.constant 0.5 : f32 278 %c0_75 = arith.constant 0.75 : f32 279 %c1 = arith.constant 1.0 : f32 280 %c1_25 = arith.constant 1.25 : f32 281 %c1_5 = arith.constant 1.5 : f32 282 %c1_75 = arith.constant 1.75 : f32 283 %c2 = arith.constant 2.0 : f32 284 %c2_25 = arith.constant 2.25 : f32 285 %c2_5 = arith.constant 2.5 : f32 286 %c2_75 = arith.constant 2.75 : f32 287 %c3 = arith.constant 3.0 : f32 288 %c3_25 = arith.constant 3.25 : f32 289 %c3_5 = arith.constant 3.5 : f32 290 %c3_75 = arith.constant 3.75 : f32 291 292 %cNeg0_25 = arith.constant -0.25 : f32 293 %cNeg0_5 = arith.constant -0.5 : f32 294 %cNeg0_75 = arith.constant -0.75 : f32 295 %cNeg1 = arith.constant -1.0 : f32 296 %cNeg1_25 = arith.constant -1.25 : f32 297 %cNeg1_5 = arith.constant -1.5 : f32 298 %cNeg1_75 = arith.constant -1.75 : f32 299 %cNeg2 = arith.constant -2.0 : f32 300 %cNeg2_25 = arith.constant -2.25 : f32 301 %cNeg2_5 = arith.constant -2.5 : f32 302 %cNeg2_75 = arith.constant -2.75 : f32 303 %cNeg3 = arith.constant -3.0 : f32 304 %cNeg3_25 = arith.constant -3.25 : f32 305 %cNeg3_5 = arith.constant -3.5 : f32 306 %cNeg3_75 = arith.constant -3.75 : f32 307 308 // CHECK-NEXT: 0 309 call @func_roundeven32(%c0_25) : (f32) -> () 310 // CHECK-NEXT: 0 311 call @func_roundeven32(%c0_5) : (f32) -> () 312 // CHECK-NEXT: 1 313 call @func_roundeven32(%c0_75) : (f32) -> () 314 // CHECK-NEXT: 1 315 call @func_roundeven32(%c1) : (f32) -> () 316 // CHECK-NEXT: 1 317 call @func_roundeven32(%c1_25) : (f32) -> () 318 // CHECK-NEXT: 2 319 call @func_roundeven32(%c1_5) : (f32) -> () 320 // CHECK-NEXT: 2 321 call @func_roundeven32(%c1_75) : (f32) -> () 322 // CHECK-NEXT: 2 323 call @func_roundeven32(%c2) : (f32) -> () 324 // CHECK-NEXT: 2 325 call @func_roundeven32(%c2_25) : (f32) -> () 326 // CHECK-NEXT: 2 327 call @func_roundeven32(%c2_5) : (f32) -> () 328 // CHECK-NEXT: 3 329 call @func_roundeven32(%c2_75) : (f32) -> () 330 // CHECK-NEXT: 3 331 call @func_roundeven32(%c3) : (f32) -> () 332 // CHECK-NEXT: 3 333 call @func_roundeven32(%c3_25) : (f32) -> () 334 // CHECK-NEXT: 4 335 call @func_roundeven32(%c3_5) : (f32) -> () 336 // CHECK-NEXT: 4 337 call @func_roundeven32(%c3_75) : (f32) -> () 338 339 // CHECK-NEXT: -0 340 call @func_roundeven32(%cNeg0_25) : (f32) -> () 341 // CHECK-NEXT: -0 342 call @func_roundeven32(%cNeg0_5) : (f32) -> () 343 // CHECK-NEXT: -1 344 call @func_roundeven32(%cNeg0_75) : (f32) -> () 345 // CHECK-NEXT: -1 346 call @func_roundeven32(%cNeg1) : (f32) -> () 347 // CHECK-NEXT: -1 348 call @func_roundeven32(%cNeg1_25) : (f32) -> () 349 // CHECK-NEXT: -2 350 call @func_roundeven32(%cNeg1_5) : (f32) -> () 351 // CHECK-NEXT: -2 352 call @func_roundeven32(%cNeg1_75) : (f32) -> () 353 // CHECK-NEXT: -2 354 call @func_roundeven32(%cNeg2) : (f32) -> () 355 // CHECK-NEXT: -2 356 call @func_roundeven32(%cNeg2_25) : (f32) -> () 357 // CHECK-NEXT: -2 358 call @func_roundeven32(%cNeg2_5) : (f32) -> () 359 // CHECK-NEXT: -3 360 call @func_roundeven32(%cNeg2_75) : (f32) -> () 361 // CHECK-NEXT: -3 362 call @func_roundeven32(%cNeg3) : (f32) -> () 363 // CHECK-NEXT: -3 364 call @func_roundeven32(%cNeg3_25) : (f32) -> () 365 // CHECK-NEXT: -4 366 call @func_roundeven32(%cNeg3_5) : (f32) -> () 367 // CHECK-NEXT: -4 368 call @func_roundeven32(%cNeg3_75) : (f32) -> () 369 370 // Special values: 0, -0, inf, -inf, nan, -nan 371 %cNeg0 = arith.constant -0.0 : f32 372 %c0 = arith.constant 0.0 : f32 373 %cInfInt = arith.constant 0x7f800000 : i32 374 %cInf = arith.bitcast %cInfInt : i32 to f32 375 %cNegInfInt = arith.constant 0xff800000 : i32 376 %cNegInf = arith.bitcast %cNegInfInt : i32 to f32 377 %cNanInt = arith.constant 0x7fc00000 : i32 378 %cNan = arith.bitcast %cNanInt : i32 to f32 379 %cNegNanInt = arith.constant 0xffc00000 : i32 380 %cNegNan = arith.bitcast %cNegNanInt : i32 to f32 381 382 // CHECK-NEXT: -0 383 call @func_roundeven32(%cNeg0) : (f32) -> () 384 // CHECK-NEXT: 0 385 call @func_roundeven32(%c0) : (f32) -> () 386 // CHECK-NEXT: inf 387 call @func_roundeven32(%cInf) : (f32) -> () 388 // CHECK-NEXT: -inf 389 call @func_roundeven32(%cNegInf) : (f32) -> () 390 // Per IEEE 754-2008, sign is not required when printing a negative NaN, so 391 // print as an int to ensure input NaN is left unchanged. 392 // CHECK-NEXT: 2143289344 393 // CHECK-NEXT: 2143289344 394 call @func_roundeven32$bitcast_result_to_int(%cNan) : (f32) -> () 395 vector.print %cNanInt : i32 396 // CHECK-NEXT: -4194304 397 // CHECK-NEXT: -4194304 398 call @func_roundeven32$bitcast_result_to_int(%cNegNan) : (f32) -> () 399 vector.print %cNegNanInt : i32 400 401 402 // Values above and below 2^23 = 8388608 403 %c8388606_5 = arith.constant 8388606.5 : f32 404 %c8388607 = arith.constant 8388607.0 : f32 405 %c8388607_5 = arith.constant 8388607.5 : f32 406 %c8388608 = arith.constant 8388608.0 : f32 407 %c8388609 = arith.constant 8388609.0 : f32 408 409 // Bitcast result to int to avoid printing in scientific notation, 410 // which does not display all significant digits. 411 412 // CHECK-NEXT: 1258291196 413 // hex: 0x4AFFFFFC 414 call @func_roundeven32$bitcast_result_to_int(%c8388606_5) : (f32) -> () 415 // CHECK-NEXT: 1258291198 416 // hex: 0x4AFFFFFE 417 call @func_roundeven32$bitcast_result_to_int(%c8388607) : (f32) -> () 418 // CHECK-NEXT: 1258291200 419 // hex: 0x4B000000 420 call @func_roundeven32$bitcast_result_to_int(%c8388607_5) : (f32) -> () 421 // CHECK-NEXT: 1258291200 422 // hex: 0x4B000000 423 call @func_roundeven32$bitcast_result_to_int(%c8388608) : (f32) -> () 424 // CHECK-NEXT: 1258291201 425 // hex: 0x4B000001 426 call @func_roundeven32$bitcast_result_to_int(%c8388609) : (f32) -> () 427 428 429 // Check that vector type works 430 %cVec = arith.constant dense<[0.5]> : vector<1xf32> 431 // CHECK-NEXT: ( 0 ) 432 call @func_roundeven32$vector(%cVec) : (vector<1xf32>) -> () 433 return 434} 435 436func.func @func_roundeven64(%a : f64) { 437 %b = math.roundeven %a : f64 438 vector.print %b : f64 439 return 440} 441 442func.func @func_roundeven64$bitcast_result_to_int(%a : f64) { 443 %b = math.roundeven %a : f64 444 %c = arith.bitcast %b : f64 to i64 445 vector.print %c : i64 446 return 447} 448 449func.func @func_roundeven64$vector(%a : vector<1xf64>) { 450 %b = math.roundeven %a : vector<1xf64> 451 vector.print %b : vector<1xf64> 452 return 453} 454 455func.func @roundeven64() { 456 %c0_25 = arith.constant 0.25 : f64 457 %c0_5 = arith.constant 0.5 : f64 458 %c0_75 = arith.constant 0.75 : f64 459 %c1 = arith.constant 1.0 : f64 460 %c1_25 = arith.constant 1.25 : f64 461 %c1_5 = arith.constant 1.5 : f64 462 %c1_75 = arith.constant 1.75 : f64 463 %c2 = arith.constant 2.0 : f64 464 %c2_25 = arith.constant 2.25 : f64 465 %c2_5 = arith.constant 2.5 : f64 466 %c2_75 = arith.constant 2.75 : f64 467 %c3 = arith.constant 3.0 : f64 468 %c3_25 = arith.constant 3.25 : f64 469 %c3_5 = arith.constant 3.5 : f64 470 %c3_75 = arith.constant 3.75 : f64 471 472 %cNeg0_25 = arith.constant -0.25 : f64 473 %cNeg0_5 = arith.constant -0.5 : f64 474 %cNeg0_75 = arith.constant -0.75 : f64 475 %cNeg1 = arith.constant -1.0 : f64 476 %cNeg1_25 = arith.constant -1.25 : f64 477 %cNeg1_5 = arith.constant -1.5 : f64 478 %cNeg1_75 = arith.constant -1.75 : f64 479 %cNeg2 = arith.constant -2.0 : f64 480 %cNeg2_25 = arith.constant -2.25 : f64 481 %cNeg2_5 = arith.constant -2.5 : f64 482 %cNeg2_75 = arith.constant -2.75 : f64 483 %cNeg3 = arith.constant -3.0 : f64 484 %cNeg3_25 = arith.constant -3.25 : f64 485 %cNeg3_5 = arith.constant -3.5 : f64 486 %cNeg3_75 = arith.constant -3.75 : f64 487 488 // CHECK-NEXT: 0 489 call @func_roundeven64(%c0_25) : (f64) -> () 490 // CHECK-NEXT: 0 491 call @func_roundeven64(%c0_5) : (f64) -> () 492 // CHECK-NEXT: 1 493 call @func_roundeven64(%c0_75) : (f64) -> () 494 // CHECK-NEXT: 1 495 call @func_roundeven64(%c1) : (f64) -> () 496 // CHECK-NEXT: 1 497 call @func_roundeven64(%c1_25) : (f64) -> () 498 // CHECK-NEXT: 2 499 call @func_roundeven64(%c1_5) : (f64) -> () 500 // CHECK-NEXT: 2 501 call @func_roundeven64(%c1_75) : (f64) -> () 502 // CHECK-NEXT: 2 503 call @func_roundeven64(%c2) : (f64) -> () 504 // CHECK-NEXT: 2 505 call @func_roundeven64(%c2_25) : (f64) -> () 506 // CHECK-NEXT: 2 507 call @func_roundeven64(%c2_5) : (f64) -> () 508 // CHECK-NEXT: 3 509 call @func_roundeven64(%c2_75) : (f64) -> () 510 // CHECK-NEXT: 3 511 call @func_roundeven64(%c3) : (f64) -> () 512 // CHECK-NEXT: 3 513 call @func_roundeven64(%c3_25) : (f64) -> () 514 // CHECK-NEXT: 4 515 call @func_roundeven64(%c3_5) : (f64) -> () 516 // CHECK-NEXT: 4 517 call @func_roundeven64(%c3_75) : (f64) -> () 518 519 // CHECK-NEXT: -0 520 call @func_roundeven64(%cNeg0_25) : (f64) -> () 521 // CHECK-NEXT: -0 522 call @func_roundeven64(%cNeg0_5) : (f64) -> () 523 // CHECK-NEXT: -1 524 call @func_roundeven64(%cNeg0_75) : (f64) -> () 525 // CHECK-NEXT: -1 526 call @func_roundeven64(%cNeg1) : (f64) -> () 527 // CHECK-NEXT: -1 528 call @func_roundeven64(%cNeg1_25) : (f64) -> () 529 // CHECK-NEXT: -2 530 call @func_roundeven64(%cNeg1_5) : (f64) -> () 531 // CHECK-NEXT: -2 532 call @func_roundeven64(%cNeg1_75) : (f64) -> () 533 // CHECK-NEXT: -2 534 call @func_roundeven64(%cNeg2) : (f64) -> () 535 // CHECK-NEXT: -2 536 call @func_roundeven64(%cNeg2_25) : (f64) -> () 537 // CHECK-NEXT: -2 538 call @func_roundeven64(%cNeg2_5) : (f64) -> () 539 // CHECK-NEXT: -3 540 call @func_roundeven64(%cNeg2_75) : (f64) -> () 541 // CHECK-NEXT: -3 542 call @func_roundeven64(%cNeg3) : (f64) -> () 543 // CHECK-NEXT: -3 544 call @func_roundeven64(%cNeg3_25) : (f64) -> () 545 // CHECK-NEXT: -4 546 call @func_roundeven64(%cNeg3_5) : (f64) -> () 547 // CHECK-NEXT: -4 548 call @func_roundeven64(%cNeg3_75) : (f64) -> () 549 550 // Special values: 0, -0, inf, -inf, nan, -nan 551 %cNeg0 = arith.constant -0.0 : f64 552 %c0 = arith.constant 0.0 : f64 553 %cInfInt = arith.constant 0x7FF0000000000000 : i64 554 %cInf = arith.bitcast %cInfInt : i64 to f64 555 %cNegInfInt = arith.constant 0xFFF0000000000000 : i64 556 %cNegInf = arith.bitcast %cNegInfInt : i64 to f64 557 %cNanInt = arith.constant 0x7FF0000000000001 : i64 558 %cNan = arith.bitcast %cNanInt : i64 to f64 559 %cNegNanInt = arith.constant 0xFFF0000000000001 : i64 560 %cNegNan = arith.bitcast %cNegNanInt : i64 to f64 561 562 // CHECK-NEXT: -0 563 call @func_roundeven64(%cNeg0) : (f64) -> () 564 // CHECK-NEXT: 0 565 call @func_roundeven64(%c0) : (f64) -> () 566 // CHECK-NEXT: inf 567 call @func_roundeven64(%cInf) : (f64) -> () 568 // CHECK-NEXT: -inf 569 call @func_roundeven64(%cNegInf) : (f64) -> () 570 571 // Values above and below 2^52 = 4503599627370496 572 %c4503599627370494_5 = arith.constant 4503599627370494.5 : f64 573 %c4503599627370495 = arith.constant 4503599627370495.0 : f64 574 %c4503599627370495_5 = arith.constant 4503599627370495.5 : f64 575 %c4503599627370496 = arith.constant 4503599627370496.0 : f64 576 %c4503599627370497 = arith.constant 4503599627370497.0 : f64 577 578 // Bitcast result to int to avoid printing in scientific notation, 579 // which does not display all significant digits. 580 581 // CHECK-NEXT: 4841369599423283196 582 // hex: 0x432ffffffffffffc 583 call @func_roundeven64$bitcast_result_to_int(%c4503599627370494_5) : (f64) -> () 584 // CHECK-NEXT: 4841369599423283198 585 // hex: 0x432ffffffffffffe 586 call @func_roundeven64$bitcast_result_to_int(%c4503599627370495) : (f64) -> () 587 // CHECK-NEXT: 4841369599423283200 588 // hex: 0x4330000000000000 589 call @func_roundeven64$bitcast_result_to_int(%c4503599627370495_5) : (f64) -> () 590 // CHECK-NEXT: 4841369599423283200 591 // hex: 0x10000000000000 592 call @func_roundeven64$bitcast_result_to_int(%c4503599627370496) : (f64) -> () 593 // CHECK-NEXT: 4841369599423283201 594 // hex: 0x10000000000001 595 call @func_roundeven64$bitcast_result_to_int(%c4503599627370497) : (f64) -> () 596 597 // Check that vector type works 598 %cVec = arith.constant dense<[0.5]> : vector<1xf64> 599 // CHECK-NEXT: ( 0 ) 600 call @func_roundeven64$vector(%cVec) : (vector<1xf64>) -> () 601 return 602} 603 604func.func @roundeven() { 605 call @roundeven32() : () -> () 606 call @roundeven64() : () -> () 607 return 608} 609 610// -------------------------------------------------------------------------- // 611// Sinh. 612// -------------------------------------------------------------------------- // 613 614func.func @sinh_f32(%a : f32) { 615 %r = math.sinh %a : f32 616 vector.print %r : f32 617 return 618} 619 620func.func @sinh_4xf32(%a : vector<4xf32>) { 621 %r = math.sinh %a : vector<4xf32> 622 vector.print %r : vector<4xf32> 623 return 624} 625 626func.func @sinh_8xf32(%a : vector<8xf32>) { 627 %r = math.sinh %a : vector<8xf32> 628 vector.print %r : vector<8xf32> 629 return 630} 631 632func.func @sinh() { 633 // CHECK: 1.60192 634 %f0 = arith.constant 1.25 : f32 635 call @sinh_f32(%f0) : (f32) -> () 636 637 // CHECK: 0.252612, 0.822317, 1.1752, 1.60192 638 %v1 = arith.constant dense<[0.25, 0.75, 1.0, 1.25]> : vector<4xf32> 639 call @sinh_4xf32(%v1) : (vector<4xf32>) -> () 640 641 // CHECK: 0.100167, 0.201336, 0.30452, 0.410752, 0.521095, 0.636654, 0.758584, 0.888106 642 %v2 = arith.constant dense<[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]> : vector<8xf32> 643 call @sinh_8xf32(%v2) : (vector<8xf32>) -> () 644 645 // CHECK: -0.100167, -0.201336, -0.30452, -0.410752, -0.521095, -0.636654, -0.758584, -0.888106 646 %v3 = arith.constant dense<[-0.1, -0.2, -0.3, -0.4, -0.5, -0.6, -0.7, -0.8]> : vector<8xf32> 647 call @sinh_8xf32(%v3) : (vector<8xf32>) -> () 648 649 // CHECK: nan 650 %nan = arith.constant 0x7fc00000 : f32 651 call @sinh_f32(%nan) : (f32) -> () 652 653 return 654} 655 656// -------------------------------------------------------------------------- // 657// Cosh. 658// -------------------------------------------------------------------------- // 659 660func.func @cosh_f32(%a : f32) { 661 %r = math.cosh %a : f32 662 vector.print %r : f32 663 return 664} 665 666func.func @cosh_4xf32(%a : vector<4xf32>) { 667 %r = math.cosh %a : vector<4xf32> 668 vector.print %r : vector<4xf32> 669 return 670} 671 672func.func @cosh_8xf32(%a : vector<8xf32>) { 673 %r = math.cosh %a : vector<8xf32> 674 vector.print %r : vector<8xf32> 675 return 676} 677 678func.func @cosh() { 679 // CHECK: 1.88842 680 %f0 = arith.constant 1.25 : f32 681 call @cosh_f32(%f0) : (f32) -> () 682 683 // CHECK: 1.03141, 1.29468, 1.54308, 1.88842 684 %v1 = arith.constant dense<[0.25, 0.75, 1.0, 1.25]> : vector<4xf32> 685 call @cosh_4xf32(%v1) : (vector<4xf32>) -> () 686 687 // CHECK: 1.005, 1.02007, 1.04534, 1.08107, 1.12763, 1.18547, 1.25517, 1.33743 688 %v2 = arith.constant dense<[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]> : vector<8xf32> 689 call @cosh_8xf32(%v2) : (vector<8xf32>) -> () 690 691 // CHECK: 1.005, 1.02007, 1.04534, 1.08107, 1.12763, 1.18547, 1.25517, 1.33743 692 %v3 = arith.constant dense<[-0.1, -0.2, -0.3, -0.4, -0.5, -0.6, -0.7, -0.8]> : vector<8xf32> 693 call @cosh_8xf32(%v3) : (vector<8xf32>) -> () 694 695 // CHECK: nan 696 %nan = arith.constant 0x7fc00000 : f32 697 call @cosh_f32(%nan) : (f32) -> () 698 699 return 700} 701 702// -------------------------------------------------------------------------- // 703// Tanh. 704// -------------------------------------------------------------------------- // 705 706func.func @tanh_8xf32(%a : vector<8xf32>) { 707 %r = math.tanh %a : vector<8xf32> 708 vector.print %r : vector<8xf32> 709 return 710} 711 712func.func @tanh() { 713 // CHECK: -1, -0.761594, -0.291313, 0, 0.291313, 0.761594, 1, 1 714 %v3 = arith.constant dense<[0xff800000, -1.0, -0.3, 0.0, 0.3, 1.0, 10.0, 0x7f800000]> : vector<8xf32> 715 call @tanh_8xf32(%v3) : (vector<8xf32>) -> () 716 717 return 718} 719 720// -------------------------------------------------------------------------- // 721// Asinh. 722// -------------------------------------------------------------------------- // 723 724func.func @asinh_f32(%a : f32) { 725 %r = math.asinh %a : f32 726 vector.print %r : f32 727 return 728} 729 730func.func @asinh_3xf32(%a : vector<3xf32>) { 731 %r = math.asinh %a : vector<3xf32> 732 vector.print %r : vector<3xf32> 733 return 734} 735 736func.func @asinh() { 737 // CHECK: 0 738 %zero = arith.constant 0.0 : f32 739 call @asinh_f32(%zero) : (f32) -> () 740 741 // CHECK: 0.881374 742 %cst1 = arith.constant 1.0 : f32 743 call @asinh_f32(%cst1) : (f32) -> () 744 745 // CHECK: -0.881374 746 %cst2 = arith.constant -1.0 : f32 747 call @asinh_f32(%cst2) : (f32) -> () 748 749 // CHECK: 1.81845 750 %cst3 = arith.constant 3.0 : f32 751 call @asinh_f32(%cst3) : (f32) -> () 752 753 // CHECK: 0.247466, 0.790169, 1.44364 754 %vec_x = arith.constant dense<[0.25, 0.875, 2.0]> : vector<3xf32> 755 call @asinh_3xf32(%vec_x) : (vector<3xf32>) -> () 756 757 return 758} 759 760// -------------------------------------------------------------------------- // 761// Acosh. 762// -------------------------------------------------------------------------- // 763 764func.func @acosh_f32(%a : f32) { 765 %r = math.acosh %a : f32 766 vector.print %r : f32 767 return 768} 769 770func.func @acosh_3xf32(%a : vector<3xf32>) { 771 %r = math.acosh %a : vector<3xf32> 772 vector.print %r : vector<3xf32> 773 return 774} 775 776func.func @acosh() { 777 // CHECK: 0 778 %zero = arith.constant 1.0 : f32 779 call @acosh_f32(%zero) : (f32) -> () 780 781 // CHECK: 1.31696 782 %cst1 = arith.constant 2.0 : f32 783 call @acosh_f32(%cst1) : (f32) -> () 784 785 // CHECK: 2.99322 786 %cst2 = arith.constant 10.0 : f32 787 call @acosh_f32(%cst2) : (f32) -> () 788 789 // CHECK: 0.962424, 1.76275, 2.47789 790 %vec_x = arith.constant dense<[1.5, 3.0, 6.0]> : vector<3xf32> 791 call @acosh_3xf32(%vec_x) : (vector<3xf32>) -> () 792 793 return 794} 795 796// -------------------------------------------------------------------------- // 797// Atanh. 798// -------------------------------------------------------------------------- // 799 800func.func @atanh_f32(%a : f32) { 801 %r = math.atanh %a : f32 802 vector.print %r : f32 803 return 804} 805 806func.func @atanh_3xf32(%a : vector<3xf32>) { 807 %r = math.atanh %a : vector<3xf32> 808 vector.print %r : vector<3xf32> 809 return 810} 811 812func.func @atanh() { 813 // CHECK: 0 814 %zero = arith.constant 0.0 : f32 815 call @atanh_f32(%zero) : (f32) -> () 816 817 // CHECK: 0.549306 818 %cst1 = arith.constant 0.5 : f32 819 call @atanh_f32(%cst1) : (f32) -> () 820 821 // CHECK: -0.549306 822 %cst2 = arith.constant -0.5 : f32 823 call @atanh_f32(%cst2) : (f32) -> () 824 825 // CHECK: inf 826 %cst3 = arith.constant 1.0 : f32 827 call @atanh_f32(%cst3) : (f32) -> () 828 829 // CHECK: 0.255413, 0.394229, 2.99448 830 %vec_x = arith.constant dense<[0.25, 0.375, 0.995]> : vector<3xf32> 831 call @atanh_3xf32(%vec_x) : (vector<3xf32>) -> () 832 833 return 834} 835 836// -------------------------------------------------------------------------- // 837// Rsqrt. 838// -------------------------------------------------------------------------- // 839 840func.func @rsqrt_f32(%a : f32) { 841 %r = math.rsqrt %a : f32 842 vector.print %r : f32 843 return 844} 845 846func.func @rsqrt_3xf32(%a : vector<3xf32>) { 847 %r = math.rsqrt %a : vector<3xf32> 848 vector.print %r : vector<3xf32> 849 return 850} 851 852func.func @rsqrt() { 853 // CHECK: 1 854 %zero = arith.constant 1.0 : f32 855 call @rsqrt_f32(%zero) : (f32) -> () 856 857 // CHECK: 0.707107 858 %cst1 = arith.constant 2.0 : f32 859 call @rsqrt_f32(%cst1) : (f32) -> () 860 861 // CHECK: inf 862 %cst2 = arith.constant 0.0 : f32 863 call @rsqrt_f32(%cst2) : (f32) -> () 864 865 // CHECK: nan 866 %cst3 = arith.constant -1.0 : f32 867 call @rsqrt_f32(%cst3) : (f32) -> () 868 869 // CHECK: 0.5, 1.41421, 0.57735 870 %vec_x = arith.constant dense<[4.0, 0.5, 3.0]> : vector<3xf32> 871 call @rsqrt_3xf32(%vec_x) : (vector<3xf32>) -> () 872 873 return 874} 875 876func.func @main() { 877 call @exp2f() : () -> () 878 call @roundf() : () -> () 879 call @powf() : () -> () 880 call @roundeven() : () -> () 881 call @sinh() : () -> () 882 call @cosh() : () -> () 883 call @tanh() : () -> () 884 call @asinh() : () -> () 885 call @acosh() : () -> () 886 call @atanh() : () -> () 887 call @rsqrt() : () -> () 888 return 889} 890