summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorL. E. Segovia <amy@centricular.com>2024-01-27 22:17:48 -0300
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>2024-02-02 13:53:43 +0000
commit1aa50ca41918a0e2a812abe1295c5a95fe069b81 (patch)
treed59c710412efdc8704d27ef174ad9004b1f37786
parent913211a8bd5ebd86702be010157d5b89b3243123 (diff)
orccompiler: Fix register allocator going beyond bounds for scalar registers
This affected the loop counter in MMX, which caused crashes in test_schro among others because of UB in the codegen. It was only detectable with %ERROR in the .S output. Part-of: <https://gitlab.freedesktop.org/gstreamer/orc/-/merge_requests/158>
-rw-r--r--orc/orccompiler.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/orc/orccompiler.c b/orc/orccompiler.c
index 307ab23..5223c53 100644
--- a/orc/orccompiler.c
+++ b/orc/orccompiler.c
@@ -189,9 +189,11 @@ orc_compiler_allocate_register (OrcCompiler *compiler, int data_reg)
// Use ORC_N_REGS to ensure forward proofed iteration
for (i = 0; i < ORC_N_REGS; i++) {
// Try with up to 64 registers starting from offset
+ // If this lands us within vector range, bail out
reg = offset + ((roff + i) & 0x3f);
- if (compiler->valid_regs[reg] &&
- compiler->alloc_regs[reg] == 0) {
+ if (reg >= compiler->target->data_register_offset && !data_reg)
+ break;
+ if (compiler->valid_regs[reg] && compiler->alloc_regs[reg] == 0) {
compiler->alloc_regs[reg]++;
compiler->used_regs[reg] = 1;
return reg;
@@ -1036,8 +1038,9 @@ orc_compiler_global_reg_alloc (OrcCompiler *compiler)
if (compiler->alloc_loop_counter && !compiler->error) {
compiler->loop_counter = orc_compiler_allocate_register (compiler, FALSE);
- /* FIXME massive hack */
- if (compiler->loop_counter == 0) {
+ // FIXME: If loop_counter is invalid, the counter must be set manually
+ // in the executor
+ if (compiler->loop_counter == ORC_REG_INVALID) {
compiler->error = FALSE;
compiler->result = ORC_COMPILE_RESULT_OK;
}