1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org> 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21bf215546Sopenharmony_ci * SOFTWARE. 22bf215546Sopenharmony_ci * 23bf215546Sopenharmony_ci * Authors: 24bf215546Sopenharmony_ci * Rob Clark <robclark@freedesktop.org> 25bf215546Sopenharmony_ci */ 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#include <math.h> 28bf215546Sopenharmony_ci#include "util/half_float.h" 29bf215546Sopenharmony_ci#include "util/u_math.h" 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci#include "ir3.h" 32bf215546Sopenharmony_ci#include "ir3_compiler.h" 33bf215546Sopenharmony_ci#include "ir3_shader.h" 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_ci#define swap(a, b) \ 36bf215546Sopenharmony_ci do { \ 37bf215546Sopenharmony_ci __typeof(a) __tmp = (a); \ 38bf215546Sopenharmony_ci (a) = (b); \ 39bf215546Sopenharmony_ci (b) = __tmp; \ 40bf215546Sopenharmony_ci } while (0) 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_ci/* 43bf215546Sopenharmony_ci * Copy Propagate: 44bf215546Sopenharmony_ci */ 45bf215546Sopenharmony_ci 46bf215546Sopenharmony_cistruct ir3_cp_ctx { 47bf215546Sopenharmony_ci struct ir3 *shader; 48bf215546Sopenharmony_ci struct ir3_shader_variant *so; 49bf215546Sopenharmony_ci bool progress; 50bf215546Sopenharmony_ci}; 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_ci/* is it a type preserving mov, with ok flags? 53bf215546Sopenharmony_ci * 54bf215546Sopenharmony_ci * @instr: the mov to consider removing 55bf215546Sopenharmony_ci * @dst_instr: the instruction consuming the mov (instr) 56bf215546Sopenharmony_ci * 57bf215546Sopenharmony_ci * TODO maybe drop allow_flags since this is only false when dst is 58bf215546Sopenharmony_ci * NULL (ie. outputs) 59bf215546Sopenharmony_ci */ 60bf215546Sopenharmony_cistatic bool 61bf215546Sopenharmony_ciis_eligible_mov(struct ir3_instruction *instr, 62bf215546Sopenharmony_ci struct ir3_instruction *dst_instr, bool allow_flags) 63bf215546Sopenharmony_ci{ 64bf215546Sopenharmony_ci if (is_same_type_mov(instr)) { 65bf215546Sopenharmony_ci struct ir3_register *dst = instr->dsts[0]; 66bf215546Sopenharmony_ci struct ir3_register *src = instr->srcs[0]; 67bf215546Sopenharmony_ci struct ir3_instruction *src_instr = ssa(src); 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_ci /* only if mov src is SSA (not const/immed): */ 70bf215546Sopenharmony_ci if (!src_instr) 71bf215546Sopenharmony_ci return false; 72bf215546Sopenharmony_ci 73bf215546Sopenharmony_ci /* no indirect: */ 74bf215546Sopenharmony_ci if (dst->flags & IR3_REG_RELATIV) 75bf215546Sopenharmony_ci return false; 76bf215546Sopenharmony_ci if (src->flags & IR3_REG_RELATIV) 77bf215546Sopenharmony_ci return false; 78bf215546Sopenharmony_ci 79bf215546Sopenharmony_ci if (src->flags & IR3_REG_ARRAY) 80bf215546Sopenharmony_ci return false; 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_ci if (!allow_flags) 83bf215546Sopenharmony_ci if (src->flags & (IR3_REG_FABS | IR3_REG_FNEG | IR3_REG_SABS | 84bf215546Sopenharmony_ci IR3_REG_SNEG | IR3_REG_BNOT)) 85bf215546Sopenharmony_ci return false; 86bf215546Sopenharmony_ci 87bf215546Sopenharmony_ci return true; 88bf215546Sopenharmony_ci } 89bf215546Sopenharmony_ci return false; 90bf215546Sopenharmony_ci} 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_ci/* we can end up with extra cmps.s from frontend, which uses a 93bf215546Sopenharmony_ci * 94bf215546Sopenharmony_ci * cmps.s p0.x, cond, 0 95bf215546Sopenharmony_ci * 96bf215546Sopenharmony_ci * as a way to mov into the predicate register. But frequently 'cond' 97bf215546Sopenharmony_ci * is itself a cmps.s/cmps.f/cmps.u. So detect this special case. 98bf215546Sopenharmony_ci */ 99bf215546Sopenharmony_cistatic bool 100bf215546Sopenharmony_ciis_foldable_double_cmp(struct ir3_instruction *cmp) 101bf215546Sopenharmony_ci{ 102bf215546Sopenharmony_ci struct ir3_instruction *cond = ssa(cmp->srcs[0]); 103bf215546Sopenharmony_ci return (cmp->dsts[0]->num == regid(REG_P0, 0)) && cond && 104bf215546Sopenharmony_ci (cmp->srcs[1]->flags & IR3_REG_IMMED) && 105bf215546Sopenharmony_ci (cmp->srcs[1]->iim_val == 0) && 106bf215546Sopenharmony_ci (cmp->cat2.condition == IR3_COND_NE) && 107bf215546Sopenharmony_ci (!cond->address || cond->address->def->instr->block == cmp->block); 108bf215546Sopenharmony_ci} 109bf215546Sopenharmony_ci 110bf215546Sopenharmony_ci/* propagate register flags from src to dst.. negates need special 111bf215546Sopenharmony_ci * handling to cancel each other out. 112bf215546Sopenharmony_ci */ 113bf215546Sopenharmony_cistatic void 114bf215546Sopenharmony_cicombine_flags(unsigned *dstflags, struct ir3_instruction *src) 115bf215546Sopenharmony_ci{ 116bf215546Sopenharmony_ci unsigned srcflags = src->srcs[0]->flags; 117bf215546Sopenharmony_ci 118bf215546Sopenharmony_ci /* if what we are combining into already has (abs) flags, 119bf215546Sopenharmony_ci * we can drop (neg) from src: 120bf215546Sopenharmony_ci */ 121bf215546Sopenharmony_ci if (*dstflags & IR3_REG_FABS) 122bf215546Sopenharmony_ci srcflags &= ~IR3_REG_FNEG; 123bf215546Sopenharmony_ci if (*dstflags & IR3_REG_SABS) 124bf215546Sopenharmony_ci srcflags &= ~IR3_REG_SNEG; 125bf215546Sopenharmony_ci 126bf215546Sopenharmony_ci if (srcflags & IR3_REG_FABS) 127bf215546Sopenharmony_ci *dstflags |= IR3_REG_FABS; 128bf215546Sopenharmony_ci if (srcflags & IR3_REG_SABS) 129bf215546Sopenharmony_ci *dstflags |= IR3_REG_SABS; 130bf215546Sopenharmony_ci if (srcflags & IR3_REG_FNEG) 131bf215546Sopenharmony_ci *dstflags ^= IR3_REG_FNEG; 132bf215546Sopenharmony_ci if (srcflags & IR3_REG_SNEG) 133bf215546Sopenharmony_ci *dstflags ^= IR3_REG_SNEG; 134bf215546Sopenharmony_ci if (srcflags & IR3_REG_BNOT) 135bf215546Sopenharmony_ci *dstflags ^= IR3_REG_BNOT; 136bf215546Sopenharmony_ci 137bf215546Sopenharmony_ci *dstflags &= ~IR3_REG_SSA; 138bf215546Sopenharmony_ci *dstflags |= srcflags & IR3_REG_SSA; 139bf215546Sopenharmony_ci *dstflags |= srcflags & IR3_REG_CONST; 140bf215546Sopenharmony_ci *dstflags |= srcflags & IR3_REG_IMMED; 141bf215546Sopenharmony_ci *dstflags |= srcflags & IR3_REG_RELATIV; 142bf215546Sopenharmony_ci *dstflags |= srcflags & IR3_REG_ARRAY; 143bf215546Sopenharmony_ci *dstflags |= srcflags & IR3_REG_SHARED; 144bf215546Sopenharmony_ci 145bf215546Sopenharmony_ci /* if src of the src is boolean we can drop the (abs) since we know 146bf215546Sopenharmony_ci * the source value is already a postitive integer. This cleans 147bf215546Sopenharmony_ci * up the absnegs that get inserted when converting between nir and 148bf215546Sopenharmony_ci * native boolean (see ir3_b2n/n2b) 149bf215546Sopenharmony_ci */ 150bf215546Sopenharmony_ci struct ir3_instruction *srcsrc = ssa(src->srcs[0]); 151bf215546Sopenharmony_ci if (srcsrc && is_bool(srcsrc)) 152bf215546Sopenharmony_ci *dstflags &= ~IR3_REG_SABS; 153bf215546Sopenharmony_ci} 154bf215546Sopenharmony_ci 155bf215546Sopenharmony_ci/* Tries lowering an immediate register argument to a const buffer access by 156bf215546Sopenharmony_ci * adding to the list of immediates to be pushed to the const buffer when 157bf215546Sopenharmony_ci * switching to this shader. 158bf215546Sopenharmony_ci */ 159bf215546Sopenharmony_cistatic bool 160bf215546Sopenharmony_cilower_immed(struct ir3_cp_ctx *ctx, struct ir3_instruction *instr, unsigned n, 161bf215546Sopenharmony_ci struct ir3_register *reg, unsigned new_flags) 162bf215546Sopenharmony_ci{ 163bf215546Sopenharmony_ci if (!(new_flags & IR3_REG_IMMED)) 164bf215546Sopenharmony_ci return false; 165bf215546Sopenharmony_ci 166bf215546Sopenharmony_ci new_flags &= ~IR3_REG_IMMED; 167bf215546Sopenharmony_ci new_flags |= IR3_REG_CONST; 168bf215546Sopenharmony_ci 169bf215546Sopenharmony_ci if (!ir3_valid_flags(instr, n, new_flags)) 170bf215546Sopenharmony_ci return false; 171bf215546Sopenharmony_ci 172bf215546Sopenharmony_ci reg = ir3_reg_clone(ctx->shader, reg); 173bf215546Sopenharmony_ci 174bf215546Sopenharmony_ci /* Half constant registers seems to handle only 32-bit values 175bf215546Sopenharmony_ci * within floating-point opcodes. So convert back to 32-bit values. 176bf215546Sopenharmony_ci */ 177bf215546Sopenharmony_ci bool f_opcode = 178bf215546Sopenharmony_ci (is_cat2_float(instr->opc) || is_cat3_float(instr->opc)) ? true : false; 179bf215546Sopenharmony_ci if (f_opcode && (new_flags & IR3_REG_HALF)) 180bf215546Sopenharmony_ci reg->uim_val = fui(_mesa_half_to_float(reg->uim_val)); 181bf215546Sopenharmony_ci 182bf215546Sopenharmony_ci /* in some cases, there are restrictions on (abs)/(neg) plus const.. 183bf215546Sopenharmony_ci * so just evaluate those and clear the flags: 184bf215546Sopenharmony_ci */ 185bf215546Sopenharmony_ci if (new_flags & IR3_REG_SABS) { 186bf215546Sopenharmony_ci reg->iim_val = abs(reg->iim_val); 187bf215546Sopenharmony_ci new_flags &= ~IR3_REG_SABS; 188bf215546Sopenharmony_ci } 189bf215546Sopenharmony_ci 190bf215546Sopenharmony_ci if (new_flags & IR3_REG_FABS) { 191bf215546Sopenharmony_ci reg->fim_val = fabs(reg->fim_val); 192bf215546Sopenharmony_ci new_flags &= ~IR3_REG_FABS; 193bf215546Sopenharmony_ci } 194bf215546Sopenharmony_ci 195bf215546Sopenharmony_ci if (new_flags & IR3_REG_SNEG) { 196bf215546Sopenharmony_ci reg->iim_val = -reg->iim_val; 197bf215546Sopenharmony_ci new_flags &= ~IR3_REG_SNEG; 198bf215546Sopenharmony_ci } 199bf215546Sopenharmony_ci 200bf215546Sopenharmony_ci if (new_flags & IR3_REG_FNEG) { 201bf215546Sopenharmony_ci reg->fim_val = -reg->fim_val; 202bf215546Sopenharmony_ci new_flags &= ~IR3_REG_FNEG; 203bf215546Sopenharmony_ci } 204bf215546Sopenharmony_ci 205bf215546Sopenharmony_ci /* Reallocate for 4 more elements whenever it's necessary. Note that ir3 206bf215546Sopenharmony_ci * printing relies on having groups of 4 dwords, so we fill the unused 207bf215546Sopenharmony_ci * slots with a dummy value. 208bf215546Sopenharmony_ci */ 209bf215546Sopenharmony_ci struct ir3_const_state *const_state = ir3_const_state(ctx->so); 210bf215546Sopenharmony_ci if (const_state->immediates_count == const_state->immediates_size) { 211bf215546Sopenharmony_ci const_state->immediates = rerzalloc( 212bf215546Sopenharmony_ci const_state, const_state->immediates, 213bf215546Sopenharmony_ci __typeof__(const_state->immediates[0]), const_state->immediates_size, 214bf215546Sopenharmony_ci const_state->immediates_size + 4); 215bf215546Sopenharmony_ci const_state->immediates_size += 4; 216bf215546Sopenharmony_ci 217bf215546Sopenharmony_ci for (int i = const_state->immediates_count; 218bf215546Sopenharmony_ci i < const_state->immediates_size; i++) 219bf215546Sopenharmony_ci const_state->immediates[i] = 0xd0d0d0d0; 220bf215546Sopenharmony_ci } 221bf215546Sopenharmony_ci 222bf215546Sopenharmony_ci int i; 223bf215546Sopenharmony_ci for (i = 0; i < const_state->immediates_count; i++) { 224bf215546Sopenharmony_ci if (const_state->immediates[i] == reg->uim_val) 225bf215546Sopenharmony_ci break; 226bf215546Sopenharmony_ci } 227bf215546Sopenharmony_ci 228bf215546Sopenharmony_ci if (i == const_state->immediates_count) { 229bf215546Sopenharmony_ci /* Add on a new immediate to be pushed, if we have space left in the 230bf215546Sopenharmony_ci * constbuf. 231bf215546Sopenharmony_ci */ 232bf215546Sopenharmony_ci if (const_state->offsets.immediate + const_state->immediates_count / 4 >= 233bf215546Sopenharmony_ci ir3_max_const(ctx->so)) 234bf215546Sopenharmony_ci return false; 235bf215546Sopenharmony_ci 236bf215546Sopenharmony_ci const_state->immediates[i] = reg->uim_val; 237bf215546Sopenharmony_ci const_state->immediates_count++; 238bf215546Sopenharmony_ci } 239bf215546Sopenharmony_ci 240bf215546Sopenharmony_ci reg->flags = new_flags; 241bf215546Sopenharmony_ci reg->num = i + (4 * const_state->offsets.immediate); 242bf215546Sopenharmony_ci 243bf215546Sopenharmony_ci instr->srcs[n] = reg; 244bf215546Sopenharmony_ci 245bf215546Sopenharmony_ci return true; 246bf215546Sopenharmony_ci} 247bf215546Sopenharmony_ci 248bf215546Sopenharmony_cistatic void 249bf215546Sopenharmony_ciunuse(struct ir3_instruction *instr) 250bf215546Sopenharmony_ci{ 251bf215546Sopenharmony_ci assert(instr->use_count > 0); 252bf215546Sopenharmony_ci 253bf215546Sopenharmony_ci if (--instr->use_count == 0) { 254bf215546Sopenharmony_ci struct ir3_block *block = instr->block; 255bf215546Sopenharmony_ci 256bf215546Sopenharmony_ci instr->barrier_class = 0; 257bf215546Sopenharmony_ci instr->barrier_conflict = 0; 258bf215546Sopenharmony_ci 259bf215546Sopenharmony_ci /* we don't want to remove anything in keeps (which could 260bf215546Sopenharmony_ci * be things like array store's) 261bf215546Sopenharmony_ci */ 262bf215546Sopenharmony_ci for (unsigned i = 0; i < block->keeps_count; i++) { 263bf215546Sopenharmony_ci assert(block->keeps[i] != instr); 264bf215546Sopenharmony_ci } 265bf215546Sopenharmony_ci } 266bf215546Sopenharmony_ci} 267bf215546Sopenharmony_ci 268bf215546Sopenharmony_ci/** 269bf215546Sopenharmony_ci * Handles the special case of the 2nd src (n == 1) to "normal" mad 270bf215546Sopenharmony_ci * instructions, which cannot reference a constant. See if it is 271bf215546Sopenharmony_ci * possible to swap the 1st and 2nd sources. 272bf215546Sopenharmony_ci */ 273bf215546Sopenharmony_cistatic bool 274bf215546Sopenharmony_citry_swap_mad_two_srcs(struct ir3_instruction *instr, unsigned new_flags) 275bf215546Sopenharmony_ci{ 276bf215546Sopenharmony_ci if (!is_mad(instr->opc)) 277bf215546Sopenharmony_ci return false; 278bf215546Sopenharmony_ci 279bf215546Sopenharmony_ci /* If we've already tried, nothing more to gain.. we will only 280bf215546Sopenharmony_ci * have previously swapped if the original 2nd src was const or 281bf215546Sopenharmony_ci * immed. So swapping back won't improve anything and could 282bf215546Sopenharmony_ci * result in an infinite "progress" loop. 283bf215546Sopenharmony_ci */ 284bf215546Sopenharmony_ci if (instr->cat3.swapped) 285bf215546Sopenharmony_ci return false; 286bf215546Sopenharmony_ci 287bf215546Sopenharmony_ci /* cat3 doesn't encode immediate, but we can lower immediate 288bf215546Sopenharmony_ci * to const if that helps: 289bf215546Sopenharmony_ci */ 290bf215546Sopenharmony_ci if (new_flags & IR3_REG_IMMED) { 291bf215546Sopenharmony_ci new_flags &= ~IR3_REG_IMMED; 292bf215546Sopenharmony_ci new_flags |= IR3_REG_CONST; 293bf215546Sopenharmony_ci } 294bf215546Sopenharmony_ci 295bf215546Sopenharmony_ci /* If the reason we couldn't fold without swapping is something 296bf215546Sopenharmony_ci * other than const source, then swapping won't help: 297bf215546Sopenharmony_ci */ 298bf215546Sopenharmony_ci if (!(new_flags & IR3_REG_CONST)) 299bf215546Sopenharmony_ci return false; 300bf215546Sopenharmony_ci 301bf215546Sopenharmony_ci instr->cat3.swapped = true; 302bf215546Sopenharmony_ci 303bf215546Sopenharmony_ci /* NOTE: pre-swap first two src's before valid_flags(), 304bf215546Sopenharmony_ci * which might try to dereference the n'th src: 305bf215546Sopenharmony_ci */ 306bf215546Sopenharmony_ci swap(instr->srcs[0], instr->srcs[1]); 307bf215546Sopenharmony_ci 308bf215546Sopenharmony_ci bool valid_swap = 309bf215546Sopenharmony_ci /* can we propagate mov if we move 2nd src to first? */ 310bf215546Sopenharmony_ci ir3_valid_flags(instr, 0, new_flags) && 311bf215546Sopenharmony_ci /* and does first src fit in second slot? */ 312bf215546Sopenharmony_ci ir3_valid_flags(instr, 1, instr->srcs[1]->flags); 313bf215546Sopenharmony_ci 314bf215546Sopenharmony_ci if (!valid_swap) { 315bf215546Sopenharmony_ci /* put things back the way they were: */ 316bf215546Sopenharmony_ci swap(instr->srcs[0], instr->srcs[1]); 317bf215546Sopenharmony_ci } /* otherwise leave things swapped */ 318bf215546Sopenharmony_ci 319bf215546Sopenharmony_ci return valid_swap; 320bf215546Sopenharmony_ci} 321bf215546Sopenharmony_ci 322bf215546Sopenharmony_ci/* Values that are uniform inside a loop can become divergent outside 323bf215546Sopenharmony_ci * it if the loop has a divergent trip count. This means that we can't 324bf215546Sopenharmony_ci * propagate a copy of a shared to non-shared register if it would 325bf215546Sopenharmony_ci * make the shared reg's live range extend outside of its loop. Users 326bf215546Sopenharmony_ci * outside the loop would see the value for the thread(s) that last 327bf215546Sopenharmony_ci * exited the loop, rather than for their own thread. 328bf215546Sopenharmony_ci */ 329bf215546Sopenharmony_cistatic bool 330bf215546Sopenharmony_ciis_valid_shared_copy(struct ir3_instruction *dst_instr, 331bf215546Sopenharmony_ci struct ir3_instruction *src_instr, 332bf215546Sopenharmony_ci struct ir3_register *src_reg) 333bf215546Sopenharmony_ci{ 334bf215546Sopenharmony_ci return !(src_reg->flags & IR3_REG_SHARED) || 335bf215546Sopenharmony_ci dst_instr->block->loop_id == src_instr->block->loop_id; 336bf215546Sopenharmony_ci} 337bf215546Sopenharmony_ci 338bf215546Sopenharmony_ci/** 339bf215546Sopenharmony_ci * Handle cp for a given src register. This additionally handles 340bf215546Sopenharmony_ci * the cases of collapsing immedate/const (which replace the src 341bf215546Sopenharmony_ci * register with a non-ssa src) or collapsing mov's from relative 342bf215546Sopenharmony_ci * src (which needs to also fixup the address src reference by the 343bf215546Sopenharmony_ci * instruction). 344bf215546Sopenharmony_ci */ 345bf215546Sopenharmony_cistatic bool 346bf215546Sopenharmony_cireg_cp(struct ir3_cp_ctx *ctx, struct ir3_instruction *instr, 347bf215546Sopenharmony_ci struct ir3_register *reg, unsigned n) 348bf215546Sopenharmony_ci{ 349bf215546Sopenharmony_ci struct ir3_instruction *src = ssa(reg); 350bf215546Sopenharmony_ci 351bf215546Sopenharmony_ci if (is_eligible_mov(src, instr, true)) { 352bf215546Sopenharmony_ci /* simple case, no immed/const/relativ, only mov's w/ ssa src: */ 353bf215546Sopenharmony_ci struct ir3_register *src_reg = src->srcs[0]; 354bf215546Sopenharmony_ci unsigned new_flags = reg->flags; 355bf215546Sopenharmony_ci 356bf215546Sopenharmony_ci if (!is_valid_shared_copy(instr, src, src_reg)) 357bf215546Sopenharmony_ci return false; 358bf215546Sopenharmony_ci 359bf215546Sopenharmony_ci combine_flags(&new_flags, src); 360bf215546Sopenharmony_ci 361bf215546Sopenharmony_ci if (ir3_valid_flags(instr, n, new_flags)) { 362bf215546Sopenharmony_ci if (new_flags & IR3_REG_ARRAY) { 363bf215546Sopenharmony_ci assert(!(reg->flags & IR3_REG_ARRAY)); 364bf215546Sopenharmony_ci reg->array = src_reg->array; 365bf215546Sopenharmony_ci } 366bf215546Sopenharmony_ci reg->flags = new_flags; 367bf215546Sopenharmony_ci reg->def = src_reg->def; 368bf215546Sopenharmony_ci 369bf215546Sopenharmony_ci instr->barrier_class |= src->barrier_class; 370bf215546Sopenharmony_ci instr->barrier_conflict |= src->barrier_conflict; 371bf215546Sopenharmony_ci 372bf215546Sopenharmony_ci unuse(src); 373bf215546Sopenharmony_ci reg->def->instr->use_count++; 374bf215546Sopenharmony_ci 375bf215546Sopenharmony_ci return true; 376bf215546Sopenharmony_ci } 377bf215546Sopenharmony_ci } else if ((is_same_type_mov(src) || is_const_mov(src)) && 378bf215546Sopenharmony_ci /* cannot collapse const/immed/etc into control flow: */ 379bf215546Sopenharmony_ci opc_cat(instr->opc) != 0) { 380bf215546Sopenharmony_ci /* immed/const/etc cases, which require some special handling: */ 381bf215546Sopenharmony_ci struct ir3_register *src_reg = src->srcs[0]; 382bf215546Sopenharmony_ci unsigned new_flags = reg->flags; 383bf215546Sopenharmony_ci 384bf215546Sopenharmony_ci if (!is_valid_shared_copy(instr, src, src_reg)) 385bf215546Sopenharmony_ci return false; 386bf215546Sopenharmony_ci 387bf215546Sopenharmony_ci if (src_reg->flags & IR3_REG_ARRAY) 388bf215546Sopenharmony_ci return false; 389bf215546Sopenharmony_ci 390bf215546Sopenharmony_ci combine_flags(&new_flags, src); 391bf215546Sopenharmony_ci 392bf215546Sopenharmony_ci if (!ir3_valid_flags(instr, n, new_flags)) { 393bf215546Sopenharmony_ci /* See if lowering an immediate to const would help. */ 394bf215546Sopenharmony_ci if (lower_immed(ctx, instr, n, src_reg, new_flags)) 395bf215546Sopenharmony_ci return true; 396bf215546Sopenharmony_ci 397bf215546Sopenharmony_ci /* special case for "normal" mad instructions, we can 398bf215546Sopenharmony_ci * try swapping the first two args if that fits better. 399bf215546Sopenharmony_ci * 400bf215546Sopenharmony_ci * the "plain" MAD's (ie. the ones that don't shift first 401bf215546Sopenharmony_ci * src prior to multiply) can swap their first two srcs if 402bf215546Sopenharmony_ci * src[0] is !CONST and src[1] is CONST: 403bf215546Sopenharmony_ci */ 404bf215546Sopenharmony_ci if ((n == 1) && try_swap_mad_two_srcs(instr, new_flags)) { 405bf215546Sopenharmony_ci return true; 406bf215546Sopenharmony_ci } else { 407bf215546Sopenharmony_ci return false; 408bf215546Sopenharmony_ci } 409bf215546Sopenharmony_ci } 410bf215546Sopenharmony_ci 411bf215546Sopenharmony_ci /* Here we handle the special case of mov from 412bf215546Sopenharmony_ci * CONST and/or RELATIV. These need to be handled 413bf215546Sopenharmony_ci * specially, because in the case of move from CONST 414bf215546Sopenharmony_ci * there is no src ir3_instruction so we need to 415bf215546Sopenharmony_ci * replace the ir3_register. And in the case of 416bf215546Sopenharmony_ci * RELATIV we need to handle the address register 417bf215546Sopenharmony_ci * dependency. 418bf215546Sopenharmony_ci */ 419bf215546Sopenharmony_ci if (src_reg->flags & IR3_REG_CONST) { 420bf215546Sopenharmony_ci /* an instruction cannot reference two different 421bf215546Sopenharmony_ci * address registers: 422bf215546Sopenharmony_ci */ 423bf215546Sopenharmony_ci if ((src_reg->flags & IR3_REG_RELATIV) && 424bf215546Sopenharmony_ci conflicts(instr->address, reg->def->instr->address)) 425bf215546Sopenharmony_ci return false; 426bf215546Sopenharmony_ci 427bf215546Sopenharmony_ci /* These macros expand to a mov in an if statement */ 428bf215546Sopenharmony_ci if ((src_reg->flags & IR3_REG_RELATIV) && 429bf215546Sopenharmony_ci is_subgroup_cond_mov_macro(instr)) 430bf215546Sopenharmony_ci return false; 431bf215546Sopenharmony_ci 432bf215546Sopenharmony_ci /* This seems to be a hw bug, or something where the timings 433bf215546Sopenharmony_ci * just somehow don't work out. This restriction may only 434bf215546Sopenharmony_ci * apply if the first src is also CONST. 435bf215546Sopenharmony_ci */ 436bf215546Sopenharmony_ci if ((opc_cat(instr->opc) == 3) && (n == 2) && 437bf215546Sopenharmony_ci (src_reg->flags & IR3_REG_RELATIV) && (src_reg->array.offset == 0)) 438bf215546Sopenharmony_ci return false; 439bf215546Sopenharmony_ci 440bf215546Sopenharmony_ci /* When narrowing constant from 32b to 16b, it seems 441bf215546Sopenharmony_ci * to work only for float. So we should do this only with 442bf215546Sopenharmony_ci * float opcodes. 443bf215546Sopenharmony_ci */ 444bf215546Sopenharmony_ci if (src->cat1.dst_type == TYPE_F16) { 445bf215546Sopenharmony_ci /* TODO: should we have a way to tell phi/collect to use a 446bf215546Sopenharmony_ci * float move so that this is legal? 447bf215546Sopenharmony_ci */ 448bf215546Sopenharmony_ci if (is_meta(instr)) 449bf215546Sopenharmony_ci return false; 450bf215546Sopenharmony_ci if (instr->opc == OPC_MOV && !type_float(instr->cat1.src_type)) 451bf215546Sopenharmony_ci return false; 452bf215546Sopenharmony_ci if (!is_cat2_float(instr->opc) && !is_cat3_float(instr->opc)) 453bf215546Sopenharmony_ci return false; 454bf215546Sopenharmony_ci } else if (src->cat1.dst_type == TYPE_U16) { 455bf215546Sopenharmony_ci /* Since we set CONSTANT_DEMOTION_ENABLE, a float reference of 456bf215546Sopenharmony_ci * what was a U16 value read from the constbuf would incorrectly 457bf215546Sopenharmony_ci * do 32f->16f conversion, when we want to read a 16f value. 458bf215546Sopenharmony_ci */ 459bf215546Sopenharmony_ci if (is_cat2_float(instr->opc) || is_cat3_float(instr->opc)) 460bf215546Sopenharmony_ci return false; 461bf215546Sopenharmony_ci if (instr->opc == OPC_MOV && type_float(instr->cat1.src_type)) 462bf215546Sopenharmony_ci return false; 463bf215546Sopenharmony_ci } 464bf215546Sopenharmony_ci 465bf215546Sopenharmony_ci src_reg = ir3_reg_clone(instr->block->shader, src_reg); 466bf215546Sopenharmony_ci src_reg->flags = new_flags; 467bf215546Sopenharmony_ci instr->srcs[n] = src_reg; 468bf215546Sopenharmony_ci 469bf215546Sopenharmony_ci if (src_reg->flags & IR3_REG_RELATIV) 470bf215546Sopenharmony_ci ir3_instr_set_address(instr, reg->def->instr->address->def->instr); 471bf215546Sopenharmony_ci 472bf215546Sopenharmony_ci return true; 473bf215546Sopenharmony_ci } 474bf215546Sopenharmony_ci 475bf215546Sopenharmony_ci if (src_reg->flags & IR3_REG_IMMED) { 476bf215546Sopenharmony_ci int32_t iim_val = src_reg->iim_val; 477bf215546Sopenharmony_ci 478bf215546Sopenharmony_ci assert((opc_cat(instr->opc) == 1) || 479bf215546Sopenharmony_ci (opc_cat(instr->opc) == 2) || 480bf215546Sopenharmony_ci (opc_cat(instr->opc) == 6) || 481bf215546Sopenharmony_ci is_meta(instr) || 482bf215546Sopenharmony_ci (is_mad(instr->opc) && (n == 0))); 483bf215546Sopenharmony_ci 484bf215546Sopenharmony_ci if ((opc_cat(instr->opc) == 2) && 485bf215546Sopenharmony_ci !ir3_cat2_int(instr->opc)) { 486bf215546Sopenharmony_ci iim_val = ir3_flut(src_reg); 487bf215546Sopenharmony_ci if (iim_val < 0) { 488bf215546Sopenharmony_ci /* Fall back to trying to load the immediate as a const: */ 489bf215546Sopenharmony_ci return lower_immed(ctx, instr, n, src_reg, new_flags); 490bf215546Sopenharmony_ci } 491bf215546Sopenharmony_ci } 492bf215546Sopenharmony_ci 493bf215546Sopenharmony_ci if (new_flags & IR3_REG_SABS) 494bf215546Sopenharmony_ci iim_val = abs(iim_val); 495bf215546Sopenharmony_ci 496bf215546Sopenharmony_ci if (new_flags & IR3_REG_SNEG) 497bf215546Sopenharmony_ci iim_val = -iim_val; 498bf215546Sopenharmony_ci 499bf215546Sopenharmony_ci if (new_flags & IR3_REG_BNOT) 500bf215546Sopenharmony_ci iim_val = ~iim_val; 501bf215546Sopenharmony_ci 502bf215546Sopenharmony_ci if (ir3_valid_flags(instr, n, new_flags) && 503bf215546Sopenharmony_ci ir3_valid_immediate(instr, iim_val)) { 504bf215546Sopenharmony_ci new_flags &= ~(IR3_REG_SABS | IR3_REG_SNEG | IR3_REG_BNOT); 505bf215546Sopenharmony_ci src_reg = ir3_reg_clone(instr->block->shader, src_reg); 506bf215546Sopenharmony_ci src_reg->flags = new_flags; 507bf215546Sopenharmony_ci src_reg->iim_val = iim_val; 508bf215546Sopenharmony_ci instr->srcs[n] = src_reg; 509bf215546Sopenharmony_ci 510bf215546Sopenharmony_ci return true; 511bf215546Sopenharmony_ci } else { 512bf215546Sopenharmony_ci /* Fall back to trying to load the immediate as a const: */ 513bf215546Sopenharmony_ci return lower_immed(ctx, instr, n, src_reg, new_flags); 514bf215546Sopenharmony_ci } 515bf215546Sopenharmony_ci } 516bf215546Sopenharmony_ci } 517bf215546Sopenharmony_ci 518bf215546Sopenharmony_ci return false; 519bf215546Sopenharmony_ci} 520bf215546Sopenharmony_ci 521bf215546Sopenharmony_ci/* Handle special case of eliminating output mov, and similar cases where 522bf215546Sopenharmony_ci * there isn't a normal "consuming" instruction. In this case we cannot 523bf215546Sopenharmony_ci * collapse flags (ie. output mov from const, or w/ abs/neg flags, cannot 524bf215546Sopenharmony_ci * be eliminated) 525bf215546Sopenharmony_ci */ 526bf215546Sopenharmony_cistatic struct ir3_instruction * 527bf215546Sopenharmony_cieliminate_output_mov(struct ir3_cp_ctx *ctx, struct ir3_instruction *instr) 528bf215546Sopenharmony_ci{ 529bf215546Sopenharmony_ci if (is_eligible_mov(instr, NULL, false)) { 530bf215546Sopenharmony_ci struct ir3_register *reg = instr->srcs[0]; 531bf215546Sopenharmony_ci if (!(reg->flags & IR3_REG_ARRAY)) { 532bf215546Sopenharmony_ci struct ir3_instruction *src_instr = ssa(reg); 533bf215546Sopenharmony_ci assert(src_instr); 534bf215546Sopenharmony_ci ctx->progress = true; 535bf215546Sopenharmony_ci return src_instr; 536bf215546Sopenharmony_ci } 537bf215546Sopenharmony_ci } 538bf215546Sopenharmony_ci return instr; 539bf215546Sopenharmony_ci} 540bf215546Sopenharmony_ci 541bf215546Sopenharmony_ci/** 542bf215546Sopenharmony_ci * Find instruction src's which are mov's that can be collapsed, replacing 543bf215546Sopenharmony_ci * the mov dst with the mov src 544bf215546Sopenharmony_ci */ 545bf215546Sopenharmony_cistatic void 546bf215546Sopenharmony_ciinstr_cp(struct ir3_cp_ctx *ctx, struct ir3_instruction *instr) 547bf215546Sopenharmony_ci{ 548bf215546Sopenharmony_ci if (instr->srcs_count == 0) 549bf215546Sopenharmony_ci return; 550bf215546Sopenharmony_ci 551bf215546Sopenharmony_ci if (ir3_instr_check_mark(instr)) 552bf215546Sopenharmony_ci return; 553bf215546Sopenharmony_ci 554bf215546Sopenharmony_ci /* walk down the graph from each src: */ 555bf215546Sopenharmony_ci bool progress; 556bf215546Sopenharmony_ci do { 557bf215546Sopenharmony_ci progress = false; 558bf215546Sopenharmony_ci foreach_src_n (reg, n, instr) { 559bf215546Sopenharmony_ci struct ir3_instruction *src = ssa(reg); 560bf215546Sopenharmony_ci 561bf215546Sopenharmony_ci if (!src) 562bf215546Sopenharmony_ci continue; 563bf215546Sopenharmony_ci 564bf215546Sopenharmony_ci instr_cp(ctx, src); 565bf215546Sopenharmony_ci 566bf215546Sopenharmony_ci /* TODO non-indirect access we could figure out which register 567bf215546Sopenharmony_ci * we actually want and allow cp.. 568bf215546Sopenharmony_ci */ 569bf215546Sopenharmony_ci if ((reg->flags & IR3_REG_ARRAY) && src->opc != OPC_META_PHI) 570bf215546Sopenharmony_ci continue; 571bf215546Sopenharmony_ci 572bf215546Sopenharmony_ci /* Don't CP absneg into meta instructions, that won't end well: */ 573bf215546Sopenharmony_ci if (is_meta(instr) && 574bf215546Sopenharmony_ci (src->opc == OPC_ABSNEG_F || src->opc == OPC_ABSNEG_S)) 575bf215546Sopenharmony_ci continue; 576bf215546Sopenharmony_ci 577bf215546Sopenharmony_ci /* Don't CP mova and mova1 into their users */ 578bf215546Sopenharmony_ci if (writes_addr0(src) || writes_addr1(src)) 579bf215546Sopenharmony_ci continue; 580bf215546Sopenharmony_ci 581bf215546Sopenharmony_ci progress |= reg_cp(ctx, instr, reg, n); 582bf215546Sopenharmony_ci ctx->progress |= progress; 583bf215546Sopenharmony_ci } 584bf215546Sopenharmony_ci } while (progress); 585bf215546Sopenharmony_ci 586bf215546Sopenharmony_ci /* After folding a mov's source we may wind up with a type-converting mov 587bf215546Sopenharmony_ci * of an immediate. This happens e.g. with texture descriptors, since we 588bf215546Sopenharmony_ci * narrow the descriptor (which may be a constant) to a half-reg in ir3. 589bf215546Sopenharmony_ci * By converting the immediate in-place to the destination type, we can 590bf215546Sopenharmony_ci * turn the mov into a same-type mov so that it can be further propagated. 591bf215546Sopenharmony_ci */ 592bf215546Sopenharmony_ci if (instr->opc == OPC_MOV && (instr->srcs[0]->flags & IR3_REG_IMMED) && 593bf215546Sopenharmony_ci instr->cat1.src_type != instr->cat1.dst_type && 594bf215546Sopenharmony_ci /* Only do uint types for now, until we generate other types of 595bf215546Sopenharmony_ci * mov's during instruction selection. 596bf215546Sopenharmony_ci */ 597bf215546Sopenharmony_ci full_type(instr->cat1.src_type) == TYPE_U32 && 598bf215546Sopenharmony_ci full_type(instr->cat1.dst_type) == TYPE_U32) { 599bf215546Sopenharmony_ci uint32_t uimm = instr->srcs[0]->uim_val; 600bf215546Sopenharmony_ci if (instr->cat1.dst_type == TYPE_U16) 601bf215546Sopenharmony_ci uimm &= 0xffff; 602bf215546Sopenharmony_ci instr->srcs[0]->uim_val = uimm; 603bf215546Sopenharmony_ci if (instr->dsts[0]->flags & IR3_REG_HALF) 604bf215546Sopenharmony_ci instr->srcs[0]->flags |= IR3_REG_HALF; 605bf215546Sopenharmony_ci else 606bf215546Sopenharmony_ci instr->srcs[0]->flags &= ~IR3_REG_HALF; 607bf215546Sopenharmony_ci instr->cat1.src_type = instr->cat1.dst_type; 608bf215546Sopenharmony_ci ctx->progress = true; 609bf215546Sopenharmony_ci } 610bf215546Sopenharmony_ci 611bf215546Sopenharmony_ci /* Re-write the instruction writing predicate register to get rid 612bf215546Sopenharmony_ci * of the double cmps. 613bf215546Sopenharmony_ci */ 614bf215546Sopenharmony_ci if ((instr->opc == OPC_CMPS_S) && is_foldable_double_cmp(instr)) { 615bf215546Sopenharmony_ci struct ir3_instruction *cond = ssa(instr->srcs[0]); 616bf215546Sopenharmony_ci switch (cond->opc) { 617bf215546Sopenharmony_ci case OPC_CMPS_S: 618bf215546Sopenharmony_ci case OPC_CMPS_F: 619bf215546Sopenharmony_ci case OPC_CMPS_U: 620bf215546Sopenharmony_ci instr->opc = cond->opc; 621bf215546Sopenharmony_ci instr->flags = cond->flags; 622bf215546Sopenharmony_ci instr->cat2 = cond->cat2; 623bf215546Sopenharmony_ci if (cond->address) 624bf215546Sopenharmony_ci ir3_instr_set_address(instr, cond->address->def->instr); 625bf215546Sopenharmony_ci instr->srcs[0] = ir3_reg_clone(ctx->shader, cond->srcs[0]); 626bf215546Sopenharmony_ci instr->srcs[1] = ir3_reg_clone(ctx->shader, cond->srcs[1]); 627bf215546Sopenharmony_ci instr->barrier_class |= cond->barrier_class; 628bf215546Sopenharmony_ci instr->barrier_conflict |= cond->barrier_conflict; 629bf215546Sopenharmony_ci unuse(cond); 630bf215546Sopenharmony_ci ctx->progress = true; 631bf215546Sopenharmony_ci break; 632bf215546Sopenharmony_ci default: 633bf215546Sopenharmony_ci break; 634bf215546Sopenharmony_ci } 635bf215546Sopenharmony_ci } 636bf215546Sopenharmony_ci 637bf215546Sopenharmony_ci /* Handle converting a sam.s2en (taking samp/tex idx params via register) 638bf215546Sopenharmony_ci * into a normal sam (encoding immediate samp/tex idx) if they are 639bf215546Sopenharmony_ci * immediate. This saves some instructions and regs in the common case 640bf215546Sopenharmony_ci * where we know samp/tex at compile time. This needs to be done in the 641bf215546Sopenharmony_ci * frontend for bindless tex, though, so don't replicate it here. 642bf215546Sopenharmony_ci */ 643bf215546Sopenharmony_ci if (is_tex(instr) && (instr->flags & IR3_INSTR_S2EN) && 644bf215546Sopenharmony_ci !(instr->flags & IR3_INSTR_B) && 645bf215546Sopenharmony_ci !(ir3_shader_debug & IR3_DBG_FORCES2EN)) { 646bf215546Sopenharmony_ci /* The first src will be a collect, if both of it's 647bf215546Sopenharmony_ci * two sources are mov from imm, then we can 648bf215546Sopenharmony_ci */ 649bf215546Sopenharmony_ci struct ir3_instruction *samp_tex = ssa(instr->srcs[0]); 650bf215546Sopenharmony_ci 651bf215546Sopenharmony_ci assert(samp_tex->opc == OPC_META_COLLECT); 652bf215546Sopenharmony_ci 653bf215546Sopenharmony_ci struct ir3_register *samp = samp_tex->srcs[0]; 654bf215546Sopenharmony_ci struct ir3_register *tex = samp_tex->srcs[1]; 655bf215546Sopenharmony_ci 656bf215546Sopenharmony_ci if ((samp->flags & IR3_REG_IMMED) && (tex->flags & IR3_REG_IMMED) && 657bf215546Sopenharmony_ci (samp->iim_val < 16) && (tex->iim_val < 16)) { 658bf215546Sopenharmony_ci instr->flags &= ~IR3_INSTR_S2EN; 659bf215546Sopenharmony_ci instr->cat5.samp = samp->iim_val; 660bf215546Sopenharmony_ci instr->cat5.tex = tex->iim_val; 661bf215546Sopenharmony_ci 662bf215546Sopenharmony_ci /* shuffle around the regs to remove the first src: */ 663bf215546Sopenharmony_ci instr->srcs_count--; 664bf215546Sopenharmony_ci for (unsigned i = 0; i < instr->srcs_count; i++) { 665bf215546Sopenharmony_ci instr->srcs[i] = instr->srcs[i + 1]; 666bf215546Sopenharmony_ci } 667bf215546Sopenharmony_ci 668bf215546Sopenharmony_ci ctx->progress = true; 669bf215546Sopenharmony_ci } 670bf215546Sopenharmony_ci } 671bf215546Sopenharmony_ci} 672bf215546Sopenharmony_ci 673bf215546Sopenharmony_cibool 674bf215546Sopenharmony_ciir3_cp(struct ir3 *ir, struct ir3_shader_variant *so) 675bf215546Sopenharmony_ci{ 676bf215546Sopenharmony_ci struct ir3_cp_ctx ctx = { 677bf215546Sopenharmony_ci .shader = ir, 678bf215546Sopenharmony_ci .so = so, 679bf215546Sopenharmony_ci }; 680bf215546Sopenharmony_ci 681bf215546Sopenharmony_ci /* This is a bit annoying, and probably wouldn't be necessary if we 682bf215546Sopenharmony_ci * tracked a reverse link from producing instruction to consumer. 683bf215546Sopenharmony_ci * But we need to know when we've eliminated the last consumer of 684bf215546Sopenharmony_ci * a mov, so we need to do a pass to first count consumers of a 685bf215546Sopenharmony_ci * mov. 686bf215546Sopenharmony_ci */ 687bf215546Sopenharmony_ci foreach_block (block, &ir->block_list) { 688bf215546Sopenharmony_ci foreach_instr (instr, &block->instr_list) { 689bf215546Sopenharmony_ci 690bf215546Sopenharmony_ci /* by the way, we don't account for false-dep's, so the CP 691bf215546Sopenharmony_ci * pass should always happen before false-dep's are inserted 692bf215546Sopenharmony_ci */ 693bf215546Sopenharmony_ci assert(instr->deps_count == 0); 694bf215546Sopenharmony_ci 695bf215546Sopenharmony_ci foreach_ssa_src (src, instr) { 696bf215546Sopenharmony_ci src->use_count++; 697bf215546Sopenharmony_ci } 698bf215546Sopenharmony_ci } 699bf215546Sopenharmony_ci } 700bf215546Sopenharmony_ci 701bf215546Sopenharmony_ci ir3_clear_mark(ir); 702bf215546Sopenharmony_ci 703bf215546Sopenharmony_ci foreach_block (block, &ir->block_list) { 704bf215546Sopenharmony_ci if (block->condition) { 705bf215546Sopenharmony_ci instr_cp(&ctx, block->condition); 706bf215546Sopenharmony_ci block->condition = eliminate_output_mov(&ctx, block->condition); 707bf215546Sopenharmony_ci } 708bf215546Sopenharmony_ci 709bf215546Sopenharmony_ci for (unsigned i = 0; i < block->keeps_count; i++) { 710bf215546Sopenharmony_ci instr_cp(&ctx, block->keeps[i]); 711bf215546Sopenharmony_ci block->keeps[i] = eliminate_output_mov(&ctx, block->keeps[i]); 712bf215546Sopenharmony_ci } 713bf215546Sopenharmony_ci } 714bf215546Sopenharmony_ci 715bf215546Sopenharmony_ci return ctx.progress; 716bf215546Sopenharmony_ci} 717