From 716361fa0fdaccce03bf92e48649cdcf37ff5bf0 Mon Sep 17 00:00:00 2001 From: Kirill Zhumarin Date: Sun, 13 Sep 2026 14:11:47 +0300 Subject: [PATCH] Support floating-point conditional expressions --- README.md | 3 ++- src/fp_emitter.S | 13 +++++++++ tests/CMakeLists.txt | 1 + tests/cases/fp-conditional/conditional.c | 9 +++++++ tests/cases/fp-conditional/host.c | 34 ++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fp-conditional/conditional.c create mode 100644 tests/cases/fp-conditional/host.c diff --git a/README.md b/README.md index 60ecc44..00da764 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ Patches and runtime libraries for TASKING C166/ST10 v8.6r1 Build 753. Changes: - removed compiler, linker and debugger demo restrictions; -- enabled `float`/`double` code generation, fixed their Classic ABI and +- enabled `float`/`double` code generation, including conditional + expressions, fixed their Classic ABI and fixed IEEE `float`/`double` width conversions, including signed zero, subnormal values, round-to-nearest-even, infinities and NaNs, and fixed indexed `float` loads in Huge model; diff --git a/src/fp_emitter.S b/src/fp_emitter.S index 6a25c02..8569ec2 100644 --- a/src/fp_emitter.S +++ b/src/fp_emitter.S @@ -17,6 +17,7 @@ .equ emit_call, 0x00428db0 .equ emit_indirect, 0x004531b0 .equ emit_comma, 0x0041b580 + .equ emit_conditional,0x0041ec90 .equ emit_deref, 0x004395c0 .equ transfer_owner, 0x004187e0 .equ release_owner, 0x00418800 @@ -139,6 +140,8 @@ fp_emitter: je .Lcall cmp al, 0x6b /* indirect/function call variant */ je .Lindirect + cmp al, 0x69 /* conditional expression */ + je .Lconditional cmp al, 0x2c /* comma */ je .Lcomma jmp .Lunsupported @@ -177,6 +180,8 @@ fp_emitter: je .Ldouble_call cmp al, 0x6b /* indirect/function call variant */ je .Lindirect + cmp al, 0x69 /* conditional expression */ + je .Lconditional cmp al, 0x2c /* comma */ je .Lcomma jmp .Lunsupported @@ -1051,6 +1056,14 @@ fp_emitter: add esp, 12 jmp .Ldone +.Lconditional: + push ebx + push edi + push esi + call emit_conditional + add esp, 12 + jmp .Ldone + .Lcomma: push ebx push edi diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 154fee2..cf7242c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -110,6 +110,7 @@ foreach(variant IN ITEMS ext ext2) add_runtime_iss_test("${variant}" "large" "iss-code-segment-boundaries") add_runtime_iss_test("${variant}" "huge" "fp-huge-indexed-load" "O2") foreach(model IN ITEMS tiny small medium large huge) + add_runtime_iss_test("${variant}" "${model}" "fp-conditional" "O2") add_runtime_iss_test("${variant}" "${model}" "fp-f64-to-f32" "O2") endforeach() endforeach() diff --git a/tests/cases/fp-conditional/conditional.c b/tests/cases/fp-conditional/conditional.c new file mode 100644 index 0000000..3b04820 --- /dev/null +++ b/tests/cases/fp-conditional/conditional.c @@ -0,0 +1,9 @@ +float select_f32(float value, unsigned int select_value) +{ + return select_value == 0x5a5aU ? value : 12345.0f; +} + +double select_f64(double value, unsigned int select_value) +{ + return select_value == 0x5a5aU ? value : 12345.0; +} diff --git a/tests/cases/fp-conditional/host.c b/tests/cases/fp-conditional/host.c new file mode 100644 index 0000000..9352a73 --- /dev/null +++ b/tests/cases/fp-conditional/host.c @@ -0,0 +1,34 @@ +#include "test.h" + +extern float select_f32(float value, unsigned int select_value); +extern double select_f64(double value, unsigned int select_value); + +void main(void) +{ + test_f32 f32_input; + test_f32 f32_output; + test_f64 f64_input; + test_f64 f64_output; + + simulator_result = 0U; + + f32_input.words[0] = 0x8000U; + f32_input.words[1] = 0x0000U; + f32_output.value = select_f32(f32_input.value, 0x5a5aU); + test_check_f32(1U, &f32_output, 0x8000U, 0x0000U); + f32_output.value = select_f32(f32_input.value, 0U); + test_check_f32(2U, &f32_output, 0x4640U, 0xe400U); + + f64_input.words[0] = 0x8000U; + f64_input.words[1] = 0x0000U; + f64_input.words[2] = 0x0000U; + f64_input.words[3] = 0x0000U; + f64_output.value = select_f64(f64_input.value, 0x5a5aU); + test_check_f64(3U, &f64_output, + 0x8000U, 0x0000U, 0x0000U, 0x0000U); + f64_output.value = select_f64(f64_input.value, 0U); + test_check_f64(4U, &f64_output, + 0x40c8U, 0x1c80U, 0x0000U, 0x0000U); + + simulator_stop(); +}