17ec681f3Smrg/* 27ec681f3Smrg * Copyright (C) 2021 Collabora, Ltd. 37ec681f3Smrg * 47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 57ec681f3Smrg * copy of this software and associated documentation files (the "Software"), 67ec681f3Smrg * to deal in the Software without restriction, including without limitation 77ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 87ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the 97ec681f3Smrg * Software is furnished to do so, subject to the following conditions: 107ec681f3Smrg * 117ec681f3Smrg * The above copyright notice and this permission notice (including the next 127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the 137ec681f3Smrg * Software. 147ec681f3Smrg * 157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 187ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 197ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 207ec681f3Smrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 217ec681f3Smrg * SOFTWARE. 227ec681f3Smrg */ 237ec681f3Smrg 247ec681f3Smrg#include "compiler.h" 257ec681f3Smrg#include "bi_test.h" 267ec681f3Smrg#include "bi_builder.h" 277ec681f3Smrg 287ec681f3Smrg#define TMP() bi_temp(b->shader) 297ec681f3Smrg 307ec681f3Smrgint main(int argc, char **argv) 317ec681f3Smrg{ 327ec681f3Smrg unsigned nr_fail = 0, nr_pass = 0; 337ec681f3Smrg void *ralloc_ctx = ralloc_context(NULL); 347ec681f3Smrg bi_builder *b = bit_builder(ralloc_ctx); 357ec681f3Smrg 367ec681f3Smrg bi_instr *mov = bi_mov_i32_to(b, TMP(), TMP()); 377ec681f3Smrg BIT_ASSERT(bi_can_fma(mov)); 387ec681f3Smrg BIT_ASSERT(bi_can_add(mov)); 397ec681f3Smrg BIT_ASSERT(!bi_must_message(mov)); 407ec681f3Smrg BIT_ASSERT(bi_reads_zero(mov)); 417ec681f3Smrg BIT_ASSERT(bi_reads_temps(mov, 0)); 427ec681f3Smrg BIT_ASSERT(bi_reads_t(mov, 0)); 437ec681f3Smrg 447ec681f3Smrg bi_instr *fma = bi_fma_f32_to(b, TMP(), TMP(), TMP(), bi_zero(), BI_ROUND_NONE); 457ec681f3Smrg BIT_ASSERT(bi_can_fma(fma)); 467ec681f3Smrg BIT_ASSERT(!bi_can_add(fma)); 477ec681f3Smrg BIT_ASSERT(!bi_must_message(fma)); 487ec681f3Smrg BIT_ASSERT(bi_reads_zero(fma)); 497ec681f3Smrg for (unsigned i = 0; i < 3; ++i) { 507ec681f3Smrg BIT_ASSERT(bi_reads_temps(fma, i)); 517ec681f3Smrg BIT_ASSERT(bi_reads_t(fma, i)); 527ec681f3Smrg } 537ec681f3Smrg 547ec681f3Smrg bi_instr *load = bi_load_i128_to(b, TMP(), TMP(), TMP(), BI_SEG_UBO); 557ec681f3Smrg BIT_ASSERT(!bi_can_fma(load)); 567ec681f3Smrg BIT_ASSERT(bi_can_add(load)); 577ec681f3Smrg BIT_ASSERT(bi_must_message(load)); 587ec681f3Smrg for (unsigned i = 0; i < 2; ++i) { 597ec681f3Smrg BIT_ASSERT(bi_reads_temps(load, i)); 607ec681f3Smrg BIT_ASSERT(bi_reads_t(load, i)); 617ec681f3Smrg } 627ec681f3Smrg 637ec681f3Smrg bi_instr *blend = bi_blend_to(b, TMP(), TMP(), TMP(), TMP(), TMP(), 4); 647ec681f3Smrg BIT_ASSERT(!bi_can_fma(load)); 657ec681f3Smrg BIT_ASSERT(bi_can_add(load)); 667ec681f3Smrg BIT_ASSERT(bi_must_message(blend)); 677ec681f3Smrg for (unsigned i = 0; i < 4; ++i) 687ec681f3Smrg BIT_ASSERT(bi_reads_temps(blend, i)); 697ec681f3Smrg BIT_ASSERT(!bi_reads_t(blend, 0)); 707ec681f3Smrg BIT_ASSERT(bi_reads_t(blend, 1)); 717ec681f3Smrg BIT_ASSERT(!bi_reads_t(blend, 2)); 727ec681f3Smrg BIT_ASSERT(!bi_reads_t(blend, 3)); 737ec681f3Smrg 747ec681f3Smrg /* Test restrictions on modifiers of same cycle temporaries */ 757ec681f3Smrg bi_instr *fadd = bi_fadd_f32_to(b, TMP(), TMP(), TMP(), BI_ROUND_NONE); 767ec681f3Smrg BIT_ASSERT(bi_reads_t(fadd, 0)); 777ec681f3Smrg 787ec681f3Smrg for (unsigned i = 0; i < 2; ++i) { 797ec681f3Smrg for (unsigned j = 0; j < 2; ++j) { 807ec681f3Smrg bi_instr *fadd = bi_fadd_f32_to(b, TMP(), TMP(), TMP(), BI_ROUND_NONE); 817ec681f3Smrg fadd->src[i] = bi_swz_16(TMP(), j, j); 827ec681f3Smrg BIT_ASSERT(bi_reads_t(fadd, 1 - i)); 837ec681f3Smrg BIT_ASSERT(!bi_reads_t(fadd, i)); 847ec681f3Smrg } 857ec681f3Smrg } 867ec681f3Smrg 877ec681f3Smrg ralloc_free(ralloc_ctx); 887ec681f3Smrg TEST_END(nr_pass, nr_fail); 897ec681f3Smrg} 90