1 switch (this->operation) { 2 case ir_unop_bit_not: 3 for (unsigned c = 0; c < op[0]->type->components(); c++) { 4 switch (op[0]->type->base_type) { 5 case GLSL_TYPE_UINT: 6 data.u[c] = ~ op[0]->value.u[c]; 7 break; 8 case GLSL_TYPE_INT: 9 data.i[c] = ~ op[0]->value.i[c]; 10 break; 11 case GLSL_TYPE_UINT64: 12 data.u64[c] = ~ op[0]->value.u64[c]; 13 break; 14 case GLSL_TYPE_INT64: 15 data.i64[c] = ~ op[0]->value.i64[c]; 16 break; 17 default: 18 unreachable("invalid type"); 19 } 20 } 21 break; 22 23 case ir_unop_logic_not: 24 for (unsigned c = 0; c < op[0]->type->components(); c++) { 25 switch (op[0]->type->base_type) { 26 case GLSL_TYPE_BOOL: 27 data.b[c] = !op[0]->value.b[c]; 28 break; 29 default: 30 unreachable("invalid type"); 31 } 32 } 33 break; 34 35 case ir_unop_neg: 36 for (unsigned c = 0; c < op[0]->type->components(); c++) { 37 switch (op[0]->type->base_type) { 38 case GLSL_TYPE_UINT: 39 data.u[c] = -((int) op[0]->value.u[c]); 40 break; 41 case GLSL_TYPE_INT: 42 data.i[c] = -op[0]->value.i[c]; 43 break; 44 case GLSL_TYPE_FLOAT: 45 data.f[c] = -op[0]->value.f[c]; 46 break; 47 case GLSL_TYPE_DOUBLE: 48 data.d[c] = -op[0]->value.d[c]; 49 break; 50 case GLSL_TYPE_UINT64: 51 data.u64[c] = -op[0]->value.u64[c]; 52 break; 53 case GLSL_TYPE_INT64: 54 data.i64[c] = -op[0]->value.i64[c]; 55 break; 56 default: 57 unreachable("invalid type"); 58 } 59 } 60 break; 61 62 case ir_unop_abs: 63 for (unsigned c = 0; c < op[0]->type->components(); c++) { 64 switch (op[0]->type->base_type) { 65 case GLSL_TYPE_INT: 66 data.i[c] = op[0]->value.i[c] < 0 ? -op[0]->value.i[c] : op[0]->value.i[c]; 67 break; 68 case GLSL_TYPE_FLOAT: 69 data.f[c] = fabsf(op[0]->value.f[c]); 70 break; 71 case GLSL_TYPE_DOUBLE: 72 data.d[c] = fabs(op[0]->value.d[c]); 73 break; 74 case GLSL_TYPE_INT64: 75 data.i64[c] = op[0]->value.i64[c] < 0 ? -op[0]->value.i64[c] : op[0]->value.i64[c]; 76 break; 77 default: 78 unreachable("invalid type"); 79 } 80 } 81 break; 82 83 case ir_unop_sign: 84 for (unsigned c = 0; c < op[0]->type->components(); c++) { 85 switch (op[0]->type->base_type) { 86 case GLSL_TYPE_INT: 87 data.i[c] = (op[0]->value.i[c] > 0) - (op[0]->value.i[c] < 0); 88 break; 89 case GLSL_TYPE_FLOAT: 90 data.f[c] = float((op[0]->value.f[c] > 0.0F) - (op[0]->value.f[c] < 0.0F)); 91 break; 92 case GLSL_TYPE_DOUBLE: 93 data.d[c] = double((op[0]->value.d[c] > 0.0) - (op[0]->value.d[c] < 0.0)); 94 break; 95 case GLSL_TYPE_INT64: 96 data.i64[c] = (op[0]->value.i64[c] > 0) - (op[0]->value.i64[c] < 0); 97 break; 98 default: 99 unreachable("invalid type"); 100 } 101 } 102 break; 103 104 case ir_unop_rcp: 105 for (unsigned c = 0; c < op[0]->type->components(); c++) { 106 switch (op[0]->type->base_type) { 107 case GLSL_TYPE_FLOAT: 108 data.f[c] = 1.0F / op[0]->value.f[c]; 109 break; 110 case GLSL_TYPE_DOUBLE: 111 data.d[c] = 1.0 / op[0]->value.d[c]; 112 break; 113 default: 114 unreachable("invalid type"); 115 } 116 } 117 break; 118 119 case ir_unop_rsq: 120 for (unsigned c = 0; c < op[0]->type->components(); c++) { 121 switch (op[0]->type->base_type) { 122 case GLSL_TYPE_FLOAT: 123 data.f[c] = 1.0F / sqrtf(op[0]->value.f[c]); 124 break; 125 case GLSL_TYPE_DOUBLE: 126 data.d[c] = 1.0 / sqrt(op[0]->value.d[c]); 127 break; 128 default: 129 unreachable("invalid type"); 130 } 131 } 132 break; 133 134 case ir_unop_sqrt: 135 for (unsigned c = 0; c < op[0]->type->components(); c++) { 136 switch (op[0]->type->base_type) { 137 case GLSL_TYPE_FLOAT: 138 data.f[c] = sqrtf(op[0]->value.f[c]); 139 break; 140 case GLSL_TYPE_DOUBLE: 141 data.d[c] = sqrt(op[0]->value.d[c]); 142 break; 143 default: 144 unreachable("invalid type"); 145 } 146 } 147 break; 148 149 case ir_unop_exp: 150 for (unsigned c = 0; c < op[0]->type->components(); c++) { 151 switch (op[0]->type->base_type) { 152 case GLSL_TYPE_FLOAT: 153 data.f[c] = expf(op[0]->value.f[c]); 154 break; 155 default: 156 unreachable("invalid type"); 157 } 158 } 159 break; 160 161 case ir_unop_log: 162 for (unsigned c = 0; c < op[0]->type->components(); c++) { 163 switch (op[0]->type->base_type) { 164 case GLSL_TYPE_FLOAT: 165 data.f[c] = logf(op[0]->value.f[c]); 166 break; 167 default: 168 unreachable("invalid type"); 169 } 170 } 171 break; 172 173 case ir_unop_exp2: 174 for (unsigned c = 0; c < op[0]->type->components(); c++) { 175 switch (op[0]->type->base_type) { 176 case GLSL_TYPE_FLOAT: 177 data.f[c] = exp2f(op[0]->value.f[c]); 178 break; 179 default: 180 unreachable("invalid type"); 181 } 182 } 183 break; 184 185 case ir_unop_log2: 186 for (unsigned c = 0; c < op[0]->type->components(); c++) { 187 switch (op[0]->type->base_type) { 188 case GLSL_TYPE_FLOAT: 189 data.f[c] = log2f(op[0]->value.f[c]); 190 break; 191 default: 192 unreachable("invalid type"); 193 } 194 } 195 break; 196 197 case ir_unop_f2i: 198 for (unsigned c = 0; c < op[0]->type->components(); c++) { 199 switch (op[0]->type->base_type) { 200 case GLSL_TYPE_FLOAT: 201 data.i[c] = (int) op[0]->value.f[c]; 202 break; 203 default: 204 unreachable("invalid type"); 205 } 206 } 207 break; 208 209 case ir_unop_f2u: 210 for (unsigned c = 0; c < op[0]->type->components(); c++) { 211 switch (op[0]->type->base_type) { 212 case GLSL_TYPE_FLOAT: 213 data.u[c] = (unsigned) op[0]->value.f[c]; 214 break; 215 default: 216 unreachable("invalid type"); 217 } 218 } 219 break; 220 221 case ir_unop_i2f: 222 for (unsigned c = 0; c < op[0]->type->components(); c++) { 223 switch (op[0]->type->base_type) { 224 case GLSL_TYPE_INT: 225 data.f[c] = (float) op[0]->value.i[c]; 226 break; 227 default: 228 unreachable("invalid type"); 229 } 230 } 231 break; 232 233 case ir_unop_f2b: 234 for (unsigned c = 0; c < op[0]->type->components(); c++) { 235 switch (op[0]->type->base_type) { 236 case GLSL_TYPE_FLOAT: 237 data.b[c] = op[0]->value.f[c] != 0.0F ? true : false; 238 break; 239 default: 240 unreachable("invalid type"); 241 } 242 } 243 break; 244 245 case ir_unop_b2f: 246 for (unsigned c = 0; c < op[0]->type->components(); c++) { 247 switch (op[0]->type->base_type) { 248 case GLSL_TYPE_BOOL: 249 data.f[c] = op[0]->value.b[c] ? 1.0F : 0.0F; 250 break; 251 default: 252 unreachable("invalid type"); 253 } 254 } 255 break; 256 257 case ir_unop_i2b: 258 for (unsigned c = 0; c < op[0]->type->components(); c++) { 259 switch (op[0]->type->base_type) { 260 case GLSL_TYPE_UINT: 261 data.b[c] = op[0]->value.u[c] ? true : false; 262 break; 263 case GLSL_TYPE_INT: 264 data.b[c] = op[0]->value.i[c] ? true : false; 265 break; 266 default: 267 unreachable("invalid type"); 268 } 269 } 270 break; 271 272 case ir_unop_b2i: 273 for (unsigned c = 0; c < op[0]->type->components(); c++) { 274 switch (op[0]->type->base_type) { 275 case GLSL_TYPE_BOOL: 276 data.i[c] = op[0]->value.b[c] ? 1 : 0; 277 break; 278 default: 279 unreachable("invalid type"); 280 } 281 } 282 break; 283 284 case ir_unop_u2f: 285 for (unsigned c = 0; c < op[0]->type->components(); c++) { 286 switch (op[0]->type->base_type) { 287 case GLSL_TYPE_UINT: 288 data.f[c] = (float) op[0]->value.u[c]; 289 break; 290 default: 291 unreachable("invalid type"); 292 } 293 } 294 break; 295 296 case ir_unop_i2u: 297 for (unsigned c = 0; c < op[0]->type->components(); c++) { 298 switch (op[0]->type->base_type) { 299 case GLSL_TYPE_INT: 300 data.u[c] = op[0]->value.i[c]; 301 break; 302 default: 303 unreachable("invalid type"); 304 } 305 } 306 break; 307 308 case ir_unop_u2i: 309 for (unsigned c = 0; c < op[0]->type->components(); c++) { 310 switch (op[0]->type->base_type) { 311 case GLSL_TYPE_UINT: 312 data.i[c] = op[0]->value.u[c]; 313 break; 314 default: 315 unreachable("invalid type"); 316 } 317 } 318 break; 319 320 case ir_unop_d2f: 321 for (unsigned c = 0; c < op[0]->type->components(); c++) { 322 switch (op[0]->type->base_type) { 323 case GLSL_TYPE_DOUBLE: 324 data.f[c] = op[0]->value.d[c]; 325 break; 326 default: 327 unreachable("invalid type"); 328 } 329 } 330 break; 331 332 case ir_unop_f2d: 333 for (unsigned c = 0; c < op[0]->type->components(); c++) { 334 switch (op[0]->type->base_type) { 335 case GLSL_TYPE_FLOAT: 336 data.d[c] = op[0]->value.f[c]; 337 break; 338 default: 339 unreachable("invalid type"); 340 } 341 } 342 break; 343 344 case ir_unop_d2i: 345 for (unsigned c = 0; c < op[0]->type->components(); c++) { 346 switch (op[0]->type->base_type) { 347 case GLSL_TYPE_DOUBLE: 348 data.i[c] = op[0]->value.d[c]; 349 break; 350 default: 351 unreachable("invalid type"); 352 } 353 } 354 break; 355 356 case ir_unop_i2d: 357 for (unsigned c = 0; c < op[0]->type->components(); c++) { 358 switch (op[0]->type->base_type) { 359 case GLSL_TYPE_INT: 360 data.d[c] = op[0]->value.i[c]; 361 break; 362 default: 363 unreachable("invalid type"); 364 } 365 } 366 break; 367 368 case ir_unop_d2u: 369 for (unsigned c = 0; c < op[0]->type->components(); c++) { 370 switch (op[0]->type->base_type) { 371 case GLSL_TYPE_DOUBLE: 372 data.u[c] = op[0]->value.d[c]; 373 break; 374 default: 375 unreachable("invalid type"); 376 } 377 } 378 break; 379 380 case ir_unop_u2d: 381 for (unsigned c = 0; c < op[0]->type->components(); c++) { 382 switch (op[0]->type->base_type) { 383 case GLSL_TYPE_UINT: 384 data.d[c] = op[0]->value.u[c]; 385 break; 386 default: 387 unreachable("invalid type"); 388 } 389 } 390 break; 391 392 case ir_unop_d2b: 393 for (unsigned c = 0; c < op[0]->type->components(); c++) { 394 switch (op[0]->type->base_type) { 395 case GLSL_TYPE_DOUBLE: 396 data.b[c] = op[0]->value.d[c] != 0.0; 397 break; 398 default: 399 unreachable("invalid type"); 400 } 401 } 402 break; 403 404 case ir_unop_bitcast_i2f: 405 for (unsigned c = 0; c < op[0]->type->components(); c++) { 406 switch (op[0]->type->base_type) { 407 case GLSL_TYPE_INT: 408 data.f[c] = bitcast_u2f(op[0]->value.i[c]); 409 break; 410 default: 411 unreachable("invalid type"); 412 } 413 } 414 break; 415 416 case ir_unop_bitcast_f2i: 417 for (unsigned c = 0; c < op[0]->type->components(); c++) { 418 switch (op[0]->type->base_type) { 419 case GLSL_TYPE_FLOAT: 420 data.i[c] = bitcast_f2u(op[0]->value.f[c]); 421 break; 422 default: 423 unreachable("invalid type"); 424 } 425 } 426 break; 427 428 case ir_unop_bitcast_u2f: 429 for (unsigned c = 0; c < op[0]->type->components(); c++) { 430 switch (op[0]->type->base_type) { 431 case GLSL_TYPE_UINT: 432 data.f[c] = bitcast_u2f(op[0]->value.u[c]); 433 break; 434 default: 435 unreachable("invalid type"); 436 } 437 } 438 break; 439 440 case ir_unop_bitcast_f2u: 441 for (unsigned c = 0; c < op[0]->type->components(); c++) { 442 switch (op[0]->type->base_type) { 443 case GLSL_TYPE_FLOAT: 444 data.u[c] = bitcast_f2u(op[0]->value.f[c]); 445 break; 446 default: 447 unreachable("invalid type"); 448 } 449 } 450 break; 451 452 case ir_unop_bitcast_u642d: 453 for (unsigned c = 0; c < op[0]->type->components(); c++) { 454 switch (op[0]->type->base_type) { 455 case GLSL_TYPE_UINT64: 456 data.d[c] = bitcast_u642d(op[0]->value.u64[c]); 457 break; 458 default: 459 unreachable("invalid type"); 460 } 461 } 462 break; 463 464 case ir_unop_bitcast_i642d: 465 for (unsigned c = 0; c < op[0]->type->components(); c++) { 466 switch (op[0]->type->base_type) { 467 case GLSL_TYPE_INT64: 468 data.d[c] = bitcast_i642d(op[0]->value.i64[c]); 469 break; 470 default: 471 unreachable("invalid type"); 472 } 473 } 474 break; 475 476 case ir_unop_bitcast_d2u64: 477 for (unsigned c = 0; c < op[0]->type->components(); c++) { 478 switch (op[0]->type->base_type) { 479 case GLSL_TYPE_DOUBLE: 480 data.u64[c] = bitcast_d2u64(op[0]->value.d[c]); 481 break; 482 default: 483 unreachable("invalid type"); 484 } 485 } 486 break; 487 488 case ir_unop_bitcast_d2i64: 489 for (unsigned c = 0; c < op[0]->type->components(); c++) { 490 switch (op[0]->type->base_type) { 491 case GLSL_TYPE_DOUBLE: 492 data.i64[c] = bitcast_d2i64(op[0]->value.d[c]); 493 break; 494 default: 495 unreachable("invalid type"); 496 } 497 } 498 break; 499 500 case ir_unop_i642i: 501 for (unsigned c = 0; c < op[0]->type->components(); c++) { 502 switch (op[0]->type->base_type) { 503 case GLSL_TYPE_INT64: 504 data.i[c] = op[0]->value.i64[c]; 505 break; 506 default: 507 unreachable("invalid type"); 508 } 509 } 510 break; 511 512 case ir_unop_u642i: 513 for (unsigned c = 0; c < op[0]->type->components(); c++) { 514 switch (op[0]->type->base_type) { 515 case GLSL_TYPE_UINT64: 516 data.i[c] = op[0]->value.u64[c]; 517 break; 518 default: 519 unreachable("invalid type"); 520 } 521 } 522 break; 523 524 case ir_unop_i642u: 525 for (unsigned c = 0; c < op[0]->type->components(); c++) { 526 switch (op[0]->type->base_type) { 527 case GLSL_TYPE_INT64: 528 data.u[c] = op[0]->value.i64[c]; 529 break; 530 default: 531 unreachable("invalid type"); 532 } 533 } 534 break; 535 536 case ir_unop_u642u: 537 for (unsigned c = 0; c < op[0]->type->components(); c++) { 538 switch (op[0]->type->base_type) { 539 case GLSL_TYPE_UINT64: 540 data.u[c] = op[0]->value.u64[c]; 541 break; 542 default: 543 unreachable("invalid type"); 544 } 545 } 546 break; 547 548 case ir_unop_i642b: 549 for (unsigned c = 0; c < op[0]->type->components(); c++) { 550 switch (op[0]->type->base_type) { 551 case GLSL_TYPE_INT64: 552 data.b[c] = op[0]->value.i64[c] != 0; 553 break; 554 default: 555 unreachable("invalid type"); 556 } 557 } 558 break; 559 560 case ir_unop_i642f: 561 for (unsigned c = 0; c < op[0]->type->components(); c++) { 562 switch (op[0]->type->base_type) { 563 case GLSL_TYPE_INT64: 564 data.f[c] = op[0]->value.i64[c]; 565 break; 566 default: 567 unreachable("invalid type"); 568 } 569 } 570 break; 571 572 case ir_unop_u642f: 573 for (unsigned c = 0; c < op[0]->type->components(); c++) { 574 switch (op[0]->type->base_type) { 575 case GLSL_TYPE_UINT64: 576 data.f[c] = op[0]->value.u64[c]; 577 break; 578 default: 579 unreachable("invalid type"); 580 } 581 } 582 break; 583 584 case ir_unop_i642d: 585 for (unsigned c = 0; c < op[0]->type->components(); c++) { 586 switch (op[0]->type->base_type) { 587 case GLSL_TYPE_INT64: 588 data.d[c] = op[0]->value.i64[c]; 589 break; 590 default: 591 unreachable("invalid type"); 592 } 593 } 594 break; 595 596 case ir_unop_u642d: 597 for (unsigned c = 0; c < op[0]->type->components(); c++) { 598 switch (op[0]->type->base_type) { 599 case GLSL_TYPE_UINT64: 600 data.d[c] = op[0]->value.u64[c]; 601 break; 602 default: 603 unreachable("invalid type"); 604 } 605 } 606 break; 607 608 case ir_unop_i2i64: 609 for (unsigned c = 0; c < op[0]->type->components(); c++) { 610 switch (op[0]->type->base_type) { 611 case GLSL_TYPE_INT: 612 data.i64[c] = op[0]->value.i[c]; 613 break; 614 default: 615 unreachable("invalid type"); 616 } 617 } 618 break; 619 620 case ir_unop_u2i64: 621 for (unsigned c = 0; c < op[0]->type->components(); c++) { 622 switch (op[0]->type->base_type) { 623 case GLSL_TYPE_UINT: 624 data.i64[c] = op[0]->value.u[c]; 625 break; 626 default: 627 unreachable("invalid type"); 628 } 629 } 630 break; 631 632 case ir_unop_b2i64: 633 for (unsigned c = 0; c < op[0]->type->components(); c++) { 634 switch (op[0]->type->base_type) { 635 case GLSL_TYPE_BOOL: 636 data.i64[c] = op[0]->value.b[c]; 637 break; 638 default: 639 unreachable("invalid type"); 640 } 641 } 642 break; 643 644 case ir_unop_f2i64: 645 for (unsigned c = 0; c < op[0]->type->components(); c++) { 646 switch (op[0]->type->base_type) { 647 case GLSL_TYPE_FLOAT: 648 data.i64[c] = op[0]->value.f[c]; 649 break; 650 default: 651 unreachable("invalid type"); 652 } 653 } 654 break; 655 656 case ir_unop_d2i64: 657 for (unsigned c = 0; c < op[0]->type->components(); c++) { 658 switch (op[0]->type->base_type) { 659 case GLSL_TYPE_DOUBLE: 660 data.i64[c] = op[0]->value.d[c]; 661 break; 662 default: 663 unreachable("invalid type"); 664 } 665 } 666 break; 667 668 case ir_unop_i2u64: 669 for (unsigned c = 0; c < op[0]->type->components(); c++) { 670 switch (op[0]->type->base_type) { 671 case GLSL_TYPE_INT: 672 data.u64[c] = op[0]->value.i[c]; 673 break; 674 default: 675 unreachable("invalid type"); 676 } 677 } 678 break; 679 680 case ir_unop_u2u64: 681 for (unsigned c = 0; c < op[0]->type->components(); c++) { 682 switch (op[0]->type->base_type) { 683 case GLSL_TYPE_UINT: 684 data.u64[c] = op[0]->value.u[c]; 685 break; 686 default: 687 unreachable("invalid type"); 688 } 689 } 690 break; 691 692 case ir_unop_f2u64: 693 for (unsigned c = 0; c < op[0]->type->components(); c++) { 694 switch (op[0]->type->base_type) { 695 case GLSL_TYPE_FLOAT: 696 data.u64[c] = op[0]->value.f[c]; 697 break; 698 default: 699 unreachable("invalid type"); 700 } 701 } 702 break; 703 704 case ir_unop_d2u64: 705 for (unsigned c = 0; c < op[0]->type->components(); c++) { 706 switch (op[0]->type->base_type) { 707 case GLSL_TYPE_DOUBLE: 708 data.u64[c] = op[0]->value.d[c]; 709 break; 710 default: 711 unreachable("invalid type"); 712 } 713 } 714 break; 715 716 case ir_unop_u642i64: 717 for (unsigned c = 0; c < op[0]->type->components(); c++) { 718 switch (op[0]->type->base_type) { 719 case GLSL_TYPE_UINT64: 720 data.i64[c] = op[0]->value.u64[c]; 721 break; 722 default: 723 unreachable("invalid type"); 724 } 725 } 726 break; 727 728 case ir_unop_i642u64: 729 for (unsigned c = 0; c < op[0]->type->components(); c++) { 730 switch (op[0]->type->base_type) { 731 case GLSL_TYPE_INT64: 732 data.u64[c] = op[0]->value.i64[c]; 733 break; 734 default: 735 unreachable("invalid type"); 736 } 737 } 738 break; 739 740 case ir_unop_trunc: 741 for (unsigned c = 0; c < op[0]->type->components(); c++) { 742 switch (op[0]->type->base_type) { 743 case GLSL_TYPE_FLOAT: 744 data.f[c] = truncf(op[0]->value.f[c]); 745 break; 746 case GLSL_TYPE_DOUBLE: 747 data.d[c] = trunc(op[0]->value.d[c]); 748 break; 749 default: 750 unreachable("invalid type"); 751 } 752 } 753 break; 754 755 case ir_unop_ceil: 756 for (unsigned c = 0; c < op[0]->type->components(); c++) { 757 switch (op[0]->type->base_type) { 758 case GLSL_TYPE_FLOAT: 759 data.f[c] = ceilf(op[0]->value.f[c]); 760 break; 761 case GLSL_TYPE_DOUBLE: 762 data.d[c] = ceil(op[0]->value.d[c]); 763 break; 764 default: 765 unreachable("invalid type"); 766 } 767 } 768 break; 769 770 case ir_unop_floor: 771 for (unsigned c = 0; c < op[0]->type->components(); c++) { 772 switch (op[0]->type->base_type) { 773 case GLSL_TYPE_FLOAT: 774 data.f[c] = floorf(op[0]->value.f[c]); 775 break; 776 case GLSL_TYPE_DOUBLE: 777 data.d[c] = floor(op[0]->value.d[c]); 778 break; 779 default: 780 unreachable("invalid type"); 781 } 782 } 783 break; 784 785 case ir_unop_fract: 786 for (unsigned c = 0; c < op[0]->type->components(); c++) { 787 switch (op[0]->type->base_type) { 788 case GLSL_TYPE_FLOAT: 789 data.f[c] = op[0]->value.f[c] - floorf(op[0]->value.f[c]); 790 break; 791 case GLSL_TYPE_DOUBLE: 792 data.d[c] = op[0]->value.d[c] - floor(op[0]->value.d[c]); 793 break; 794 default: 795 unreachable("invalid type"); 796 } 797 } 798 break; 799 800 case ir_unop_round_even: 801 for (unsigned c = 0; c < op[0]->type->components(); c++) { 802 switch (op[0]->type->base_type) { 803 case GLSL_TYPE_FLOAT: 804 data.f[c] = _mesa_roundevenf(op[0]->value.f[c]); 805 break; 806 case GLSL_TYPE_DOUBLE: 807 data.d[c] = _mesa_roundeven(op[0]->value.d[c]); 808 break; 809 default: 810 unreachable("invalid type"); 811 } 812 } 813 break; 814 815 case ir_unop_sin: 816 for (unsigned c = 0; c < op[0]->type->components(); c++) { 817 switch (op[0]->type->base_type) { 818 case GLSL_TYPE_FLOAT: 819 data.f[c] = sinf(op[0]->value.f[c]); 820 break; 821 default: 822 unreachable("invalid type"); 823 } 824 } 825 break; 826 827 case ir_unop_cos: 828 for (unsigned c = 0; c < op[0]->type->components(); c++) { 829 switch (op[0]->type->base_type) { 830 case GLSL_TYPE_FLOAT: 831 data.f[c] = cosf(op[0]->value.f[c]); 832 break; 833 default: 834 unreachable("invalid type"); 835 } 836 } 837 break; 838 839 case ir_unop_dFdx: 840 for (unsigned c = 0; c < op[0]->type->components(); c++) { 841 switch (op[0]->type->base_type) { 842 case GLSL_TYPE_FLOAT: 843 data.f[c] = 0.0f; 844 break; 845 default: 846 unreachable("invalid type"); 847 } 848 } 849 break; 850 851 case ir_unop_dFdx_coarse: 852 for (unsigned c = 0; c < op[0]->type->components(); c++) { 853 switch (op[0]->type->base_type) { 854 case GLSL_TYPE_FLOAT: 855 data.f[c] = 0.0f; 856 break; 857 default: 858 unreachable("invalid type"); 859 } 860 } 861 break; 862 863 case ir_unop_dFdx_fine: 864 for (unsigned c = 0; c < op[0]->type->components(); c++) { 865 switch (op[0]->type->base_type) { 866 case GLSL_TYPE_FLOAT: 867 data.f[c] = 0.0f; 868 break; 869 default: 870 unreachable("invalid type"); 871 } 872 } 873 break; 874 875 case ir_unop_dFdy: 876 for (unsigned c = 0; c < op[0]->type->components(); c++) { 877 switch (op[0]->type->base_type) { 878 case GLSL_TYPE_FLOAT: 879 data.f[c] = 0.0f; 880 break; 881 default: 882 unreachable("invalid type"); 883 } 884 } 885 break; 886 887 case ir_unop_dFdy_coarse: 888 for (unsigned c = 0; c < op[0]->type->components(); c++) { 889 switch (op[0]->type->base_type) { 890 case GLSL_TYPE_FLOAT: 891 data.f[c] = 0.0f; 892 break; 893 default: 894 unreachable("invalid type"); 895 } 896 } 897 break; 898 899 case ir_unop_dFdy_fine: 900 for (unsigned c = 0; c < op[0]->type->components(); c++) { 901 switch (op[0]->type->base_type) { 902 case GLSL_TYPE_FLOAT: 903 data.f[c] = 0.0f; 904 break; 905 default: 906 unreachable("invalid type"); 907 } 908 } 909 break; 910 911 case ir_unop_pack_snorm_2x16: 912 switch (op[0]->type->base_type) { 913 case GLSL_TYPE_FLOAT: 914 data.u[0] = pack_2x16(pack_snorm_1x16, op[0]->value.f[0], op[0]->value.f[1]); 915 break; 916 default: 917 unreachable("invalid type"); 918 } 919 break; 920 921 case ir_unop_pack_snorm_4x8: 922 switch (op[0]->type->base_type) { 923 case GLSL_TYPE_FLOAT: 924 data.u[0] = pack_4x8(pack_snorm_1x8, op[0]->value.f[0], op[0]->value.f[1], op[0]->value.f[2], op[0]->value.f[3]); 925 break; 926 default: 927 unreachable("invalid type"); 928 } 929 break; 930 931 case ir_unop_pack_unorm_2x16: 932 switch (op[0]->type->base_type) { 933 case GLSL_TYPE_FLOAT: 934 data.u[0] = pack_2x16(pack_unorm_1x16, op[0]->value.f[0], op[0]->value.f[1]); 935 break; 936 default: 937 unreachable("invalid type"); 938 } 939 break; 940 941 case ir_unop_pack_unorm_4x8: 942 switch (op[0]->type->base_type) { 943 case GLSL_TYPE_FLOAT: 944 data.u[0] = pack_4x8(pack_unorm_1x8, op[0]->value.f[0], op[0]->value.f[1], op[0]->value.f[2], op[0]->value.f[3]); 945 break; 946 default: 947 unreachable("invalid type"); 948 } 949 break; 950 951 case ir_unop_pack_half_2x16: 952 switch (op[0]->type->base_type) { 953 case GLSL_TYPE_FLOAT: 954 data.u[0] = pack_2x16(pack_half_1x16, op[0]->value.f[0], op[0]->value.f[1]); 955 break; 956 default: 957 unreachable("invalid type"); 958 } 959 break; 960 961 case ir_unop_unpack_snorm_2x16: 962 unpack_2x16(unpack_snorm_1x16, op[0]->value.u[0], &data.f[0], &data.f[1]); 963 break; 964 965 case ir_unop_unpack_snorm_4x8: 966 unpack_4x8(unpack_snorm_1x8, op[0]->value.u[0], &data.f[0], &data.f[1], &data.f[2], &data.f[3]); 967 break; 968 969 case ir_unop_unpack_unorm_2x16: 970 unpack_2x16(unpack_unorm_1x16, op[0]->value.u[0], &data.f[0], &data.f[1]); 971 break; 972 973 case ir_unop_unpack_unorm_4x8: 974 unpack_4x8(unpack_unorm_1x8, op[0]->value.u[0], &data.f[0], &data.f[1], &data.f[2], &data.f[3]); 975 break; 976 977 case ir_unop_unpack_half_2x16: 978 unpack_2x16(unpack_half_1x16, op[0]->value.u[0], &data.f[0], &data.f[1]); 979 break; 980 981 case ir_unop_bitfield_reverse: 982 for (unsigned c = 0; c < op[0]->type->components(); c++) { 983 switch (op[0]->type->base_type) { 984 case GLSL_TYPE_UINT: 985 data.u[c] = bitfield_reverse(op[0]->value.u[c]); 986 break; 987 case GLSL_TYPE_INT: 988 data.i[c] = bitfield_reverse(op[0]->value.i[c]); 989 break; 990 default: 991 unreachable("invalid type"); 992 } 993 } 994 break; 995 996 case ir_unop_bit_count: 997 for (unsigned c = 0; c < op[0]->type->components(); c++) { 998 switch (op[0]->type->base_type) { 999 case GLSL_TYPE_UINT: 1000 data.i[c] = _mesa_bitcount(op[0]->value.u[c]); 1001 break; 1002 case GLSL_TYPE_INT: 1003 data.i[c] = _mesa_bitcount(op[0]->value.i[c]); 1004 break; 1005 default: 1006 unreachable("invalid type"); 1007 } 1008 } 1009 break; 1010 1011 case ir_unop_find_msb: 1012 for (unsigned c = 0; c < op[0]->type->components(); c++) { 1013 switch (op[0]->type->base_type) { 1014 case GLSL_TYPE_UINT: 1015 data.i[c] = find_msb_uint(op[0]->value.u[c]); 1016 break; 1017 case GLSL_TYPE_INT: 1018 data.i[c] = find_msb_int(op[0]->value.i[c]); 1019 break; 1020 default: 1021 unreachable("invalid type"); 1022 } 1023 } 1024 break; 1025 1026 case ir_unop_find_lsb: 1027 for (unsigned c = 0; c < op[0]->type->components(); c++) { 1028 switch (op[0]->type->base_type) { 1029 case GLSL_TYPE_UINT: 1030 data.i[c] = find_msb_uint(op[0]->value.u[c] & -op[0]->value.u[c]); 1031 break; 1032 case GLSL_TYPE_INT: 1033 data.i[c] = find_msb_uint(op[0]->value.i[c] & -op[0]->value.i[c]); 1034 break; 1035 default: 1036 unreachable("invalid type"); 1037 } 1038 } 1039 break; 1040 1041 case ir_unop_saturate: 1042 for (unsigned c = 0; c < op[0]->type->components(); c++) { 1043 switch (op[0]->type->base_type) { 1044 case GLSL_TYPE_FLOAT: 1045 data.f[c] = CLAMP(op[0]->value.f[c], 0.0f, 1.0f); 1046 break; 1047 default: 1048 unreachable("invalid type"); 1049 } 1050 } 1051 break; 1052 1053 case ir_unop_pack_double_2x32: 1054 memcpy(&data.d[0], &op[0]->value.u[0], sizeof(double)); 1055 break; 1056 1057 case ir_unop_unpack_double_2x32: 1058 memcpy(&data.u[0], &op[0]->value.d[0], sizeof(double)); 1059 break; 1060 1061 case ir_unop_pack_sampler_2x32: 1062 memcpy(&data.u64[0], &op[0]->value.u[0], sizeof(uint64_t)); 1063 break; 1064 1065 case ir_unop_pack_image_2x32: 1066 memcpy(&data.u64[0], &op[0]->value.u[0], sizeof(uint64_t)); 1067 break; 1068 1069 case ir_unop_unpack_sampler_2x32: 1070 memcpy(&data.u[0], &op[0]->value.u64[0], sizeof(uint64_t)); 1071 break; 1072 1073 case ir_unop_unpack_image_2x32: 1074 memcpy(&data.u[0], &op[0]->value.u64[0], sizeof(uint64_t)); 1075 break; 1076 1077 case ir_unop_pack_int_2x32: 1078 memcpy(&data.i64[0], &op[0]->value.i[0], sizeof(int64_t)); 1079 break; 1080 1081 case ir_unop_pack_uint_2x32: 1082 memcpy(&data.u64[0], &op[0]->value.u[0], sizeof(uint64_t)); 1083 break; 1084 1085 case ir_unop_unpack_int_2x32: 1086 memcpy(&data.i[0], &op[0]->value.i64[0], sizeof(int64_t)); 1087 break; 1088 1089 case ir_unop_unpack_uint_2x32: 1090 memcpy(&data.u[0], &op[0]->value.u64[0], sizeof(uint64_t)); 1091 break; 1092 1093 case ir_binop_add: 1094 assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); 1095 for (unsigned c = 0, c0 = 0, c1 = 0; 1096 c < components; 1097 c0 += c0_inc, c1 += c1_inc, c++) { 1098 1099 switch (op[0]->type->base_type) { 1100 case GLSL_TYPE_UINT: 1101 data.u[c] = op[0]->value.u[c0] + op[1]->value.u[c1]; 1102 break; 1103 case GLSL_TYPE_INT: 1104 data.i[c] = op[0]->value.i[c0] + op[1]->value.i[c1]; 1105 break; 1106 case GLSL_TYPE_FLOAT: 1107 data.f[c] = op[0]->value.f[c0] + op[1]->value.f[c1]; 1108 break; 1109 case GLSL_TYPE_DOUBLE: 1110 data.d[c] = op[0]->value.d[c0] + op[1]->value.d[c1]; 1111 break; 1112 case GLSL_TYPE_UINT64: 1113 data.u64[c] = op[0]->value.u64[c0] + op[1]->value.u64[c1]; 1114 break; 1115 case GLSL_TYPE_INT64: 1116 data.i64[c] = op[0]->value.i64[c0] + op[1]->value.i64[c1]; 1117 break; 1118 default: 1119 unreachable("invalid type"); 1120 } 1121 } 1122 break; 1123 1124 case ir_binop_sub: 1125 assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); 1126 for (unsigned c = 0, c0 = 0, c1 = 0; 1127 c < components; 1128 c0 += c0_inc, c1 += c1_inc, c++) { 1129 1130 switch (op[0]->type->base_type) { 1131 case GLSL_TYPE_UINT: 1132 data.u[c] = op[0]->value.u[c0] - op[1]->value.u[c1]; 1133 break; 1134 case GLSL_TYPE_INT: 1135 data.i[c] = op[0]->value.i[c0] - op[1]->value.i[c1]; 1136 break; 1137 case GLSL_TYPE_FLOAT: 1138 data.f[c] = op[0]->value.f[c0] - op[1]->value.f[c1]; 1139 break; 1140 case GLSL_TYPE_DOUBLE: 1141 data.d[c] = op[0]->value.d[c0] - op[1]->value.d[c1]; 1142 break; 1143 case GLSL_TYPE_UINT64: 1144 data.u64[c] = op[0]->value.u64[c0] - op[1]->value.u64[c1]; 1145 break; 1146 case GLSL_TYPE_INT64: 1147 data.i64[c] = op[0]->value.i64[c0] - op[1]->value.i64[c1]; 1148 break; 1149 default: 1150 unreachable("invalid type"); 1151 } 1152 } 1153 break; 1154 1155 case ir_binop_mul: 1156 /* Check for equal types, or unequal types involving scalars */ 1157 if ((op[0]->type == op[1]->type && !op[0]->type->is_matrix()) 1158 || op0_scalar || op1_scalar) { 1159 for (unsigned c = 0, c0 = 0, c1 = 0; 1160 c < components; 1161 c0 += c0_inc, c1 += c1_inc, c++) { 1162 1163 switch (op[0]->type->base_type) { 1164 case GLSL_TYPE_UINT: 1165 data.u[c] = op[0]->value.u[c0] * op[1]->value.u[c1]; 1166 break; 1167 case GLSL_TYPE_INT: 1168 data.i[c] = op[0]->value.i[c0] * op[1]->value.i[c1]; 1169 break; 1170 case GLSL_TYPE_FLOAT: 1171 data.f[c] = op[0]->value.f[c0] * op[1]->value.f[c1]; 1172 break; 1173 case GLSL_TYPE_DOUBLE: 1174 data.d[c] = op[0]->value.d[c0] * op[1]->value.d[c1]; 1175 break; 1176 case GLSL_TYPE_UINT64: 1177 data.u64[c] = op[0]->value.u64[c0] * op[1]->value.u64[c1]; 1178 break; 1179 case GLSL_TYPE_INT64: 1180 data.i64[c] = op[0]->value.i64[c0] * op[1]->value.i64[c1]; 1181 break; 1182 default: 1183 unreachable("invalid type"); 1184 } 1185 } 1186 } else { 1187 assert(op[0]->type->is_matrix() || op[1]->type->is_matrix()); 1188 1189 /* Multiply an N-by-M matrix with an M-by-P matrix. Since either 1190 * matrix can be a GLSL vector, either N or P can be 1. 1191 * 1192 * For vec*mat, the vector is treated as a row vector. This 1193 * means the vector is a 1-row x M-column matrix. 1194 * 1195 * For mat*vec, the vector is treated as a column vector. Since 1196 * matrix_columns is 1 for vectors, this just works. 1197 */ 1198 const unsigned n = op[0]->type->is_vector() 1199 ? 1 : op[0]->type->vector_elements; 1200 const unsigned m = op[1]->type->vector_elements; 1201 const unsigned p = op[1]->type->matrix_columns; 1202 for (unsigned j = 0; j < p; j++) { 1203 for (unsigned i = 0; i < n; i++) { 1204 for (unsigned k = 0; k < m; k++) { 1205 if (op[0]->type->is_double()) 1206 data.d[i+n*j] += op[0]->value.d[i+n*k]*op[1]->value.d[k+m*j]; 1207 else 1208 data.f[i+n*j] += op[0]->value.f[i+n*k]*op[1]->value.f[k+m*j]; 1209 } 1210 } 1211 } 1212 } 1213 break; 1214 1215 case ir_binop_div: 1216 assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); 1217 for (unsigned c = 0, c0 = 0, c1 = 0; 1218 c < components; 1219 c0 += c0_inc, c1 += c1_inc, c++) { 1220 1221 switch (op[0]->type->base_type) { 1222 case GLSL_TYPE_UINT: 1223 data.u[c] = op[1]->value.u[c1] == 0 ? 0 : op[0]->value.u[c0] / op[1]->value.u[c1]; 1224 break; 1225 case GLSL_TYPE_INT: 1226 data.i[c] = op[1]->value.i[c1] == 0 ? 0 : op[0]->value.i[c0] / op[1]->value.i[c1]; 1227 break; 1228 case GLSL_TYPE_FLOAT: 1229 data.f[c] = op[0]->value.f[c0] / op[1]->value.f[c1]; 1230 break; 1231 case GLSL_TYPE_DOUBLE: 1232 data.d[c] = op[0]->value.d[c0] / op[1]->value.d[c1]; 1233 break; 1234 case GLSL_TYPE_UINT64: 1235 data.u64[c] = op[1]->value.u64[c1] == 0 ? 0 : op[0]->value.u64[c0] / op[1]->value.u64[c1]; 1236 break; 1237 case GLSL_TYPE_INT64: 1238 data.i64[c] = op[1]->value.i64[c1] == 0 ? 0 : op[0]->value.i64[c0] / op[1]->value.i64[c1]; 1239 break; 1240 default: 1241 unreachable("invalid type"); 1242 } 1243 } 1244 break; 1245 1246 case ir_binop_mod: 1247 assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); 1248 for (unsigned c = 0, c0 = 0, c1 = 0; 1249 c < components; 1250 c0 += c0_inc, c1 += c1_inc, c++) { 1251 1252 switch (op[0]->type->base_type) { 1253 case GLSL_TYPE_UINT: 1254 data.u[c] = op[1]->value.u[c1] == 0 ? 0 : op[0]->value.u[c0] % op[1]->value.u[c1]; 1255 break; 1256 case GLSL_TYPE_INT: 1257 data.i[c] = op[1]->value.i[c1] == 0 ? 0 : op[0]->value.i[c0] % op[1]->value.i[c1]; 1258 break; 1259 case GLSL_TYPE_FLOAT: 1260 data.f[c] = op[0]->value.f[c0] - op[1]->value.f[c1] * floorf(op[0]->value.f[c0] / op[1]->value.f[c1]); 1261 break; 1262 case GLSL_TYPE_DOUBLE: 1263 data.d[c] = op[0]->value.d[c0] - op[1]->value.d[c1] * floor(op[0]->value.d[c0] / op[1]->value.d[c1]); 1264 break; 1265 case GLSL_TYPE_UINT64: 1266 data.u64[c] = op[1]->value.u64[c1] == 0 ? 0 : op[0]->value.u64[c0] % op[1]->value.u64[c1]; 1267 break; 1268 case GLSL_TYPE_INT64: 1269 data.i64[c] = op[1]->value.i64[c1] == 0 ? 0 : op[0]->value.i64[c0] % op[1]->value.i64[c1]; 1270 break; 1271 default: 1272 unreachable("invalid type"); 1273 } 1274 } 1275 break; 1276 1277 case ir_binop_less: 1278 for (unsigned c = 0; c < op[0]->type->components(); c++) { 1279 switch (op[0]->type->base_type) { 1280 case GLSL_TYPE_UINT: 1281 data.b[c] = op[0]->value.u[c] < op[1]->value.u[c]; 1282 break; 1283 case GLSL_TYPE_INT: 1284 data.b[c] = op[0]->value.i[c] < op[1]->value.i[c]; 1285 break; 1286 case GLSL_TYPE_FLOAT: 1287 data.b[c] = op[0]->value.f[c] < op[1]->value.f[c]; 1288 break; 1289 case GLSL_TYPE_DOUBLE: 1290 data.b[c] = op[0]->value.d[c] < op[1]->value.d[c]; 1291 break; 1292 case GLSL_TYPE_UINT64: 1293 data.b[c] = op[0]->value.u64[c] < op[1]->value.u64[c]; 1294 break; 1295 case GLSL_TYPE_INT64: 1296 data.b[c] = op[0]->value.i64[c] < op[1]->value.i64[c]; 1297 break; 1298 default: 1299 unreachable("invalid type"); 1300 } 1301 } 1302 break; 1303 1304 case ir_binop_gequal: 1305 for (unsigned c = 0; c < op[0]->type->components(); c++) { 1306 switch (op[0]->type->base_type) { 1307 case GLSL_TYPE_UINT: 1308 data.b[c] = op[0]->value.u[c] >= op[1]->value.u[c]; 1309 break; 1310 case GLSL_TYPE_INT: 1311 data.b[c] = op[0]->value.i[c] >= op[1]->value.i[c]; 1312 break; 1313 case GLSL_TYPE_FLOAT: 1314 data.b[c] = op[0]->value.f[c] >= op[1]->value.f[c]; 1315 break; 1316 case GLSL_TYPE_DOUBLE: 1317 data.b[c] = op[0]->value.d[c] >= op[1]->value.d[c]; 1318 break; 1319 case GLSL_TYPE_UINT64: 1320 data.b[c] = op[0]->value.u64[c] >= op[1]->value.u64[c]; 1321 break; 1322 case GLSL_TYPE_INT64: 1323 data.b[c] = op[0]->value.i64[c] >= op[1]->value.i64[c]; 1324 break; 1325 default: 1326 unreachable("invalid type"); 1327 } 1328 } 1329 break; 1330 1331 case ir_binop_equal: 1332 for (unsigned c = 0; c < op[0]->type->components(); c++) { 1333 switch (op[0]->type->base_type) { 1334 case GLSL_TYPE_UINT: 1335 data.b[c] = op[0]->value.u[c] == op[1]->value.u[c]; 1336 break; 1337 case GLSL_TYPE_INT: 1338 data.b[c] = op[0]->value.i[c] == op[1]->value.i[c]; 1339 break; 1340 case GLSL_TYPE_FLOAT: 1341 data.b[c] = op[0]->value.f[c] == op[1]->value.f[c]; 1342 break; 1343 case GLSL_TYPE_DOUBLE: 1344 data.b[c] = op[0]->value.d[c] == op[1]->value.d[c]; 1345 break; 1346 case GLSL_TYPE_UINT64: 1347 data.b[c] = op[0]->value.u64[c] == op[1]->value.u64[c]; 1348 break; 1349 case GLSL_TYPE_INT64: 1350 data.b[c] = op[0]->value.i64[c] == op[1]->value.i64[c]; 1351 break; 1352 case GLSL_TYPE_BOOL: 1353 data.b[c] = op[0]->value.b[c] == op[1]->value.b[c]; 1354 break; 1355 default: 1356 unreachable("invalid type"); 1357 } 1358 } 1359 break; 1360 1361 case ir_binop_nequal: 1362 for (unsigned c = 0; c < op[0]->type->components(); c++) { 1363 switch (op[0]->type->base_type) { 1364 case GLSL_TYPE_UINT: 1365 data.b[c] = op[0]->value.u[c] != op[1]->value.u[c]; 1366 break; 1367 case GLSL_TYPE_INT: 1368 data.b[c] = op[0]->value.i[c] != op[1]->value.i[c]; 1369 break; 1370 case GLSL_TYPE_FLOAT: 1371 data.b[c] = op[0]->value.f[c] != op[1]->value.f[c]; 1372 break; 1373 case GLSL_TYPE_DOUBLE: 1374 data.b[c] = op[0]->value.d[c] != op[1]->value.d[c]; 1375 break; 1376 case GLSL_TYPE_UINT64: 1377 data.b[c] = op[0]->value.u64[c] != op[1]->value.u64[c]; 1378 break; 1379 case GLSL_TYPE_INT64: 1380 data.b[c] = op[0]->value.i64[c] != op[1]->value.i64[c]; 1381 break; 1382 case GLSL_TYPE_BOOL: 1383 data.b[c] = op[0]->value.b[c] != op[1]->value.b[c]; 1384 break; 1385 default: 1386 unreachable("invalid type"); 1387 } 1388 } 1389 break; 1390 1391 case ir_binop_all_equal: 1392 data.b[0] = op[0]->has_value(op[1]); 1393 break; 1394 1395 case ir_binop_any_nequal: 1396 data.b[0] = !op[0]->has_value(op[1]); 1397 break; 1398 1399 case ir_binop_lshift: 1400 assert(op[0]->type->base_type == GLSL_TYPE_UINT || 1401 op[0]->type->base_type == GLSL_TYPE_INT || 1402 op[0]->type->base_type == GLSL_TYPE_UINT64 || 1403 op[0]->type->base_type == GLSL_TYPE_INT64); 1404 assert(op[1]->type->base_type == GLSL_TYPE_UINT || 1405 op[1]->type->base_type == GLSL_TYPE_INT || 1406 op[1]->type->base_type == GLSL_TYPE_UINT64 || 1407 op[1]->type->base_type == GLSL_TYPE_INT64); 1408 for (unsigned c = 0, c0 = 0, c1 = 0; 1409 c < components; 1410 c0 += c0_inc, c1 += c1_inc, c++) { 1411 1412 switch (op[0]->type->base_type) { 1413 case GLSL_TYPE_UINT: 1414 data.u[c] = op[0]->value.u[c0] << op[1]->value.u[c1]; 1415 break; 1416 case GLSL_TYPE_INT: 1417 data.i[c] = op[0]->value.i[c0] << op[1]->value.i[c1]; 1418 break; 1419 case GLSL_TYPE_UINT64: 1420 data.u64[c] = op[0]->value.u64[c0] << op[1]->value.u64[c1]; 1421 break; 1422 case GLSL_TYPE_INT64: 1423 data.i64[c] = op[0]->value.i64[c0] << op[1]->value.i64[c1]; 1424 break; 1425 default: 1426 unreachable("invalid type"); 1427 } 1428 } 1429 break; 1430 1431 case ir_binop_rshift: 1432 assert(op[0]->type->base_type == GLSL_TYPE_UINT || 1433 op[0]->type->base_type == GLSL_TYPE_INT || 1434 op[0]->type->base_type == GLSL_TYPE_UINT64 || 1435 op[0]->type->base_type == GLSL_TYPE_INT64); 1436 assert(op[1]->type->base_type == GLSL_TYPE_UINT || 1437 op[1]->type->base_type == GLSL_TYPE_INT || 1438 op[1]->type->base_type == GLSL_TYPE_UINT64 || 1439 op[1]->type->base_type == GLSL_TYPE_INT64); 1440 for (unsigned c = 0, c0 = 0, c1 = 0; 1441 c < components; 1442 c0 += c0_inc, c1 += c1_inc, c++) { 1443 1444 switch (op[0]->type->base_type) { 1445 case GLSL_TYPE_UINT: 1446 data.u[c] = op[0]->value.u[c0] >> op[1]->value.u[c1]; 1447 break; 1448 case GLSL_TYPE_INT: 1449 data.i[c] = op[0]->value.i[c0] >> op[1]->value.i[c1]; 1450 break; 1451 case GLSL_TYPE_UINT64: 1452 data.u64[c] = op[0]->value.u64[c0] >> op[1]->value.u64[c1]; 1453 break; 1454 case GLSL_TYPE_INT64: 1455 data.i64[c] = op[0]->value.i64[c0] >> op[1]->value.i64[c1]; 1456 break; 1457 default: 1458 unreachable("invalid type"); 1459 } 1460 } 1461 break; 1462 1463 case ir_binop_bit_and: 1464 assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); 1465 for (unsigned c = 0, c0 = 0, c1 = 0; 1466 c < components; 1467 c0 += c0_inc, c1 += c1_inc, c++) { 1468 1469 switch (op[0]->type->base_type) { 1470 case GLSL_TYPE_UINT: 1471 data.u[c] = op[0]->value.u[c0] & op[1]->value.u[c1]; 1472 break; 1473 case GLSL_TYPE_INT: 1474 data.i[c] = op[0]->value.i[c0] & op[1]->value.i[c1]; 1475 break; 1476 case GLSL_TYPE_UINT64: 1477 data.u64[c] = op[0]->value.u64[c0] & op[1]->value.u64[c1]; 1478 break; 1479 case GLSL_TYPE_INT64: 1480 data.i64[c] = op[0]->value.i64[c0] & op[1]->value.i64[c1]; 1481 break; 1482 default: 1483 unreachable("invalid type"); 1484 } 1485 } 1486 break; 1487 1488 case ir_binop_bit_xor: 1489 assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); 1490 for (unsigned c = 0, c0 = 0, c1 = 0; 1491 c < components; 1492 c0 += c0_inc, c1 += c1_inc, c++) { 1493 1494 switch (op[0]->type->base_type) { 1495 case GLSL_TYPE_UINT: 1496 data.u[c] = op[0]->value.u[c0] ^ op[1]->value.u[c1]; 1497 break; 1498 case GLSL_TYPE_INT: 1499 data.i[c] = op[0]->value.i[c0] ^ op[1]->value.i[c1]; 1500 break; 1501 case GLSL_TYPE_UINT64: 1502 data.u64[c] = op[0]->value.u64[c0] ^ op[1]->value.u64[c1]; 1503 break; 1504 case GLSL_TYPE_INT64: 1505 data.i64[c] = op[0]->value.i64[c0] ^ op[1]->value.i64[c1]; 1506 break; 1507 default: 1508 unreachable("invalid type"); 1509 } 1510 } 1511 break; 1512 1513 case ir_binop_bit_or: 1514 assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); 1515 for (unsigned c = 0, c0 = 0, c1 = 0; 1516 c < components; 1517 c0 += c0_inc, c1 += c1_inc, c++) { 1518 1519 switch (op[0]->type->base_type) { 1520 case GLSL_TYPE_UINT: 1521 data.u[c] = op[0]->value.u[c0] | op[1]->value.u[c1]; 1522 break; 1523 case GLSL_TYPE_INT: 1524 data.i[c] = op[0]->value.i[c0] | op[1]->value.i[c1]; 1525 break; 1526 case GLSL_TYPE_UINT64: 1527 data.u64[c] = op[0]->value.u64[c0] | op[1]->value.u64[c1]; 1528 break; 1529 case GLSL_TYPE_INT64: 1530 data.i64[c] = op[0]->value.i64[c0] | op[1]->value.i64[c1]; 1531 break; 1532 default: 1533 unreachable("invalid type"); 1534 } 1535 } 1536 break; 1537 1538 case ir_binop_logic_and: 1539 for (unsigned c = 0; c < op[0]->type->components(); c++) { 1540 switch (op[0]->type->base_type) { 1541 case GLSL_TYPE_BOOL: 1542 data.b[c] = op[0]->value.b[c] && op[1]->value.b[c]; 1543 break; 1544 default: 1545 unreachable("invalid type"); 1546 } 1547 } 1548 break; 1549 1550 case ir_binop_logic_xor: 1551 for (unsigned c = 0; c < op[0]->type->components(); c++) { 1552 switch (op[0]->type->base_type) { 1553 case GLSL_TYPE_BOOL: 1554 data.b[c] = op[0]->value.b[c] != op[1]->value.b[c]; 1555 break; 1556 default: 1557 unreachable("invalid type"); 1558 } 1559 } 1560 break; 1561 1562 case ir_binop_logic_or: 1563 for (unsigned c = 0; c < op[0]->type->components(); c++) { 1564 switch (op[0]->type->base_type) { 1565 case GLSL_TYPE_BOOL: 1566 data.b[c] = op[0]->value.b[c] || op[1]->value.b[c]; 1567 break; 1568 default: 1569 unreachable("invalid type"); 1570 } 1571 } 1572 break; 1573 1574 case ir_binop_dot: 1575 switch (op[0]->type->base_type) { 1576 case GLSL_TYPE_FLOAT: 1577 data.f[0] = dot_f(op[0], op[1]); 1578 break; 1579 case GLSL_TYPE_DOUBLE: 1580 data.d[0] = dot_d(op[0], op[1]); 1581 break; 1582 default: 1583 unreachable("invalid type"); 1584 } 1585 break; 1586 1587 case ir_binop_min: 1588 assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); 1589 for (unsigned c = 0, c0 = 0, c1 = 0; 1590 c < components; 1591 c0 += c0_inc, c1 += c1_inc, c++) { 1592 1593 switch (op[0]->type->base_type) { 1594 case GLSL_TYPE_UINT: 1595 data.u[c] = MIN2(op[0]->value.u[c0], op[1]->value.u[c1]); 1596 break; 1597 case GLSL_TYPE_INT: 1598 data.i[c] = MIN2(op[0]->value.i[c0], op[1]->value.i[c1]); 1599 break; 1600 case GLSL_TYPE_FLOAT: 1601 data.f[c] = MIN2(op[0]->value.f[c0], op[1]->value.f[c1]); 1602 break; 1603 case GLSL_TYPE_DOUBLE: 1604 data.d[c] = MIN2(op[0]->value.d[c0], op[1]->value.d[c1]); 1605 break; 1606 case GLSL_TYPE_UINT64: 1607 data.u64[c] = MIN2(op[0]->value.u64[c0], op[1]->value.u64[c1]); 1608 break; 1609 case GLSL_TYPE_INT64: 1610 data.i64[c] = MIN2(op[0]->value.i64[c0], op[1]->value.i64[c1]); 1611 break; 1612 default: 1613 unreachable("invalid type"); 1614 } 1615 } 1616 break; 1617 1618 case ir_binop_max: 1619 assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); 1620 for (unsigned c = 0, c0 = 0, c1 = 0; 1621 c < components; 1622 c0 += c0_inc, c1 += c1_inc, c++) { 1623 1624 switch (op[0]->type->base_type) { 1625 case GLSL_TYPE_UINT: 1626 data.u[c] = MAX2(op[0]->value.u[c0], op[1]->value.u[c1]); 1627 break; 1628 case GLSL_TYPE_INT: 1629 data.i[c] = MAX2(op[0]->value.i[c0], op[1]->value.i[c1]); 1630 break; 1631 case GLSL_TYPE_FLOAT: 1632 data.f[c] = MAX2(op[0]->value.f[c0], op[1]->value.f[c1]); 1633 break; 1634 case GLSL_TYPE_DOUBLE: 1635 data.d[c] = MAX2(op[0]->value.d[c0], op[1]->value.d[c1]); 1636 break; 1637 case GLSL_TYPE_UINT64: 1638 data.u64[c] = MAX2(op[0]->value.u64[c0], op[1]->value.u64[c1]); 1639 break; 1640 case GLSL_TYPE_INT64: 1641 data.i64[c] = MAX2(op[0]->value.i64[c0], op[1]->value.i64[c1]); 1642 break; 1643 default: 1644 unreachable("invalid type"); 1645 } 1646 } 1647 break; 1648 1649 case ir_binop_pow: 1650 for (unsigned c = 0; c < op[0]->type->components(); c++) { 1651 switch (op[0]->type->base_type) { 1652 case GLSL_TYPE_FLOAT: 1653 data.f[c] = powf(op[0]->value.f[c], op[1]->value.f[c]); 1654 break; 1655 default: 1656 unreachable("invalid type"); 1657 } 1658 } 1659 break; 1660 1661 case ir_binop_ldexp: 1662 for (unsigned c = 0; c < op[0]->type->components(); c++) { 1663 switch (op[0]->type->base_type) { 1664 case GLSL_TYPE_FLOAT: 1665 data.f[c] = ldexpf_flush_subnormal(op[0]->value.f[c], op[1]->value.i[c]); 1666 break; 1667 case GLSL_TYPE_DOUBLE: 1668 data.d[c] = ldexp_flush_subnormal(op[0]->value.d[c], op[1]->value.i[c]); 1669 break; 1670 default: 1671 unreachable("invalid type"); 1672 } 1673 } 1674 break; 1675 1676 case ir_binop_vector_extract: { 1677 const int c = CLAMP(op[1]->value.i[0], 0, 1678 (int) op[0]->type->vector_elements - 1); 1679 1680 switch (op[0]->type->base_type) { 1681 case GLSL_TYPE_UINT: 1682 data.u[0] = op[0]->value.u[c]; 1683 break; 1684 case GLSL_TYPE_INT: 1685 data.i[0] = op[0]->value.i[c]; 1686 break; 1687 case GLSL_TYPE_FLOAT: 1688 data.f[0] = op[0]->value.f[c]; 1689 break; 1690 case GLSL_TYPE_DOUBLE: 1691 data.d[0] = op[0]->value.d[c]; 1692 break; 1693 case GLSL_TYPE_UINT64: 1694 data.u64[0] = op[0]->value.u64[c]; 1695 break; 1696 case GLSL_TYPE_INT64: 1697 data.i64[0] = op[0]->value.i64[c]; 1698 break; 1699 case GLSL_TYPE_BOOL: 1700 data.b[0] = op[0]->value.b[c]; 1701 break; 1702 default: 1703 unreachable("invalid type"); 1704 } 1705 break; 1706 } 1707 1708 case ir_triop_fma: 1709 for (unsigned c = 0; c < op[0]->type->components(); c++) { 1710 switch (op[0]->type->base_type) { 1711 case GLSL_TYPE_FLOAT: 1712 data.f[c] = op[0]->value.f[c] * op[1]->value.f[c] + op[2]->value.f[c]; 1713 break; 1714 case GLSL_TYPE_DOUBLE: 1715 data.d[c] = op[0]->value.d[c] * op[1]->value.d[c] + op[2]->value.d[c]; 1716 break; 1717 default: 1718 unreachable("invalid type"); 1719 } 1720 } 1721 break; 1722 1723 case ir_triop_lrp: { 1724 assert(op[0]->type->is_float() || op[0]->type->is_double()); 1725 assert(op[1]->type->is_float() || op[1]->type->is_double()); 1726 assert(op[2]->type->is_float() || op[2]->type->is_double()); 1727 1728 unsigned c2_inc = op[2]->type->is_scalar() ? 0 : 1; 1729 for (unsigned c = 0, c2 = 0; c < components; c2 += c2_inc, c++) { 1730 switch (this->type->base_type) { 1731 case GLSL_TYPE_FLOAT: 1732 data.f[c] = op[0]->value.f[c] * (1.0f - op[2]->value.f[c2]) + (op[1]->value.f[c] * op[2]->value.f[c2]); 1733 break; 1734 case GLSL_TYPE_DOUBLE: 1735 data.d[c] = op[0]->value.d[c] * (1.0 - op[2]->value.d[c2]) + (op[1]->value.d[c] * op[2]->value.d[c2]); 1736 break; 1737 default: 1738 unreachable("invalid type"); 1739 } 1740 } 1741 break; 1742 } 1743 1744 case ir_triop_csel: 1745 for (unsigned c = 0; c < components; c++) { 1746 switch (this->type->base_type) { 1747 case GLSL_TYPE_UINT: 1748 data.u[c] = op[0]->value.b[c] ? op[1]->value.u[c] : op[2]->value.u[c]; 1749 break; 1750 case GLSL_TYPE_INT: 1751 data.i[c] = op[0]->value.b[c] ? op[1]->value.i[c] : op[2]->value.i[c]; 1752 break; 1753 case GLSL_TYPE_FLOAT: 1754 data.f[c] = op[0]->value.b[c] ? op[1]->value.f[c] : op[2]->value.f[c]; 1755 break; 1756 case GLSL_TYPE_DOUBLE: 1757 data.d[c] = op[0]->value.b[c] ? op[1]->value.d[c] : op[2]->value.d[c]; 1758 break; 1759 case GLSL_TYPE_UINT64: 1760 data.u64[c] = op[0]->value.b[c] ? op[1]->value.u64[c] : op[2]->value.u64[c]; 1761 break; 1762 case GLSL_TYPE_INT64: 1763 data.i64[c] = op[0]->value.b[c] ? op[1]->value.i64[c] : op[2]->value.i64[c]; 1764 break; 1765 case GLSL_TYPE_BOOL: 1766 data.b[c] = op[0]->value.b[c] ? op[1]->value.b[c] : op[2]->value.b[c]; 1767 break; 1768 default: 1769 unreachable("invalid type"); 1770 } 1771 } 1772 break; 1773 1774 case ir_triop_bitfield_extract: 1775 for (unsigned c = 0; c < op[0]->type->components(); c++) { 1776 switch (op[0]->type->base_type) { 1777 case GLSL_TYPE_UINT: 1778 data.i[c] = bitfield_extract_uint(op[0]->value.u[c], op[1]->value.i[c], op[2]->value.i[c]); 1779 break; 1780 case GLSL_TYPE_INT: 1781 data.i[c] = bitfield_extract_int(op[0]->value.i[c], op[1]->value.i[c], op[2]->value.i[c]); 1782 break; 1783 default: 1784 unreachable("invalid type"); 1785 } 1786 } 1787 break; 1788 1789 case ir_triop_vector_insert: { 1790 const unsigned idx = op[2]->value.u[0]; 1791 1792 memcpy(&data, &op[0]->value, sizeof(data)); 1793 1794 switch (this->type->base_type) { 1795 case GLSL_TYPE_UINT: 1796 data.u[idx] = op[1]->value.u[0]; 1797 break; 1798 case GLSL_TYPE_INT: 1799 data.i[idx] = op[1]->value.i[0]; 1800 break; 1801 case GLSL_TYPE_FLOAT: 1802 data.f[idx] = op[1]->value.f[0]; 1803 break; 1804 case GLSL_TYPE_DOUBLE: 1805 data.d[idx] = op[1]->value.d[0]; 1806 break; 1807 case GLSL_TYPE_UINT64: 1808 data.u64[idx] = op[1]->value.u64[0]; 1809 break; 1810 case GLSL_TYPE_INT64: 1811 data.i64[idx] = op[1]->value.i64[0]; 1812 break; 1813 case GLSL_TYPE_BOOL: 1814 data.b[idx] = op[1]->value.b[0]; 1815 break; 1816 default: 1817 unreachable("invalid type"); 1818 } 1819 break; 1820 } 1821 1822 case ir_quadop_bitfield_insert: 1823 for (unsigned c = 0; c < op[0]->type->components(); c++) { 1824 switch (op[0]->type->base_type) { 1825 case GLSL_TYPE_UINT: 1826 data.u[c] = bitfield_insert(op[0]->value.u[c], op[1]->value.u[c], op[2]->value.i[c], op[3]->value.i[c]); 1827 break; 1828 case GLSL_TYPE_INT: 1829 data.i[c] = bitfield_insert(op[0]->value.i[c], op[1]->value.i[c], op[2]->value.i[c], op[3]->value.i[c]); 1830 break; 1831 default: 1832 unreachable("invalid type"); 1833 } 1834 } 1835 break; 1836 1837 case ir_quadop_vector: 1838 for (unsigned c = 0; c < this->type->vector_elements; c++) { 1839 switch (this->type->base_type) { 1840 case GLSL_TYPE_UINT: 1841 data.u[c] = op[c]->value.u[0]; 1842 break; 1843 case GLSL_TYPE_INT: 1844 data.i[c] = op[c]->value.i[0]; 1845 break; 1846 case GLSL_TYPE_FLOAT: 1847 data.f[c] = op[c]->value.f[0]; 1848 break; 1849 case GLSL_TYPE_DOUBLE: 1850 data.d[c] = op[c]->value.d[0]; 1851 break; 1852 case GLSL_TYPE_UINT64: 1853 data.u64[c] = op[c]->value.u64[0]; 1854 break; 1855 case GLSL_TYPE_INT64: 1856 data.i64[c] = op[c]->value.i64[0]; 1857 break; 1858 case GLSL_TYPE_BOOL: 1859 data.b[c] = op[c]->value.b[0]; 1860 break; 1861 default: 1862 unreachable("invalid type"); 1863 } 1864 } 1865 break; 1866 1867 default: 1868 /* FINISHME: Should handle all expression types. */ 1869 return NULL; 1870 } 1871 1872