1bf215546Sopenharmony_ci 2bf215546Sopenharmony_ci/* 3bf215546Sopenharmony_ci * Copyright (C) 2021 Collabora Ltd. 4bf215546Sopenharmony_ci * 5bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 6bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 7bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 8bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 10bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 11bf215546Sopenharmony_ci * 12bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 13bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 14bf215546Sopenharmony_ci * Software. 15bf215546Sopenharmony_ci * 16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22bf215546Sopenharmony_ci * SOFTWARE. 23bf215546Sopenharmony_ci */ 24bf215546Sopenharmony_ci 25bf215546Sopenharmony_ci#include "va_compiler.h" 26bf215546Sopenharmony_ci#include "valhall.h" 27bf215546Sopenharmony_ci#include "bi_builder.h" 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_civoid 30bf215546Sopenharmony_civa_count_instr_stats(bi_instr *I, struct va_stats *stats) 31bf215546Sopenharmony_ci{ 32bf215546Sopenharmony_ci /* Adjusted for 64-bit arithmetic */ 33bf215546Sopenharmony_ci unsigned words = bi_count_write_registers(I, 0); 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_ci switch (valhall_opcodes[I->op].unit) { 36bf215546Sopenharmony_ci /* Arithmetic is 2x slower for 64-bit than 32-bit */ 37bf215546Sopenharmony_ci case VA_UNIT_FMA: 38bf215546Sopenharmony_ci stats->fma += words; 39bf215546Sopenharmony_ci return; 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ci case VA_UNIT_CVT: 42bf215546Sopenharmony_ci stats->cvt += words; 43bf215546Sopenharmony_ci return; 44bf215546Sopenharmony_ci 45bf215546Sopenharmony_ci case VA_UNIT_SFU: 46bf215546Sopenharmony_ci stats->sfu += words; 47bf215546Sopenharmony_ci return; 48bf215546Sopenharmony_ci 49bf215546Sopenharmony_ci /* Varying is scaled by 16-bit components interpolated */ 50bf215546Sopenharmony_ci case VA_UNIT_V: 51bf215546Sopenharmony_ci stats->v += (I->vecsize + 1) * 52bf215546Sopenharmony_ci (bi_is_regfmt_16(I->register_format) ? 1 : 2); 53bf215546Sopenharmony_ci return; 54bf215546Sopenharmony_ci 55bf215546Sopenharmony_ci /* We just count load/store and texturing for now */ 56bf215546Sopenharmony_ci case VA_UNIT_LS: 57bf215546Sopenharmony_ci stats->ls++; 58bf215546Sopenharmony_ci return; 59bf215546Sopenharmony_ci 60bf215546Sopenharmony_ci case VA_UNIT_T: 61bf215546Sopenharmony_ci stats->t++; 62bf215546Sopenharmony_ci return; 63bf215546Sopenharmony_ci 64bf215546Sopenharmony_ci /* Fused varying+texture loads 2 FP32 components of varying for texture 65bf215546Sopenharmony_ci * coordinates and then textures */ 66bf215546Sopenharmony_ci case VA_UNIT_VT: 67bf215546Sopenharmony_ci stats->ls += (2 * 2); 68bf215546Sopenharmony_ci stats->t++; 69bf215546Sopenharmony_ci return; 70bf215546Sopenharmony_ci 71bf215546Sopenharmony_ci /* Nothing to do here */ 72bf215546Sopenharmony_ci case VA_UNIT_NONE: 73bf215546Sopenharmony_ci return; 74bf215546Sopenharmony_ci } 75bf215546Sopenharmony_ci 76bf215546Sopenharmony_ci unreachable("Invalid unit"); 77bf215546Sopenharmony_ci} 78