From 57f961b3965e4a3df7e5a2ccbd65b41f552b3c2b Mon Sep 17 00:00:00 2001 From: a-hamitouche Date: Mon, 2 Oct 2023 13:46:11 +0200 Subject: [PATCH 1/8] Adding fma support for long double type (when __float128 is'nt available) --- fma/fmaqApproxM.c | 24 ++++++++++++++++++++++++ fma/fmaqApproxM.h | 15 +++++++++++++++ fma/interflop_fma.cxx | 4 ++++ 3 files changed, 43 insertions(+) create mode 100644 fma/fmaqApproxM.c create mode 100644 fma/fmaqApproxM.h diff --git a/fma/fmaqApproxM.c b/fma/fmaqApproxM.c new file mode 100644 index 0000000..eea1cef --- /dev/null +++ b/fma/fmaqApproxM.c @@ -0,0 +1,24 @@ +#include +#include "fmaqApprox.h" + +__float128 fmaqApprox(__float128 x, __float128 y, __float128 z) { + +} + +double fmadApprox(double x, double y, double z) { + long double x128 = (long double) x; + long double y128 = (long double) y; + long double z128 = (long double) z; + + long double res = fmal(x128, y128, z128); + return (double)res; +} + +float fmafApprox(float x, float y, float z) { + long double x128 = (long double) x; + long double y128 = (long double) y; + long double z128 = (long double) z; + + long double res = (long double)fmal (x128, y128, z128); + return (float)res; +} diff --git a/fma/fmaqApproxM.h b/fma/fmaqApproxM.h new file mode 100644 index 0000000..1214da6 --- /dev/null +++ b/fma/fmaqApproxM.h @@ -0,0 +1,15 @@ +#pragma once + +#if defined(__cplusplus) +extern "C" { +#endif + +__float128 fmaqApprox(__float128 x, __float128 y, __float128 z); + +double fmadApprox(double x, double y, double z); + +float fmafApprox(float x, float y, float z); + +#if defined(__cplusplus) +} +#endif \ No newline at end of file diff --git a/fma/interflop_fma.cxx b/fma/interflop_fma.cxx index 63224b2..87305ad 100644 --- a/fma/interflop_fma.cxx +++ b/fma/interflop_fma.cxx @@ -1,5 +1,9 @@ #include "interflop_fma.h" +#ifdef PIN_CRT +#include "fmaqApproxM.h" +#else #include "fmaqApprox.h" +#endif #if HAVE_FMA_INTRINSIC #include "vr_fma.hxx" From 283225a813269414430092c4e1cdf15c36e8eea9 Mon Sep 17 00:00:00 2001 From: a-hamitouche Date: Mon, 2 Oct 2023 13:47:05 +0200 Subject: [PATCH 2/8] feat: adding vectoriel interface --- interflop_vinterface.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 interflop_vinterface.h diff --git a/interflop_vinterface.h b/interflop_vinterface.h new file mode 100644 index 0000000..845052c --- /dev/null +++ b/interflop_vinterface.h @@ -0,0 +1,33 @@ +#ifndef __INTERFLOP_VINTERFACE_H__ +#define __INTERFLOP_VINTERFACE_H__ + +struct interflop_vector_op_interface_t +{ + void (*op_vector_float_1) (float *a, float *b, float *c, void *context); + void (*op_vector_float_4) (float *a, float *b, float *c, void *context); + void (*op_vector_float_8) (float *a, float *b, float *c, void *context); + void (*op_vector_float_16) (float *a, float *b, float *c, void *context); + + void (*op_vector_double_1) (double *a, double *b, double *c, void *context); + void (*op_vector_double_2) (double *a, double *b, double *c, void *context); + void (*op_vector_double_4) (double *a, double *b, double *c, void *context); + void (*op_vector_double_8) (double *a, double *b, double *c, void *context); +}; + +struct interflop_vector_type_t +{ + struct interflop_vector_op_interface_t add; + struct interflop_vector_op_interface_t sub; + struct interflop_vector_op_interface_t mul; + struct interflop_vector_op_interface_t div; +}; + +struct interflop_backend_vector_interface_t +{ + struct interflop_vector_type_t scalar; + struct interflop_vector_type_t vector128; + struct interflop_vector_type_t vector256; + struct interflop_vector_type_t vector512; +}; + +#endif \ No newline at end of file From 6085741464a65d40e7d7f06c099d73680d4e6451 Mon Sep 17 00:00:00 2001 From: a-hamitouche Date: Mon, 2 Oct 2023 13:47:31 +0200 Subject: [PATCH 3/8] feat: adding vectoriel interface to interflop interface --- interflop.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/interflop.h b/interflop.h index 2a364bf..52fb92c 100644 --- a/interflop.h +++ b/interflop.h @@ -8,6 +8,7 @@ extern "C" { #endif #include "interflop/interflop_stdlib.h" +#include "interflop/interflop_vinterface.h" /* interflop backend interface */ @@ -115,6 +116,9 @@ struct interflop_backend_interface_t { /* interflop_finalize: called at the end of the instrumented program * execution */ void (*interflop_finalize)(void *context); + + int enabled_vbackend; + struct interflop_backend_vector_interface_t vbackend; }; /** From ffd55c54a38284c235f8e93e6c7c5f438d9e1c7f Mon Sep 17 00:00:00 2001 From: a-hamitouche Date: Mon, 2 Oct 2023 13:48:32 +0200 Subject: [PATCH 4/8] build: adding cmake file to build shared object with input option for pintools --- CMakeLists.txt | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0706708 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,42 @@ +project("Interflop_stdlib") + +# fmaqApprox.c was removed because of quad implementation depending on compiler runtime. +# PinCRT doesn't support this part of GCC C library +# usage of fmaq for single and double precision was replaced by fmal (lib math) +set (INTERFLOP_STDLIB_C_SRC + # FMA + "fma/fmaqApproxM.c" + # # HASHMAP + "hashmap/vfc_hashmap.c" + # # IOSTREAM + "iostream/logger.c" + # PRNG + "prng/tinymt64.c" + # # RNG + "rng/splitmix64.c" + "rng/vfc_rng.c" + "rng/xoroshiro128.c" + "interflop_stdlib.c" +) + +set (INTERFLOP_STDLIB_CXX_SRC + # FMA + "fma/interflop_fma.cxx" + # PRNG + "prng/xoshiro.cxx" +) + +add_library(interflop_stdlib_c OBJECT ${INTERFLOP_STDLIB_C_SRC}) +target_compile_definitions(interflop_stdlib_c PRIVATE ${CRT_COMPILE_DEFINITIONS}) +target_compile_options (interflop_stdlib_c PRIVATE ${CRT_PREPROCESS_OPTIONS} ${CRT_COMPILE_OPTIONS}) + + +add_library(interflop_stdlib_cxx OBJECT ${INTERFLOP_STDLIB_CXX_SRC}) +target_compile_definitions(interflop_stdlib_cxx PRIVATE ${CRT_COMPILE_DEFINITIONS}) +target_compile_options (interflop_stdlib_cxx PRIVATE ${CRT_PREPROCESS_OPTIONS} ${CRT_COMPILE_OPTIONS} ${CRT_CXX_COMPILE_OPTIONS}) + + + +add_library (interflop_stdlib SHARED $ $) +target_link_options (interflop_stdlib PRIVATE ${CRT_LINK_OPTIONS}) +target_link_libraries (interflop_stdlib ${CRT_LINK_LIBRARIES}) \ No newline at end of file From 6c7c86fadb31208079270559191aabd841b686b9 Mon Sep 17 00:00:00 2001 From: a-hamitouche Date: Mon, 2 Oct 2023 13:49:50 +0200 Subject: [PATCH 5/8] fix: replacing __float128 by long double --- common/float_struct.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/float_struct.h b/common/float_struct.h index 8eb7ee7..536d66b 100644 --- a/common/float_struct.h +++ b/common/float_struct.h @@ -12,6 +12,8 @@ #error "No way!" #endif +#define __float128 long double + /* Main union type we use to manipulate the floating-point type. */ typedef union { From 1059f8a07232e066ff1c2cb4490adf3e83b96822 Mon Sep 17 00:00:00 2001 From: Akli Hamitouche Date: Mon, 27 Nov 2023 19:28:37 +0100 Subject: [PATCH 6/8] fix: moving float128 definition as long double into libmath based fmaqApproxM implementation --- common/float_struct.h | 2 -- fma/fmaqApproxM.c | 2 +- fma/fmaqApproxM.h | 4 +++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/float_struct.h b/common/float_struct.h index 536d66b..8eb7ee7 100644 --- a/common/float_struct.h +++ b/common/float_struct.h @@ -12,8 +12,6 @@ #error "No way!" #endif -#define __float128 long double - /* Main union type we use to manipulate the floating-point type. */ typedef union { diff --git a/fma/fmaqApproxM.c b/fma/fmaqApproxM.c index eea1cef..5faa6bc 100644 --- a/fma/fmaqApproxM.c +++ b/fma/fmaqApproxM.c @@ -2,7 +2,7 @@ #include "fmaqApprox.h" __float128 fmaqApprox(__float128 x, __float128 y, __float128 z) { - + return fmal(x, y, z); } double fmadApprox(double x, double y, double z) { diff --git a/fma/fmaqApproxM.h b/fma/fmaqApproxM.h index 1214da6..d28ffc5 100644 --- a/fma/fmaqApproxM.h +++ b/fma/fmaqApproxM.h @@ -4,6 +4,8 @@ extern "C" { #endif +#define __float128 long double + __float128 fmaqApprox(__float128 x, __float128 y, __float128 z); double fmadApprox(double x, double y, double z); @@ -12,4 +14,4 @@ float fmafApprox(float x, float y, float z); #if defined(__cplusplus) } -#endif \ No newline at end of file +#endif From 50458762f5c6551009a58996b209628392af7fbe Mon Sep 17 00:00:00 2001 From: Akli Hamitouche Date: Thu, 30 Nov 2023 23:39:19 +0100 Subject: [PATCH 7/8] fix: include right header in fmaqApproxM.c --- fma/fmaqApproxM.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fma/fmaqApproxM.c b/fma/fmaqApproxM.c index 5faa6bc..f9b4180 100644 --- a/fma/fmaqApproxM.c +++ b/fma/fmaqApproxM.c @@ -1,5 +1,5 @@ #include -#include "fmaqApprox.h" +#include "fmaqApproxM.h" __float128 fmaqApprox(__float128 x, __float128 y, __float128 z) { return fmal(x, y, z); From fc7ebdda53497624a8c73811187b70bf9080a8e9 Mon Sep 17 00:00:00 2001 From: Akli Hamitouche Date: Tue, 16 Jan 2024 17:13:59 +0100 Subject: [PATCH 8/8] fix: change output directory for generated lib --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0706708..01c4107 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,7 @@ target_compile_definitions(interflop_stdlib_cxx PRIVATE ${CRT_COMPILE_DEFINITIO target_compile_options (interflop_stdlib_cxx PRIVATE ${CRT_PREPROCESS_OPTIONS} ${CRT_COMPILE_OPTIONS} ${CRT_CXX_COMPILE_OPTIONS}) - +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY}) add_library (interflop_stdlib SHARED $ $) target_link_options (interflop_stdlib PRIVATE ${CRT_LINK_OPTIONS}) -target_link_libraries (interflop_stdlib ${CRT_LINK_LIBRARIES}) \ No newline at end of file +target_link_libraries (interflop_stdlib ${CRT_LINK_LIBRARIES})