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);
}
}
#include <glib.h>
#include <sys/types.h>
#include <ltt/ltt.h>
+#include <endian.h>
#ifndef max
/* 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 {
//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
//#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 */