From: compudj Date: Tue, 23 Aug 2005 20:41:21 +0000 (+0000) Subject: float handling X-Git-Tag: v0.12.20~2425 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=3b10b765f2ed7b5758cf37c4dea8cb511edd289a;p=lttv.git float handling git-svn-id: http://ltt.polymtl.ca/svn@1064 04897980-b3bd-0310-b5e0-8ef037075253 --- diff --git a/ltt/branches/poly/ltt/event.c b/ltt/branches/poly/ltt/event.c index 2827cff9..3f8dab9c 100644 --- a/ltt/branches/poly/ltt/event.c +++ b/ltt/branches/poly/ltt/event.c @@ -614,35 +614,29 @@ gint64 ltt_event_get_long_int(LttEvent *e, LttField *f) float ltt_event_get_float(LttEvent *e, LttField *f) { - gboolean reverse_byte_order = LTT_GET_BO(e->tracefile); + g_assert(LTT_HAS_FLOAT(e->tracefile)); + gboolean reverse_byte_order = LTT_GET_FLOAT_BO(e->tracefile); g_assert(f->field_type->type_class == LTT_FLOAT && f->field_size == 4); if(reverse_byte_order == 0) return *(float *)(e->data + f->offset_root); else{ -// guint32 aInt; void *ptr = e->data + f->offset_root; -// memcpy((void*)&aInt, e->data + f->offset_root, 4); -// aInt = bswap_32(); -// return ((float)aInt); return *(float*)bswap_32(*(guint32*)ptr); } } double ltt_event_get_double(LttEvent *e, LttField *f) { - gboolean reverse_byte_order = LTT_GET_BO(e->tracefile); + g_assert(LTT_HAS_FLOAT(e->tracefile)); + gboolean reverse_byte_order = LTT_GET_FLOAT_BO(e->tracefile); g_assert(f->field_type->type_class == LTT_FLOAT && f->field_size == 8); if(reverse_byte_order == 0) return *(double *)(e->data + f->offset_root); - else{ + else { void *ptr = e->data + f->offset_root; return *(double*)bswap_64(*(guint64*)ptr); - //guint64 aInt; - //memcpy((void*)&aInt, e->data + f->offset_root, 8); - //aInt = ___swab64(aInt); - //return ((double)aInt); } } diff --git a/ltt/branches/poly/ltt/ltt-private.h b/ltt/branches/poly/ltt/ltt-private.h index 929e54ae..25f2d824 100644 --- a/ltt/branches/poly/ltt/ltt-private.h +++ b/ltt/branches/poly/ltt/ltt-private.h @@ -22,6 +22,7 @@ #include #include #include +#include #ifndef max @@ -38,6 +39,14 @@ /* Hardcoded facilities */ #define LTT_FACILITY_CORE 0 + +/* Byte ordering */ +#define LTT_GET_BO(t) ((t)->reverse_bo) + +#define LTT_HAS_FLOAT(t) ((t)->float_word_order!=0) +#define LTT_GET_FLOAT_BO(t) \ + (((t)->float_word_order==__BYTE_ORDER)?0:1) + /* Hardcoded core events */ enum ltt_core_events { @@ -317,6 +326,7 @@ struct _LttTracefile{ //unsigned block_size; //block_size unsigned int num_blocks; //number of blocks in the file gboolean reverse_bo; //must we reverse byte order ? + gboolean float_word_order; //what is the byte order of floats ? /* Current event */ LttEvent event; //Event currently accessible in the trace @@ -391,7 +401,5 @@ struct _LttSystemDescription { //#define EVENT_ID_SIZE sizeof(guint16) //#define EVENT_HEADER_SIZE (TIMESTAMP_SIZE + EVENT_ID_SIZE) -#define LTT_GET_BO(t) ((t)->reverse_bo) - #endif /* LTT_PRIVATE_H */