kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

commit 87ffbeeee00a842e9209d9665120e25ce814e3d4
parent e4a333278d9c614276c265232293826e26aa3b63
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Wed,  3 Jun 2026 21:27:16 -0700

Test ABI split-lane scalar query

Diffstat:
Mtest/api/abi_classify_test.c | 67++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 64 insertions(+), 3 deletions(-)

diff --git a/test/api/abi_classify_test.c b/test/api/abi_classify_test.c @@ -1,10 +1,14 @@ -/* ABI classification regression tests for wide16 scalars (i128, long double). +/* ABI classification regression tests for wide scalar ABI contracts. * * Locks in the behaviour described in doc/CBACKEND.md "Wide16 classification * is incomplete in some native ABIs". Each (target, type) case asserts the * shape the ABI vtable should produce for an argument and a return — i.e. * what the C frontend / CG layer would see if the wide16 CG-layer shortcut - * were removed. */ + * were removed. + * + * Also pins the ABI-local split-lane scalar query used by generic CG lowering: + * a target opts in when an otherwise scalar value must be represented as + * multiple addressable machine-word lanes. */ #include <kit/cg.h> #include <kit/core.h> @@ -25,9 +29,19 @@ static KitUnit g_u; static void expect_direct_1x_int(const char* tag, const ABIArgInfo* ai, u32 want_size); +static KitTargetSpec test_target_spec(KitArchKind arch, KitOSKind os, + KitObjFmt obj) { + KitTargetSpec t = kit_unit_target(arch, os, obj); + if (arch == KIT_ARCH_RV32 || arch == KIT_ARCH_WASM) { + t.ptr_size = 4; + t.ptr_align = 4; + } + return t; +} + static KitCompiler* new_compiler(KitArchKind arch, KitOSKind os, KitObjFmt obj) { - KitTargetSpec t = kit_unit_target(arch, os, obj); + KitTargetSpec t = test_target_spec(arch, os, obj); KitCompiler* c = NULL; if (kit_unit_compiler_new(&g_u, t, &c) != KIT_OK || !c) { fprintf(stderr, "compiler_new failed for arch=%d os=%d\n", (int)arch, @@ -65,8 +79,12 @@ static const char* arch_name(KitArchKind a) { return "x64"; case KIT_ARCH_ARM_64: return "aarch64"; + case KIT_ARCH_RV32: + return "rv32"; case KIT_ARCH_RV64: return "rv64"; + case KIT_ARCH_WASM: + return "wasm"; default: return "?"; } @@ -79,6 +97,10 @@ static const char* os_name(KitOSKind o) { return "macos"; case KIT_OS_WINDOWS: return "windows"; + case KIT_OS_FREESTANDING: + return "freestanding"; + case KIT_OS_WASI: + return "wasi"; default: return "?"; } @@ -566,6 +588,44 @@ static void test_apple_arm64_stack_traits(void) { kit_compiler_free(c); } +static void check_scalar_split_lane_target(KitArchKind arch, KitOSKind os, + KitObjFmt obj, const char* tag, + u32 want_i64, u32 want_f64) { + KitCompiler* c = new_compiler(arch, os, obj); + KitCgBuiltinTypes bi = kit_cg_builtin_types(c); + TargetABI* abi = ((Compiler*)c)->abi; + + EXPECT(abi_cg_scalar_split_lane_size(abi, bi.id[KIT_CG_BUILTIN_I64]) == + want_i64, + "%s i64 split lane=%u want %u", tag, + (unsigned)abi_cg_scalar_split_lane_size(abi, + bi.id[KIT_CG_BUILTIN_I64]), + (unsigned)want_i64); + EXPECT(abi_cg_scalar_split_lane_size(abi, bi.id[KIT_CG_BUILTIN_F64]) == + want_f64, + "%s f64 split lane=%u want %u", tag, + (unsigned)abi_cg_scalar_split_lane_size(abi, + bi.id[KIT_CG_BUILTIN_F64]), + (unsigned)want_f64); + EXPECT(abi_cg_scalar_split_lane_size(abi, bi.id[KIT_CG_BUILTIN_I32]) == 0, + "%s i32 should not be split-lane", tag); + EXPECT(abi_cg_scalar_split_lane_size(abi, bi.id[KIT_CG_BUILTIN_F32]) == 0, + "%s f32 should not be split-lane", tag); + + kit_compiler_free(c); +} + +static void test_scalar_split_lane_size(void) { + /* RV32's default profile is ilp32f: 64-bit ints and soft doubles are + * represented as two 4-byte integer lanes. */ + check_scalar_split_lane_target(KIT_ARCH_RV32, KIT_OS_LINUX, KIT_OBJ_ELF, + "rv32", 4, 4); + check_scalar_split_lane_target(KIT_ARCH_RV64, KIT_OS_LINUX, KIT_OBJ_ELF, + "rv64", 0, 0); + check_scalar_split_lane_target(KIT_ARCH_WASM, KIT_OS_WASI, KIT_OBJ_WASM, + "wasm32", 0, 0); +} + int main(void) { kit_unit_init(&g_u); check_target(KIT_ARCH_X86_64, KIT_OS_LINUX, KIT_OBJ_ELF); @@ -577,6 +637,7 @@ int main(void) { test_win64_specifics(); test_aarch64_windows_variadic(); test_apple_arm64_stack_traits(); + test_scalar_split_lane_size(); kit_unit_summary(&g_u, "abi_classify_test"); return kit_unit_status(&g_u); }