mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
stage1: Fix handling of C ABI parameters split in multiple regs
Take into account the increased number of parameters when flattening a structure into one or more SSE registers. Fixes #9061
This commit is contained in:
parent
2a7fdd56c6
commit
43a09f7efc
@ -2161,11 +2161,11 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
|
||||
// Register 2: (ptr + 1).*
|
||||
|
||||
// One floating point register per f64 or 2 f32's
|
||||
size_t number_of_fp_regs = (size_t)ceilf((float)ty_size / (float)8);
|
||||
size_t number_of_fp_regs = (ty_size + 7) / 8;
|
||||
|
||||
switch (fn_walk->id) {
|
||||
case FnWalkIdAttrs: {
|
||||
fn_walk->data.attrs.gen_i += 1;
|
||||
fn_walk->data.attrs.gen_i += number_of_fp_regs;
|
||||
break;
|
||||
}
|
||||
case FnWalkIdCall: {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
void zig_panic();
|
||||
|
||||
@ -253,6 +254,13 @@ void c_small_struct_floats(Vector3 vec) {
|
||||
assert_or_panic(vec.z == 12.0);
|
||||
}
|
||||
|
||||
void c_small_struct_floats_extra(Vector3 vec, const char *str) {
|
||||
assert_or_panic(vec.x == 3.0);
|
||||
assert_or_panic(vec.y == 6.0);
|
||||
assert_or_panic(vec.z == 12.0);
|
||||
assert_or_panic(!strcmp(str, "hello"));
|
||||
}
|
||||
|
||||
void c_big_struct_floats(Vector5 vec) {
|
||||
assert_or_panic(vec.x == 76.0);
|
||||
assert_or_panic(vec.y == -1.0);
|
||||
|
||||
@ -257,6 +257,7 @@ const Vector3 = extern struct {
|
||||
z: f32,
|
||||
};
|
||||
extern fn c_small_struct_floats(Vector3) void;
|
||||
extern fn c_small_struct_floats_extra(Vector3, ?[*]const u8) void;
|
||||
|
||||
const Vector5 = extern struct {
|
||||
x: f32,
|
||||
@ -274,6 +275,7 @@ test "C ABI structs of floats as parameter" {
|
||||
.z = 12.0,
|
||||
};
|
||||
c_small_struct_floats(v3);
|
||||
c_small_struct_floats_extra(v3, "hello");
|
||||
|
||||
var v5 = Vector5{
|
||||
.x = 76.0,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user