agx: test constant compaction

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28483>
This commit is contained in:
Alyssa Rosenzweig 2024-03-02 09:46:41 -04:00 committed by Marge Bot
parent fb785a5503
commit c274566bbf
2 changed files with 58 additions and 0 deletions

View file

@ -106,6 +106,7 @@ if with_tests
executable(
'agx_tests',
files(
'test/test-compact-constants.cpp',
'test/test-minifloat.cpp',
'test/test-optimizer.cpp',
'test/test-lower-pseudo.cpp',

View file

@ -0,0 +1,57 @@
/*
* Copyright 2021 Collabora, Ltd.
* SPDX-License-Identifier: MIT
*/
#include "agx_builder.h"
#include "agx_compiler.h"
#include "agx_test.h"
#include <gtest/gtest.h>
#define CASE(instr, expected, size) \
INSTRUCTION_CASE( \
{ \
UNUSED agx_index out = agx_temp(b->shader, AGX_SIZE_##size); \
instr; \
agx_unit_test(b, out); \
}, \
{ \
UNUSED agx_index out = agx_temp(b->shader, AGX_SIZE_##size); \
expected; \
agx_unit_test(b, out); \
}, \
agx_opt_compact_constants)
#define NEGCASE(instr, size) CASE(instr, instr, size)
#define CASE32(instr, expected) CASE(instr, expected, 32)
#define NEGCASE32(instr) NEGCASE(instr, 32)
class CompactConstants : public testing::Test {
protected:
CompactConstants()
{
mem_ctx = ralloc_context(NULL);
wx = agx_register(0, AGX_SIZE_32);
}
~CompactConstants()
{
ralloc_free(mem_ctx);
}
void *mem_ctx;
agx_index wx;
};
TEST_F(CompactConstants, FP32)
{
CASE32(agx_fadd_to(b, out, wx, agx_mov_imm(b, 32, fui(32768.0))),
agx_fadd_to(b, out, wx, agx_mov_imm(b, 16, 0x7800)));
}
TEST_F(CompactConstants, InexactFP32)
{
NEGCASE32(agx_fadd_to(b, out, wx, agx_mov_imm(b, 32, fui(32769.0))));
}