Repository navigation
[risc-v][vector] Restore vstart after vector configuration #11861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8f88139
risc-v: restore vstart after vector configuration
PiyushPatle26 36afba2
[risc-v][vector] Restore vstart after vector configuration
PiyushPatle26 8f376ff
[risc-v][utest] Integrate RVV restore regression and CI variants
PiyushPatle26 73e4f97
[risc-v][utest] Fix legacy vector testcase build
PiyushPatle26 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
bsp/qemu-virt64-riscv/.ci/attachconfig/ci.attachconfig.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| utest.rvv.vlen128: | ||
| scons_arg: | ||
| - '--strict' | ||
| kconfig: | ||
| - CONFIG_ENABLE_VECTOR=y | ||
| - CONFIG_RT_USING_HEAP=y | ||
| - CONFIG_RT_USING_UTEST=y | ||
| - CONFIG_ARCH_VECTOR_VLEN_128=y | ||
| - CONFIG_ARCH_VECTOR_VLEN_256=n | ||
| - CONFIG_RT_USING_SMP=n | ||
| utest.rvv.vlen256: | ||
| scons_arg: | ||
| - '--strict' | ||
| kconfig: | ||
| - CONFIG_ENABLE_VECTOR=y | ||
| - CONFIG_RT_USING_HEAP=y | ||
| - CONFIG_RT_USING_UTEST=y | ||
| - CONFIG_ARCH_VECTOR_VLEN_128=n | ||
| - CONFIG_ARCH_VECTOR_VLEN_256=y | ||
| - CONFIG_RT_USING_SMP=n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
bsp/qemu-virt64-riscv/applications/test/test_vector/vector_context_gcc.S
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * Copyright (c) 2006-2026, RT-Thread Development Team | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #ifndef __ASSEMBLY__ | ||
| #define __ASSEMBLY__ | ||
| #endif | ||
| #define REGBYTES 8 | ||
| #define STORE sd | ||
| #define LOAD ld | ||
|
|
||
| #include <rtconfig.h> | ||
| #include "vector_encoding.h" | ||
| #include "rvv_context.h" | ||
|
|
||
| .text | ||
| .align 2 | ||
|
|
||
| /* Test-only helpers; SAVE_VECTOR must not change the caller's controls. */ | ||
| .globl rt_hw_vector_ctx_save | ||
| .type rt_hw_vector_ctx_save, @function | ||
| rt_hw_vector_ctx_save: | ||
| csrrci a3, sstatus, 2 | ||
| li t0, SSTATUS_VS | ||
| csrs sstatus, t0 | ||
| SAVE_VECTOR a0 | ||
| RESTORE_VECTOR a0 | ||
| csrw sstatus, a3 | ||
| ret | ||
| .size rt_hw_vector_ctx_save, . - rt_hw_vector_ctx_save | ||
|
|
||
| .globl rt_hw_vector_ctx_restore | ||
| .type rt_hw_vector_ctx_restore, @function | ||
| rt_hw_vector_ctx_restore: | ||
| csrrci a3, sstatus, 2 | ||
| li t0, SSTATUS_VS | ||
| csrs sstatus, t0 | ||
| RESTORE_VECTOR a0 | ||
| csrw sstatus, a3 | ||
| ret | ||
| .size rt_hw_vector_ctx_restore, . - rt_hw_vector_ctx_restore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| from building import * | ||
|
|
||
| cwd = GetCurrentDir() | ||
| src = ['rvv_vstart_tc.c', 'rvv_vstart_probe_gcc.S'] | ||
|
|
||
| group = DefineGroup('RVV utestcases', src, | ||
| depend = ['RT_USING_UTEST', 'ENABLE_VECTOR', 'RT_USING_HEAP'], | ||
| CPPPATH = [cwd]) | ||
|
|
||
| Return('group') |
46 changes: 46 additions & 0 deletions
46
bsp/qemu-virt64-riscv/applications/utest/rvv_vstart_probe_gcc.S
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * Copyright (c) 2006-2026, RT-Thread Development Team | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Change Logs: | ||
| * Date Author Notes | ||
| * 2026-10-10 Piyush Patle Add RVV restore regression probe | ||
| */ | ||
|
|
||
| #ifndef __ASSEMBLY__ | ||
| #define __ASSEMBLY__ | ||
| #endif | ||
| #define REGBYTES 8 | ||
| #define STORE sd | ||
| #define LOAD ld | ||
|
|
||
| #include <rtconfig.h> | ||
| #include "vector_encoding.h" | ||
| #include "rvv_context.h" | ||
|
|
||
| .text | ||
| .align 2 | ||
| .option push | ||
| .option arch, +v | ||
|
|
||
| /* a0: expected frame, a1: observed frame, a2: caller's vector frame. */ | ||
| .globl rvv_vstart_probe | ||
| .type rvv_vstart_probe, @function | ||
| rvv_vstart_probe: | ||
| /* Keep interrupts masked until the caller's complete state is restored. */ | ||
| csrrci a3, sstatus, 2 | ||
| li t0, SSTATUS_VS | ||
| csrs sstatus, t0 | ||
| SAVE_VECTOR a2 | ||
|
|
||
| RESTORE_VECTOR a0 | ||
| /* SAVE_VECTOR records vstart before issuing any vector instruction. */ | ||
| SAVE_VECTOR a1 | ||
|
|
||
| RESTORE_VECTOR a2 | ||
| csrw sstatus, a3 | ||
| ret | ||
| .size rvv_vstart_probe, . - rvv_vstart_probe | ||
|
|
||
| .option pop |
121 changes: 121 additions & 0 deletions
121
bsp/qemu-virt64-riscv/applications/utest/rvv_vstart_tc.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /* | ||
| * Copyright (c) 2006-2026, RT-Thread Development Team | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Change Logs: | ||
| * Date Author Notes | ||
| * 2026-10-10 Piyush Patle Test zero and nonzero RVV restart indices | ||
| */ | ||
|
|
||
| #include <rtthread.h> | ||
|
|
||
| /* Run with: utest_run testcases.libcpu.rvv_vstart */ | ||
| #if defined(ENABLE_VECTOR) && defined(RT_USING_HEAP) && defined(RT_USING_UTEST) | ||
| #include "rvv_context.h" | ||
|
|
||
| /* RV64 vector frames contain four control words followed by v0 through v31. */ | ||
| #define VECTOR_CONTROL_WORDS 4 | ||
| #define VECTOR_GUARD 0x5a5a5a5aUL | ||
|
|
||
| struct vector_test_frame | ||
| { | ||
| rt_ubase_t before[2]; | ||
| rt_ubase_t image[CTX_VECTOR_REG_NR]; | ||
| rt_ubase_t after[2]; | ||
| }; | ||
|
|
||
| void rvv_vstart_probe(const rt_ubase_t *input, rt_ubase_t *output, rt_ubase_t *backup); | ||
|
|
||
| static void frame_init(struct vector_test_frame *frame) | ||
| { | ||
| rt_memset(frame, 0, sizeof(*frame)); | ||
| frame->before[0] = frame->before[1] = VECTOR_GUARD; | ||
| frame->after[0] = frame->after[1] = VECTOR_GUARD; | ||
| } | ||
|
|
||
| static rt_bool_t frame_guards_valid(const struct vector_test_frame *frame) | ||
| { | ||
| return frame->before[0] == VECTOR_GUARD && frame->before[1] == VECTOR_GUARD && | ||
| frame->after[0] == VECTOR_GUARD && frame->after[1] == VECTOR_GUARD; | ||
| } | ||
|
|
||
| static int rvv_vstart_test(void) | ||
| { | ||
| rt_ubase_t vlenb; | ||
| rt_ubase_t starts[3]; | ||
| struct vector_test_frame *frames; | ||
| struct vector_test_frame *expected; | ||
| struct vector_test_frame *observed; | ||
| struct vector_test_frame *saved; | ||
| rt_uint8_t *payload; | ||
| rt_size_t payload_size = sizeof(expected->image) - VECTOR_CONTROL_WORDS * sizeof(rt_ubase_t); | ||
| rt_size_t i; | ||
| rt_size_t j; | ||
|
|
||
| __asm__ volatile("csrr %0, vlenb" : "=r"(vlenb)); | ||
| if (payload_size != 32 * vlenb) | ||
| { | ||
| rt_kprintf("RVV test: configured frame does not match vlenb=%lu\n", vlenb); | ||
| return -RT_ERROR; | ||
| } | ||
|
|
||
| /* Each invocation owns its frames, including the caller-state backup. */ | ||
| frames = rt_malloc(3 * sizeof(*frames)); | ||
| if (frames == RT_NULL) | ||
| { | ||
| return -RT_ENOMEM; | ||
| } | ||
| expected = &frames[0]; | ||
| observed = &frames[1]; | ||
| saved = &frames[2]; | ||
| payload = (rt_uint8_t *)&expected->image[VECTOR_CONTROL_WORDS]; | ||
| frame_init(expected); | ||
| for (i = 0; i < payload_size; i++) | ||
| { | ||
| payload[i] = (rt_uint8_t)(i * 37 + i / vlenb + 0x5a); | ||
| } | ||
|
|
||
| starts[0] = 0; | ||
| starts[1] = 1; | ||
| starts[2] = vlenb - 1; | ||
|
|
||
| for (i = 0; i < sizeof(starts) / sizeof(starts[0]); i++) | ||
| { | ||
| for (j = 0; j < 3; j++) | ||
| { | ||
| expected->image[0] = starts[i]; | ||
| expected->image[1] = 0; /* e8, m1, tail/mask undisturbed */ | ||
| expected->image[2] = vlenb; | ||
| expected->image[3] = j * 3; /* Exercise vxrm and vxsat through vcsr. */ | ||
| frame_init(observed); | ||
| frame_init(saved); | ||
|
|
||
| rvv_vstart_probe(expected->image, observed->image, saved->image); | ||
|
|
||
| if (!frame_guards_valid(expected) || !frame_guards_valid(observed) || | ||
| !frame_guards_valid(saved) || | ||
| rt_memcmp(expected->image, observed->image, sizeof(expected->image)) != 0) | ||
| { | ||
| rt_kprintf("RVV restore failed: vstart expected=%lu observed=%lu\n", | ||
| starts[i], observed->image[0]); | ||
| rt_free(frames); | ||
| return -RT_ERROR; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| rt_free(frames); | ||
| rt_kprintf("RVV restore passed: vlenb=%lu, 9 control/register checks\n", vlenb); | ||
| return RT_EOK; | ||
| } | ||
|
|
||
| #include <utest.h> | ||
|
|
||
| static void testcase(void) | ||
| { | ||
| uassert_int_equal(rvv_vstart_test(), RT_EOK); | ||
| } | ||
|
|
||
| UTEST_TC_EXPORT(testcase, "testcases.libcpu.rvv_vstart", RT_NULL, RT_NULL, 10); | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is recommended to move the test and its assembly probe to a dedicated utest directory and enable conditional build integration. Add additional CI configuration to enable vector support, heap, and UTest for VLEN=128 and VLEN=256.
You can refer to the BSP of K230:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the guidance. I moved the regression and assembly probe to applications/utest/ with conditional build integration, and added CI configurations for VLEN=128 and 256.
Both vector-enabled builds and the new UTest regression pass locally. I also added a separate minimal commit fixing the legacy testcase’s compilation errors. Please review the updated commits.