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

Tests FFI calls with types that have unique ABI handling rules. More...

#include "common/double_tap.h"
#include "common/infix_config.h"
#include <infix/infix.h>
Include dependency graph for 403_special_types.c:

Macros

#define DBLTAP_IMPLEMENTATION
 
#define HAS_DISTINCT_LONG_DOUBLE   1
 

Functions

long double passthrough_long_double (long double v)
 
bool check_s128 (__int128_t val)
 
bool check_u128 (__uint128_t val)
 
__int128_t return_s128 (void)
 
bool s128_callback_handler (__int128_t val)
 
 subtest ("Special type: long double")
 
 subtest ("Special type: __int128_t")
 
 subtest ("Special type: __uint128_t")
 

Variables

const __int128_t S128_CONSTANT = (((__int128_t)0x12345678ABCDDCBA) << 64) | 0x1122334455667788
 
const __uint128_t U128_CONSTANT = (((__uint128_t)0xFFFFFFFFFFFFFFFF) << 64) | 0xAABBCCDDEEFF0011
 
 TEST
 

Detailed Description

Tests FFI calls with types that have unique ABI handling rules.

Copyright (c) 2025 Sanko Robinson

This source code is dual-licensed under the Artistic License 2.0 or the MIT License. You may choose to use this code under the terms of either license.

SPDX-License-Identifier: (Artistic-2.0 OR MIT)

The documentation blocks within this file are licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0).

SPDX-License-Identifier: CC-BY-4.0

This suite focuses on C types that are not handled as simple primitives by the target ABI. These often involve legacy hardware (like the x87 FPU) or require values to be split across multiple registers.

It covers two main categories of special types:

  1. **long double:** On the System V x64 ABI (Linux/BSD), this is an 80-bit extended-precision type passed on the x87 FPU stack, not in SSE/XMM registers. On AArch64, it's a 128-bit type passed in a full Q-register. This test verifies these special-case mechanisms for both passing and returning the type.
  2. **__int128_t / __uint128_t:** These 128-bit integers are a non-standard compiler extension (not available on MSVC). They are too large for a single GPR and are passed/returned in a register pair (e.g., RAX:RDX on SysV, X0:X1 on AArch64). This test verifies that the library correctly splits and reassembles these large integer values for both forward and reverse FFI calls.

Macro Definition Documentation

◆ DBLTAP_IMPLEMENTATION

#define DBLTAP_IMPLEMENTATION

◆ HAS_DISTINCT_LONG_DOUBLE

#define HAS_DISTINCT_LONG_DOUBLE   1

Function Documentation

◆ check_s128()

bool check_s128 ( __int128_t  val)

◆ check_u128()

bool check_u128 ( __uint128_t  val)

◆ passthrough_long_double()

long double passthrough_long_double ( long double  v)

◆ return_s128()

__int128_t return_s128 ( void  )

◆ s128_callback_handler()

bool s128_callback_handler ( __int128_t  val)

◆ subtest() [1/3]

subtest ( "Special type: __int128_t"  )

◆ subtest() [2/3]

subtest ( "Special type: __uint128_t"  )

◆ subtest() [3/3]

subtest ( "Special type: long double"  )

Variable Documentation

◆ S128_CONSTANT

const __int128_t S128_CONSTANT = (((__int128_t)0x12345678ABCDDCBA) << 64) | 0x1122334455667788

◆ TEST

TEST
Initial value:
{
plan(3)
#define plan(count)
Definition double_tap.h:132

◆ U128_CONSTANT

const __uint128_t U128_CONSTANT = (((__uint128_t)0xFFFFFFFFFFFFFFFF) << 64) | 0xAABBCCDDEEFF0011