Extend floating point support
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 27 Sep 2010 21:08:54 +0000 (17:08 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 27 Sep 2010 21:08:54 +0000 (17:08 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/ctf/align.h
include/ctf/bitfield.h
include/ctf/ctf-types-bitfield.h
include/ctf/ctf-types.h
lib/types/enum.c
lib/types/float.c
lib/types/integer.c
lib/types/string.c
lib/types/struct.c
lib/types/types.c
tests/test-bitfield.c

index ad4a0134fb7f45c0b28a659bac718da260185ec0..5adac7f3007306cb4d5774ce7c253f33e679b717 100644 (file)
@@ -1,6 +1,26 @@
 #ifndef _CTF_ALIGN_H
 #define _CTF_ALIGN_H
 
+/*
+ * align.h - alignment header
+ *
+ * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
 #include <ctf/compiler.h>
 
 #define ALIGN(x, a)            __ALIGN_MASK(x, (typeof(x))(a) - 1)
index ba1532512af1cba6efc6c2e18ffa88378ae98a02..e1eb3abc65a320ba3a70ae67c192631b877a1b21 100644 (file)
@@ -205,7 +205,7 @@ do {                                                                        \
        _ctf_bitfield_write_le(ptr, _start, _length, _v)
        
 #define ctf_bitfield_write_be(ptr, _start, _length, _v)                        \
-       _ctf_bitfield_write_be((uint8_t *) (ptr), _start, _length, _v)
+       _ctf_bitfield_write_be((unsigned char *) (ptr), _start, _length, _v)
 
 #elif (BYTE_ORDER == BIG_ENDIAN)
 
@@ -213,7 +213,7 @@ do {                                                                        \
        _ctf_bitfield_write_be(ptr, _start, _length, _v)
 
 #define ctf_bitfield_write_le(ptr, _start, _length, _v)                        \
-       _ctf_bitfield_write_le((uint8_t *) (ptr), _start, _length, _v)
+       _ctf_bitfield_write_le((unsigned char *) (ptr), _start, _length, _v)
        
 #define ctf_bitfield_write_be(ptr, _start, _length, _v)                        \
        _ctf_bitfield_write_be(ptr, _start, _length, _v)
@@ -368,7 +368,7 @@ do {                                                                        \
        _ctf_bitfield_read_le(ptr, _start, _length, _vptr)
        
 #define ctf_bitfield_read_be(ptr, _start, _length, _vptr)              \
-       _ctf_bitfield_read_be((const uint8_t *) (ptr), _start, _length, _vptr)
+       _ctf_bitfield_read_be((const unsigned char *) (ptr), _start, _length, _vptr)
 
 #elif (BYTE_ORDER == BIG_ENDIAN)
 
@@ -376,7 +376,7 @@ do {                                                                        \
        _ctf_bitfield_read_be(ptr, _start, _length, _vptr)
 
 #define ctf_bitfield_read_le(ptr, _start, _length, _vptr)              \
-       _ctf_bitfield_read_le((const uint8_t *) (ptr), _start, _length, _vptr)
+       _ctf_bitfield_read_le((const unsigned char *) (ptr), _start, _length, _vptr)
        
 #define ctf_bitfield_read_be(ptr, _start, _length, _vptr)              \
        _ctf_bitfield_read_be(ptr, _start, _length, _vptr)
index a6764bf5bdb72ab1f94dd5d9f050870dbfa1c8ce..82ee1120192858cd3d10ed134e898ee1cd6d0d9f 100644 (file)
@@ -6,16 +6,28 @@
  *
  * Bitfields read/write functions.
  *
- * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * Dual LGPL v2.1/GPL v2 license.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <ctf/bitfield.h>
 #include <endian.h>
 
 static inline
-uint64_t ctf_bitfield_unsigned_read(const uint8_t *ptr,
+uint64_t ctf_bitfield_unsigned_read(const unsigned char *ptr,
                                    unsigned long start, unsigned long len,
                                    int byte_order)
 {
@@ -29,7 +41,7 @@ uint64_t ctf_bitfield_unsigned_read(const uint8_t *ptr,
 }
 
 static inline
-int64_t ctf_bitfield_signed_read(const uint8_t *ptr,
+int64_t ctf_bitfield_signed_read(const unsigned char *ptr,
                                 unsigned long start, unsigned long len,
                                 int byte_order)
 {
@@ -43,7 +55,7 @@ int64_t ctf_bitfield_signed_read(const uint8_t *ptr,
 }
 
 static inline
-size_t ctf_bitfield_unsigned_write(uint8_t *ptr,
+size_t ctf_bitfield_unsigned_write(unsigned char *ptr,
                                   unsigned long start, unsigned long len,
                                   int byte_order, uint64_t v)
 {
@@ -58,7 +70,7 @@ end:
 }
 
 static inline
-size_t ctf_bitfield_signed_write(uint8_t *ptr,
+size_t ctf_bitfield_signed_write(unsigned char *ptr,
                                 unsigned long start, unsigned long len,
                                 int byte_order, int64_t v)
 {
index 79a20213aa238d96cc52043fa3ede94a93e6e275..25ec34666c3c8c957a1dfd70e3136c45d453c9f8 100644 (file)
@@ -6,24 +6,39 @@
  *
  * Type header
  *
- * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * Dual LGPL v2.1/GPL v2 license.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <stdint.h>
 #include <glib.h>
 
 /*
- * All write primitives,(as well as read for dynamically sized entities, can
+ * IMPORTANT: All lengths (len) and offsets (start, end) are expressed in bits,
+ *            *not* in bytes.
+ *
+ * All write primitives, as well as read for dynamically sized entities, can
  * receive a NULL ptr/dest parameter. In this case, no write is performed, but
  * the size is returned.
  */
 
-uint64_t ctf_uint_read(const uint8_t *ptr, int byte_order, size_t len);
-int64_t ctf_int_read(const uint8_t *ptr, int byte_order, size_t len);
-size_t ctf_uint_write(uint8_t *ptr, int byte_order, size_t len, uint64_t v);
-size_t ctf_int_write(uint8_t *ptr, int byte_order, size_t len, int64_t v);
+uint64_t ctf_uint_read(const unsigned char *ptr, int byte_order, size_t len);
+int64_t ctf_int_read(const unsigned char *ptr, int byte_order, size_t len);
+size_t ctf_uint_write(unsigned char *ptr, int byte_order, size_t len, uint64_t v);
+size_t ctf_int_write(unsigned char *ptr, int byte_order, size_t len, int64_t v);
 
 /*
  * ctf-types-bitfield.h declares:
@@ -35,10 +50,22 @@ size_t ctf_int_write(uint8_t *ptr, int byte_order, size_t len, int64_t v);
  */
 #include <ctf/ctf-types-bitfield.h>
 
-double ctf_float_read(const uint8_t *ptr, int byte_order, size_t len);
-size_t ctf_float_write(uint8_t *ptr, int byte_order, size_t len, double v);
+double ctf_double_read(const unsigned char *ptr, const struct ctf_float *src)
+size_t ctf_double_write(unsigned char *ptr, const struct ctf_float *dest,
+                       double v);
+long double ctf_ldouble_read(const unsigned char *ptr,
+                            const struct ctf_float *src)
+size_t ctf_ldouble_write(unsigned char *ptr, const struct ctf_float *dest,
+                        long double v);
+struct ctf_float {
+       size_t exp_len;
+       size_t mantissa_len;    /* Including sign bit */
+       int byte_order;
+};
+void ctf_float_copy(unsigned char *destp, const struct ctf_float *dest,
+                   const unsigned char *srcp, const struct ctf_float *src);
 
-size_t ctf_string_copy(char *dest, const char *src);
+size_t ctf_string_copy(unsigned char *dest, const unsigned char *src);
 
 /*
  * A GQuark can be translated to/from strings with g_quark_from_string() and
index cae154784070e20b0dbba6122d2d7ff4ff50e4a0..0117dd32721f7f2945b699054e793ec17e57749d 100644 (file)
@@ -3,9 +3,21 @@
  *
  * Enumeration mapping strings (quarks) from/to integers.
  *
- * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * Dual LGPL v2.1/GPL v2 license.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <ctf/ctf-types.h>
index e3311cd7b981fefb9f1d2bccecf8f8ed446db968..1f33f8078003b8cabdd0510e178aba0e3a6409f6 100644 (file)
@@ -3,17 +3,36 @@
  *
  * Floating point read/write functions.
  *
- * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * Reference: ISO C99 standard 5.2.4
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  *
- * Dual LGPL v2.1/GPL v2 license.
+ * Reference: ISO C99 standard 5.2.4
  */
 
 #include <ctf/ctf-types.h>
 #include <glib.h>
+#include <float.h>     /* C99 floating point definitions */
 #include <endian.h>
 
+/*
+ * This library is limited to binary representation of floating point values.
+ * Sign-extension of the exponents is assumed to keep the NaN, +inf, -inf
+ * values, but this should be double-checked (TODO).
+ */
+
 /*
  * Aliasing float/double and unsigned long is not strictly permitted by strict
  * aliasing, but in practice type prunning is well supported, and this permits
 #define HAS_TYPE_PRUNING
 #endif
 
-union floatIEEE754 {
-       float v;
-#ifdef HAS_TYPE_PRUNING
-       unsigned long bits[(sizeof(float) + sizeof(unsigned long) - 1) / sizeof(unsigned long)];
-#else
-       unsigned char bits[sizeof(float)];
+#if (FLT_RADIX != 2)
+
+#error "Unsupported floating point radix"
+
 #endif
-};
 
 union doubleIEEE754 {
        double v;
@@ -42,179 +58,125 @@ union doubleIEEE754 {
 #endif
 };
 
-double float_read(const uint8_t *ptr, size_t len, int byte_order)
+union ldoubleIEEE754 {
+       long double v;
+#ifdef HAS_TYPE_PRUNING
+       unsigned long bits[(sizeof(long double) + sizeof(unsigned long) - 1) / sizeof(unsigned long)];
+#else
+       unsigned char bits[sizeof(long double)];
+#endif
+};
+
+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)
 {
-       int rbo = (byte_order != __FLOAT_WORD_ORDER);   /* reverse byte order */
-
-       switch (len) {
-       case 32:
-       {
-               union floatIEEE754 u;
-               uint32_t tmp;
-
-               if (!rbo)
-                       return (double) *(const float *) ptr;
-               /*
-                * Need to reverse byte order. Read the opposite from our
-                * architecture.
-                */
-               if (__FLOAT_WORD_ORDER == LITTLE_ENDIAN) {
-                       /* Read big endian */
-                       tmp = bitfield_unsigned_read(ptr, 0, 1, BIG_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 31, 1, LITTLE_ENDIAN,
-                                               tmp);
-                       tmp = bitfield_unsigned_read(ptr, 1, 8, BIG_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 23, 8, LITTLE_ENDIAN,
-                                               tmp);
-                       tmp = bitfield_unsigned_read(ptr, 9, 23, BIG_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 0, 23, LITTLE_ENDIAN,
-                                               tmp);
-               } else {
-                       /* Read little endian */
-                       tmp = bitfield_unsigned_read(ptr, 31, 1, LITTLE_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 0, 1, BIG_ENDIAN,
-                                               tmp);
-                       tmp = bitfield_unsigned_read(ptr, 23, 8, LITTLE_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 1, 8, BIG_ENDIAN,
-                                               tmp);
-                       tmp = bitfield_unsigned_read(ptr, 0, 23, LITTLE_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 9, 23, BIG_ENDIAN,
-                                               tmp);
-               }
-               return (double) u.v;
-       }
-       case 64:
-       {
-               union doubleIEEE754 u;
-               uint64_t tmp;
-
-               if (!rbo)
-                       return (double) *(const double *) ptr;
-               /*
-                * Need to reverse byte order. Read the opposite from our
-                * architecture.
-                */
-               if (__FLOAT_WORD_ORDER == LITTLE_ENDIAN) {
-                       /* Read big endian */
-                       tmp = bitfield_unsigned_read(ptr, 0, 1, BIG_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 63, 1, LITTLE_ENDIAN,
-                                               tmp);
-                       tmp = bitfield_unsigned_read(ptr, 1, 11, BIG_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 52, 11, LITTLE_ENDIAN,
-                                               tmp);
-                       tmp = bitfield_unsigned_read(ptr, 12, 52, BIG_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 0, 52, LITTLE_ENDIAN,
-                                               tmp);
-               } else {
-                       /* Read little endian */
-                       tmp = bitfield_unsigned_read(ptr, 63, 1, LITTLE_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 0, 1, BIG_ENDIAN,
-                                               tmp);
-                       tmp = bitfield_unsigned_read(ptr, 52, 11, LITTLE_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 1, 11, BIG_ENDIAN,
-                                               tmp);
-                       tmp = bitfield_unsigned_read(ptr, 0, 52, LITTLE_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 12, 52, BIG_ENDIAN,
-                                               tmp);
-               }
-               return u.v;
+       unsigned long long tmp;
+       struct pos_len destpos, srcpos;
+
+       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;
+       } else {
+               destpos.sign_start = 0;
+               destpos.exp_start = 1;
+               destpos.mantissa_start = destpos.exp_start + dest->exp_len;
        }
-       default:
-               printf("float read unavailable for size %u\n", len);
-               assert(0);
+
+       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;
+       } else {
+               srcpos.sign_start = 0;
+               srcpos.exp_start = 1;
+               srcpos.mantissa_start = srcpos.exp_start + src->exp_len;
        }
+
+       /* sign */
+       tmp = bitfield_unsigned_read(ptr, srcpos.sign_start, 1,
+                                    src->byte_order);
+       bitfield_unsigned_write(&u.bits, destpos.sign_start, 1,
+                               dest->byte_order, tmp);
+
+       /* mantissa (except sign). No sign extend. */
+       tmp = 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);
+
+       /* exponent, with sign-extend. */
+       tmp = 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);
 }
 
-size_t float_write(uint8_t *ptr, size_t len, int byte_order, double v)
+double ctf_double_read(const unsigned char *ptr, const struct ctf_float *src)
 {
-       int rbo = (byte_order != __FLOAT_WORD_ORDER);   /* reverse byte order */
+       union doubleIEEE754 u;
+       struct ctf_float dest = {
+               .exp_len = sizeof(double) * CHAR_BIT - DBL_MANT_DIG,
+               .mantissa_len = DBL_MANT_DIG,
+               .byte_order = BYTE_ORDER,
+       };
+
+       float_copy(&u.bits, &dest, ptr, src);
+       return u.v;
+}
+
+size_t ctf_double_write(unsigned char *ptr, const struct ctf_float *dest,
+                       double v)
+{
+       union doubleIEEE754 u;
+       struct ctf_float src = {
+               .exp_len = sizeof(double) * CHAR_BIT - DBL_MANT_DIG,
+               .mantissa_len = DBL_MANT_DIG,
+               .byte_order = BYTE_ORDER,
+       };
 
        if (!ptr)
                goto end;
+       u.v = v;
+       float_copy(ptr, dest, &u.bits, &src);
+end:
+       return len;
+}
 
-       switch (len) {
-       case 32:
-       {
-               union floatIEEE754 u;
-               uint32_t tmp;
-
-               if (!rbo) {
-                       *(float *) ptr = (float) v;
-                       break;
-               }
-               u.v = v;
-               /*
-                * Need to reverse byte order. Write the opposite from our
-                * architecture.
-                */
-               if (__FLOAT_WORD_ORDER == LITTLE_ENDIAN) {
-                       /* Write big endian */
-                       tmp = bitfield_unsigned_read(ptr, 31, 1, LITTLE_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 0, 1, BIG_ENDIAN,
-                                               tmp);
-                       tmp = bitfield_unsigned_read(ptr, 23, 8, LITTLE_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 1, 8, BIG_ENDIAN,
-                                               tmp);
-                       tmp = bitfield_unsigned_read(ptr, 0, 23, LITTLE_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 9, 23, BIG_ENDIAN,
-                                               tmp);
-               } else {
-                       /* Write little endian */
-                       tmp = bitfield_unsigned_read(ptr, 0, 1, BIG_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 31, 1, LITTLE_ENDIAN,
-                                               tmp);
-                       tmp = bitfield_unsigned_read(ptr, 1, 8, BIG_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 23, 8, LITTLE_ENDIAN,
-                                               tmp);
-                       tmp = bitfield_unsigned_read(ptr, 9, 23, BIG_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 0, 23, LITTLE_ENDIAN,
-                                               tmp);
-               }
-               break;
-       }
-       case 64:
-       {
-               union doubleIEEE754 u;
-               uint64_t tmp;
-
-               if (!rbo) {
-                       *(double *) ptr = v;
-                       break;
-               }
-               u.v = v;
-               /*
-                * Need to reverse byte order. Write the opposite from our
-                * architecture.
-                */
-               if (__FLOAT_WORD_ORDER == LITTLE_ENDIAN) {
-                       /* Write big endian */
-                       tmp = bitfield_unsigned_read(ptr, 63, 1, LITTLE_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 0, 1, BIG_ENDIAN,
-                                               tmp);
-                       tmp = bitfield_unsigned_read(ptr, 52, 11, LITTLE_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 1, 11, BIG_ENDIAN,
-                                               tmp);
-                       tmp = bitfield_unsigned_read(ptr, 0, 52, LITTLE_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 12, 52, BIG_ENDIAN,
-                                               tmp);
-               } else {
-                       /* Write little endian */
-                       tmp = bitfield_unsigned_read(ptr, 0, 1, BIG_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 63, 1, LITTLE_ENDIAN,
-                                               tmp);
-                       tmp = bitfield_unsigned_read(ptr, 1, 11, BIG_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 52, 11, LITTLE_ENDIAN,
-                                               tmp);
-                       tmp = bitfield_unsigned_read(ptr, 12, 52, BIG_ENDIAN);
-                       bitfield_unsigned_write(&u.bits, 0, 52, LITTLE_ENDIAN,
-                                               tmp);
-               }
-               break;
-       }
-       default:
-               printf("float write unavailable for size %u\n", len);
-               assert(0);
-       }
+long double ctf_ldouble_read(const unsigned char *ptr,
+                            const struct ctf_float *src)
+{
+       union ldoubleIEEE754 u;
+       struct ctf_float dest = {
+               .exp_len = sizeof(double) * CHAR_BIT - LDBL_MANT_DIG,
+               .mantissa_len = LDBL_MANT_DIG,
+               .byte_order = BYTE_ORDER,
+       };
+
+       float_copy(&u.bits, &dest, ptr, src);
+       return u.v;
+}
+
+size_t ctf_ldouble_write(unsigned char *ptr, const struct ctf_float *dest,
+                        long double v)
+{
+       union ldoubleIEEE754 u;
+       struct ctf_float src = {
+               .exp_len = sizeof(double) * CHAR_BIT - LDBL_MANT_DIG,
+               .mantissa_len = LDBL_MANT_DIG,
+               .byte_order = BYTE_ORDER,
+       };
+
+       if (!ptr)
+               goto end;
+       u.v = v;
+       float_copy(ptr, dest, &u.bits, &src);
 end:
        return len;
 }
index 2310ad30236653b94fdcf752092cc31749d3643a..cd81b17aa0d47d29f98334e0f798f1e7fd625119 100644 (file)
@@ -3,9 +3,21 @@
  *
  * Integers read/write functions.
  *
- * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * Dual LGPL v2.1/GPL v2 license.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <ctf/ctf-types.h>
index c61bfcdc84cfc35b2105e85b5c180b4dde9b74ba..578388d15936065a242d3a4e0b30e6be09072c2d 100644 (file)
@@ -3,9 +3,21 @@
  *
  * Strings read/write functions.
  *
- * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * Dual LGPL v2.1/GPL v2 license.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <ctf/ctf-types.h>
index d2d59cf4c6807e222735ccb293c271b1eb5a4144..3aa8d58764e280e0c9811eed1209be8d9b29e228 100644 (file)
@@ -3,9 +3,21 @@
  *
  * Structure write/access functions.
  *
- * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * Dual LGPL v2.1/GPL v2 license.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <ctf/ctf-types.h>
index 545bdb91bbcda3173720ede402fcf2ff3d2b00c5..1b9a3dfb5956544310051c6d5090ca045d75ee98 100644 (file)
@@ -3,9 +3,21 @@
  *
  * Types registry.
  *
- * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * Dual LGPL v2.1/GPL v2 license.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <ctf/ctf-types.h>
index 16b2d2e44c919fc74d14353fe33185a16a2d3ef2..5911eb461b404bce951184319b9b5347b2598b72 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Common Trace Format - bitfield test program
  *
- * Copyright February 2009 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
This page took 0.034683 seconds and 4 git commands to generate.