diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..01c4107 --- /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}) + + +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}) diff --git a/fma/fmaqApproxM.c b/fma/fmaqApproxM.c new file mode 100644 index 0000000..f9b4180 --- /dev/null +++ b/fma/fmaqApproxM.c @@ -0,0 +1,24 @@ +#include +#include "fmaqApproxM.h" + +__float128 fmaqApprox(__float128 x, __float128 y, __float128 z) { + return fmal(x, y, 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..d28ffc5 --- /dev/null +++ b/fma/fmaqApproxM.h @@ -0,0 +1,17 @@ +#pragma once + +#if defined(__cplusplus) +extern "C" { +#endif + +#define __float128 long double + +__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 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" 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; }; /** 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