Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: 64bit long double tests #24

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ BINUTILS_BRANCH=${BINUTILS_BRANCH:-woarm64}
BINUTILS_VERSION=binutils-master

GCC_REPO=https://github.com/ZacWalk/gcc-woarm64.git
GCC_BRANCH=${GCC_BRANCH:-woarm64}
GCC_BRANCH=${GCC_BRANCH:-long-double-64}
# GCC_VERSION=gcc-12.2.0
GCC_VERSION=gcc-master

Expand All @@ -32,7 +32,7 @@ MSYS2_CONFIG=1
TARGET=$TARGET_ARCH-w64-mingw32
# TARGET=$TARGET_ARCH-pc-cygwin
BUILD_DIR=build-$TARGET
PARALLEL_MAKE=-j6
PARALLEL_MAKE=-j$(nproc)
MPFR_VERSION=mpfr-4.1.0
GMP_VERSION=gmp-6.2.1
MPC_VERSION=mpc-1.2.1
Expand Down Expand Up @@ -172,7 +172,7 @@ build_mingw_headers()
{
echo "==== build mingw headers"
cd $BUILD_DIR/mingw-headers
make
make $PARALLEL_MAKE
make install
cd ../..
# Symlink for gcc
Expand Down Expand Up @@ -227,7 +227,7 @@ build_mingw_libs()
{
echo "==== build mingw libs"
cd $BUILD_DIR/mingw
make
make $PARALLEL_MAKE
make install
cd ../..
}
Expand Down
21 changes: 10 additions & 11 deletions tests/build-tests.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
rm *.s *.dump *.gkd *.exe *.dll *.log
rm -f *.s *.dump *.gkd *.exe *.dll *.log

~/cross/bin/aarch64-w64-mingw32-g++ -S test-bigdata.cpp -o test-bigdata.s -fdump-final-insns
~/cross/bin/aarch64-w64-mingw32-g++ -S test-throw.cpp -o test-throw.s -fdump-final-insns
~/cross/bin/aarch64-w64-mingw32-g++ -S test-iostream.cpp -o test-iostream.cpp.s -fdump-final-insns
~/cross/bin/aarch64-w64-mingw32-g++ -S test-iostream.cpp -o test-iostream.s -fdump-final-insns
~/cross/bin/aarch64-w64-mingw32-gcc -S test-math.c -o test-math.c.s -fdump-final-insns
~/cross/bin/aarch64-w64-mingw32-gcc -S test-pdata.c -o test-pdata.s -fdump-final-insns
~/cross/bin/aarch64-w64-mingw32-gcc -S test-struct.c -o test-struct.s -fdump-final-insns
~/cross/bin/aarch64-w64-mingw32-gcc -S test-pdata.c -o test-pdata.c.s -fdump-final-insns
~/cross/bin/aarch64-w64-mingw32-gcc -S test-struct.c -o test-struct.c.s -fdump-final-insns

~/cross/bin/aarch64-w64-mingw32-g++ -g test-bigdata.cpp -o test-bigdata.exe >> test-bigdata.log
~/cross/bin/aarch64-w64-mingw32-g++ -g test-throw.cpp -o test-throw.exe >> test-throw.log
~/cross/bin/aarch64-w64-mingw32-g++ -g test-iostream.cpp -o test-iostream.exe >> test-iostream.log
~/cross/bin/aarch64-w64-mingw32-gcc -g test-math.c -o test-math.c.exe >> test-math.c.log
~/cross/bin/aarch64-w64-mingw32-gcc -g test-pdata.c -ldbghelp -o test-pdata.exe >> test-pdata.log
~/cross/bin/aarch64-w64-mingw32-gcc -g test-struct.c -o test-struct.exe >> test-struct.log
~/cross/bin/aarch64-w64-mingw32-gcc -g test-math.c -o test-math.exe >> test-math.log
~/cross/bin/aarch64-w64-mingw32-gcc -g test-varargs.c -o test-varargs.exe >> test-varargs.log
~/cross/bin/aarch64-w64-mingw32-gcc -g test-sjlj.c -o test-sjlj.exe >> test-sjlj.log
~/cross/bin/aarch64-w64-mingw32-gcc -g -fopenmp test-omp.c -o test-omp.exe >> test-omp.log
~/cross/bin/aarch64-w64-mingw32-gcc -g test-pdata.c -ldbghelp -o test-pdata.c.exe >> test-pdata.c.log
~/cross/bin/aarch64-w64-mingw32-gcc -g test-struct.c -o test-struct.c.exe >> test-struct.c.log
~/cross/bin/aarch64-w64-mingw32-gcc -g test-varargs.c -o test-varargs.c.exe >> test-varargs.c.log
~/cross/bin/aarch64-w64-mingw32-gcc -g test-sjlj.c -o test-sjlj.c.exe >> test-sjlj.c.log
~/cross/bin/aarch64-w64-mingw32-gcc -g -fopenmp test-omp.c -o test-omp.c.exe >> test-omp.c.log

#
# DLL examples
Expand All @@ -38,6 +37,6 @@ rm *.s *.dump *.gkd *.exe *.dll *.log
~/cross/bin/aarch64-w64-mingw32-objdump -dr test-throw.exe >> test-throw.dump
~/cross/bin/aarch64-w64-mingw32-objdump -dr test-dll-auto.exe >> test-dll-auto.dump
~/cross/bin/aarch64-w64-mingw32-objdump -dr test-dll-export.exe >> test-dll-export.dump
~/cross/bin/aarch64-w64-mingw32-objdump -dr test-struct.exe >> test-struct.dump
~/cross/bin/aarch64-w64-mingw32-objdump -dr test-struct.c.exe >> test-struct.c.dump


133 changes: 106 additions & 27 deletions tests/test-math.c
Original file line number Diff line number Diff line change
@@ -1,38 +1,117 @@
#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>

_Float128 foo (_Float128 x)
{
_Complex _Float128 z1, z2;
// Sources:
// - https://cpufun.substack.com/p/portable-support-for-128b-floats
// - https://cplusplus.com/reference/cstdio/printf/

z1 = x;
z2 = x / 7.F128;
z2 /= z1;
#define M_E_LD 2.718281828459045235360287471352662498L

return (_Float128) z2;
}
#define assert_sizeof(type, size) \
printf ("expected: sizeof(%s) == %d\n", #type, size); \
printf ("actual: sizeof(%s) == %d\n", #type, sizeof (type)); \
assert (sizeof (type) == size);

_Float128 bar (_Float128 x)
void assert_snprintf(const char* expected, const char* format, ...)
{
return x * __builtin_huge_valf128 ();
va_list list;
va_start (list, format);

const int SIZE = 1024;
char actual[SIZE];
snprintf (actual, SIZE, format, list);
printf ("expected: %s\n", expected);
printf ("actual: %s\n", actual);
assert (strncmp (expected, actual, SIZE) == 0);

va_end(list);
}

_Float128 baz (_Float128 x)
int main()
{
return x * __builtin_huge_valf128 ();
}
assert_sizeof (float, 4);
assert_sizeof (double, 8);
assert_sizeof (long double, 8);

float f = 1.23456f;
double d = 1.23456;
long double ld = M_E_LD;

int main()
{
foo (1.2Q);
bar (1.2Q);
foo (1.2F128);
bar (1.2F128);
baz (1.2F128);
foo (1.2Q);
bar (1.2Q);
baz (1.2Q);

printf("ok\n");
return 0;
}
assert_snprintf ("float %f => 1.234560", "float %%f => %f", f);
assert_snprintf ("float %F => 1.234560", "float %%F => %F", f);
assert_snprintf ("float %e => 1.234560e+00", "float %%e => %e", f);
assert_snprintf ("float %E => 1.234560E+00", "float %%E => %E", f);
assert_snprintf ("float %g => 1.23456", "float %%g => %g", f);
assert_snprintf ("float %G => 1.23456", "float %%G => %G", f);
assert_snprintf ("float %a => 0x1.3c0c2p+0", "float %%a => %a", f);
assert_snprintf ("float %A => 0X1.3C0C2P+0", "float %%A => %A", f);

assert_snprintf ("double %f => 1.234560", "double %%f => %f", d);
assert_snprintf ("double %F => 1.234560", "double %%F => %F", d);
assert_snprintf ("double %e => 1.234560e+00", "double %%e => %e", d);
assert_snprintf ("double %E => 1.234560E+00", "double %%E => %E", d);
assert_snprintf ("double %g => 1.23456", "double %%g => %g", d);
assert_snprintf ("double %G => 1.23456", "double %%G => %G", d);
assert_snprintf ("double %a => 0x1.3c0c1fc8f3238p+0", "double %%a => %a", d);
assert_snprintf ("double %A => 0X1.3C0C1FC8F3238P+0", "double %%A => %A", d);

assert_snprintf ("long double %f => 2.718282", "long double %%f => %f", ld);
assert_snprintf ("long double %F => 2.718282", "long double %%F => %F", ld);
assert_snprintf ("long double %e => 2.718282e+00", "long double %%e => %e", ld);
assert_snprintf ("long double %E => 2.718282E+00", "long double %%E => %E", ld);
assert_snprintf ("long double %g => 2.71828", "long double %%g => %g", ld);
assert_snprintf ("long double %G => 2.71828", "long double %%G => %G", ld);
assert_snprintf ("long double %a => 0x1.5bf0a8b145769p+1", "long double %%a => %a", ld);
assert_snprintf ("long double %A => 0X1.5BF0A8B145769P+1", "long double %%A => %A", ld);

assert_snprintf ("long double %Lf => 2.718282", "long double %%Lf => %Lf", ld);
assert_snprintf ("long double %LF => 2.718282", "long double %%LF => %LF", ld);
assert_snprintf ("long double %Le => 2.718282e+00", "long double %%Le => %Le", ld);
assert_snprintf ("long double %LE => 2.718282E+00", "long double %%LE => %LE", ld);
assert_snprintf ("long double %Lg => 2.71828", "long double %%Lg => %Lg", ld);
assert_snprintf ("long double %LG => 2.71828", "long double %%LG => %LG", ld);
assert_snprintf ("long double %La => 0x1.5bf0a8b145769p+1", "long double %%La => %La", ld);
assert_snprintf ("long double %LA => 0X1.5BF0A8B145769P+1", "long double %%LA => %LA", ld);

assert_snprintf ("long double %lf => 2.718282", "long double %%lf => %lf", ld);
assert_snprintf ("long double %lF => 2.718282", "long double %%lF => %lF", ld);
assert_snprintf ("long double %le => 2.718282e+00", "long double %%le => %le", ld);
assert_snprintf ("long double %lE => 2.718282E+00", "long double %%lE => %lE", ld);
assert_snprintf ("long double %lg => 2.71828", "long double %%lg => %lg", ld);
assert_snprintf ("long double %lG => 2.71828", "long double %%lG => %lG", ld);
assert_snprintf ("long double %la => 0x1.5bf0a8b145769p+1", "long double %%la => %la", ld);
assert_snprintf ("long double %lA => 0X1.5BF0A8B145769P+1", "long double %%lA => %lA", ld);

assert_snprintf ("long double %llf => 2.718282", "long double %%llf => %llf", ld);
assert_snprintf ("long double %llF => 2.718282", "long double %%llF => %llF", ld);
assert_snprintf ("long double %lle => 2.718282e+00", "long double %%lle => %lle", ld);
assert_snprintf ("long double %llE => 2.718282E+00", "long double %%llE => %llE", ld);
assert_snprintf ("long double %llg => 2.71828", "long double %%llg => %llg", ld);
assert_snprintf ("long double %llG => 2.71828", "long double %%llG => %llG", ld);
assert_snprintf ("long double %lla => 0x1.5bf0a8b145769p+1", "long double %%lla => %lla", ld);
assert_snprintf ("long double %llA => 0X1.5BF0A8B145769P+1", "long double %%llA => %llA", ld);

assert_snprintf ("long double %Qf => 2.718282", "long double %%Qf => %Qf", ld);
assert_snprintf ("long double %QF => 2.718282", "long double %%QF => %QF", ld);
assert_snprintf ("long double %Qe => 2.718282e+00", "long double %%Qe => %Qe", ld);
assert_snprintf ("long double %QE => 2.718282E+00", "long double %%QE => %QE", ld);
assert_snprintf ("long double %Qg => 2.71828", "long double %%Qg => %Qg", ld);
assert_snprintf ("long double %QG => 2.71828", "long double %%QG => %QG", ld);
assert_snprintf ("long double %Qa => 0x1.5bf0a8b145769p+1", "long double %%Qa => %Qa", ld);
assert_snprintf ("long double %QA => 0X1.5BF0A8B145769P+1", "long double %%QA => %QA", ld);

assert_snprintf ("long double %qf => 2.718282", "long double %%qf => %qf", ld);
assert_snprintf ("long double %qF => 2.718282", "long double %%qF => %qF", ld);
assert_snprintf ("long double %qe => 2.718282e+00", "long double %%qe => %qe", ld);
assert_snprintf ("long double %qE => 2.718282E+00", "long double %%qE => %qE", ld);
assert_snprintf ("long double %qg => 2.71828", "long double %%qg => %qg", ld);
assert_snprintf ("long double %qG => 2.71828", "long double %%qG => %qG", ld);
assert_snprintf ("long double %qa => 0x1.5bf0a8b145769p+1", "long double %%qa => %qa", ld);
assert_snprintf ("long double %qA => 0X1.5BF0A8B145769P+1", "long double %%qA => %qA", ld);

printf ("ok\n");

return 0;
}