1 /************************************************************************** 2 * 3 * Copyright 2011-2012 Advanced Micro Devices, Inc. 4 * Copyright 2009 VMware, Inc. 5 * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas. 6 * All Rights Reserved. 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a 9 * copy of this software and associated documentation files (the 10 * "Software"), to deal in the Software without restriction, including 11 * without limitation the rights to use, copy, modify, merge, publish, 12 * distribute, sub license, and/or sell copies of the Software, and to 13 * permit persons to whom the Software is furnished to do so, subject to 14 * the following conditions: 15 * 16 * The above copyright notice and this permission notice (including the 17 * next paragraph) shall be included in all copies or substantial portions 18 * of the Software. 19 * 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 23 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 24 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 * 28 **************************************************************************/ 29 30 /** 31 * @file 32 * TGSI to LLVM IR translation. 33 * 34 * @author Jose Fonseca <jfonseca (at) vmware.com> 35 * @author Tom Stellard <thomas.stellard (at) amd.com> 36 * 37 * Based on tgsi_sse2.c code written by Michal Krol, Keith Whitwell, 38 * Brian Paul, and others. 39 */ 40 41 42 #include "lp_bld_tgsi_action.h" 43 44 #include "lp_bld_tgsi.h" 45 #include "lp_bld_arit.h" 46 #include "lp_bld_bitarit.h" 47 #include "lp_bld_const.h" 48 #include "lp_bld_gather.h" 49 #include "lp_bld_logic.h" 50 51 #include "tgsi/tgsi_exec.h" 52 53 /* XXX: The CPU only defaults should be repaced by generic ones. In most 54 * cases, the CPU defaults are just wrappers around a function in 55 * lp_build_arit.c and these functions should be inlined here and the CPU 56 * generic code should be removed and placed elsewhere. 57 */ 58 59 /* Default actions */ 60 61 /* Generic fetch_arg functions */ 62 63 static void scalar_unary_fetch_args( 64 struct lp_build_tgsi_context * bld_base, 65 struct lp_build_emit_data * emit_data) 66 { 67 /* src0.x */ 68 emit_data->args[0] = lp_build_emit_fetch(bld_base, emit_data->inst, 0, 0); 69 emit_data->arg_count = 1; 70 emit_data->dst_type = LLVMTypeOf(emit_data->args[0]); 71 } 72 73 static void scalar_binary_fetch_args( 74 struct lp_build_tgsi_context * bld_base, 75 struct lp_build_emit_data * emit_data) 76 { 77 /* src0.x */ 78 emit_data->args[0] = lp_build_emit_fetch(bld_base, emit_data->inst, 79 0, TGSI_CHAN_X); 80 /* src1.x */ 81 emit_data->args[1] = lp_build_emit_fetch(bld_base, emit_data->inst, 82 1, TGSI_CHAN_X); 83 emit_data->arg_count = 2; 84 emit_data->dst_type = LLVMTypeOf(emit_data->args[0]); 85 } 86 87 /* TGSI_OPCODE_ADD */ 88 static void 89 add_emit( 90 const struct lp_build_tgsi_action * action, 91 struct lp_build_tgsi_context * bld_base, 92 struct lp_build_emit_data * emit_data) 93 { 94 emit_data->output[emit_data->chan] = LLVMBuildFAdd( 95 bld_base->base.gallivm->builder, 96 emit_data->args[0], emit_data->args[1], ""); 97 } 98 99 /* TGSI_OPCODE_ARR */ 100 static void 101 arr_emit( 102 const struct lp_build_tgsi_action * action, 103 struct lp_build_tgsi_context * bld_base, 104 struct lp_build_emit_data * emit_data) 105 { 106 LLVMValueRef tmp = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_ROUND, emit_data->args[0]); 107 emit_data->output[emit_data->chan] = LLVMBuildFPToSI(bld_base->base.gallivm->builder, tmp, 108 bld_base->uint_bld.vec_type, ""); 109 } 110 111 /* TGSI_OPCODE_CLAMP */ 112 static void 113 clamp_emit( 114 const struct lp_build_tgsi_action * action, 115 struct lp_build_tgsi_context * bld_base, 116 struct lp_build_emit_data * emit_data) 117 { 118 LLVMValueRef tmp; 119 tmp = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MAX, 120 emit_data->args[0], 121 emit_data->args[1]); 122 emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base, 123 TGSI_OPCODE_MIN, tmp, emit_data->args[2]); 124 } 125 126 /* DP* Helper */ 127 128 static void 129 dp_fetch_args( 130 struct lp_build_tgsi_context * bld_base, 131 struct lp_build_emit_data * emit_data, 132 unsigned dp_components) 133 { 134 unsigned chan, src; 135 for (src = 0; src < 2; src++) { 136 for (chan = 0; chan < dp_components; chan++) { 137 emit_data->args[(src * dp_components) + chan] = 138 lp_build_emit_fetch(bld_base, emit_data->inst, src, chan); 139 } 140 } 141 emit_data->dst_type = bld_base->base.elem_type; 142 } 143 144 /* TGSI_OPCODE_DP2 */ 145 static void 146 dp2_fetch_args( 147 struct lp_build_tgsi_context * bld_base, 148 struct lp_build_emit_data * emit_data) 149 { 150 dp_fetch_args(bld_base, emit_data, 2); 151 } 152 153 static void 154 dp2_emit( 155 const struct lp_build_tgsi_action * action, 156 struct lp_build_tgsi_context * bld_base, 157 struct lp_build_emit_data * emit_data) 158 { 159 LLVMValueRef tmp0, tmp1; 160 tmp0 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, 161 emit_data->args[0] /* src0.x */, 162 emit_data->args[2] /* src1.x */); 163 tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, 164 emit_data->args[1] /* src0.y */, 165 emit_data->args[3] /* src1.y */); 166 emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base, 167 TGSI_OPCODE_ADD, tmp0, tmp1); 168 } 169 170 static struct lp_build_tgsi_action dp2_action = { 171 dp2_fetch_args, /* fetch_args */ 172 dp2_emit /* emit */ 173 }; 174 175 /* TGSI_OPCODE_DP2A */ 176 static void 177 dp2a_fetch_args( 178 struct lp_build_tgsi_context * bld_base, 179 struct lp_build_emit_data * emit_data) 180 { 181 dp_fetch_args(bld_base, emit_data, 2); 182 emit_data->args[5] = lp_build_emit_fetch(bld_base, emit_data->inst, 183 2, TGSI_CHAN_X); 184 } 185 186 static void 187 dp2a_emit( 188 const struct lp_build_tgsi_action * action, 189 struct lp_build_tgsi_context * bld_base, 190 struct lp_build_emit_data * emit_data) 191 { 192 LLVMValueRef tmp; 193 tmp = lp_build_emit_llvm(bld_base, TGSI_OPCODE_DP2, emit_data); 194 emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_ADD, 195 emit_data->args[5], tmp); 196 } 197 198 static struct lp_build_tgsi_action dp2a_action = { 199 dp2a_fetch_args, /* fetch_args */ 200 dp2a_emit /* emit */ 201 }; 202 203 /* TGSI_OPCODE_DP3 */ 204 static void 205 dp3_fetch_args( 206 struct lp_build_tgsi_context * bld_base, 207 struct lp_build_emit_data * emit_data) 208 { 209 dp_fetch_args(bld_base, emit_data, 3); 210 } 211 212 static void 213 dp3_emit( 214 const struct lp_build_tgsi_action * action, 215 struct lp_build_tgsi_context * bld_base, 216 struct lp_build_emit_data * emit_data) 217 { 218 LLVMValueRef tmp0, tmp1; 219 tmp0 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, 220 emit_data->args[0] /* src0.x */, 221 emit_data->args[3] /* src1.x */); 222 tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, 223 emit_data->args[1] /* src0.y */, 224 emit_data->args[4] /* src1.y */); 225 tmp0 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_ADD, tmp1, tmp0); 226 tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, 227 emit_data->args[2] /* src0.z */, 228 emit_data->args[5] /* src1.z */); 229 emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base, 230 TGSI_OPCODE_ADD, tmp0, tmp1); 231 } 232 233 static struct lp_build_tgsi_action dp3_action = { 234 dp3_fetch_args, /* fetch_args */ 235 dp3_emit /* emit */ 236 }; 237 238 /* TGSI_OPCODDE_DP4 */ 239 240 static void 241 dp4_fetch_args( 242 struct lp_build_tgsi_context * bld_base, 243 struct lp_build_emit_data * emit_data) 244 { 245 dp_fetch_args(bld_base, emit_data, 4); 246 } 247 248 static void 249 dp4_emit( 250 const struct lp_build_tgsi_action * action, 251 struct lp_build_tgsi_context * bld_base, 252 struct lp_build_emit_data * emit_data) 253 { 254 LLVMValueRef tmp0, tmp1; 255 tmp0 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, 256 emit_data->args[0] /* src0.x */, 257 emit_data->args[4] /* src1.x */); 258 tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, 259 emit_data->args[1] /* src0.y */, 260 emit_data->args[5] /* src1.y */); 261 tmp0 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_ADD, tmp0, tmp1); 262 tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, 263 emit_data->args[2] /* src0.z */, 264 emit_data->args[6] /* src1.z */); 265 tmp0 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_ADD, tmp0, tmp1); 266 tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, 267 emit_data->args[3] /* src0.w */, 268 emit_data->args[7] /* src1.w */); 269 emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base, 270 TGSI_OPCODE_ADD, tmp0, tmp1); 271 } 272 273 static struct lp_build_tgsi_action dp4_action = { 274 dp4_fetch_args, /* fetch_args */ 275 dp4_emit /* emit */ 276 }; 277 278 /* TGSI_OPCODE_DPH */ 279 static void 280 dph_fetch_args( 281 struct lp_build_tgsi_context * bld_base, 282 struct lp_build_emit_data * emit_data) 283 { 284 dp_fetch_args(bld_base, emit_data, 4); 285 /* src0.w */ 286 emit_data->args[3] = bld_base->base.one; 287 } 288 289 const struct lp_build_tgsi_action dph_action = { 290 dph_fetch_args, /* fetch_args */ 291 dp4_emit /* emit */ 292 }; 293 294 /* TGSI_OPCODE_DST */ 295 static void 296 dst_fetch_args( 297 struct lp_build_tgsi_context * bld_base, 298 struct lp_build_emit_data * emit_data) 299 { 300 /* src0.y */ 301 emit_data->args[0] = lp_build_emit_fetch(bld_base, emit_data->inst, 302 0, TGSI_CHAN_Y); 303 /* src0.z */ 304 emit_data->args[1] = lp_build_emit_fetch(bld_base, emit_data->inst, 305 0, TGSI_CHAN_Z); 306 /* src1.y */ 307 emit_data->args[2] = lp_build_emit_fetch(bld_base, emit_data->inst, 308 1, TGSI_CHAN_Y); 309 /* src1.w */ 310 emit_data->args[3] = lp_build_emit_fetch(bld_base, emit_data->inst, 311 1, TGSI_CHAN_W); 312 } 313 314 static void 315 dst_emit( 316 const struct lp_build_tgsi_action * action, 317 struct lp_build_tgsi_context * bld_base, 318 struct lp_build_emit_data * emit_data) 319 { 320 /* dst.x */ 321 emit_data->output[TGSI_CHAN_X] = bld_base->base.one; 322 323 /* dst.y */ 324 emit_data->output[TGSI_CHAN_Y] = lp_build_emit_llvm_binary(bld_base, 325 TGSI_OPCODE_MUL, 326 emit_data->args[0] /* src0.y */, 327 emit_data->args[2] /* src1.y */); 328 /* dst.z */ 329 emit_data->output[TGSI_CHAN_Z] = emit_data->args[1]; /* src0.z */ 330 331 /* dst.w */ 332 emit_data->output[TGSI_CHAN_W] = emit_data->args[3]; /* src1.w */ 333 } 334 335 static struct lp_build_tgsi_action dst_action = { 336 dst_fetch_args, /* fetch_args */ 337 dst_emit /* emit */ 338 }; 339 340 /* TGSI_OPCODE_END */ 341 static void 342 end_emit( 343 const struct lp_build_tgsi_action * action, 344 struct lp_build_tgsi_context * bld_base, 345 struct lp_build_emit_data * emit_data) 346 { 347 bld_base->pc = -1; 348 } 349 350 /* TGSI_OPCODE_EXP */ 351 352 static void 353 exp_emit( 354 const struct lp_build_tgsi_action * action, 355 struct lp_build_tgsi_context * bld_base, 356 struct lp_build_emit_data * emit_data) 357 { 358 LLVMValueRef floor_x; 359 360 /* floor( src0.x ) */ 361 floor_x = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_FLR, 362 emit_data->args[0]); 363 364 /* 2 ^ floor( src0.x ) */ 365 emit_data->output[TGSI_CHAN_X] = lp_build_emit_llvm_unary(bld_base, 366 TGSI_OPCODE_EX2, floor_x); 367 368 /* src0.x - floor( src0.x ) */ 369 emit_data->output[TGSI_CHAN_Y] = lp_build_emit_llvm_binary(bld_base, 370 TGSI_OPCODE_SUB, emit_data->args[0] /* src0.x */, floor_x); 371 372 /* 2 ^ src0.x */ 373 emit_data->output[TGSI_CHAN_Z] = lp_build_emit_llvm_unary(bld_base, 374 TGSI_OPCODE_EX2, emit_data->args[0] /* src0.x */); 375 376 emit_data->output[TGSI_CHAN_W] = bld_base->base.one; 377 } 378 379 const struct lp_build_tgsi_action exp_action = { 380 scalar_unary_fetch_args, /* fetch_args */ 381 exp_emit /* emit */ 382 }; 383 384 /* TGSI_OPCODE_FRC */ 385 386 static void 387 frc_emit( 388 const struct lp_build_tgsi_action * action, 389 struct lp_build_tgsi_context * bld_base, 390 struct lp_build_emit_data * emit_data) 391 { 392 LLVMValueRef tmp; 393 tmp = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_FLR, 394 emit_data->args[0]); 395 emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base, 396 TGSI_OPCODE_SUB, emit_data->args[0], tmp); 397 } 398 399 /* TGSI_OPCODE_KIL */ 400 401 static void 402 kil_fetch_args( 403 struct lp_build_tgsi_context * bld_base, 404 struct lp_build_emit_data * emit_data) 405 { 406 /* src0.x */ 407 emit_data->args[0] = lp_build_emit_fetch(bld_base, emit_data->inst, 408 0, TGSI_CHAN_X); 409 /* src0.y */ 410 emit_data->args[1] = lp_build_emit_fetch(bld_base, emit_data->inst, 411 0, TGSI_CHAN_Y); 412 /* src0.z */ 413 emit_data->args[2] = lp_build_emit_fetch(bld_base, emit_data->inst, 414 0, TGSI_CHAN_Z); 415 /* src0.w */ 416 emit_data->args[3] = lp_build_emit_fetch(bld_base, emit_data->inst, 417 0, TGSI_CHAN_W); 418 emit_data->arg_count = 4; 419 emit_data->dst_type = LLVMVoidTypeInContext(bld_base->base.gallivm->context); 420 } 421 422 /* TGSI_OPCODE_KILP */ 423 424 static void 425 kilp_fetch_args( 426 struct lp_build_tgsi_context * bld_base, 427 struct lp_build_emit_data * emit_data) 428 { 429 emit_data->dst_type = LLVMVoidTypeInContext(bld_base->base.gallivm->context); 430 } 431 432 /* TGSI_OPCODE_LIT */ 433 434 static void 435 lit_fetch_args( 436 struct lp_build_tgsi_context * bld_base, 437 struct lp_build_emit_data * emit_data) 438 { 439 /* src0.x */ 440 emit_data->args[0] = lp_build_emit_fetch(bld_base, emit_data->inst, 0, TGSI_CHAN_X); 441 /* src0.y */ 442 emit_data->args[1] = lp_build_emit_fetch(bld_base, emit_data->inst, 0, TGSI_CHAN_Y); 443 /* src0.w */ 444 emit_data->args[2] = lp_build_emit_fetch(bld_base, emit_data->inst, 0, TGSI_CHAN_W); 445 emit_data->arg_count = 3; 446 } 447 448 static void 449 lit_emit( 450 const struct lp_build_tgsi_action * action, 451 struct lp_build_tgsi_context * bld_base, 452 struct lp_build_emit_data * emit_data) 453 { 454 LLVMValueRef tmp0, tmp1, tmp2; 455 456 /* dst.x */ 457 emit_data->output[TGSI_CHAN_X] = bld_base->base.one; 458 459 /* dst. y */ 460 emit_data->output[TGSI_CHAN_Y] = lp_build_emit_llvm_binary(bld_base, 461 TGSI_OPCODE_MAX, 462 emit_data->args[0] /* src0.x */, 463 bld_base->base.zero); 464 465 /* dst.z */ 466 /* XMM[1] = SrcReg[0].yyyy */ 467 tmp1 = emit_data->args[1]; 468 /* XMM[1] = max(XMM[1], 0) */ 469 tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MAX, 470 tmp1, bld_base->base.zero); 471 /* XMM[2] = SrcReg[0].wwww */ 472 tmp2 = emit_data->args[2]; 473 tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_POW, 474 tmp1, tmp2); 475 tmp0 = emit_data->args[0]; 476 emit_data->output[TGSI_CHAN_Z] = lp_build_emit_llvm_ternary(bld_base, 477 TGSI_OPCODE_CMP, 478 tmp0, bld_base->base.zero, tmp1); 479 /* dst.w */ 480 emit_data->output[TGSI_CHAN_W] = bld_base->base.one; 481 } 482 483 static struct lp_build_tgsi_action lit_action = { 484 lit_fetch_args, /* fetch_args */ 485 lit_emit /* emit */ 486 }; 487 488 /* TGSI_OPCODE_LOG */ 489 490 static void 491 log_emit( 492 const struct lp_build_tgsi_action * action, 493 struct lp_build_tgsi_context * bld_base, 494 struct lp_build_emit_data * emit_data) 495 { 496 497 LLVMValueRef abs_x, log_abs_x, flr_log_abs_x, ex2_flr_log_abs_x; 498 499 /* abs( src0.x) */ 500 abs_x = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_ABS, 501 emit_data->args[0] /* src0.x */); 502 503 /* log( abs( src0.x ) ) */ 504 log_abs_x = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_LG2, 505 abs_x); 506 507 /* floor( log( abs( src0.x ) ) ) */ 508 flr_log_abs_x = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_FLR, 509 log_abs_x); 510 /* dst.x */ 511 emit_data->output[TGSI_CHAN_X] = flr_log_abs_x; 512 513 /* dst.y */ 514 ex2_flr_log_abs_x = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_EX2, 515 flr_log_abs_x); 516 517 /* abs( src0.x ) / 2^( floor( lg2( abs( src0.x ) ) ) ) */ 518 emit_data->output[TGSI_CHAN_Y] = lp_build_emit_llvm_binary(bld_base, 519 TGSI_OPCODE_DIV, abs_x, ex2_flr_log_abs_x); 520 521 /* dst.x */ 522 emit_data->output[TGSI_CHAN_Z] = log_abs_x; 523 524 /* dst.w */ 525 emit_data->output[TGSI_CHAN_W] = bld_base->base.one; 526 } 527 528 static struct lp_build_tgsi_action log_action = { 529 scalar_unary_fetch_args, /* fetch_args */ 530 log_emit /* emit */ 531 }; 532 533 /* TGSI_OPCODE_LRP */ 534 535 static void 536 lrp_emit( 537 const struct lp_build_tgsi_action * action, 538 struct lp_build_tgsi_context * bld_base, 539 struct lp_build_emit_data * emit_data) 540 { 541 LLVMValueRef tmp; 542 tmp = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_SUB, 543 emit_data->args[1], 544 emit_data->args[2]); 545 emit_data->output[emit_data->chan] = lp_build_emit_llvm_ternary(bld_base, 546 TGSI_OPCODE_MAD, emit_data->args[0], tmp, emit_data->args[2]); 547 } 548 549 /* TGSI_OPCODE_MAD */ 550 551 static void 552 mad_emit( 553 const struct lp_build_tgsi_action * action, 554 struct lp_build_tgsi_context * bld_base, 555 struct lp_build_emit_data * emit_data) 556 { 557 LLVMValueRef tmp; 558 tmp = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, 559 emit_data->args[0], 560 emit_data->args[1]); 561 emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base, 562 TGSI_OPCODE_ADD, tmp, emit_data->args[2]); 563 } 564 565 /* TGSI_OPCODE_MOV */ 566 567 static void 568 mov_emit( 569 const struct lp_build_tgsi_action * action, 570 struct lp_build_tgsi_context * bld_base, 571 struct lp_build_emit_data * emit_data) 572 { 573 emit_data->output[emit_data->chan] = emit_data->args[0]; 574 } 575 576 /* TGSI_OPCODE_MUL */ 577 static void 578 mul_emit( 579 const struct lp_build_tgsi_action * action, 580 struct lp_build_tgsi_context * bld_base, 581 struct lp_build_emit_data * emit_data) 582 { 583 emit_data->output[emit_data->chan] = lp_build_mul(&bld_base->base, 584 emit_data->args[0], emit_data->args[1]); 585 } 586 587 /* TGSI_OPCODE_POW */ 588 589 static void 590 pow_emit( 591 const struct lp_build_tgsi_action * action, 592 struct lp_build_tgsi_context * bld_base, 593 struct lp_build_emit_data * emit_data) 594 { 595 emit_data->output[emit_data->chan] = lp_build_pow(&bld_base->base, 596 emit_data->args[0], emit_data->args[1]); 597 } 598 599 static struct lp_build_tgsi_action pow_action = { 600 scalar_binary_fetch_args, /* fetch_args */ 601 pow_emit /* emit */ 602 }; 603 604 /* TGSI_OPCODE_RSQ */ 605 606 static void 607 rsq_emit( 608 const struct lp_build_tgsi_action * action, 609 struct lp_build_tgsi_context * bld_base, 610 struct lp_build_emit_data * emit_data) 611 { 612 emit_data->args[0] = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_ABS, 613 emit_data->args[0]); 614 if (bld_base->rsq_action.emit) { 615 bld_base->rsq_action.emit(&bld_base->rsq_action, bld_base, emit_data); 616 } else { 617 emit_data->output[emit_data->chan] = bld_base->base.undef; 618 } 619 } 620 621 const struct lp_build_tgsi_action rsq_action = { 622 scalar_unary_fetch_args, /* fetch_args */ 623 rsq_emit /* emit */ 624 625 }; 626 627 /* TGSI_OPCODE_SCS */ 628 static void 629 scs_emit( 630 const struct lp_build_tgsi_action * action, 631 struct lp_build_tgsi_context * bld_base, 632 struct lp_build_emit_data * emit_data) 633 { 634 /* dst.x */ 635 emit_data->output[TGSI_CHAN_X] = lp_build_emit_llvm_unary(bld_base, 636 TGSI_OPCODE_COS, emit_data->args[0]); 637 /* dst.y */ 638 emit_data->output[TGSI_CHAN_Y] = lp_build_emit_llvm_unary(bld_base, 639 TGSI_OPCODE_SIN, emit_data->args[0]); 640 /* dst.z */ 641 emit_data->output[TGSI_CHAN_Z] = bld_base->base.zero; 642 643 /* dst.w */ 644 emit_data->output[TGSI_CHAN_W] = bld_base->base.one; 645 } 646 647 const struct lp_build_tgsi_action scs_action = { 648 scalar_unary_fetch_args, /* fetch_args */ 649 scs_emit /* emit */ 650 }; 651 652 /* TGSI_OPCODE_SFL */ 653 654 static void 655 sfl_emit( 656 const struct lp_build_tgsi_action * action, 657 struct lp_build_tgsi_context * bld_base, 658 struct lp_build_emit_data * emit_data) 659 { 660 emit_data->output[emit_data->chan] = bld_base->base.zero; 661 } 662 663 /* TGSI_OPCODE_STR */ 664 665 static void 666 str_emit( 667 const struct lp_build_tgsi_action * action, 668 struct lp_build_tgsi_context * bld_base, 669 struct lp_build_emit_data * emit_data) 670 { 671 emit_data->output[emit_data->chan] = bld_base->base.one; 672 } 673 674 /* TGSI_OPCODE_SUB */ 675 static void 676 sub_emit( 677 const struct lp_build_tgsi_action * action, 678 struct lp_build_tgsi_context * bld_base, 679 struct lp_build_emit_data * emit_data) 680 { 681 emit_data->output[emit_data->chan] = LLVMBuildFSub( 682 bld_base->base.gallivm->builder, 683 emit_data->args[0], 684 emit_data->args[1], ""); 685 } 686 687 /* TGSI_OPCODE_U2F */ 688 static void 689 u2f_emit( 690 const struct lp_build_tgsi_action * action, 691 struct lp_build_tgsi_context * bld_base, 692 struct lp_build_emit_data * emit_data) 693 { 694 emit_data->output[emit_data->chan] = LLVMBuildUIToFP(bld_base->base.gallivm->builder, 695 emit_data->args[0], 696 bld_base->base.vec_type, ""); 697 } 698 699 static void 700 umad_emit( 701 const struct lp_build_tgsi_action * action, 702 struct lp_build_tgsi_context * bld_base, 703 struct lp_build_emit_data * emit_data) 704 { 705 LLVMValueRef tmp; 706 tmp = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_UMUL, 707 emit_data->args[0], 708 emit_data->args[1]); 709 emit_data->output[emit_data->chan] = lp_build_emit_llvm_binary(bld_base, 710 TGSI_OPCODE_UADD, tmp, emit_data->args[2]); 711 } 712 713 /* TGSI_OPCODE_UMUL */ 714 static void 715 umul_emit( 716 const struct lp_build_tgsi_action * action, 717 struct lp_build_tgsi_context * bld_base, 718 struct lp_build_emit_data * emit_data) 719 { 720 emit_data->output[emit_data->chan] = lp_build_mul(&bld_base->uint_bld, 721 emit_data->args[0], emit_data->args[1]); 722 } 723 724 /* TGSI_OPCODE_XPD */ 725 726 static void 727 xpd_fetch_args( 728 struct lp_build_tgsi_context * bld_base, 729 struct lp_build_emit_data * emit_data) 730 { 731 dp_fetch_args(bld_base, emit_data, 3); 732 } 733 734 /** 735 * (a * b) - (c * d) 736 */ 737 static LLVMValueRef 738 xpd_helper( 739 struct lp_build_tgsi_context * bld_base, 740 LLVMValueRef a, 741 LLVMValueRef b, 742 LLVMValueRef c, 743 LLVMValueRef d) 744 { 745 LLVMValueRef tmp0, tmp1; 746 747 tmp0 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, a, b); 748 tmp1 = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MUL, c, d); 749 750 return lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_SUB, tmp0, tmp1); 751 } 752 753 static void 754 xpd_emit( 755 const struct lp_build_tgsi_action * action, 756 struct lp_build_tgsi_context * bld_base, 757 struct lp_build_emit_data * emit_data) 758 { 759 emit_data->output[TGSI_CHAN_X] = xpd_helper(bld_base, 760 emit_data->args[1] /* src0.y */, emit_data->args[5] /* src1.z */, 761 emit_data->args[4] /* src1.y */, emit_data->args[2] /* src0.z */); 762 763 emit_data->output[TGSI_CHAN_Y] = xpd_helper(bld_base, 764 emit_data->args[2] /* src0.z */, emit_data->args[3] /* src1.x */, 765 emit_data->args[5] /* src1.z */, emit_data->args[0] /* src0.x */); 766 767 emit_data->output[TGSI_CHAN_Z] = xpd_helper(bld_base, 768 emit_data->args[0] /* src0.x */, emit_data->args[4] /* src1.y */, 769 emit_data->args[3] /* src1.x */, emit_data->args[1] /* src0.y */); 770 771 emit_data->output[TGSI_CHAN_W] = bld_base->base.one; 772 } 773 774 const struct lp_build_tgsi_action xpd_action = { 775 xpd_fetch_args, /* fetch_args */ 776 xpd_emit /* emit */ 777 }; 778 779 void 780 lp_set_default_actions(struct lp_build_tgsi_context * bld_base) 781 { 782 bld_base->op_actions[TGSI_OPCODE_DP2] = dp2_action; 783 bld_base->op_actions[TGSI_OPCODE_DP3] = dp3_action; 784 bld_base->op_actions[TGSI_OPCODE_DP4] = dp4_action; 785 bld_base->op_actions[TGSI_OPCODE_DP2A] = dp2a_action; 786 bld_base->op_actions[TGSI_OPCODE_DPH] = dph_action; 787 bld_base->op_actions[TGSI_OPCODE_DST] = dst_action; 788 bld_base->op_actions[TGSI_OPCODE_EXP] = exp_action; 789 bld_base->op_actions[TGSI_OPCODE_LIT] = lit_action; 790 bld_base->op_actions[TGSI_OPCODE_LOG] = log_action; 791 bld_base->op_actions[TGSI_OPCODE_RSQ] = rsq_action; 792 bld_base->op_actions[TGSI_OPCODE_POW] = pow_action; 793 bld_base->op_actions[TGSI_OPCODE_SCS] = scs_action; 794 bld_base->op_actions[TGSI_OPCODE_XPD] = xpd_action; 795 796 bld_base->op_actions[TGSI_OPCODE_COS].fetch_args = scalar_unary_fetch_args; 797 bld_base->op_actions[TGSI_OPCODE_EX2].fetch_args = scalar_unary_fetch_args; 798 bld_base->op_actions[TGSI_OPCODE_IF].fetch_args = scalar_unary_fetch_args; 799 bld_base->op_actions[TGSI_OPCODE_KIL].fetch_args = kil_fetch_args; 800 bld_base->op_actions[TGSI_OPCODE_KILP].fetch_args = kilp_fetch_args; 801 bld_base->op_actions[TGSI_OPCODE_RCP].fetch_args = scalar_unary_fetch_args; 802 bld_base->op_actions[TGSI_OPCODE_SIN].fetch_args = scalar_unary_fetch_args; 803 bld_base->op_actions[TGSI_OPCODE_LG2].fetch_args = scalar_unary_fetch_args; 804 805 bld_base->op_actions[TGSI_OPCODE_ADD].emit = add_emit; 806 bld_base->op_actions[TGSI_OPCODE_ARR].emit = arr_emit; 807 bld_base->op_actions[TGSI_OPCODE_CLAMP].emit = clamp_emit; 808 bld_base->op_actions[TGSI_OPCODE_END].emit = end_emit; 809 bld_base->op_actions[TGSI_OPCODE_FRC].emit = frc_emit; 810 bld_base->op_actions[TGSI_OPCODE_LRP].emit = lrp_emit; 811 bld_base->op_actions[TGSI_OPCODE_MAD].emit = mad_emit; 812 bld_base->op_actions[TGSI_OPCODE_MOV].emit = mov_emit; 813 bld_base->op_actions[TGSI_OPCODE_MUL].emit = mul_emit; 814 bld_base->op_actions[TGSI_OPCODE_SFL].emit = sfl_emit; 815 bld_base->op_actions[TGSI_OPCODE_STR].emit = str_emit; 816 bld_base->op_actions[TGSI_OPCODE_SUB].emit = sub_emit; 817 818 bld_base->op_actions[TGSI_OPCODE_UARL].emit = mov_emit; 819 bld_base->op_actions[TGSI_OPCODE_U2F].emit = u2f_emit; 820 bld_base->op_actions[TGSI_OPCODE_UMAD].emit = umad_emit; 821 bld_base->op_actions[TGSI_OPCODE_UMUL].emit = umul_emit; 822 } 823 824 /* CPU Only default actions */ 825 826 /* These actions are CPU only, because they could potentially output SSE 827 * intrinsics. 828 */ 829 830 /* TGSI_OPCODE_ABS (CPU Only)*/ 831 832 static void 833 abs_emit_cpu( 834 const struct lp_build_tgsi_action * action, 835 struct lp_build_tgsi_context * bld_base, 836 struct lp_build_emit_data * emit_data) 837 { 838 emit_data->output[emit_data->chan] = lp_build_abs(&bld_base->base, 839 emit_data->args[0]); 840 } 841 842 /* TGSI_OPCODE_ADD (CPU Only) */ 843 static void 844 add_emit_cpu( 845 const struct lp_build_tgsi_action * action, 846 struct lp_build_tgsi_context * bld_base, 847 struct lp_build_emit_data * emit_data) 848 { 849 emit_data->output[emit_data->chan] = lp_build_add(&bld_base->base, 850 emit_data->args[0], emit_data->args[1]); 851 } 852 853 /* TGSI_OPCODE_AND (CPU Only) */ 854 static void 855 and_emit_cpu( 856 const struct lp_build_tgsi_action * action, 857 struct lp_build_tgsi_context * bld_base, 858 struct lp_build_emit_data * emit_data) 859 { 860 emit_data->output[emit_data->chan] = lp_build_and(&bld_base->uint_bld, 861 emit_data->args[0], emit_data->args[1]); 862 } 863 864 /* TGSI_OPCODE_ARL (CPU Only) */ 865 static void 866 arl_emit_cpu( 867 const struct lp_build_tgsi_action * action, 868 struct lp_build_tgsi_context * bld_base, 869 struct lp_build_emit_data * emit_data) 870 { 871 LLVMValueRef tmp; 872 tmp = lp_build_floor(&bld_base->base, 873 emit_data->args[0]); 874 emit_data->output[emit_data->chan] = LLVMBuildFPToSI(bld_base->base.gallivm->builder, tmp, 875 bld_base->uint_bld.vec_type, ""); 876 } 877 878 /* TGSI_OPCODE_ARR (CPU Only) */ 879 static void 880 arr_emit_cpu( 881 const struct lp_build_tgsi_action * action, 882 struct lp_build_tgsi_context * bld_base, 883 struct lp_build_emit_data * emit_data) 884 { 885 emit_data->output[emit_data->chan] = lp_build_iround(&bld_base->base, emit_data->args[0]); 886 } 887 888 /* TGSI_OPCODE_CEIL (CPU Only) */ 889 static void 890 ceil_emit_cpu( 891 const struct lp_build_tgsi_action * action, 892 struct lp_build_tgsi_context * bld_base, 893 struct lp_build_emit_data * emit_data) 894 { 895 emit_data->output[emit_data->chan] = lp_build_ceil(&bld_base->base, 896 emit_data->args[0]); 897 } 898 899 /* TGSI_OPCODE_CMP (CPU Only) */ 900 static void 901 cmp_emit_cpu( 902 const struct lp_build_tgsi_action * action, 903 struct lp_build_tgsi_context * bld_base, 904 struct lp_build_emit_data * emit_data) 905 { 906 LLVMValueRef cond = lp_build_cmp(&bld_base->base, PIPE_FUNC_LESS, 907 emit_data->args[0], bld_base->base.zero); 908 emit_data->output[emit_data->chan] = lp_build_select(&bld_base->base, 909 cond, emit_data->args[1], emit_data->args[2]); 910 } 911 912 /* TGSI_OPCODE_CND (CPU Only) */ 913 static void 914 cnd_emit_cpu( 915 const struct lp_build_tgsi_action * action, 916 struct lp_build_tgsi_context * bld_base, 917 struct lp_build_emit_data * emit_data) 918 { 919 LLVMValueRef half, tmp; 920 half = lp_build_const_vec(bld_base->base.gallivm, bld_base->base.type, 0.5); 921 tmp = lp_build_cmp(&bld_base->base, PIPE_FUNC_GREATER, 922 emit_data->args[2], half); 923 emit_data->output[emit_data->chan] = lp_build_select(&bld_base->base, 924 tmp, 925 emit_data->args[0], 926 emit_data->args[1]); 927 } 928 929 /* TGSI_OPCODE_COS (CPU Only) */ 930 static void 931 cos_emit_cpu( 932 const struct lp_build_tgsi_action * action, 933 struct lp_build_tgsi_context * bld_base, 934 struct lp_build_emit_data * emit_data) 935 { 936 emit_data->output[emit_data->chan] = lp_build_cos(&bld_base->base, 937 emit_data->args[0]); 938 } 939 940 /* TGSI_OPCODE_DIV (CPU Only) */ 941 static void 942 div_emit_cpu( 943 const struct lp_build_tgsi_action * action, 944 struct lp_build_tgsi_context * bld_base, 945 struct lp_build_emit_data * emit_data) 946 { 947 emit_data->output[emit_data->chan] = lp_build_div(&bld_base->base, 948 emit_data->args[0], emit_data->args[1]); 949 } 950 951 /* TGSI_OPCODE_EX2 (CPU Only) */ 952 static void 953 ex2_emit_cpu( 954 const struct lp_build_tgsi_action * action, 955 struct lp_build_tgsi_context * bld_base, 956 struct lp_build_emit_data * emit_data) 957 { 958 emit_data->output[emit_data->chan] = lp_build_exp2(&bld_base->base, 959 emit_data->args[0]); 960 } 961 962 /* TGSI_OPCODE_EXP (CPU Only) */ 963 static void 964 exp_emit_cpu( 965 const struct lp_build_tgsi_action * action, 966 struct lp_build_tgsi_context * bld_base, 967 struct lp_build_emit_data * emit_data) 968 { 969 lp_build_exp2_approx(&bld_base->base, emit_data->args[0], 970 &emit_data->output[TGSI_CHAN_X], 971 &emit_data->output[TGSI_CHAN_Y], 972 &emit_data->output[TGSI_CHAN_Z]); 973 emit_data->output[TGSI_CHAN_W] = bld_base->base.one; 974 } 975 976 /* TGSI_OPCODE_F2I (CPU Only) */ 977 static void 978 f2i_emit_cpu( 979 const struct lp_build_tgsi_action * action, 980 struct lp_build_tgsi_context * bld_base, 981 struct lp_build_emit_data * emit_data) 982 { 983 emit_data->output[emit_data->chan] = lp_build_itrunc(&bld_base->base, 984 emit_data->args[0]); 985 } 986 987 /* TGSI_OPCODE_F2U (CPU Only) */ 988 static void 989 f2u_emit_cpu( 990 const struct lp_build_tgsi_action * action, 991 struct lp_build_tgsi_context * bld_base, 992 struct lp_build_emit_data * emit_data) 993 { 994 /* FIXME: implement and use lp_build_utrunc() */ 995 emit_data->output[emit_data->chan] = lp_build_itrunc(&bld_base->base, 996 emit_data->args[0]); 997 } 998 999 /* TGSI_OPCODE_FLR (CPU Only) */ 1000 1001 static void 1002 flr_emit_cpu( 1003 const struct lp_build_tgsi_action * action, 1004 struct lp_build_tgsi_context * bld_base, 1005 struct lp_build_emit_data * emit_data) 1006 { 1007 emit_data->output[emit_data->chan] = lp_build_floor(&bld_base->base, 1008 emit_data->args[0]); 1009 } 1010 1011 /* TGSI_OPCODE_I2F (CPU Only) */ 1012 static void 1013 i2f_emit_cpu( 1014 const struct lp_build_tgsi_action * action, 1015 struct lp_build_tgsi_context * bld_base, 1016 struct lp_build_emit_data * emit_data) 1017 { 1018 emit_data->output[emit_data->chan] = lp_build_int_to_float(&bld_base->base, 1019 emit_data->args[0]); 1020 } 1021 1022 /* TGSI_OPCODE_IABS (CPU Only) */ 1023 static void 1024 iabs_emit_cpu( 1025 const struct lp_build_tgsi_action * action, 1026 struct lp_build_tgsi_context * bld_base, 1027 struct lp_build_emit_data * emit_data) 1028 { 1029 emit_data->output[emit_data->chan] = lp_build_abs(&bld_base->int_bld, 1030 emit_data->args[0]); 1031 } 1032 1033 /* TGSI_OPCODE_IDIV (CPU Only) */ 1034 static void 1035 idiv_emit_cpu( 1036 const struct lp_build_tgsi_action * action, 1037 struct lp_build_tgsi_context * bld_base, 1038 struct lp_build_emit_data * emit_data) 1039 { 1040 emit_data->output[emit_data->chan] = lp_build_div(&bld_base->int_bld, 1041 emit_data->args[0], emit_data->args[1]); 1042 } 1043 1044 /* TGSI_OPCODE_INEG (CPU Only) */ 1045 static void 1046 ineg_emit_cpu( 1047 const struct lp_build_tgsi_action * action, 1048 struct lp_build_tgsi_context * bld_base, 1049 struct lp_build_emit_data * emit_data) 1050 { 1051 emit_data->output[emit_data->chan] = lp_build_sub(&bld_base->int_bld, 1052 bld_base->int_bld.zero, 1053 emit_data->args[0]); 1054 } 1055 1056 /* TGSI_OPCODE_ISET Helper (CPU Only) */ 1057 static void 1058 iset_emit_cpu( 1059 const struct lp_build_tgsi_action * action, 1060 struct lp_build_tgsi_context * bld_base, 1061 struct lp_build_emit_data * emit_data, 1062 unsigned pipe_func) 1063 { 1064 LLVMValueRef nz = lp_build_const_vec(bld_base->base.gallivm, 1065 bld_base->int_bld.type, ~0U); 1066 LLVMValueRef cond = lp_build_cmp(&bld_base->int_bld, pipe_func, 1067 emit_data->args[0], emit_data->args[1]); 1068 emit_data->output[emit_data->chan] = lp_build_select(&bld_base->int_bld, 1069 cond, 1070 nz, 1071 bld_base->int_bld.zero); 1072 } 1073 1074 /* TGSI_OPCODE_IMAX (CPU Only) */ 1075 static void 1076 imax_emit_cpu( 1077 const struct lp_build_tgsi_action * action, 1078 struct lp_build_tgsi_context * bld_base, 1079 struct lp_build_emit_data * emit_data) 1080 { 1081 emit_data->output[emit_data->chan] = lp_build_max(&bld_base->int_bld, 1082 emit_data->args[0], emit_data->args[1]); 1083 } 1084 1085 /* TGSI_OPCODE_IMIN (CPU Only) */ 1086 static void 1087 imin_emit_cpu( 1088 const struct lp_build_tgsi_action * action, 1089 struct lp_build_tgsi_context * bld_base, 1090 struct lp_build_emit_data * emit_data) 1091 { 1092 emit_data->output[emit_data->chan] = lp_build_min(&bld_base->int_bld, 1093 emit_data->args[0], emit_data->args[1]); 1094 } 1095 1096 /* TGSI_OPCODE_ISGE (CPU Only) */ 1097 static void 1098 isge_emit_cpu( 1099 const struct lp_build_tgsi_action * action, 1100 struct lp_build_tgsi_context * bld_base, 1101 struct lp_build_emit_data * emit_data) 1102 { 1103 iset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_GEQUAL); 1104 } 1105 1106 /* TGSI_OPCODE_ISHR (CPU Only) */ 1107 static void 1108 ishr_emit_cpu( 1109 const struct lp_build_tgsi_action * action, 1110 struct lp_build_tgsi_context * bld_base, 1111 struct lp_build_emit_data * emit_data) 1112 { 1113 emit_data->output[emit_data->chan] = lp_build_shr(&bld_base->int_bld, 1114 emit_data->args[0], emit_data->args[1]); 1115 } 1116 1117 /* TGSI_OPCODE_ISLT (CPU Only) */ 1118 static void 1119 islt_emit_cpu( 1120 const struct lp_build_tgsi_action * action, 1121 struct lp_build_tgsi_context * bld_base, 1122 struct lp_build_emit_data * emit_data) 1123 { 1124 iset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_LESS); 1125 } 1126 1127 1128 /* TGSI_OPCODE_ISSG (CPU Only) */ 1129 static void 1130 issg_emit_cpu( 1131 const struct lp_build_tgsi_action * action, 1132 struct lp_build_tgsi_context * bld_base, 1133 struct lp_build_emit_data * emit_data) 1134 { 1135 emit_data->output[emit_data->chan] = lp_build_sgn(&bld_base->int_bld, 1136 emit_data->args[0]); 1137 } 1138 1139 /* TGSI_OPCODE_LG2 (CPU Only) */ 1140 static void 1141 lg2_emit_cpu( 1142 const struct lp_build_tgsi_action * action, 1143 struct lp_build_tgsi_context * bld_base, 1144 struct lp_build_emit_data * emit_data) 1145 { 1146 emit_data->output[emit_data->chan] = lp_build_log2(&bld_base->base, 1147 emit_data->args[0]); 1148 } 1149 1150 /* TGSI_OPCODE_LOG (CPU Only) */ 1151 static void 1152 log_emit_cpu( 1153 const struct lp_build_tgsi_action * action, 1154 struct lp_build_tgsi_context * bld_base, 1155 struct lp_build_emit_data * emit_data) 1156 { 1157 LLVMValueRef p_floor_log2; 1158 LLVMValueRef p_exp; 1159 LLVMValueRef p_log2; 1160 LLVMValueRef src0 = emit_data->args[0]; 1161 1162 lp_build_log2_approx(&bld_base->base, src0, 1163 &p_exp, &p_floor_log2, &p_log2); 1164 1165 emit_data->output[TGSI_CHAN_X] = p_floor_log2; 1166 1167 emit_data->output[TGSI_CHAN_Y] = lp_build_emit_llvm_binary(bld_base, 1168 TGSI_OPCODE_DIV, 1169 src0, p_exp); 1170 emit_data->output[TGSI_CHAN_Z] = p_log2; 1171 1172 emit_data->output[TGSI_CHAN_W] = bld_base->base.one; 1173 1174 } 1175 1176 /* TGSI_OPCODE_MAX (CPU Only) */ 1177 1178 static void 1179 max_emit_cpu( 1180 const struct lp_build_tgsi_action * action, 1181 struct lp_build_tgsi_context * bld_base, 1182 struct lp_build_emit_data * emit_data) 1183 { 1184 emit_data->output[emit_data->chan] = lp_build_max(&bld_base->base, 1185 emit_data->args[0], emit_data->args[1]); 1186 } 1187 1188 /* TGSI_OPCODE_MIN (CPU Only) */ 1189 static void 1190 min_emit_cpu( 1191 const struct lp_build_tgsi_action * action, 1192 struct lp_build_tgsi_context * bld_base, 1193 struct lp_build_emit_data * emit_data) 1194 { 1195 emit_data->output[emit_data->chan] = lp_build_min(&bld_base->base, 1196 emit_data->args[0], emit_data->args[1]); 1197 } 1198 1199 /* TGSI_OPCODE_MOD (CPU Only) */ 1200 static void 1201 mod_emit_cpu( 1202 const struct lp_build_tgsi_action * action, 1203 struct lp_build_tgsi_context * bld_base, 1204 struct lp_build_emit_data * emit_data) 1205 { 1206 emit_data->output[emit_data->chan] = lp_build_mod(&bld_base->int_bld, 1207 emit_data->args[0], emit_data->args[1]); 1208 } 1209 1210 /* TGSI_OPCODE_NOT */ 1211 static void 1212 not_emit_cpu( 1213 const struct lp_build_tgsi_action * action, 1214 struct lp_build_tgsi_context * bld_base, 1215 struct lp_build_emit_data * emit_data) 1216 { 1217 emit_data->output[emit_data->chan] = lp_build_not(&bld_base->base, 1218 emit_data->args[0]); 1219 } 1220 1221 /* TGSI_OPCODE_OR (CPU Only) */ 1222 static void 1223 or_emit_cpu( 1224 const struct lp_build_tgsi_action * action, 1225 struct lp_build_tgsi_context * bld_base, 1226 struct lp_build_emit_data * emit_data) 1227 { 1228 emit_data->output[emit_data->chan] = lp_build_or(&bld_base->uint_bld, 1229 emit_data->args[0], emit_data->args[1]); 1230 } 1231 1232 /* TGSI_OPCODE_POW (CPU Only) */ 1233 static void 1234 pow_emit_cpu( 1235 const struct lp_build_tgsi_action * action, 1236 struct lp_build_tgsi_context * bld_base, 1237 struct lp_build_emit_data * emit_data) 1238 { 1239 emit_data->output[emit_data->chan] = lp_build_pow(&bld_base->base, 1240 emit_data->args[0], emit_data->args[1]); 1241 } 1242 1243 1244 /* TGSI_OPCODE_RCP (CPU Only) */ 1245 1246 static void 1247 rcp_emit_cpu( 1248 const struct lp_build_tgsi_action * action, 1249 struct lp_build_tgsi_context * bld_base, 1250 struct lp_build_emit_data * emit_data) 1251 { 1252 emit_data->output[emit_data->chan] = lp_build_rcp(&bld_base->base, 1253 emit_data->args[0]); 1254 } 1255 1256 /* Reciprical squareroot (CPU Only) */ 1257 1258 /* This is not the same as TGSI_OPCODE_RSQ, which requres the argument to be 1259 * greater than or equal to 0 */ 1260 static void 1261 recip_sqrt_emit_cpu( 1262 const struct lp_build_tgsi_action * action, 1263 struct lp_build_tgsi_context * bld_base, 1264 struct lp_build_emit_data * emit_data) 1265 { 1266 emit_data->output[emit_data->chan] = lp_build_rsqrt(&bld_base->base, 1267 emit_data->args[0]); 1268 } 1269 1270 /* TGSI_OPCODE_ROUND (CPU Only) */ 1271 static void 1272 round_emit_cpu( 1273 const struct lp_build_tgsi_action * action, 1274 struct lp_build_tgsi_context * bld_base, 1275 struct lp_build_emit_data * emit_data) 1276 { 1277 emit_data->output[emit_data->chan] = lp_build_round(&bld_base->base, 1278 emit_data->args[0]); 1279 } 1280 1281 /* TGSI_OPCODE_SET Helper (CPU Only) */ 1282 1283 static void 1284 set_emit_cpu( 1285 const struct lp_build_tgsi_action * action, 1286 struct lp_build_tgsi_context * bld_base, 1287 struct lp_build_emit_data * emit_data, 1288 unsigned pipe_func) 1289 { 1290 LLVMValueRef cond = lp_build_cmp(&bld_base->base, pipe_func, 1291 emit_data->args[0], emit_data->args[1]); 1292 emit_data->output[emit_data->chan] = lp_build_select(&bld_base->base, 1293 cond, 1294 bld_base->base.one, 1295 bld_base->base.zero); 1296 } 1297 1298 /* TGSI_OPCODE_SEQ (CPU Only) */ 1299 1300 static void 1301 seq_emit_cpu( 1302 const struct lp_build_tgsi_action * action, 1303 struct lp_build_tgsi_context * bld_base, 1304 struct lp_build_emit_data * emit_data) 1305 { 1306 set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_EQUAL); 1307 } 1308 1309 /* TGSI_OPCODE_SGE (CPU Only) */ 1310 static void 1311 sge_emit_cpu( 1312 const struct lp_build_tgsi_action * action, 1313 struct lp_build_tgsi_context * bld_base, 1314 struct lp_build_emit_data * emit_data) 1315 { 1316 set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_GEQUAL); 1317 } 1318 1319 /* TGSI_OPCODE_SGT (CPU Only)*/ 1320 1321 static void 1322 sgt_emit_cpu( 1323 const struct lp_build_tgsi_action * action, 1324 struct lp_build_tgsi_context * bld_base, 1325 struct lp_build_emit_data * emit_data) 1326 { 1327 set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_GREATER); 1328 } 1329 1330 /* TGSI_OPCODE_SHL (CPU Only) */ 1331 static void 1332 shl_emit_cpu( 1333 const struct lp_build_tgsi_action * action, 1334 struct lp_build_tgsi_context * bld_base, 1335 struct lp_build_emit_data * emit_data) 1336 { 1337 emit_data->output[emit_data->chan] = lp_build_shl(&bld_base->uint_bld, 1338 emit_data->args[0], emit_data->args[1]); 1339 } 1340 1341 /* TGSI_OPCODE_SIN (CPU Only) */ 1342 static void 1343 sin_emit_cpu( 1344 const struct lp_build_tgsi_action * action, 1345 struct lp_build_tgsi_context * bld_base, 1346 struct lp_build_emit_data * emit_data) 1347 { 1348 emit_data->output[emit_data->chan] = lp_build_sin(&bld_base->base, 1349 emit_data->args[0]); 1350 } 1351 1352 /* TGSI_OPCODE_SLE (CPU Only) */ 1353 static void 1354 sle_emit_cpu( 1355 const struct lp_build_tgsi_action * action, 1356 struct lp_build_tgsi_context * bld_base, 1357 struct lp_build_emit_data * emit_data) 1358 { 1359 set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_LEQUAL); 1360 } 1361 1362 /* TGSI_OPCODE_SLT (CPU Only) */ 1363 static void 1364 slt_emit_cpu( 1365 const struct lp_build_tgsi_action * action, 1366 struct lp_build_tgsi_context * bld_base, 1367 struct lp_build_emit_data * emit_data) 1368 { 1369 set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_LESS); 1370 } 1371 1372 /* TGSI_OPCODE_SNE (CPU Only) */ 1373 1374 static void 1375 sne_emit_cpu( 1376 const struct lp_build_tgsi_action * action, 1377 struct lp_build_tgsi_context * bld_base, 1378 struct lp_build_emit_data * emit_data) 1379 { 1380 set_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_NOTEQUAL); 1381 } 1382 1383 /* TGSI_OPCODE_SSG (CPU Only) */ 1384 1385 static void 1386 ssg_emit_cpu( 1387 const struct lp_build_tgsi_action * action, 1388 struct lp_build_tgsi_context * bld_base, 1389 struct lp_build_emit_data * emit_data) 1390 { 1391 emit_data->output[emit_data->chan] = lp_build_sgn(&bld_base->base, 1392 emit_data->args[0]); 1393 } 1394 1395 /* TGSI_OPCODE_SUB (CPU Only) */ 1396 1397 static void 1398 sub_emit_cpu( 1399 const struct lp_build_tgsi_action * action, 1400 struct lp_build_tgsi_context * bld_base, 1401 struct lp_build_emit_data * emit_data) 1402 { 1403 emit_data->output[emit_data->chan] = lp_build_sub(&bld_base->base, 1404 emit_data->args[0], 1405 emit_data->args[1]); 1406 } 1407 1408 /* TGSI_OPCODE_TRUNC (CPU Only) */ 1409 1410 static void 1411 trunc_emit_cpu( 1412 const struct lp_build_tgsi_action * action, 1413 struct lp_build_tgsi_context * bld_base, 1414 struct lp_build_emit_data * emit_data) 1415 { 1416 emit_data->output[emit_data->chan] = lp_build_trunc(&bld_base->base, 1417 emit_data->args[0]); 1418 } 1419 1420 /* TGSI_OPCODE_UADD (CPU Only) */ 1421 static void 1422 uadd_emit_cpu( 1423 const struct lp_build_tgsi_action * action, 1424 struct lp_build_tgsi_context * bld_base, 1425 struct lp_build_emit_data * emit_data) 1426 { 1427 emit_data->output[emit_data->chan] = lp_build_add(&bld_base->uint_bld, 1428 emit_data->args[0], emit_data->args[1]); 1429 } 1430 1431 /* TGSI_OPCODE_UDIV (CPU Only) */ 1432 static void 1433 udiv_emit_cpu( 1434 const struct lp_build_tgsi_action * action, 1435 struct lp_build_tgsi_context * bld_base, 1436 struct lp_build_emit_data * emit_data) 1437 { 1438 emit_data->output[emit_data->chan] = lp_build_div(&bld_base->uint_bld, 1439 emit_data->args[0], emit_data->args[1]); 1440 } 1441 1442 /* TGSI_OPCODE_UMAX (CPU Only) */ 1443 static void 1444 umax_emit_cpu( 1445 const struct lp_build_tgsi_action * action, 1446 struct lp_build_tgsi_context * bld_base, 1447 struct lp_build_emit_data * emit_data) 1448 { 1449 emit_data->output[emit_data->chan] = lp_build_max(&bld_base->uint_bld, 1450 emit_data->args[0], emit_data->args[1]); 1451 } 1452 1453 /* TGSI_OPCODE_UMIN (CPU Only) */ 1454 static void 1455 umin_emit_cpu( 1456 const struct lp_build_tgsi_action * action, 1457 struct lp_build_tgsi_context * bld_base, 1458 struct lp_build_emit_data * emit_data) 1459 { 1460 emit_data->output[emit_data->chan] = lp_build_min(&bld_base->uint_bld, 1461 emit_data->args[0], emit_data->args[1]); 1462 } 1463 1464 /* TGSI_OPCODE_UMOD (CPU Only) */ 1465 static void 1466 umod_emit_cpu( 1467 const struct lp_build_tgsi_action * action, 1468 struct lp_build_tgsi_context * bld_base, 1469 struct lp_build_emit_data * emit_data) 1470 { 1471 emit_data->output[emit_data->chan] = lp_build_mod(&bld_base->uint_bld, 1472 emit_data->args[0], emit_data->args[1]); 1473 } 1474 1475 /* TGSI_OPCODE_USET Helper (CPU Only) */ 1476 static void 1477 uset_emit_cpu( 1478 const struct lp_build_tgsi_action * action, 1479 struct lp_build_tgsi_context * bld_base, 1480 struct lp_build_emit_data * emit_data, 1481 unsigned pipe_func) 1482 { 1483 LLVMValueRef nz = lp_build_const_vec(bld_base->base.gallivm, 1484 bld_base->uint_bld.type, ~0U); 1485 LLVMValueRef cond = lp_build_cmp(&bld_base->uint_bld, pipe_func, 1486 emit_data->args[0], emit_data->args[1]); 1487 emit_data->output[emit_data->chan] = lp_build_select(&bld_base->uint_bld, 1488 cond, 1489 nz, 1490 bld_base->uint_bld.zero); 1491 } 1492 1493 1494 /* TGSI_OPCODE_USEQ (CPU Only) */ 1495 static void 1496 useq_emit_cpu( 1497 const struct lp_build_tgsi_action * action, 1498 struct lp_build_tgsi_context * bld_base, 1499 struct lp_build_emit_data * emit_data) 1500 { 1501 uset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_EQUAL); 1502 } 1503 1504 /* TGSI_OPCODE_ISGE (CPU Only) */ 1505 static void 1506 usge_emit_cpu( 1507 const struct lp_build_tgsi_action * action, 1508 struct lp_build_tgsi_context * bld_base, 1509 struct lp_build_emit_data * emit_data) 1510 { 1511 uset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_GEQUAL); 1512 } 1513 1514 /* TGSI_OPCODE_USHR (CPU Only) */ 1515 static void 1516 ushr_emit_cpu( 1517 const struct lp_build_tgsi_action * action, 1518 struct lp_build_tgsi_context * bld_base, 1519 struct lp_build_emit_data * emit_data) 1520 { 1521 emit_data->output[emit_data->chan] = lp_build_shr(&bld_base->uint_bld, 1522 emit_data->args[0], emit_data->args[1]); 1523 } 1524 1525 /* TGSI_OPCODE_ISLT (CPU Only) */ 1526 static void 1527 uslt_emit_cpu( 1528 const struct lp_build_tgsi_action * action, 1529 struct lp_build_tgsi_context * bld_base, 1530 struct lp_build_emit_data * emit_data) 1531 { 1532 uset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_LESS); 1533 } 1534 1535 /* TGSI_OPCODE_USNE (CPU Only) */ 1536 1537 static void 1538 usne_emit_cpu( 1539 const struct lp_build_tgsi_action * action, 1540 struct lp_build_tgsi_context * bld_base, 1541 struct lp_build_emit_data * emit_data) 1542 { 1543 uset_emit_cpu(action, bld_base, emit_data, PIPE_FUNC_NOTEQUAL); 1544 } 1545 1546 /* TGSI_OPCODE_XOR */ 1547 static void 1548 xor_emit_cpu( 1549 const struct lp_build_tgsi_action * action, 1550 struct lp_build_tgsi_context * bld_base, 1551 struct lp_build_emit_data * emit_data) 1552 { 1553 emit_data->output[emit_data->chan] = lp_build_xor(&bld_base->uint_bld, 1554 emit_data->args[0], 1555 emit_data->args[1]); 1556 } 1557 1558 void 1559 lp_set_default_actions_cpu( 1560 struct lp_build_tgsi_context * bld_base) 1561 { 1562 lp_set_default_actions(bld_base); 1563 bld_base->op_actions[TGSI_OPCODE_ABS].emit = abs_emit_cpu; 1564 bld_base->op_actions[TGSI_OPCODE_ADD].emit = add_emit_cpu; 1565 bld_base->op_actions[TGSI_OPCODE_AND].emit = and_emit_cpu; 1566 bld_base->op_actions[TGSI_OPCODE_ARL].emit = arl_emit_cpu; 1567 bld_base->op_actions[TGSI_OPCODE_ARR].emit = arr_emit_cpu; 1568 bld_base->op_actions[TGSI_OPCODE_CEIL].emit = ceil_emit_cpu; 1569 bld_base->op_actions[TGSI_OPCODE_CND].emit = cnd_emit_cpu; 1570 bld_base->op_actions[TGSI_OPCODE_COS].emit = cos_emit_cpu; 1571 bld_base->op_actions[TGSI_OPCODE_CMP].emit = cmp_emit_cpu; 1572 bld_base->op_actions[TGSI_OPCODE_DIV].emit = div_emit_cpu; 1573 bld_base->op_actions[TGSI_OPCODE_EX2].emit = ex2_emit_cpu; 1574 bld_base->op_actions[TGSI_OPCODE_EXP].emit = exp_emit_cpu; 1575 bld_base->op_actions[TGSI_OPCODE_F2I].emit = f2i_emit_cpu; 1576 bld_base->op_actions[TGSI_OPCODE_F2U].emit = f2u_emit_cpu; 1577 bld_base->op_actions[TGSI_OPCODE_FLR].emit = flr_emit_cpu; 1578 1579 bld_base->op_actions[TGSI_OPCODE_I2F].emit = i2f_emit_cpu; 1580 bld_base->op_actions[TGSI_OPCODE_IABS].emit = iabs_emit_cpu; 1581 bld_base->op_actions[TGSI_OPCODE_IDIV].emit = idiv_emit_cpu; 1582 bld_base->op_actions[TGSI_OPCODE_INEG].emit = ineg_emit_cpu; 1583 bld_base->op_actions[TGSI_OPCODE_IMAX].emit = imax_emit_cpu; 1584 bld_base->op_actions[TGSI_OPCODE_IMIN].emit = imin_emit_cpu; 1585 bld_base->op_actions[TGSI_OPCODE_ISGE].emit = isge_emit_cpu; 1586 bld_base->op_actions[TGSI_OPCODE_ISHR].emit = ishr_emit_cpu; 1587 bld_base->op_actions[TGSI_OPCODE_ISLT].emit = islt_emit_cpu; 1588 bld_base->op_actions[TGSI_OPCODE_ISSG].emit = issg_emit_cpu; 1589 1590 bld_base->op_actions[TGSI_OPCODE_LG2].emit = lg2_emit_cpu; 1591 bld_base->op_actions[TGSI_OPCODE_LOG].emit = log_emit_cpu; 1592 bld_base->op_actions[TGSI_OPCODE_MAX].emit = max_emit_cpu; 1593 bld_base->op_actions[TGSI_OPCODE_MIN].emit = min_emit_cpu; 1594 bld_base->op_actions[TGSI_OPCODE_MOD].emit = mod_emit_cpu; 1595 bld_base->op_actions[TGSI_OPCODE_NOT].emit = not_emit_cpu; 1596 bld_base->op_actions[TGSI_OPCODE_OR].emit = or_emit_cpu; 1597 bld_base->op_actions[TGSI_OPCODE_POW].emit = pow_emit_cpu; 1598 bld_base->op_actions[TGSI_OPCODE_RCP].emit = rcp_emit_cpu; 1599 bld_base->op_actions[TGSI_OPCODE_ROUND].emit = round_emit_cpu; 1600 bld_base->op_actions[TGSI_OPCODE_SEQ].emit = seq_emit_cpu; 1601 bld_base->op_actions[TGSI_OPCODE_SGE].emit = sge_emit_cpu; 1602 bld_base->op_actions[TGSI_OPCODE_SGT].emit = sgt_emit_cpu; 1603 bld_base->op_actions[TGSI_OPCODE_SIN].emit = sin_emit_cpu; 1604 bld_base->op_actions[TGSI_OPCODE_SHL].emit = shl_emit_cpu; 1605 bld_base->op_actions[TGSI_OPCODE_SLE].emit = sle_emit_cpu; 1606 bld_base->op_actions[TGSI_OPCODE_SLT].emit = slt_emit_cpu; 1607 bld_base->op_actions[TGSI_OPCODE_SNE].emit = sne_emit_cpu; 1608 bld_base->op_actions[TGSI_OPCODE_SSG].emit = ssg_emit_cpu; 1609 bld_base->op_actions[TGSI_OPCODE_SUB].emit = sub_emit_cpu; 1610 bld_base->op_actions[TGSI_OPCODE_TRUNC].emit = trunc_emit_cpu; 1611 1612 bld_base->rsq_action.emit = recip_sqrt_emit_cpu; 1613 1614 bld_base->op_actions[TGSI_OPCODE_UADD].emit = uadd_emit_cpu; 1615 bld_base->op_actions[TGSI_OPCODE_UDIV].emit = udiv_emit_cpu; 1616 bld_base->op_actions[TGSI_OPCODE_UMAX].emit = umax_emit_cpu; 1617 bld_base->op_actions[TGSI_OPCODE_UMIN].emit = umin_emit_cpu; 1618 bld_base->op_actions[TGSI_OPCODE_UMOD].emit = umod_emit_cpu; 1619 bld_base->op_actions[TGSI_OPCODE_USEQ].emit = useq_emit_cpu; 1620 bld_base->op_actions[TGSI_OPCODE_USGE].emit = usge_emit_cpu; 1621 bld_base->op_actions[TGSI_OPCODE_USHR].emit = ushr_emit_cpu; 1622 bld_base->op_actions[TGSI_OPCODE_USLT].emit = uslt_emit_cpu; 1623 bld_base->op_actions[TGSI_OPCODE_USNE].emit = usne_emit_cpu; 1624 1625 bld_base->op_actions[TGSI_OPCODE_XOR].emit = xor_emit_cpu; 1626 1627 } 1628