mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
200 lines
6.0 KiB
Plaintext
200 lines
6.0 KiB
Plaintext
// #target: linux-riscv32
|
|
// #opt: --riscvfloat=float
|
|
module test;
|
|
|
|
// Verify that the tracking of used GPRs and FPRs works correctly by checking
|
|
// that small integers are sign/zero extended when passed in registers.
|
|
|
|
// Floats are passed in FPRs, so argument 'i' will be passed zero-extended
|
|
// because it will be passed in a GPR.
|
|
|
|
fn void f_fpr_tracking(float a, float b, float c, float d, float e, float f,
|
|
float g, float h, char i) {}
|
|
|
|
// Check that fp, fp+fp, and int+fp structs are lowered correctly. These will
|
|
// be passed in FPR, FPR+FPR, or GPR+FPR regs if sufficient registers are
|
|
// available the widths are <= XLEN and FLEN, and should be expanded to
|
|
// separate arguments in IR. They are passed by the same rules for returns,
|
|
// but will be lowered to simple two-element structs if necessary (as LLVM IR
|
|
// functions cannot return multiple values).
|
|
|
|
// A struct containing just one floating-point real is passed as though it
|
|
// were a standalone floating-point real.
|
|
|
|
struct Float_s { float f; }
|
|
|
|
fn void f_float_s_arg(Float_s a) {}
|
|
|
|
fn Float_s f_ret_float_s() {
|
|
return {1.0};
|
|
}
|
|
|
|
|
|
// Check that structs containing two float values (FLEN <= width) are expanded
|
|
// provided sufficient FPRs are available.
|
|
|
|
struct Float_float_s { float f; float g; }
|
|
|
|
fn void f_float_float_s_arg(Float_float_s a) {}
|
|
|
|
fn Float_float_s f_ret_float_float_s() {
|
|
return {1.0, 2.0};
|
|
}
|
|
|
|
fn void f_float_float_s_arg_insufficient_fprs(float a, float b, float c, float d,
|
|
float e, float f, float g, Float_float_s h) {}
|
|
|
|
// Check that structs containing int+float values are expanded, provided
|
|
// sufficient FPRs and GPRs are available. The integer components are neither
|
|
// sign or zero-extended.
|
|
|
|
struct Float_int8_s { float f; ichar i; }
|
|
struct Float_uint8_s { float f; char i; }
|
|
struct Float_int32_s { float f; int i; }
|
|
struct Float_int64_s { float f; long i; }
|
|
|
|
fn void f_float_int8_s_arg(Float_int8_s a) {}
|
|
|
|
fn Float_int8_s f_ret_float_int8_s() {
|
|
return {1.0, 2};
|
|
}
|
|
|
|
fn void f_float_uint8_s_arg(Float_uint8_s a) {}
|
|
|
|
fn Float_uint8_s f_ret_float_uint8_s() {
|
|
return {1.0, 2};
|
|
}
|
|
|
|
fn void f_float_int32_s_arg(Float_int32_s a) {}
|
|
|
|
fn Float_int32_s f_ret_float_int32_s() {
|
|
return {1.0, 2};
|
|
}
|
|
|
|
fn void f_float_int64_s_arg(Float_int64_s a) {}
|
|
|
|
fn Float_int64_s f_ret_float_int64_s() {
|
|
return {1.0, 2};
|
|
}
|
|
|
|
|
|
fn void f_float_int8_s_arg_insufficient_gprs(int a, int b, int c, int d, int e,
|
|
int f, int g, int h, Float_int8_s i) {}
|
|
|
|
fn void f_struct_float_int8_insufficient_fprs(float a, float b, float c, float d,
|
|
float e, float f, float g, float h, Float_int8_s i) {}
|
|
|
|
// Test single or two-element structs that need flattening. e.g. those
|
|
// containing nested structs, floats in small arrays, zero-length structs etc.
|
|
|
|
struct Floatarr1_s { float[1] a; }
|
|
|
|
fn void f_floatarr1_s_arg(Floatarr1_s a) {}
|
|
|
|
fn Floatarr1_s f_ret_floatarr1_s() {
|
|
return {{1.0}};
|
|
}
|
|
|
|
struct Floatarr2_s { float[2] a; }
|
|
|
|
fn void f_floatarr2_s_arg(Floatarr2_s a) {}
|
|
|
|
fn Floatarr2_s f_ret_floatarr2_s() {
|
|
return {{1.0, 2.0}};
|
|
}
|
|
|
|
struct Inner { float[1] f; }
|
|
struct Floatarr2_tricky1_s { Inner[2] g; }
|
|
|
|
fn void f_floatarr2_tricky1_s_arg(Floatarr2_tricky1_s a) {}
|
|
|
|
fn Floatarr2_tricky1_s f_ret_floatarr2_tricky1_s() {
|
|
return {{{{1.0}}, {{2.0}}}};
|
|
}
|
|
|
|
// Test structs that should be passed according to the normal integer calling
|
|
// convention.
|
|
|
|
struct Int_float_int_s { int a; float b; int c; }
|
|
|
|
fn void f_int_float_int_s_arg(Int_float_int_s a) {}
|
|
|
|
fn Int_float_int_s f_ret_int_float_int_s() {
|
|
return {1, 2.0, 3};
|
|
}
|
|
|
|
struct Int64_float_s { long a; float b; }
|
|
|
|
fn void f_int64_float_s_arg(Int64_float_s a) {}
|
|
|
|
fn Int64_float_s f_ret_int64_float_s() {
|
|
return {1, 2.0};
|
|
}
|
|
|
|
struct Char_char_float_s { char a; char b; float c; }
|
|
|
|
fn void f_char_char_float_s_arg(Char_char_float_s a) {}
|
|
|
|
fn Char_char_float_s f_ret_char_char_float_s() {
|
|
return {1, 2, 3.0};
|
|
}
|
|
|
|
// Unions are always passed according to the integer calling convention, even
|
|
// if they can only contain a float.
|
|
|
|
union Float_u { float a; }
|
|
|
|
fn void f_float_u_arg(Float_u a) {}
|
|
|
|
fn Float_u f_ret_float_u() {
|
|
return {1.0};
|
|
}
|
|
|
|
|
|
/* #expect: test.ll
|
|
|
|
define void @test.f_fpr_tracking(float %0, float %1, float %2, float %3, float %4, float %5, float %6, float %7, i8 zeroext %8)
|
|
|
|
define void @test.f_float_s_arg(float %0)
|
|
define float @test.f_ret_float_s()
|
|
|
|
define void @test.f_float_float_s_arg(float %0, float %1)
|
|
define { float, float } @test.f_ret_float_float_s()
|
|
|
|
define void @test.f_float_float_s_arg_insufficient_fprs(float %0, float %1, float %2, float %3, float %4, float %5, float %6, [2 x i32] %7) #0 {
|
|
|
|
define void @test.f_float_int8_s_arg(float %0, i8 %1)
|
|
define { float, i8 } @test.f_ret_float_int8_s()
|
|
|
|
define void @test.f_float_uint8_s_arg(float %0, i8 %1)
|
|
define { float, i8 } @test.f_ret_float_uint8_s()
|
|
|
|
define void @test.f_float_int32_s_arg(float %0, i32 %1)
|
|
define { float, i32 } @test.f_ret_float_int32_s()
|
|
|
|
define void @test.f_float_int64_s_arg(ptr align 8 %0)
|
|
define void @test.f_ret_float_int64_s(ptr noalias sret(%Float_int64_s) align 8 %0)
|
|
|
|
define void @test.f_float_int8_s_arg_insufficient_gprs(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, [2 x i32] %8)
|
|
define void @test.f_struct_float_int8_insufficient_fprs(float %0, float %1, float %2, float %3, float %4, float %5, float %6, float %7, [2 x i32] %8)
|
|
|
|
define void @test.f_floatarr1_s_arg(float %0)
|
|
define float @test.f_ret_floatarr1_s()
|
|
|
|
define void @test.f_floatarr2_s_arg(float %0, float %1)
|
|
define { float, float } @test.f_ret_floatarr2_s()
|
|
|
|
define void @test.f_floatarr2_tricky1_s_arg(float %0, float %1)
|
|
define { float, float } @test.f_ret_floatarr2_tricky1_s()
|
|
|
|
define void @test.f_int_float_int_s_arg(ptr align 4 %0)
|
|
define void @test.f_ret_int_float_int_s(ptr noalias sret(%Int_float_int_s) align 4 %0)
|
|
|
|
define void @test.f_int64_float_s_arg(ptr align 8 %0)
|
|
define void @test.f_ret_int64_float_s(ptr noalias sret(%Int64_float_s) align 8 %0)
|
|
|
|
define void @test.f_char_char_float_s_arg([2 x i32] %0)
|
|
define [2 x i32] @test.f_ret_char_char_float_s()
|
|
|
|
define void @test.f_float_u_arg(i32 %0)
|
|
define i32 @test.f_ret_float_u() |