Implement floating point type support
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 20 Oct 2022 15:50:42 +0000 (11:50 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 20 Oct 2022 15:50:42 +0000 (11:50 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/side/trace.h
src/test.c
src/tracer.c

index ed039fa77c8b15d5483978dadc5a26449f7a6764..ca1d8c97931374206f47bd43e58e53cfa6287e3f 100644 (file)
@@ -10,6 +10,7 @@
 #include <inttypes.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <math.h>
 #include <side/macros.h>
 
 /* SIDE stands for "Static Instrumentation Dynamically Enabled" */
@@ -36,6 +37,11 @@ enum side_type {
        SIDE_TYPE_S32,
        SIDE_TYPE_S64,
 
+       SIDE_TYPE_FLOAT_BINARY16,
+       SIDE_TYPE_FLOAT_BINARY32,
+       SIDE_TYPE_FLOAT_BINARY64,
+       SIDE_TYPE_FLOAT_BINARY128,
+
        SIDE_TYPE_STRING,
 
        SIDE_TYPE_STRUCT,
@@ -78,6 +84,11 @@ enum side_dynamic_type {
        SIDE_DYNAMIC_TYPE_S32,
        SIDE_DYNAMIC_TYPE_S64,
 
+       SIDE_DYNAMIC_TYPE_FLOAT_BINARY16,
+       SIDE_DYNAMIC_TYPE_FLOAT_BINARY32,
+       SIDE_DYNAMIC_TYPE_FLOAT_BINARY64,
+       SIDE_DYNAMIC_TYPE_FLOAT_BINARY128,
+
        SIDE_DYNAMIC_TYPE_STRING,
 
        SIDE_DYNAMIC_TYPE_STRUCT,
@@ -186,6 +197,19 @@ struct side_arg_dynamic_vec {
                int32_t side_s32;
                int64_t side_s64;
 
+#if __HAVE_FLOAT16
+               _Float16 side_float_binary16;
+#endif
+#if __HAVE_FLOAT32
+               _Float32 side_float_binary32;
+#endif
+#if __HAVE_FLOAT64
+               _Float64 side_float_binary64;
+#endif
+#if __HAVE_FLOAT128
+               _Float128 side_float_binary128;
+#endif
+
                const char *string;
 
                const struct side_arg_dynamic_event_struct *side_dynamic_struct;
@@ -226,6 +250,19 @@ struct side_arg_vec {
                int32_t side_s32;
                int64_t side_s64;
 
+#if __HAVE_FLOAT16
+               _Float16 side_float_binary16;
+#endif
+#if __HAVE_FLOAT32
+               _Float32 side_float_binary32;
+#endif
+#if __HAVE_FLOAT64
+               _Float64 side_float_binary64;
+#endif
+#if __HAVE_FLOAT128
+               _Float128 side_float_binary128;
+#endif
+
                const char *string;
                const struct side_arg_vec_description *side_struct;
                const struct side_arg_vec_description *side_array;
@@ -380,6 +417,11 @@ struct side_tracer_dynamic_vla_visitor_ctx {
 #define side_arg_s16(val)              { .type = SIDE_TYPE_S16, .u = { .side_s16 = (val) } }
 #define side_arg_s32(val)              { .type = SIDE_TYPE_S32, .u = { .side_s32 = (val) } }
 #define side_arg_s64(val)              { .type = SIDE_TYPE_S64, .u = { .side_s64 = (val) } }
+#define side_arg_float_binary16(val)   { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (val) } }
+#define side_arg_float_binary32(val)   { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (val) } }
+#define side_arg_float_binary64(val)   { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (val) } }
+#define side_arg_float_binary128(val)  { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (val) } }
+
 #define side_arg_string(val)           { .type = SIDE_TYPE_STRING, .u = { .string = (val) } }
 #define side_arg_struct(_side_type)    { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } }
 #define side_arg_array(_side_type)     { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } }
@@ -503,6 +545,43 @@ struct side_tracer_dynamic_vla_visitor_ctx {
                }, \
        }
 
+#define side_arg_dynamic_float_binary16(_val, _attr) \
+       { \
+               .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, \
+               .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
+               .attr = _attr, \
+               .u = { \
+                       .side_float_binary16 = (_val), \
+               }, \
+       }
+#define side_arg_dynamic_float_binary32(_val, _attr) \
+       { \
+               .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, \
+               .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
+               .attr = _attr, \
+               .u = { \
+                       .side_float_binary32 = (_val), \
+               }, \
+       }
+#define side_arg_dynamic_float_binary64(_val, _attr) \
+       { \
+               .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, \
+               .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
+               .attr = _attr, \
+               .u = { \
+                       .side_float_binary64 = (_val), \
+               }, \
+       }
+#define side_arg_dynamic_float_binary128(_val, _attr) \
+       { \
+               .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, \
+               .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
+               .attr = _attr, \
+               .u = { \
+                       .side_float_binary128 = (_val), \
+               }, \
+       }
+
 #define side_arg_dynamic_string(_val, _attr) \
        { \
                .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
index 4ff2c8d846110e846d52c3a3d9d5940357853162..97cefaca495fad33b76463c10e7b32b0ac2a32b4 100644 (file)
@@ -854,6 +854,83 @@ void test_variadic_struct_attr(void)
        }
 }
 
+static side_define_event(my_provider_event_float, "myprovider", "myeventfloat", SIDE_LOGLEVEL_DEBUG,
+       side_field_list(
+#if __HAVE_FLOAT16
+               side_field("binary16", SIDE_TYPE_FLOAT_BINARY16, side_attr_list()),
+#endif
+#if __HAVE_FLOAT32
+               side_field("binary32", SIDE_TYPE_FLOAT_BINARY32, side_attr_list()),
+#endif
+#if __HAVE_FLOAT64
+               side_field("binary64", SIDE_TYPE_FLOAT_BINARY64, side_attr_list()),
+#endif
+#if __HAVE_FLOAT128
+               side_field("binary128", SIDE_TYPE_FLOAT_BINARY128, side_attr_list()),
+#endif
+       ),
+       side_attr_list()
+);
+
+static
+void test_float(void)
+{
+       my_provider_event_float.enabled = 1;
+       side_event(&my_provider_event_float,
+               side_arg_list(
+#if __HAVE_FLOAT16
+                       side_arg_float_binary16(1.1),
+#endif
+#if __HAVE_FLOAT32
+                       side_arg_float_binary32(2.2),
+#endif
+#if __HAVE_FLOAT64
+                       side_arg_float_binary64(3.3),
+#endif
+#if __HAVE_FLOAT128
+                       side_arg_float_binary128(4.4),
+#endif
+               )
+       );
+}
+
+static side_define_event_variadic(my_provider_event_variadic_float,
+       "myprovider", "myvariadicfloat", SIDE_LOGLEVEL_DEBUG,
+       side_field_list(),
+       side_attr_list()
+);
+
+static
+void test_variadic_float(void)
+{
+       my_provider_event_variadic_float.enabled = 1;
+       side_event_variadic(&my_provider_event_variadic_float,
+               side_arg_list(),
+               side_arg_list(
+#if __HAVE_FLOAT16
+                       side_arg_dynamic_field("binary16",
+                               side_arg_dynamic_float_binary16(1.1, side_attr_list())
+                       ),
+#endif
+#if __HAVE_FLOAT32
+                       side_arg_dynamic_field("binary32",
+                               side_arg_dynamic_float_binary32(2.2, side_attr_list())
+                       ),
+#endif
+#if __HAVE_FLOAT64
+                       side_arg_dynamic_field("binary64",
+                               side_arg_dynamic_float_binary64(3.3, side_attr_list())
+                       ),
+#endif
+#if __HAVE_FLOAT128
+                       side_arg_dynamic_field("binary128",
+                               side_arg_dynamic_float_binary128(4.4, side_attr_list())
+                       ),
+#endif
+               )
+       );
+}
+
 int main()
 {
        test_fields();
@@ -883,5 +960,7 @@ int main()
        test_variadic_attr();
        test_variadic_vla_attr();
        test_variadic_struct_attr();
+       test_float();
+       test_variadic_float();
        return 0;
 }
index fd8ed5eb7314e0bf04b5e085e7e3d65bfcc5b483..dcdf26fc8204367380e48735e6d845e9733f315e 100644 (file)
@@ -111,6 +111,38 @@ void tracer_print_type(const struct side_type_description *type_desc, const stru
        case SIDE_TYPE_S64:
                printf("%" PRId64, item->u.side_s64);
                break;
+       case SIDE_TYPE_FLOAT_BINARY16:
+#if __HAVE_FLOAT16
+               printf("%g", (double) item->u.side_float_binary16);
+               break;
+#else
+               printf("ERROR: Unsupported binary16 float type\n");
+               abort();
+#endif
+       case SIDE_TYPE_FLOAT_BINARY32:
+#if __HAVE_FLOAT32
+               printf("%g", (double) item->u.side_float_binary32);
+               break;
+#else
+               printf("ERROR: Unsupported binary32 float type\n");
+               abort();
+#endif
+       case SIDE_TYPE_FLOAT_BINARY64:
+#if __HAVE_FLOAT64
+               printf("%g", (double) item->u.side_float_binary64);
+               break;
+#else
+               printf("ERROR: Unsupported binary64 float type\n");
+               abort();
+#endif
+       case SIDE_TYPE_FLOAT_BINARY128:
+#if __HAVE_FLOAT128
+               printf("%Lg", (long double) item->u.side_float_binary128);
+               break;
+#else
+               printf("ERROR: Unsupported binary128 float type\n");
+               abort();
+#endif
        case SIDE_TYPE_STRING:
                printf("\"%s\"", item->u.string);
                break;
@@ -597,6 +629,38 @@ void tracer_print_dynamic(const struct side_arg_dynamic_vec *item)
        case SIDE_DYNAMIC_TYPE_S64:
                printf("%" PRId64, item->u.side_s64);
                break;
+       case SIDE_DYNAMIC_TYPE_FLOAT_BINARY16:
+#if __HAVE_FLOAT16
+               printf("%g", (double) item->u.side_float_binary16);
+               break;
+#else
+               printf("ERROR: Unsupported binary16 float type\n");
+               abort();
+#endif
+       case SIDE_DYNAMIC_TYPE_FLOAT_BINARY32:
+#if __HAVE_FLOAT32
+               printf("%g", (double) item->u.side_float_binary32);
+               break;
+#else
+               printf("ERROR: Unsupported binary32 float type\n");
+               abort();
+#endif
+       case SIDE_DYNAMIC_TYPE_FLOAT_BINARY64:
+#if __HAVE_FLOAT64
+               printf("%g", (double) item->u.side_float_binary64);
+               break;
+#else
+               printf("ERROR: Unsupported binary64 float type\n");
+               abort();
+#endif
+       case SIDE_DYNAMIC_TYPE_FLOAT_BINARY128:
+#if __HAVE_FLOAT128
+               printf("%Lg", (long double) item->u.side_float_binary128);
+               break;
+#else
+               printf("ERROR: Unsupported binary128 float type\n");
+               abort();
+#endif
        case SIDE_DYNAMIC_TYPE_STRING:
                printf("\"%s\"", item->u.string);
                break;
This page took 0.032796 seconds and 4 git commands to generate.