17ec681f3Smrg/* Copyright (c) 2018-2019 Alyssa Rosenzweig (alyssa@rosenzweig.io) 27ec681f3Smrg * Copyright (C) 2019-2020 Collabora, Ltd. 37ec681f3Smrg * 47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a copy 57ec681f3Smrg * of this software and associated documentation files (the "Software"), to deal 67ec681f3Smrg * in the Software without restriction, including without limitation the rights 77ec681f3Smrg * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 87ec681f3Smrg * copies of the Software, and to permit persons to whom the Software is 97ec681f3Smrg * furnished to do so, subject to the following conditions: 107ec681f3Smrg * 117ec681f3Smrg * The above copyright notice and this permission notice shall be included in 127ec681f3Smrg * all copies or substantial portions of the Software. 137ec681f3Smrg * 147ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 157ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 167ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 177ec681f3Smrg * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 187ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 197ec681f3Smrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 207ec681f3Smrg * THE SOFTWARE. 217ec681f3Smrg */ 227ec681f3Smrg 237ec681f3Smrg#ifndef __MDG_HELPERS_H 247ec681f3Smrg#define __MDG_HELPERS_H 257ec681f3Smrg 267ec681f3Smrg#include "util/macros.h" 277ec681f3Smrg#include <stdio.h> 287ec681f3Smrg#include <string.h> 297ec681f3Smrg 307ec681f3Smrg#define OP_IS_LOAD_VARY_F(op) (\ 317ec681f3Smrg op == midgard_op_ld_vary_16 || \ 327ec681f3Smrg op == midgard_op_ld_vary_32 \ 337ec681f3Smrg ) 347ec681f3Smrg 357ec681f3Smrg#define OP_IS_PROJECTION(op) ( \ 367ec681f3Smrg op == midgard_op_ldst_perspective_div_y || \ 377ec681f3Smrg op == midgard_op_ldst_perspective_div_z || \ 387ec681f3Smrg op == midgard_op_ldst_perspective_div_w \ 397ec681f3Smrg ) 407ec681f3Smrg 417ec681f3Smrg#define OP_IS_VEC4_ONLY(op) ( \ 427ec681f3Smrg OP_IS_PROJECTION(op) || \ 437ec681f3Smrg op == midgard_op_ld_cubemap_coords \ 447ec681f3Smrg ) 457ec681f3Smrg 467ec681f3Smrg#define OP_IS_MOVE(op) ( \ 477ec681f3Smrg (op >= midgard_alu_op_fmov && op <= midgard_alu_op_fmov_rtp) || \ 487ec681f3Smrg op == midgard_alu_op_imov \ 497ec681f3Smrg ) 507ec681f3Smrg 517ec681f3Smrg#define OP_IS_UBO_READ(op) ( \ 527ec681f3Smrg op >= midgard_op_ld_ubo_u8 && \ 537ec681f3Smrg op <= midgard_op_ld_ubo_128_bswap8 \ 547ec681f3Smrg ) 557ec681f3Smrg 567ec681f3Smrg#define OP_IS_CSEL_V(op) ( \ 577ec681f3Smrg op == midgard_alu_op_icsel_v || \ 587ec681f3Smrg op == midgard_alu_op_fcsel_v \ 597ec681f3Smrg ) 607ec681f3Smrg 617ec681f3Smrg#define OP_IS_CSEL(op) ( \ 627ec681f3Smrg OP_IS_CSEL_V(op) || \ 637ec681f3Smrg op == midgard_alu_op_icsel || \ 647ec681f3Smrg op == midgard_alu_op_fcsel \ 657ec681f3Smrg ) 667ec681f3Smrg 677ec681f3Smrg#define OP_IS_UNSIGNED_CMP(op) ( \ 687ec681f3Smrg op == midgard_alu_op_ult || \ 697ec681f3Smrg op == midgard_alu_op_ule \ 707ec681f3Smrg ) 717ec681f3Smrg 727ec681f3Smrg#define OP_IS_INTEGER_CMP(op) ( \ 737ec681f3Smrg op == midgard_alu_op_ieq || \ 747ec681f3Smrg op == midgard_alu_op_ine || \ 757ec681f3Smrg op == midgard_alu_op_ilt || \ 767ec681f3Smrg op == midgard_alu_op_ile || \ 777ec681f3Smrg OP_IS_UNSIGNED_CMP(op) \ 787ec681f3Smrg ) 797ec681f3Smrg 807ec681f3Smrg#define OP_IS_COMMON_STORE(op) ( \ 817ec681f3Smrg op >= midgard_op_st_u8 && \ 827ec681f3Smrg op <= midgard_op_st_128_bswap8 \ 837ec681f3Smrg ) 847ec681f3Smrg 857ec681f3Smrg#define OP_IS_IMAGE(op) ( \ 867ec681f3Smrg (op >= midgard_op_ld_image_32f && op <= midgard_op_ld_image_32i) || \ 877ec681f3Smrg (op >= midgard_op_st_image_32f && op <= midgard_op_st_image_32i) || \ 887ec681f3Smrg op == midgard_op_lea_image \ 897ec681f3Smrg ) 907ec681f3Smrg 917ec681f3Smrg#define OP_IS_SPECIAL(op) ( \ 927ec681f3Smrg (op >= midgard_op_ld_special_32f && op <= midgard_op_ld_special_32i) || \ 937ec681f3Smrg (op >= midgard_op_st_special_32f && op <= midgard_op_st_special_32i) \ 947ec681f3Smrg ) 957ec681f3Smrg 967ec681f3Smrg#define OP_IS_PACK_COLOUR(op) ( \ 977ec681f3Smrg (op >= midgard_op_pack_colour_f32 && op <= midgard_op_pack_colour_s32) \ 987ec681f3Smrg ) 997ec681f3Smrg 1007ec681f3Smrg#define OP_IS_UNPACK_COLOUR(op) ( \ 1017ec681f3Smrg (op >= midgard_op_unpack_colour_f32 && op <= midgard_op_unpack_colour_s32) \ 1027ec681f3Smrg ) 1037ec681f3Smrg 1047ec681f3Smrg/* Instructions that are on the load/store unit but don't access memory */ 1057ec681f3Smrg#define OP_IS_REG2REG_LDST(op) ( \ 1067ec681f3Smrg op >= midgard_op_unpack_colour_f32 && \ 1077ec681f3Smrg op <= midgard_op_ldst_perspective_div_w \ 1087ec681f3Smrg ) 1097ec681f3Smrg 1107ec681f3Smrg/* ALU control words are single bit fields with a lot of space */ 1117ec681f3Smrg 1127ec681f3Smrg#define ALU_ENAB_VEC_MUL (1 << 17) 1137ec681f3Smrg#define ALU_ENAB_SCAL_ADD (1 << 19) 1147ec681f3Smrg#define ALU_ENAB_VEC_ADD (1 << 21) 1157ec681f3Smrg#define ALU_ENAB_SCAL_MUL (1 << 23) 1167ec681f3Smrg#define ALU_ENAB_VEC_LUT (1 << 25) 1177ec681f3Smrg#define ALU_ENAB_BR_COMPACT (1 << 26) 1187ec681f3Smrg#define ALU_ENAB_BRANCH (1 << 27) 1197ec681f3Smrg 1207ec681f3Smrg/* Other opcode properties that don't conflict with the ALU_ENABs, non-ISA */ 1217ec681f3Smrg 1227ec681f3Smrg/* Denotes an opcode that takes a vector input with a fixed-number of 1237ec681f3Smrg * channels, but outputs to only a single output channel, like dot products. 1247ec681f3Smrg * For these, to determine the effective mask, this quirk can be set. We have 1257ec681f3Smrg * an intentional off-by-one (a la MALI_POSITIVE), since 0-channel makes no 1267ec681f3Smrg * sense but we need to fit 4 channels in 2-bits. Similarly, 1-channel doesn't 1277ec681f3Smrg * make sense (since then why are we quirked?), so that corresponds to "no 1287ec681f3Smrg * count set" */ 1297ec681f3Smrg 1307ec681f3Smrg#define OP_CHANNEL_COUNT(c) ((c - 1) << 0) 1317ec681f3Smrg#define GET_CHANNEL_COUNT(c) ((c & (0x3 << 0)) ? ((c & (0x3 << 0)) + 1) : 0) 1327ec681f3Smrg 1337ec681f3Smrg/* For instructions that take a single argument, normally the first argument 1347ec681f3Smrg * slot is used for the argument and the second slot is a dummy #0 constant. 1357ec681f3Smrg * However, there are exceptions: instructions like fmov store their argument 1367ec681f3Smrg * in the _second_ slot and store a dummy r24 in the first slot, designated by 1377ec681f3Smrg * QUIRK_FLIPPED_R24 */ 1387ec681f3Smrg 1397ec681f3Smrg#define QUIRK_FLIPPED_R24 (1 << 2) 1407ec681f3Smrg 1417ec681f3Smrg/* Is the op commutative? */ 1427ec681f3Smrg#define OP_COMMUTES (1 << 3) 1437ec681f3Smrg 1447ec681f3Smrg/* Does the op convert types between int- and float- space (i2f/f2u/etc) */ 1457ec681f3Smrg#define OP_TYPE_CONVERT (1 << 4) 1467ec681f3Smrg 1477ec681f3Smrg/* Is this opcode the first in a f2x (rte, rtz, rtn, rtp) sequence? If so, 1487ec681f3Smrg * takes a roundmode argument in the IR. This has the semantic of rounding the 1497ec681f3Smrg * source (it's all fused in), which is why it doesn't necessarily make sense 1507ec681f3Smrg * for i2f (though folding there might be necessary for OpenCL reasons). Comes 1517ec681f3Smrg * up in format conversion, i.e. f2u_rte */ 1527ec681f3Smrg#define MIDGARD_ROUNDS (1 << 5) 1537ec681f3Smrg 1547ec681f3Smrg/* Vector-independant shorthands for the above; these numbers are arbitrary and 1557ec681f3Smrg * not from the ISA. Convert to the above with unit_enum_to_midgard */ 1567ec681f3Smrg 1577ec681f3Smrg#define UNIT_MUL 0 1587ec681f3Smrg#define UNIT_ADD 1 1597ec681f3Smrg#define UNIT_LUT 2 1607ec681f3Smrg 1617ec681f3Smrg#define IS_ALU(tag) (tag >= TAG_ALU_4) 1627ec681f3Smrg 1637ec681f3Smrg/* Special register aliases */ 1647ec681f3Smrg 1657ec681f3Smrg#define MAX_WORK_REGISTERS 16 1667ec681f3Smrg 1677ec681f3Smrg/* Uniforms are begin at (REGISTER_UNIFORMS - uniform_count) */ 1687ec681f3Smrg#define REGISTER_UNIFORMS 24 1697ec681f3Smrg 1707ec681f3Smrg/* r24 and r25 are special registers that only exist during the pipeline, 1717ec681f3Smrg * by using them when we don't care about the register we skip a roundtrip 1727ec681f3Smrg * to the register file. */ 1737ec681f3Smrg#define REGISTER_UNUSED 24 1747ec681f3Smrg#define REGISTER_CONSTANT 26 1757ec681f3Smrg#define REGISTER_LDST_BASE 26 1767ec681f3Smrg#define REGISTER_TEXTURE_BASE 28 1777ec681f3Smrg#define REGISTER_SELECT 31 1787ec681f3Smrg 1797ec681f3Smrg/* The following registers are read-only */ 1807ec681f3Smrg 1817ec681f3Smrg/* XY is Program Counter, ZW is Stack Pointer */ 1827ec681f3Smrg#define REGISTER_LDST_PC_SP 2 1837ec681f3Smrg 1847ec681f3Smrg/* XY is Thread Local Storage pointer, ZW is Workgroup Local Storage pointer */ 1857ec681f3Smrg#define REGISTER_LDST_LOCAL_STORAGE_PTR 3 1867ec681f3Smrg 1877ec681f3Smrg#define REGISTER_LDST_LOCAL_THREAD_ID 4 1887ec681f3Smrg#define REGISTER_LDST_GROUP_ID 5 1897ec681f3Smrg#define REGISTER_LDST_GLOBAL_THREAD_ID 6 1907ec681f3Smrg 1917ec681f3Smrg/* This register is always zeroed when read. */ 1927ec681f3Smrg#define REGISTER_LDST_ZERO 7 1937ec681f3Smrg 1947ec681f3Smrg/* SSA helper aliases to mimic the registers. */ 1957ec681f3Smrg 1967ec681f3Smrg#define SSA_FIXED_SHIFT 24 1977ec681f3Smrg#define SSA_FIXED_REGISTER(reg) (((1 + (reg)) << SSA_FIXED_SHIFT) | 1) 1987ec681f3Smrg#define SSA_REG_FROM_FIXED(reg) ((((reg) & ~1) >> SSA_FIXED_SHIFT) - 1) 1997ec681f3Smrg#define SSA_FIXED_MINIMUM SSA_FIXED_REGISTER(0) 2007ec681f3Smrg 2017ec681f3Smrg#define COMPONENT_X 0x0 2027ec681f3Smrg#define COMPONENT_Y 0x1 2037ec681f3Smrg#define COMPONENT_Z 0x2 2047ec681f3Smrg#define COMPONENT_W 0x3 2057ec681f3Smrg 2067ec681f3Smrg#define SWIZZLE_IDENTITY { \ 2077ec681f3Smrg { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, \ 2087ec681f3Smrg { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, \ 2097ec681f3Smrg { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, \ 2107ec681f3Smrg { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } \ 2117ec681f3Smrg} 2127ec681f3Smrg 2137ec681f3Smrg#define SWIZZLE_IDENTITY_4 { \ 2147ec681f3Smrg { 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, \ 2157ec681f3Smrg { 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, \ 2167ec681f3Smrg { 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, \ 2177ec681f3Smrg { 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, \ 2187ec681f3Smrg} 2197ec681f3Smrg 2207ec681f3Smrgstatic inline unsigned 2217ec681f3Smrgmask_of(unsigned nr_comp) 2227ec681f3Smrg{ 2237ec681f3Smrg return (1 << nr_comp) - 1; 2247ec681f3Smrg} 2257ec681f3Smrg 2267ec681f3Smrg/* See ISA notes */ 2277ec681f3Smrg 2287ec681f3Smrg#define LDST_NOP (3) 2297ec681f3Smrg 2307ec681f3Smrg/* There are five ALU units: VMUL, VADD, SMUL, SADD, LUT. A given opcode is 2317ec681f3Smrg * implemented on some subset of these units (or occassionally all of them). 2327ec681f3Smrg * This table encodes a bit mask of valid units for each opcode, so the 2337ec681f3Smrg * scheduler can figure where to plonk the instruction. */ 2347ec681f3Smrg 2357ec681f3Smrg/* Shorthands for each unit */ 2367ec681f3Smrg#define UNIT_VMUL ALU_ENAB_VEC_MUL 2377ec681f3Smrg#define UNIT_SADD ALU_ENAB_SCAL_ADD 2387ec681f3Smrg#define UNIT_VADD ALU_ENAB_VEC_ADD 2397ec681f3Smrg#define UNIT_SMUL ALU_ENAB_SCAL_MUL 2407ec681f3Smrg#define UNIT_VLUT ALU_ENAB_VEC_LUT 2417ec681f3Smrg 2427ec681f3Smrg/* Shorthands for usual combinations of units */ 2437ec681f3Smrg 2447ec681f3Smrg#define UNITS_MUL (UNIT_VMUL | UNIT_SMUL) 2457ec681f3Smrg#define UNITS_ADD (UNIT_VADD | UNIT_SADD) 2467ec681f3Smrg#define UNITS_MOST (UNITS_MUL | UNITS_ADD) 2477ec681f3Smrg#define UNITS_ALL (UNITS_MOST | UNIT_VLUT) 2487ec681f3Smrg#define UNITS_SCALAR (UNIT_SADD | UNIT_SMUL) 2497ec681f3Smrg#define UNITS_VECTOR (UNIT_VMUL | UNIT_VADD) 2507ec681f3Smrg#define UNITS_ANY_VECTOR (UNITS_VECTOR | UNIT_VLUT) 2517ec681f3Smrg 2527ec681f3Smrgstruct mir_op_props { 2537ec681f3Smrg const char *name; 2547ec681f3Smrg unsigned props; 2557ec681f3Smrg}; 2567ec681f3Smrg 2577ec681f3Smrg/* For load/store */ 2587ec681f3Smrg 2597ec681f3Smrgstruct mir_ldst_op_props { 2607ec681f3Smrg const char *name; 2617ec681f3Smrg unsigned props; 2627ec681f3Smrg}; 2637ec681f3Smrg 2647ec681f3Smrgstruct mir_tex_op_props { 2657ec681f3Smrg const char *name; 2667ec681f3Smrg unsigned props; 2677ec681f3Smrg}; 2687ec681f3Smrg 2697ec681f3Smrgstruct mir_tag_props { 2707ec681f3Smrg const char *name; 2717ec681f3Smrg unsigned size; 2727ec681f3Smrg}; 2737ec681f3Smrg 2747ec681f3Smrg/* Lower 2-bits are a midgard_reg_mode */ 2757ec681f3Smrg#define GET_LDST_SIZE(c) (c & 3) 2767ec681f3Smrg 2777ec681f3Smrg/* Store (so the primary register is a source, not a destination */ 2787ec681f3Smrg#define LDST_STORE (1 << 2) 2797ec681f3Smrg 2807ec681f3Smrg/* Mask has special meaning and should not be manipulated directly */ 2817ec681f3Smrg#define LDST_SPECIAL_MASK (1 << 3) 2827ec681f3Smrg 2837ec681f3Smrg/* Non-store operation has side effects and should not be eliminated even if 2847ec681f3Smrg * its mask is 0 */ 2857ec681f3Smrg#define LDST_SIDE_FX (1 << 4) 2867ec681f3Smrg 2877ec681f3Smrg/* Computes an address according to indirects/zext/shift/etc */ 2887ec681f3Smrg#define LDST_ADDRESS (1 << 5) 2897ec681f3Smrg 2907ec681f3Smrg/* Some fields such swizzle and address have special meanings */ 2917ec681f3Smrg#define LDST_ATOMIC (1 << 6) 2927ec681f3Smrg 2937ec681f3Smrg/* Operates on attributes/varyings (including images) */ 2947ec681f3Smrg#define LDST_ATTRIB (1 << 7) 2957ec681f3Smrg 2967ec681f3Smrg/* This file is common, so don't define the tables themselves. #include 2977ec681f3Smrg * midgard_op.h if you need that, or edit midgard_ops.c directly */ 2987ec681f3Smrg 2997ec681f3Smrg/* Duplicate bits to convert a per-component to duplicated 8-bit format, 3007ec681f3Smrg * which is used for vector units */ 3017ec681f3Smrg 3027ec681f3Smrgstatic inline unsigned 3037ec681f3Smrgexpand_writemask(unsigned mask, unsigned log2_channels) 3047ec681f3Smrg{ 3057ec681f3Smrg unsigned o = 0; 3067ec681f3Smrg unsigned factor = 8 >> log2_channels; 3077ec681f3Smrg unsigned expanded = (1 << factor) - 1; 3087ec681f3Smrg 3097ec681f3Smrg for (unsigned i = 0; i < (1 << log2_channels); ++i) 3107ec681f3Smrg if (mask & (1 << i)) 3117ec681f3Smrg o |= (expanded << (factor * i)); 3127ec681f3Smrg 3137ec681f3Smrg return o; 3147ec681f3Smrg} 3157ec681f3Smrg 3167ec681f3Smrg/* Coerce structs to integer */ 3177ec681f3Smrg 3187ec681f3Smrgstatic inline unsigned 3197ec681f3Smrgvector_alu_srco_unsigned(midgard_vector_alu_src src) 3207ec681f3Smrg{ 3217ec681f3Smrg unsigned u; 3227ec681f3Smrg memcpy(&u, &src, sizeof(src)); 3237ec681f3Smrg return u; 3247ec681f3Smrg} 3257ec681f3Smrg 3267ec681f3Smrgstatic inline midgard_vector_alu_src 3277ec681f3Smrgvector_alu_from_unsigned(unsigned u) 3287ec681f3Smrg{ 3297ec681f3Smrg midgard_vector_alu_src s; 3307ec681f3Smrg memcpy(&s, &u, sizeof(s)); 3317ec681f3Smrg return s; 3327ec681f3Smrg} 3337ec681f3Smrg 3347ec681f3Smrgstatic inline void 3357ec681f3Smrgmir_compose_swizzle(unsigned *left, unsigned *right, unsigned *final_out) 3367ec681f3Smrg{ 3377ec681f3Smrg unsigned out[16]; 3387ec681f3Smrg 3397ec681f3Smrg for (unsigned c = 0; c < 16; ++c) 3407ec681f3Smrg out[c] = right[left[c]]; 3417ec681f3Smrg 3427ec681f3Smrg memcpy(final_out, out, sizeof(out)); 3437ec681f3Smrg} 3447ec681f3Smrg 3457ec681f3Smrg/* Checks for an xyzw.. swizzle, given a mask */ 3467ec681f3Smrg 3477ec681f3Smrgstatic inline bool 3487ec681f3Smrgmir_is_simple_swizzle(unsigned *swizzle, unsigned mask) 3497ec681f3Smrg{ 3507ec681f3Smrg for (unsigned i = 0; i < 16; ++i) { 3517ec681f3Smrg if (!(mask & (1 << i))) continue; 3527ec681f3Smrg 3537ec681f3Smrg if (swizzle[i] != i) 3547ec681f3Smrg return false; 3557ec681f3Smrg } 3567ec681f3Smrg 3577ec681f3Smrg return true; 3587ec681f3Smrg} 3597ec681f3Smrg 3607ec681f3Smrg/* Packs a load/store argument */ 3617ec681f3Smrg 3627ec681f3Smrgstatic inline uint8_t 3637ec681f3Smrgmidgard_ldst_comp(unsigned reg, unsigned component, unsigned size) 3647ec681f3Smrg{ 3657ec681f3Smrg assert((reg & ~1) == 0); 3667ec681f3Smrg assert(size == 16 || size == 32 || size == 64); 3677ec681f3Smrg 3687ec681f3Smrg /* Shift so everything is in terms of 32-bit units */ 3697ec681f3Smrg if (size == 64) { 3707ec681f3Smrg assert(component < 2); 3717ec681f3Smrg component <<= 1; 3727ec681f3Smrg } else if (size == 16) { 3737ec681f3Smrg assert((component & 1) == 0); 3747ec681f3Smrg component >>= 1; 3757ec681f3Smrg } 3767ec681f3Smrg 3777ec681f3Smrg return component; 3787ec681f3Smrg} 3797ec681f3Smrg 3807ec681f3Smrg/* Packs/unpacks a ubo index immediate */ 3817ec681f3Smrg 3827ec681f3Smrgvoid midgard_pack_ubo_index_imm(midgard_load_store_word *word, unsigned index); 3837ec681f3Smrgunsigned midgard_unpack_ubo_index_imm(midgard_load_store_word word); 3847ec681f3Smrg 3857ec681f3Smrg/* Packs/unpacks varying parameters. 3867ec681f3Smrg * FIXME: IMPORTANT: We currently handle varying mode weirdly, by passing all 3877ec681f3Smrg * parameters via an offset and using REGISTER_LDST_ZERO as base. This works 3887ec681f3Smrg * for most parameters, but does not allow us to encode/decode direct sample 3897ec681f3Smrg * position. */ 3907ec681f3Smrgvoid midgard_pack_varying_params(midgard_load_store_word *word, midgard_varying_params p); 3917ec681f3Smrgmidgard_varying_params midgard_unpack_varying_params(midgard_load_store_word word); 3927ec681f3Smrg 3937ec681f3Smrg/* Load/store ops' displacement helpers. 3947ec681f3Smrg * This is useful because different types of load/store ops have different 3957ec681f3Smrg * displacement bitsize. */ 3967ec681f3Smrg 3977ec681f3Smrg#define UNPACK_LDST_ATTRIB_OFS(a) ((a) >> 9) 3987ec681f3Smrg#define UNPACK_LDST_VERTEX_OFS(a) util_sign_extend((a) & 0x1FF, 9) 3997ec681f3Smrg#define UNPACK_LDST_SELECTOR_OFS(a) ((a) >> 9) 4007ec681f3Smrg#define UNPACK_LDST_UBO_OFS(a) ((a) >> 2) 4017ec681f3Smrg#define UNPACK_LDST_MEM_OFS(a) ((a)) 4027ec681f3Smrg 4037ec681f3Smrg#define PACK_LDST_ATTRIB_OFS(a) ((a) << 9) 4047ec681f3Smrg#define PACK_LDST_VERTEX_OFS(a) ((a) & 0x1FF) 4057ec681f3Smrg#define PACK_LDST_SELECTOR_OFS(a) ((a) << 9) 4067ec681f3Smrg#define PACK_LDST_UBO_OFS(a) ((a) << 2) 4077ec681f3Smrg#define PACK_LDST_MEM_OFS(a) ((a)) 4087ec681f3Smrg 4097ec681f3Smrgstatic inline bool 4107ec681f3Smrgmidgard_is_branch_unit(unsigned unit) 4117ec681f3Smrg{ 4127ec681f3Smrg return (unit == ALU_ENAB_BRANCH) || (unit == ALU_ENAB_BR_COMPACT); 4137ec681f3Smrg} 4147ec681f3Smrg 4157ec681f3Smrg/* Packs ALU mod argument */ 4167ec681f3Smrgstruct midgard_instruction; 4177ec681f3Smrgunsigned mir_pack_mod(struct midgard_instruction *ins, unsigned i, bool scalar); 4187ec681f3Smrg 4197ec681f3Smrgvoid 4207ec681f3Smrgmir_print_constant_component(FILE *fp, const midgard_constants *consts, 4217ec681f3Smrg unsigned c, midgard_reg_mode reg_mode, bool half, 4227ec681f3Smrg unsigned mod, midgard_alu_op op); 4237ec681f3Smrg 4247ec681f3Smrg#endif 425