1b8e80941Smrg/* 2b8e80941Smrg * Copyright © 2012 Intel Corporation 3b8e80941Smrg * 4b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a 5b8e80941Smrg * copy of this software and associated documentation files (the "Software"), 6b8e80941Smrg * to deal in the Software without restriction, including without limitation 7b8e80941Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8b8e80941Smrg * and/or sell copies of the Software, and to permit persons to whom the 9b8e80941Smrg * Software is furnished to do so, subject to the following conditions: 10b8e80941Smrg * 11b8e80941Smrg * The above copyright notice and this permission notice (including the next 12b8e80941Smrg * paragraph) shall be included in all copies or substantial portions of the 13b8e80941Smrg * Software. 14b8e80941Smrg * 15b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16b8e80941Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17b8e80941Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18b8e80941Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19b8e80941Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20b8e80941Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21b8e80941Smrg * IN THE SOFTWARE. 22b8e80941Smrg */ 23b8e80941Smrg 24b8e80941Smrg#include "ir_builder.h" 25b8e80941Smrg#include "program/prog_instruction.h" 26b8e80941Smrg 27b8e80941Smrgusing namespace ir_builder; 28b8e80941Smrg 29b8e80941Smrgnamespace ir_builder { 30b8e80941Smrg 31b8e80941Smrgvoid 32b8e80941Smrgir_factory::emit(ir_instruction *ir) 33b8e80941Smrg{ 34b8e80941Smrg instructions->push_tail(ir); 35b8e80941Smrg} 36b8e80941Smrg 37b8e80941Smrgir_variable * 38b8e80941Smrgir_factory::make_temp(const glsl_type *type, const char *name) 39b8e80941Smrg{ 40b8e80941Smrg ir_variable *var; 41b8e80941Smrg 42b8e80941Smrg var = new(mem_ctx) ir_variable(type, name, ir_var_temporary); 43b8e80941Smrg emit(var); 44b8e80941Smrg 45b8e80941Smrg return var; 46b8e80941Smrg} 47b8e80941Smrg 48b8e80941Smrgir_assignment * 49b8e80941Smrgassign(deref lhs, operand rhs, operand condition, int writemask) 50b8e80941Smrg{ 51b8e80941Smrg void *mem_ctx = ralloc_parent(lhs.val); 52b8e80941Smrg 53b8e80941Smrg ir_assignment *assign = new(mem_ctx) ir_assignment(lhs.val, 54b8e80941Smrg rhs.val, 55b8e80941Smrg condition.val, 56b8e80941Smrg writemask); 57b8e80941Smrg 58b8e80941Smrg return assign; 59b8e80941Smrg} 60b8e80941Smrg 61b8e80941Smrgir_assignment * 62b8e80941Smrgassign(deref lhs, operand rhs) 63b8e80941Smrg{ 64b8e80941Smrg return assign(lhs, rhs, (1 << lhs.val->type->vector_elements) - 1); 65b8e80941Smrg} 66b8e80941Smrg 67b8e80941Smrgir_assignment * 68b8e80941Smrgassign(deref lhs, operand rhs, int writemask) 69b8e80941Smrg{ 70b8e80941Smrg return assign(lhs, rhs, (ir_rvalue *) NULL, writemask); 71b8e80941Smrg} 72b8e80941Smrg 73b8e80941Smrgir_assignment * 74b8e80941Smrgassign(deref lhs, operand rhs, operand condition) 75b8e80941Smrg{ 76b8e80941Smrg return assign(lhs, rhs, condition, (1 << lhs.val->type->vector_elements) - 1); 77b8e80941Smrg} 78b8e80941Smrg 79b8e80941Smrgir_return * 80b8e80941Smrgret(operand retval) 81b8e80941Smrg{ 82b8e80941Smrg void *mem_ctx = ralloc_parent(retval.val); 83b8e80941Smrg return new(mem_ctx) ir_return(retval.val); 84b8e80941Smrg} 85b8e80941Smrg 86b8e80941Smrgir_swizzle * 87b8e80941Smrgswizzle(operand a, int swizzle, int components) 88b8e80941Smrg{ 89b8e80941Smrg void *mem_ctx = ralloc_parent(a.val); 90b8e80941Smrg 91b8e80941Smrg return new(mem_ctx) ir_swizzle(a.val, 92b8e80941Smrg GET_SWZ(swizzle, 0), 93b8e80941Smrg GET_SWZ(swizzle, 1), 94b8e80941Smrg GET_SWZ(swizzle, 2), 95b8e80941Smrg GET_SWZ(swizzle, 3), 96b8e80941Smrg components); 97b8e80941Smrg} 98b8e80941Smrg 99b8e80941Smrgir_swizzle * 100b8e80941Smrgswizzle_for_size(operand a, unsigned components) 101b8e80941Smrg{ 102b8e80941Smrg void *mem_ctx = ralloc_parent(a.val); 103b8e80941Smrg 104b8e80941Smrg if (a.val->type->vector_elements < components) 105b8e80941Smrg components = a.val->type->vector_elements; 106b8e80941Smrg 107b8e80941Smrg unsigned s[4] = { 0, 1, 2, 3 }; 108b8e80941Smrg for (int i = components; i < 4; i++) 109b8e80941Smrg s[i] = components - 1; 110b8e80941Smrg 111b8e80941Smrg return new(mem_ctx) ir_swizzle(a.val, s, components); 112b8e80941Smrg} 113b8e80941Smrg 114b8e80941Smrgir_swizzle * 115b8e80941Smrgswizzle_xxxx(operand a) 116b8e80941Smrg{ 117b8e80941Smrg return swizzle(a, SWIZZLE_XXXX, 4); 118b8e80941Smrg} 119b8e80941Smrg 120b8e80941Smrgir_swizzle * 121b8e80941Smrgswizzle_yyyy(operand a) 122b8e80941Smrg{ 123b8e80941Smrg return swizzle(a, SWIZZLE_YYYY, 4); 124b8e80941Smrg} 125b8e80941Smrg 126b8e80941Smrgir_swizzle * 127b8e80941Smrgswizzle_zzzz(operand a) 128b8e80941Smrg{ 129b8e80941Smrg return swizzle(a, SWIZZLE_ZZZZ, 4); 130b8e80941Smrg} 131b8e80941Smrg 132b8e80941Smrgir_swizzle * 133b8e80941Smrgswizzle_wwww(operand a) 134b8e80941Smrg{ 135b8e80941Smrg return swizzle(a, SWIZZLE_WWWW, 4); 136b8e80941Smrg} 137b8e80941Smrg 138b8e80941Smrgir_swizzle * 139b8e80941Smrgswizzle_x(operand a) 140b8e80941Smrg{ 141b8e80941Smrg return swizzle(a, SWIZZLE_XXXX, 1); 142b8e80941Smrg} 143b8e80941Smrg 144b8e80941Smrgir_swizzle * 145b8e80941Smrgswizzle_y(operand a) 146b8e80941Smrg{ 147b8e80941Smrg return swizzle(a, SWIZZLE_YYYY, 1); 148b8e80941Smrg} 149b8e80941Smrg 150b8e80941Smrgir_swizzle * 151b8e80941Smrgswizzle_z(operand a) 152b8e80941Smrg{ 153b8e80941Smrg return swizzle(a, SWIZZLE_ZZZZ, 1); 154b8e80941Smrg} 155b8e80941Smrg 156b8e80941Smrgir_swizzle * 157b8e80941Smrgswizzle_w(operand a) 158b8e80941Smrg{ 159b8e80941Smrg return swizzle(a, SWIZZLE_WWWW, 1); 160b8e80941Smrg} 161b8e80941Smrg 162b8e80941Smrgir_swizzle * 163b8e80941Smrgswizzle_xy(operand a) 164b8e80941Smrg{ 165b8e80941Smrg return swizzle(a, SWIZZLE_XYZW, 2); 166b8e80941Smrg} 167b8e80941Smrg 168b8e80941Smrgir_swizzle * 169b8e80941Smrgswizzle_xyz(operand a) 170b8e80941Smrg{ 171b8e80941Smrg return swizzle(a, SWIZZLE_XYZW, 3); 172b8e80941Smrg} 173b8e80941Smrg 174b8e80941Smrgir_swizzle * 175b8e80941Smrgswizzle_xyzw(operand a) 176b8e80941Smrg{ 177b8e80941Smrg return swizzle(a, SWIZZLE_XYZW, 4); 178b8e80941Smrg} 179b8e80941Smrg 180b8e80941Smrgir_expression * 181b8e80941Smrgexpr(ir_expression_operation op, operand a) 182b8e80941Smrg{ 183b8e80941Smrg void *mem_ctx = ralloc_parent(a.val); 184b8e80941Smrg 185b8e80941Smrg return new(mem_ctx) ir_expression(op, a.val); 186b8e80941Smrg} 187b8e80941Smrg 188b8e80941Smrgir_expression * 189b8e80941Smrgexpr(ir_expression_operation op, operand a, operand b) 190b8e80941Smrg{ 191b8e80941Smrg void *mem_ctx = ralloc_parent(a.val); 192b8e80941Smrg 193b8e80941Smrg return new(mem_ctx) ir_expression(op, a.val, b.val); 194b8e80941Smrg} 195b8e80941Smrg 196b8e80941Smrgir_expression * 197b8e80941Smrgexpr(ir_expression_operation op, operand a, operand b, operand c) 198b8e80941Smrg{ 199b8e80941Smrg void *mem_ctx = ralloc_parent(a.val); 200b8e80941Smrg 201b8e80941Smrg return new(mem_ctx) ir_expression(op, a.val, b.val, c.val); 202b8e80941Smrg} 203b8e80941Smrg 204b8e80941Smrgir_expression *add(operand a, operand b) 205b8e80941Smrg{ 206b8e80941Smrg return expr(ir_binop_add, a, b); 207b8e80941Smrg} 208b8e80941Smrg 209b8e80941Smrgir_expression *sub(operand a, operand b) 210b8e80941Smrg{ 211b8e80941Smrg return expr(ir_binop_sub, a, b); 212b8e80941Smrg} 213b8e80941Smrg 214b8e80941Smrgir_expression *min2(operand a, operand b) 215b8e80941Smrg{ 216b8e80941Smrg return expr(ir_binop_min, a, b); 217b8e80941Smrg} 218b8e80941Smrg 219b8e80941Smrgir_expression *max2(operand a, operand b) 220b8e80941Smrg{ 221b8e80941Smrg return expr(ir_binop_max, a, b); 222b8e80941Smrg} 223b8e80941Smrg 224b8e80941Smrgir_expression *mul(operand a, operand b) 225b8e80941Smrg{ 226b8e80941Smrg return expr(ir_binop_mul, a, b); 227b8e80941Smrg} 228b8e80941Smrg 229b8e80941Smrgir_expression *imul_high(operand a, operand b) 230b8e80941Smrg{ 231b8e80941Smrg return expr(ir_binop_imul_high, a, b); 232b8e80941Smrg} 233b8e80941Smrg 234b8e80941Smrgir_expression *div(operand a, operand b) 235b8e80941Smrg{ 236b8e80941Smrg return expr(ir_binop_div, a, b); 237b8e80941Smrg} 238b8e80941Smrg 239b8e80941Smrgir_expression *carry(operand a, operand b) 240b8e80941Smrg{ 241b8e80941Smrg return expr(ir_binop_carry, a, b); 242b8e80941Smrg} 243b8e80941Smrg 244b8e80941Smrgir_expression *borrow(operand a, operand b) 245b8e80941Smrg{ 246b8e80941Smrg return expr(ir_binop_borrow, a, b); 247b8e80941Smrg} 248b8e80941Smrg 249b8e80941Smrgir_expression *trunc(operand a) 250b8e80941Smrg{ 251b8e80941Smrg return expr(ir_unop_trunc, a); 252b8e80941Smrg} 253b8e80941Smrg 254b8e80941Smrgir_expression *round_even(operand a) 255b8e80941Smrg{ 256b8e80941Smrg return expr(ir_unop_round_even, a); 257b8e80941Smrg} 258b8e80941Smrg 259b8e80941Smrgir_expression *fract(operand a) 260b8e80941Smrg{ 261b8e80941Smrg return expr(ir_unop_fract, a); 262b8e80941Smrg} 263b8e80941Smrg 264b8e80941Smrg/* dot for vectors, mul for scalars */ 265b8e80941Smrgir_expression *dot(operand a, operand b) 266b8e80941Smrg{ 267b8e80941Smrg assert(a.val->type == b.val->type); 268b8e80941Smrg 269b8e80941Smrg if (a.val->type->vector_elements == 1) 270b8e80941Smrg return expr(ir_binop_mul, a, b); 271b8e80941Smrg 272b8e80941Smrg return expr(ir_binop_dot, a, b); 273b8e80941Smrg} 274b8e80941Smrg 275b8e80941Smrgir_expression* 276b8e80941Smrgclamp(operand a, operand b, operand c) 277b8e80941Smrg{ 278b8e80941Smrg return expr(ir_binop_min, expr(ir_binop_max, a, b), c); 279b8e80941Smrg} 280b8e80941Smrg 281b8e80941Smrgir_expression * 282b8e80941Smrgsaturate(operand a) 283b8e80941Smrg{ 284b8e80941Smrg return expr(ir_unop_saturate, a); 285b8e80941Smrg} 286b8e80941Smrg 287b8e80941Smrgir_expression * 288b8e80941Smrgabs(operand a) 289b8e80941Smrg{ 290b8e80941Smrg return expr(ir_unop_abs, a); 291b8e80941Smrg} 292b8e80941Smrg 293b8e80941Smrgir_expression * 294b8e80941Smrgneg(operand a) 295b8e80941Smrg{ 296b8e80941Smrg return expr(ir_unop_neg, a); 297b8e80941Smrg} 298b8e80941Smrg 299b8e80941Smrgir_expression * 300b8e80941Smrgsin(operand a) 301b8e80941Smrg{ 302b8e80941Smrg return expr(ir_unop_sin, a); 303b8e80941Smrg} 304b8e80941Smrg 305b8e80941Smrgir_expression * 306b8e80941Smrgcos(operand a) 307b8e80941Smrg{ 308b8e80941Smrg return expr(ir_unop_cos, a); 309b8e80941Smrg} 310b8e80941Smrg 311b8e80941Smrgir_expression * 312b8e80941Smrgexp(operand a) 313b8e80941Smrg{ 314b8e80941Smrg return expr(ir_unop_exp, a); 315b8e80941Smrg} 316b8e80941Smrg 317b8e80941Smrgir_expression * 318b8e80941Smrgrcp(operand a) 319b8e80941Smrg{ 320b8e80941Smrg return expr(ir_unop_rcp, a); 321b8e80941Smrg} 322b8e80941Smrg 323b8e80941Smrgir_expression * 324b8e80941Smrgrsq(operand a) 325b8e80941Smrg{ 326b8e80941Smrg return expr(ir_unop_rsq, a); 327b8e80941Smrg} 328b8e80941Smrg 329b8e80941Smrgir_expression * 330b8e80941Smrgsqrt(operand a) 331b8e80941Smrg{ 332b8e80941Smrg return expr(ir_unop_sqrt, a); 333b8e80941Smrg} 334b8e80941Smrg 335b8e80941Smrgir_expression * 336b8e80941Smrglog(operand a) 337b8e80941Smrg{ 338b8e80941Smrg return expr(ir_unop_log, a); 339b8e80941Smrg} 340b8e80941Smrg 341b8e80941Smrgir_expression * 342b8e80941Smrgsign(operand a) 343b8e80941Smrg{ 344b8e80941Smrg return expr(ir_unop_sign, a); 345b8e80941Smrg} 346b8e80941Smrg 347b8e80941Smrgir_expression * 348b8e80941Smrgsubr_to_int(operand a) 349b8e80941Smrg{ 350b8e80941Smrg return expr(ir_unop_subroutine_to_int, a); 351b8e80941Smrg} 352b8e80941Smrg 353b8e80941Smrgir_expression* 354b8e80941Smrgequal(operand a, operand b) 355b8e80941Smrg{ 356b8e80941Smrg return expr(ir_binop_equal, a, b); 357b8e80941Smrg} 358b8e80941Smrg 359b8e80941Smrgir_expression* 360b8e80941Smrgnequal(operand a, operand b) 361b8e80941Smrg{ 362b8e80941Smrg return expr(ir_binop_nequal, a, b); 363b8e80941Smrg} 364b8e80941Smrg 365b8e80941Smrgir_expression* 366b8e80941Smrgless(operand a, operand b) 367b8e80941Smrg{ 368b8e80941Smrg return expr(ir_binop_less, a, b); 369b8e80941Smrg} 370b8e80941Smrg 371b8e80941Smrgir_expression* 372b8e80941Smrggreater(operand a, operand b) 373b8e80941Smrg{ 374b8e80941Smrg return expr(ir_binop_less, b, a); 375b8e80941Smrg} 376b8e80941Smrg 377b8e80941Smrgir_expression* 378b8e80941Smrglequal(operand a, operand b) 379b8e80941Smrg{ 380b8e80941Smrg return expr(ir_binop_gequal, b, a); 381b8e80941Smrg} 382b8e80941Smrg 383b8e80941Smrgir_expression* 384b8e80941Smrggequal(operand a, operand b) 385b8e80941Smrg{ 386b8e80941Smrg return expr(ir_binop_gequal, a, b); 387b8e80941Smrg} 388b8e80941Smrg 389b8e80941Smrgir_expression* 390b8e80941Smrglogic_not(operand a) 391b8e80941Smrg{ 392b8e80941Smrg return expr(ir_unop_logic_not, a); 393b8e80941Smrg} 394b8e80941Smrg 395b8e80941Smrgir_expression* 396b8e80941Smrglogic_and(operand a, operand b) 397b8e80941Smrg{ 398b8e80941Smrg return expr(ir_binop_logic_and, a, b); 399b8e80941Smrg} 400b8e80941Smrg 401b8e80941Smrgir_expression* 402b8e80941Smrglogic_or(operand a, operand b) 403b8e80941Smrg{ 404b8e80941Smrg return expr(ir_binop_logic_or, a, b); 405b8e80941Smrg} 406b8e80941Smrg 407b8e80941Smrgir_expression* 408b8e80941Smrgbit_not(operand a) 409b8e80941Smrg{ 410b8e80941Smrg return expr(ir_unop_bit_not, a); 411b8e80941Smrg} 412b8e80941Smrg 413b8e80941Smrgir_expression* 414b8e80941Smrgbit_and(operand a, operand b) 415b8e80941Smrg{ 416b8e80941Smrg return expr(ir_binop_bit_and, a, b); 417b8e80941Smrg} 418b8e80941Smrg 419b8e80941Smrgir_expression* 420b8e80941Smrgbit_or(operand a, operand b) 421b8e80941Smrg{ 422b8e80941Smrg return expr(ir_binop_bit_or, a, b); 423b8e80941Smrg} 424b8e80941Smrg 425b8e80941Smrgir_expression* 426b8e80941Smrgbit_xor(operand a, operand b) 427b8e80941Smrg{ 428b8e80941Smrg return expr(ir_binop_bit_xor, a, b); 429b8e80941Smrg} 430b8e80941Smrg 431b8e80941Smrgir_expression* 432b8e80941Smrglshift(operand a, operand b) 433b8e80941Smrg{ 434b8e80941Smrg return expr(ir_binop_lshift, a, b); 435b8e80941Smrg} 436b8e80941Smrg 437b8e80941Smrgir_expression* 438b8e80941Smrgrshift(operand a, operand b) 439b8e80941Smrg{ 440b8e80941Smrg return expr(ir_binop_rshift, a, b); 441b8e80941Smrg} 442b8e80941Smrg 443b8e80941Smrgir_expression* 444b8e80941Smrgf2i(operand a) 445b8e80941Smrg{ 446b8e80941Smrg return expr(ir_unop_f2i, a); 447b8e80941Smrg} 448b8e80941Smrg 449b8e80941Smrgir_expression* 450b8e80941Smrgbitcast_f2i(operand a) 451b8e80941Smrg{ 452b8e80941Smrg return expr(ir_unop_bitcast_f2i, a); 453b8e80941Smrg} 454b8e80941Smrg 455b8e80941Smrgir_expression* 456b8e80941Smrgi2f(operand a) 457b8e80941Smrg{ 458b8e80941Smrg return expr(ir_unop_i2f, a); 459b8e80941Smrg} 460b8e80941Smrg 461b8e80941Smrgir_expression* 462b8e80941Smrgbitcast_i2f(operand a) 463b8e80941Smrg{ 464b8e80941Smrg return expr(ir_unop_bitcast_i2f, a); 465b8e80941Smrg} 466b8e80941Smrg 467b8e80941Smrgir_expression* 468b8e80941Smrgi2u(operand a) 469b8e80941Smrg{ 470b8e80941Smrg return expr(ir_unop_i2u, a); 471b8e80941Smrg} 472b8e80941Smrg 473b8e80941Smrgir_expression* 474b8e80941Smrgu2i(operand a) 475b8e80941Smrg{ 476b8e80941Smrg return expr(ir_unop_u2i, a); 477b8e80941Smrg} 478b8e80941Smrg 479b8e80941Smrgir_expression* 480b8e80941Smrgf2u(operand a) 481b8e80941Smrg{ 482b8e80941Smrg return expr(ir_unop_f2u, a); 483b8e80941Smrg} 484b8e80941Smrg 485b8e80941Smrgir_expression* 486b8e80941Smrgbitcast_f2u(operand a) 487b8e80941Smrg{ 488b8e80941Smrg return expr(ir_unop_bitcast_f2u, a); 489b8e80941Smrg} 490b8e80941Smrg 491b8e80941Smrgir_expression* 492b8e80941Smrgu2f(operand a) 493b8e80941Smrg{ 494b8e80941Smrg return expr(ir_unop_u2f, a); 495b8e80941Smrg} 496b8e80941Smrg 497b8e80941Smrgir_expression* 498b8e80941Smrgbitcast_u2f(operand a) 499b8e80941Smrg{ 500b8e80941Smrg return expr(ir_unop_bitcast_u2f, a); 501b8e80941Smrg} 502b8e80941Smrg 503b8e80941Smrgir_expression* 504b8e80941Smrgi2b(operand a) 505b8e80941Smrg{ 506b8e80941Smrg return expr(ir_unop_i2b, a); 507b8e80941Smrg} 508b8e80941Smrg 509b8e80941Smrgir_expression* 510b8e80941Smrgb2i(operand a) 511b8e80941Smrg{ 512b8e80941Smrg return expr(ir_unop_b2i, a); 513b8e80941Smrg} 514b8e80941Smrg 515b8e80941Smrgir_expression * 516b8e80941Smrgf2b(operand a) 517b8e80941Smrg{ 518b8e80941Smrg return expr(ir_unop_f2b, a); 519b8e80941Smrg} 520b8e80941Smrg 521b8e80941Smrgir_expression * 522b8e80941Smrgb2f(operand a) 523b8e80941Smrg{ 524b8e80941Smrg return expr(ir_unop_b2f, a); 525b8e80941Smrg} 526b8e80941Smrg 527b8e80941Smrgir_expression* 528b8e80941Smrgbitcast_d2i64(operand a) 529b8e80941Smrg{ 530b8e80941Smrg return expr(ir_unop_bitcast_d2i64, a); 531b8e80941Smrg} 532b8e80941Smrg 533b8e80941Smrgir_expression* 534b8e80941Smrgbitcast_d2u64(operand a) 535b8e80941Smrg{ 536b8e80941Smrg return expr(ir_unop_bitcast_d2u64, a); 537b8e80941Smrg} 538b8e80941Smrg 539b8e80941Smrgir_expression* 540b8e80941Smrgbitcast_i642d(operand a) 541b8e80941Smrg{ 542b8e80941Smrg return expr(ir_unop_bitcast_i642d, a); 543b8e80941Smrg} 544b8e80941Smrg 545b8e80941Smrgir_expression* 546b8e80941Smrgbitcast_u642d(operand a) 547b8e80941Smrg{ 548b8e80941Smrg return expr(ir_unop_bitcast_u642d, a); 549b8e80941Smrg} 550b8e80941Smrg 551b8e80941Smrgir_expression * 552b8e80941Smrginterpolate_at_centroid(operand a) 553b8e80941Smrg{ 554b8e80941Smrg return expr(ir_unop_interpolate_at_centroid, a); 555b8e80941Smrg} 556b8e80941Smrg 557b8e80941Smrgir_expression * 558b8e80941Smrginterpolate_at_offset(operand a, operand b) 559b8e80941Smrg{ 560b8e80941Smrg return expr(ir_binop_interpolate_at_offset, a, b); 561b8e80941Smrg} 562b8e80941Smrg 563b8e80941Smrgir_expression * 564b8e80941Smrginterpolate_at_sample(operand a, operand b) 565b8e80941Smrg{ 566b8e80941Smrg return expr(ir_binop_interpolate_at_sample, a, b); 567b8e80941Smrg} 568b8e80941Smrg 569b8e80941Smrgir_expression * 570b8e80941Smrgf2d(operand a) 571b8e80941Smrg{ 572b8e80941Smrg return expr(ir_unop_f2d, a); 573b8e80941Smrg} 574b8e80941Smrg 575b8e80941Smrgir_expression * 576b8e80941Smrgi2d(operand a) 577b8e80941Smrg{ 578b8e80941Smrg return expr(ir_unop_i2d, a); 579b8e80941Smrg} 580b8e80941Smrg 581b8e80941Smrgir_expression * 582b8e80941Smrgu2d(operand a) 583b8e80941Smrg{ 584b8e80941Smrg return expr(ir_unop_u2d, a); 585b8e80941Smrg} 586b8e80941Smrg 587b8e80941Smrgir_expression * 588b8e80941Smrgfma(operand a, operand b, operand c) 589b8e80941Smrg{ 590b8e80941Smrg return expr(ir_triop_fma, a, b, c); 591b8e80941Smrg} 592b8e80941Smrg 593b8e80941Smrgir_expression * 594b8e80941Smrglrp(operand x, operand y, operand a) 595b8e80941Smrg{ 596b8e80941Smrg return expr(ir_triop_lrp, x, y, a); 597b8e80941Smrg} 598b8e80941Smrg 599b8e80941Smrgir_expression * 600b8e80941Smrgcsel(operand a, operand b, operand c) 601b8e80941Smrg{ 602b8e80941Smrg return expr(ir_triop_csel, a, b, c); 603b8e80941Smrg} 604b8e80941Smrg 605b8e80941Smrgir_expression * 606b8e80941Smrgbitfield_extract(operand a, operand b, operand c) 607b8e80941Smrg{ 608b8e80941Smrg return expr(ir_triop_bitfield_extract, a, b, c); 609b8e80941Smrg} 610b8e80941Smrg 611b8e80941Smrgir_expression * 612b8e80941Smrgbitfield_insert(operand a, operand b, operand c, operand d) 613b8e80941Smrg{ 614b8e80941Smrg void *mem_ctx = ralloc_parent(a.val); 615b8e80941Smrg return new(mem_ctx) ir_expression(ir_quadop_bitfield_insert, 616b8e80941Smrg a.val->type, a.val, b.val, c.val, d.val); 617b8e80941Smrg} 618b8e80941Smrg 619b8e80941Smrgir_if* 620b8e80941Smrgif_tree(operand condition, 621b8e80941Smrg ir_instruction *then_branch) 622b8e80941Smrg{ 623b8e80941Smrg assert(then_branch != NULL); 624b8e80941Smrg 625b8e80941Smrg void *mem_ctx = ralloc_parent(condition.val); 626b8e80941Smrg 627b8e80941Smrg ir_if *result = new(mem_ctx) ir_if(condition.val); 628b8e80941Smrg result->then_instructions.push_tail(then_branch); 629b8e80941Smrg return result; 630b8e80941Smrg} 631b8e80941Smrg 632b8e80941Smrgir_if* 633b8e80941Smrgif_tree(operand condition, 634b8e80941Smrg ir_instruction *then_branch, 635b8e80941Smrg ir_instruction *else_branch) 636b8e80941Smrg{ 637b8e80941Smrg assert(then_branch != NULL); 638b8e80941Smrg assert(else_branch != NULL); 639b8e80941Smrg 640b8e80941Smrg void *mem_ctx = ralloc_parent(condition.val); 641b8e80941Smrg 642b8e80941Smrg ir_if *result = new(mem_ctx) ir_if(condition.val); 643b8e80941Smrg result->then_instructions.push_tail(then_branch); 644b8e80941Smrg result->else_instructions.push_tail(else_branch); 645b8e80941Smrg return result; 646b8e80941Smrg} 647b8e80941Smrg 648b8e80941Smrg} /* namespace ir_builder */ 649