infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
101_by_value.c File Reference

Unit test for passing and returning aggregates and vectors by value. More...

#include "common/double_tap.h"
#include "common/infix_internals.h"
#include "types.h"
#include <infix/infix.h>
#include <math.h>
#include <stdbool.h>
Include dependency graph for 101_by_value.c:

Classes

struct  Char20Struct
 

Macros

#define DBLTAP_IMPLEMENTATION
 

Functions

double process_point_by_value (Point p)
 
Point return_point_by_value (void)
 
int process_mixed_struct (MixedIntDouble s)
 
float sum_vector4 (Vector4 vec)
 
int process_char20_struct (Char20Struct s)
 A C function that receives the 20-byte struct.
 
int process_char_array_param (char s[20])
 A C function that receives a char array parameter.
 
 subtest ("Simple struct (Point) passed and returned by value")
 
 subtest ("ABI Specific: System V x64 mixed-register struct")
 
 subtest ("ABI Specific: AArch64 Homogeneous Floating-point Aggregate (HFA)")
 
 subtest ("ABI Specific: 128-bit SIMD Vector")
 
 subtest ("ABI Specific: 256-bit AVX Vector")
 
 subtest ("ABI Specific: ARM64 Scalable Vector (SVE)")
 
 subtest ("ABI Specific: 512-bit AVX-512 Vector (__m512d)")
 
 subtest ("ABI Specific: 512-bit AVX-512 Vector (__m512)")
 
 subtest ("SysV ABI: Passing a 20-byte aggregate")
 
 subtest ("SysV ABI: Passing an array parameter (decays to pointer)")
 

Variables

 TEST
 

Detailed Description

Unit test for passing and returning aggregates and vectors by value.

This test file is crucial for validating the ABI implementation for passing and returning aggregate types (structs, arrays, vectors) directly in CPU registers, where the ABI allows it. Different ABIs have complex and divergent rules for this, which this test aims to cover.

It tests several key ABI-specific scenarios:

  • Simple Structs: Verifies that small structs composed of identical types (e.g., { double, double }) are correctly passed and returned in floating-point or general-purpose registers as per the ABI (e.g., in XMM0/XMM1 on SysV, or X0/X1 on AArch64).
  • System V x64 Mixed-Register Structs: Tests the specific SysV rule where a struct like { int, double } is split and passed in both a GPR (for the int) and an XMM register (for the double).
  • AArch64 Homogeneous Floating-point Aggregates (HFAs): Tests the AAPCS64 rule where a struct of up to four identical floats or doubles is passed in consecutive floating-point registers (V0-V3).
  • SIMD Vectors: Verifies that native hardware vector types (like __m128d on x86 or float64x2_t on ARM) are correctly passed and returned in SIMD registers. This includes checks for SSE2, AVX2, and NEON types, conditionally compiled based on architecture.

Macro Definition Documentation

◆ DBLTAP_IMPLEMENTATION

#define DBLTAP_IMPLEMENTATION

Function Documentation

◆ process_char20_struct()

int process_char20_struct ( Char20Struct  s)

A C function that receives the 20-byte struct.

It checks if the received data matches the expected pattern. A correct call will result in a return value of 1, while a call where the argument was corrupted (e.g., by being partially passed in registers) will fail the check and return 0.

◆ process_char_array_param()

int process_char_array_param ( char  s[20])

A C function that receives a char array parameter.

The ABI will treat s as char*. This function verifies that the pointer is valid and the data it points to is correct.

◆ process_mixed_struct()

int process_mixed_struct ( MixedIntDouble  s)

◆ process_point_by_value()

double process_point_by_value ( Point  p)

◆ return_point_by_value()

Point return_point_by_value ( void  )

◆ subtest() [1/10]

subtest ( "ABI Specific: 128-bit SIMD Vector"  )

◆ subtest() [2/10]

subtest ( "ABI Specific: 256-bit AVX Vector"  )

◆ subtest() [3/10]

subtest ( "ABI Specific: 512-bit AVX-512 Vector (__m512)"  )

◆ subtest() [4/10]

subtest ( "ABI Specific: 512-bit AVX-512 Vector (__m512d)"  )

◆ subtest() [5/10]

subtest ( "ABI Specific: AArch64 Homogeneous Floating-point Aggregate (HFA)"  )

◆ subtest() [6/10]

subtest ( "ABI Specific: ARM64 Scalable Vector (SVE)"  )

◆ subtest() [7/10]

subtest ( "ABI Specific: System V x64 mixed-register struct"  )

◆ subtest() [8/10]

subtest ( "Simple struct (Point) passed and returned by value"  )

◆ subtest() [9/10]

subtest ( "SysV ABI: Passing a 20-byte aggregate"  )

◆ subtest() [10/10]

subtest ( "SysV ABI: Passing an array parameter (decays to pointer)"  )

◆ sum_vector4()

float sum_vector4 ( Vector4  vec)

Variable Documentation

◆ TEST

TEST
Initial value:
{
plan(10)
#define plan(count)
Definition double_tap.h:154