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

Add of a Vector Interface to InterFLOP #1

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
42 changes: 42 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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_OBJECTS:interflop_stdlib_c> $<TARGET_OBJECTS:interflop_stdlib_cxx>)
target_link_options (interflop_stdlib PRIVATE ${CRT_LINK_OPTIONS})
target_link_libraries (interflop_stdlib ${CRT_LINK_LIBRARIES})
24 changes: 24 additions & 0 deletions fma/fmaqApproxM.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <math.h>
#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;
}
17 changes: 17 additions & 0 deletions fma/fmaqApproxM.h
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions fma/interflop_fma.cxx
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 4 additions & 0 deletions interflop.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern "C" {
#endif

#include "interflop/interflop_stdlib.h"
#include "interflop/interflop_vinterface.h"

/* interflop backend interface */

Expand Down Expand Up @@ -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;
};

/**
Expand Down
33 changes: 33 additions & 0 deletions interflop_vinterface.h
Original file line number Diff line number Diff line change
@@ -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