systems-nuts / unifico

Compiler and build harness for heterogeneous-ISA binaries with the same stack layout.
3 stars 1 forks source link

X86 calculates fabs using a 16-byte vector #303

Closed blackgeorge-boom closed 9 months ago

blackgeorge-boom commented 10 months ago
#include <stdio.h>
#include <math.h>

void results(char Class, double epsilon)
{
    double err;
    double zeta_verify_value = 22.712745482631;

    if (Class != 'U') {
        err = fabs(epsilon - zeta_verify_value) / zeta_verify_value;
    }
    err += fabs(epsilon - zeta_verify_value);
    printf(" Error is   %20.14E\n", err);
    return;
}

int main()
{
    results('S', 1.0);

    return 0;
}

For the calculation of fabs, X86 uses vector operands and spills a 16-byte value into memory. AArch64 only uses one fp64 operand and doesn't spill it.

0x0  : ||d0-------|| : -0x10    0x0  : ||xmm0-----|| : -0x20 
0x8  : ||---------|| : -0x8     0x8  : ||---------|| : -0x18 
0x10 : ||x29------|| : 0x0      0x10 : ||---------|| : -0x10 
0x18 : ||x30------|| : 0x8      0x18 : ||---------|| : -0x8  
                            0x20 : ||rbp------|| : 0x0   
sp : 0x0                    0x28 : ||---------|| : 0x8   
x29: 0x10   
                                rsp: 0x0
                                rbp: 0x20