From a87a82f7d8029a79cb5eb4b4bca031c1097061c2 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Thu, 10 Sep 2026 16:06:32 +0300 Subject: [PATCH] Memory alignment fix in TExpr impl for RISC-V RVV --- modules/core/src/arithm_expr.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/core/src/arithm_expr.cpp b/modules/core/src/arithm_expr.cpp index 6949b42181..1372a3193e 100644 --- a/modules/core/src/arithm_expr.cpp +++ b/modules/core/src/arithm_expr.cpp @@ -1175,10 +1175,12 @@ void TExpr::exec(const Mat* const* inputs, Mat* outputs) // scratch is totalEsz*wf0 (<= ~16KB). const int totalEsz = bufEszPrefix[nbuffers]; const int wf0 = std::min((int)total, capElems); + + const size_t region = alignSize((size_t)wf0, 8); // Scratch for the temp buffers. AutoBuffer no longer value-inits its tail, so a fresh per-call // buffer is free (we only WRITE to it); the inline 16KB covers the L1-capped size, heap backs // the rare larger case. - AutoBuffer scratchBuf((size_t)totalEsz * (size_t)wf0); + AutoBuffer scratchBuf((size_t)totalEsz * region); uchar* scratch = scratchBuf.data(); for (int x0 = 0; x0 < (int)total; x0 += wf0) { @@ -1191,7 +1193,7 @@ void TExpr::exec(const Mat* const* inputs, Mat* outputs) if (ai.kind == OUTPUT) return (uchar*)outputs[ai.index].data + (size_t)x0 * esz; if (ai.kind != TEMP) return nullptr; // NONE: moved-from const int b = bufferOfTemp.empty() ? ai.index : bufferOfTemp[ai.index]; // TEMP - return scratch + (size_t)bufEszPrefix[b] * (size_t)wf0; // fragment-local + return scratch + (size_t)bufEszPrefix[b] * region; // fragment-local }; for (int n = 0; n < ninsn; n++) {