String type: complete migration to bitwise position
[babeltrace.git] / formats / ctf / types / float.c
index eb0291ec6eca080b11cfd42ee40efd7df78d9e1d..09a20e3ab991b487a4a1f7e3d8f164023143eca4 100644 (file)
  * Reference: ISO C99 standard 5.2.4
  */
 
-#include <ctf/ctf-types.h>
+#include <babeltrace/ctf/types.h>
 #include <glib.h>
 #include <float.h>     /* C99 floating point definitions */
+#include <limits.h>    /* C99 limits */
 #include <endian.h>
 
 /*
@@ -71,8 +72,10 @@ struct pos_len {
        size_t sign_start, exp_start, mantissa_start, len;
 };
 
-void ctf_float_copy(unsigned char *destp, const struct ctf_float *dest,
-                   const unsigned char *src, const struct ctf_float *src)
+/* TODO */
+
+void ctf_float_copy(unsigned char *destp, const struct type_class_float *dest,
+                   const unsigned char *src, const struct type_class_float *src)
 {
        struct pos_len destpos, srcpos;
        union {
@@ -80,8 +83,8 @@ void ctf_float_copy(unsigned char *destp, const struct ctf_float *dest,
                long long s;
        } tmp;
 
-       destpos.len = dest.exp_len + dest.mantissa_len;
-       if (dest.byte_order == LITTLE_ENDIAN) {
+       destpos.len = dest->exp_len + dest->mantissa_len;
+       if (dest->byte_order == LITTLE_ENDIAN) {
                destpos.sign_start = destpos.len - 1;
                destpos.exp_start = destpos.sign_start - dest->exp_len;
                destpos.mantissa_start = 0;
@@ -91,8 +94,8 @@ void ctf_float_copy(unsigned char *destp, const struct ctf_float *dest,
                destpos.mantissa_start = destpos.exp_start + dest->exp_len;
        }
 
-       srcpos.len = src.exp_len + src.mantissa_len;
-       if (src.byte_order == LITTLE_ENDIAN) {
+       srcpos.len = src->exp_len + src->mantissa_len;
+       if (src->byte_order == LITTLE_ENDIAN) {
                srcpos.sign_start = srcpos.len - 1;
                srcpos.exp_start = srcpos.sign_start - src->exp_len;
                srcpos.mantissa_start = 0;
@@ -103,25 +106,27 @@ void ctf_float_copy(unsigned char *destp, const struct ctf_float *dest,
        }
 
        /* sign */
-       tmp.u = bitfield_unsigned_read(ptr, srcpos.sign_start, 1,
-                                      src->byte_order);
-       bitfield_unsigned_write(&u.bits, destpos.sign_start, 1,
-                               dest->byte_order, tmp.u);
+       tmp.u = ctf_bitfield_unsigned_read(ptr, srcpos.sign_start, 1,
+                                          src->byte_order);
+       ctf_bitfield_unsigned_write(&u.bits, destpos.sign_start, 1,
+                                   dest->byte_order, tmp.u);
 
        /* mantissa (without leading 1). No sign extend. */
-       tmp.u = bitfield_unsigned_read(ptr, srcpos.mantissa_start,
-                                      src->mantissa_len - 1, src->byte_order);
-       bitfield_unsigned_write(&u.bits, destpos.mantissa_start,
-                               dest->mantissa_len - 1, dest->byte_order, tmp.u);
+       tmp.u = ctf_bitfield_unsigned_read(ptr, srcpos.mantissa_start,
+                                          src->mantissa_len - 1,
+                                          src->byte_order);
+       ctf_bitfield_unsigned_write(&u.bits, destpos.mantissa_start,
+                                   dest->mantissa_len - 1, dest->byte_order,
+                                   tmp.u);
 
        /* exponent, with sign-extend. */
-       tmp.s = bitfield_signed_read(ptr, srcpos.exp_start, src->exp_len,
-                                    src->byte_order);
-       bitfield_signed_write(&u.bits, destpos.exp_start, dest->exp_len,
-                             dest->byte_order, tmp.s);
+       tmp.s = ctf_bitfield_signed_read(ptr, srcpos.exp_start, src->exp_len,
+                                        src->byte_order);
+       ctf_bitfield_signed_write(&u.bits, destpos.exp_start, dest->exp_len,
+                                 dest->byte_order, tmp.s);
 }
 
-double ctf_double_read(const unsigned char *ptr, const struct ctf_float *src)
+double ctf_double_read(const unsigned char *ptr, const struct type_class_float *src)
 {
        union doubleIEEE754 u;
        struct ctf_float dest = {
@@ -130,11 +135,11 @@ double ctf_double_read(const unsigned char *ptr, const struct ctf_float *src)
                .byte_order = BYTE_ORDER,
        };
 
-       float_copy(&u.bits, &dest, ptr, src);
+       ctf_float_copy(&u.bits, &dest, ptr, src);
        return u.v;
 }
 
-size_t ctf_double_write(unsigned char *ptr, const struct ctf_float *dest,
+size_t ctf_double_write(unsigned char *ptr, const struct type_class_float *dest,
                        double v)
 {
        union doubleIEEE754 u;
@@ -147,13 +152,13 @@ size_t ctf_double_write(unsigned char *ptr, const struct ctf_float *dest,
        if (!ptr)
                goto end;
        u.v = v;
-       float_copy(ptr, dest, &u.bits, &src);
+       ctf_float_copy(ptr, dest, &u.bits, &src);
 end:
        return len;
 }
 
 long double ctf_ldouble_read(const unsigned char *ptr,
-                            const struct ctf_float *src)
+                            const struct type_class_float *src)
 {
        union ldoubleIEEE754 u;
        struct ctf_float dest = {
@@ -162,11 +167,11 @@ long double ctf_ldouble_read(const unsigned char *ptr,
                .byte_order = BYTE_ORDER,
        };
 
-       float_copy(&u.bits, &dest, ptr, src);
+       ctf_float_copy(&u.bits, &dest, ptr, src);
        return u.v;
 }
 
-size_t ctf_ldouble_write(unsigned char *ptr, const struct ctf_float *dest,
+size_t ctf_ldouble_write(unsigned char *ptr, const struct type_class_float *dest,
                         long double v)
 {
        union ldoubleIEEE754 u;
@@ -179,7 +184,7 @@ size_t ctf_ldouble_write(unsigned char *ptr, const struct ctf_float *dest,
        if (!ptr)
                goto end;
        u.v = v;
-       float_copy(ptr, dest, &u.bits, &src);
+       ctf_float_copy(ptr, dest, &u.bits, &src);
 end:
        return len;
 }
This page took 0.026279 seconds and 4 git commands to generate.