Remove bitfields, which are just a bit-addressed integer
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 4 Oct 2010 18:57:09 +0000 (14:57 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 4 Oct 2010 18:57:09 +0000 (14:57 -0400)
Because we can directly map bitfields to non-byte-aligned integers, we don't
need to have a separate class type for bitfields. Merge them with integers. We
can eventually use faster read/write functions for integers aligned on byte
boundaries and which length is a multiple of 1 byte.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/ctf.c
formats/ctf/types/bitfield.c [deleted file]
formats/ctf/types/enum.c
formats/ctf/types/float.c
formats/ctf/types/integer.c
include/babeltrace/ctf/types.h
include/babeltrace/format.h
include/babeltrace/types.h
types/bitfield.c [deleted file]
types/enum.c
types/float.c

index 9a0e003a2fa3e5081ca331cad3c533c7223706af..eec36148573eef6a3283808aff916ba22d08ef58 100644 (file)
@@ -30,10 +30,6 @@ static const struct format ctf_format = {
        .int_read = ctf_int_read,
        .uint_write = ctf_uint_write,
        .int_write = ctf_int_write,
-       .bitfield_unsigned_read = ctf_bitfield_unsigned_read,
-       .bitfield_signed_read = ctf_bitfield_signed_read,
-       .bitfield_unsigned_write = ctf_bitfield_unsigned_write,
-       .bitfield_signed_write = ctf_bitfield_signed_write,
        .double_read = ctf_double_read,
        .double_write = ctf_double_write,
        .float_copy = ctf_float_copy,
diff --git a/formats/ctf/types/bitfield.c b/formats/ctf/types/bitfield.c
deleted file mode 100644 (file)
index 2d7a2ae..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Common Trace Format
- *
- * Bitfields read/write functions.
- *
- * 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/bitfield.h>
-#include <endian.h>
-
-uint64_t ctf_bitfield_unsigned_read(struct stream_pos *pos,
-                       const struct type_class_bitfield *bitfield_class)
-{
-       uint64_t v;
-
-       align_pos(pos, bitfield_class->p.p.alignment);
-       if (bitfield_class->p.byte_order == LITTLE_ENDIAN)
-               ctf_bitfield_read_le(pos->base, pos->offset,
-                                    bitfield_class->p.len, &v);
-       else
-               ctf_bitfield_read_be(pos->base, pos->offset,
-                                    bitfield_class->p.len, &v);
-       move_pos(pos, bitfield_class->p.len);
-       return v;
-}
-
-int64_t ctf_bitfield_signed_read(struct stream_pos *pos,
-                       const struct type_class_bitfield *bitfield_class)
-{
-       int64_t v;
-
-       align_pos(pos, bitfield_class->p.p.alignment);
-
-       if (bitfield_class->p.byte_order == LITTLE_ENDIAN)
-               ctf_bitfield_read_le(pos->base, pos->offset,
-                                    bitfield_class->p.len, &v);
-       else
-               ctf_bitfield_read_be(pos->base, pos->offset,
-                                    bitfield_class->p.len, &v);
-       move_pos(pos, bitfield_class->p.len);
-       return v;
-}
-
-void ctf_bitfield_unsigned_write(struct stream_pos *pos,
-                       const struct type_class_bitfield *bitfield_class,
-                       uint64_t v)
-{
-       align_pos(pos, bitfield_class->p.p.alignment);
-       if (pos->dummy)
-               goto end;
-       if (bitfield_class->p.byte_order == LITTLE_ENDIAN)
-               ctf_bitfield_write_le(pos->base, pos->offset,
-                                     bitfield_class->p.len, v);
-       else
-               ctf_bitfield_write_be(pos->base, pos->offset,
-                                     bitfield_class->p.len,, v);
-end:
-       move_pos(pos, bitfield_class->p.len);
-}
-
-void ctf_bitfield_signed_write(struct stream_pos *pos,
-                       const struct type_class_bitfield *bitfield_class,
-                       int64_t v)
-{
-       align_pos(pos, bitfield_class->p.p.alignment);
-       if (pos->dummy)
-               goto end;
-       if (bitfield_class->p.byte_order == LITTLE_ENDIAN)
-               ctf_bitfield_write_le(pos->base, pos->offset,
-                                     bitfield_class->p.len, v);
-       else
-               ctf_bitfield_write_be(pos->base, pos->offset,
-                                     bitfield_class->p.len, v);
-end:
-       move_pos(pos, bitfield_class->p.len);
-}
index a209b47d0cdc1f169ce71b544a339bf98f7a8965..37859f03a5afb040cc90abfeab9ebbd674a9ce0e 100644 (file)
 GQuark ctf_enum_read(struct stream_pos *pos,
                     const struct type_class_enum *src)
 {
-       struct type_class_bitfield *bitfield_class = &src->p;
-       struct type_class_integer *int_class = &bitfield_class->p;
+       struct type_class_integer *int_class = &src->p;
 
        if (!int_class->signedness) {
                uint64_t v;
 
-               v = ctf_bitfield_unsigned_read(pos, bitfield_class);
+               v = ctf_uint_read(pos, int_class);
                return enum_uint_to_quark(src, v);
        } else {
                int64_t v;
 
-               v = fsrc->bitfield_signed_read(pos, bitfield_class);
+               v = fsrc->ctf_int_read(pos, int_class);
                return enum_int_to_quark(src, v);
        }
 }
@@ -47,18 +46,17 @@ size_t ctf_enum_write(struct stream_pos *pos,
                      const struct type_class_enum *dest,
                      GQuark q)
 {
-       struct type_class_bitfield *bitfield_class = &dest->p;
-       struct type_class_integer *int_class = &bitfield_class->p;
+       struct type_class_integer *int_class = &dest->p;
 
        if (!int_class->signedness) {
                uint64_t v;
 
                v = enum_quark_to_uint(dest, q);
-               return ctf_bitfield_unsigned_write(pos, bitfield_class, v);
+               return ctf_uint_write(pos, int_class, v);
        } else {
                int64_t v;
 
                v = enum_quark_to_int(dest, q);
-               return ctf_bitfield_signed_write(pos, bitfield_class, v);
+               return ctf_int_write(pos, int_class, v);
        }
 }
index 20cf7fa537c8e96e7a4e14359688f58f967655c3..6fd0c72ef4dc97f5ce426d8a992022edbc7c16ee 100644 (file)
@@ -83,27 +83,23 @@ void _ctf_float_copy(struct stream_pos *destp,
 
        /* Read */
        if (src->byte_order == LITTLE_ENDIAN) {
-               mantissa = ctf_bitfield_unsigned_read(srcp,
-                                                     src_class->mantissa);
-               exp = ctf_bitfield_signed_read(srcp, src_class->exp);
-               sign = ctf_bitfield_unsigned_read(srcp, src_class->sign);
+               mantissa = ctf_uint_read(srcp, src_class->mantissa);
+               exp = ctf_int_read(srcp, src_class->exp);
+               sign = ctf_uint_read(srcp, src_class->sign);
        } else {
-               sign = ctf_bitfield_unsigned_read(srcp, src_class->sign);
-               exp = ctf_bitfield_signed_read(srcp, src_class->exp);
-               mantissa = ctf_bitfield_unsigned_read(srcp,
-                                                     src_class->mantissa);
+               sign = ctf_uint_read(srcp, src_class->sign);
+               exp = ctf_int_read(srcp, src_class->exp);
+               mantissa = ctf_uint_read(srcp, src_class->mantissa);
        }
        /* Write */
        if (dest->byte_order == LITTLE_ENDIAN) {
-               ctf_bitfield_unsigned_write(destp, dest_class->mantissa,
-                                           mantissa);
-               ctf_bitfield_signed_write(destp, dest_class->exp, exp);
-               ctf_bitfield_unsigned_write(destp, dest_class->sign, sign);
+               ctf_uint_write(destp, dest_class->mantissa, mantissa);
+               ctf_int_write(destp, dest_class->exp, exp);
+               ctf_uint_write(destp, dest_class->sign, sign);
        } else {
-               ctf_bitfield_unsigned_write(destp, dest_class->sign, sign);
-               ctf_bitfield_signed_write(destp, dest_class->exp, exp);
-               ctf_bitfield_unsigned_write(destp, dest_class->mantissa,
-                                           mantissa);
+               ctf_uint_write(destp, dest_class->sign, sign);
+               ctf_int_write(destp, dest_class->exp, exp);
+               ctf_uint_write(destp, dest_class->mantissa, mantissa);
        }
 }
 
index b2c429f5129e095ac82412650cd3698ccfb9efdb..f7f5f23df1135353374f2366ef3a257a3c564b93 100644 (file)
  */
 
 #include <ctf/ctf-types.h>
+#include <ctf/bitfield.h>
 #include <stdint.h>
 #include <glib.h>
 #include <endian.h>
 
-uint64_t ctf_uint_read(struct stream_pos *pos,
+static
+uint64_t _aligned_uint_read(struct stream_pos *pos,
                       const struct type_class_integer *int_class)
 {
        int rbo = (int_class->byte_order != BYTE_ORDER);        /* reverse byte order */
@@ -70,7 +72,8 @@ uint64_t ctf_uint_read(struct stream_pos *pos,
        }
 }
 
-int64_t ctf_int_read(struct stream_pos *pos,
+static
+int64_t _aligned_int_read(struct stream_pos *pos,
                     const struct type_class_integer *int_class)
 {
        int rbo = (int_class->byte_order != BYTE_ORDER);        /* reverse byte order */
@@ -115,7 +118,8 @@ int64_t ctf_int_read(struct stream_pos *pos,
        }
 }
 
-void ctf_uint_write(struct stream_pos *pos,
+static
+void _aligned_uint_write(struct stream_pos *pos,
                    const struct type_class_integer *int_class,
                    uint64_t v)
 {
@@ -150,7 +154,8 @@ end:
        move_pos(pos, int_class->len);
 }
 
-void ctf_int_write(struct stream_pos *pos,
+static
+void _aligned_int_write(struct stream_pos *pos,
                   const struct type_class_integer *int_class,
                   int64_t v)
 {
@@ -185,3 +190,69 @@ end:
        move_pos(pos, int_class->len);
        return;
 }
+
+uint64_t ctf_uint_read(struct stream_pos *pos,
+                       const struct type_class_bitfield *int_class)
+{
+       uint64_t v;
+
+       align_pos(pos, int_class->p.alignment);
+       if (int_class->byte_order == LITTLE_ENDIAN)
+               ctf_bitfield_read_le(pos->base, pos->offset,
+                                    int_class->len, &v);
+       else
+               ctf_bitfield_read_be(pos->base, pos->offset,
+                                    int_class->len, &v);
+       move_pos(pos, int_class->len);
+       return v;
+}
+
+int64_t ctf_int_read(struct stream_pos *pos,
+                       const struct type_class_bitfield *int_class)
+{
+       int64_t v;
+
+       align_pos(pos, int_class->p.alignment);
+       if (int_class->byte_order == LITTLE_ENDIAN)
+               ctf_bitfield_read_le(pos->base, pos->offset,
+                                    int_class->len, &v);
+       else
+               ctf_bitfield_read_be(pos->base, pos->offset,
+                                    int_class->len, &v);
+       move_pos(pos, int_class->len);
+       return v;
+}
+
+void ctf_uint_write(struct stream_pos *pos,
+                       const struct type_class_bitfield *int_class,
+                       uint64_t v)
+{
+       align_pos(pos, int_class->p.alignment);
+       if (pos->dummy)
+               goto end;
+       if (int_class->byte_order == LITTLE_ENDIAN)
+               ctf_bitfield_write_le(pos->base, pos->offset,
+                                     int_class->len, v);
+       else
+               ctf_bitfield_write_be(pos->base, pos->offset,
+                                     int_class->len,, v);
+end:
+       move_pos(pos, int_class->len);
+}
+
+void ctf_int_write(struct stream_pos *pos,
+                       const struct type_class_bitfield *int_class,
+                       int64_t v)
+{
+       align_pos(pos, int_class->p.alignment);
+       if (pos->dummy)
+               goto end;
+       if (int_class->byte_order == LITTLE_ENDIAN)
+               ctf_bitfield_write_le(pos->base, pos->offset,
+                                     int_class->len, v);
+       else
+               ctf_bitfield_write_be(pos->base, pos->offset,
+                                     int_class->len, v);
+end:
+       move_pos(pos, int_class->len);
+}
index 40b89847d759ec6bb410e56cd65b5461982804c5..49427a5bba4d3d33116528b34f7b82c9e5ae6f3d 100644 (file)
@@ -46,17 +46,6 @@ void ctf_int_write(struct stream_pos *pos,
                const struct type_class_integer *int_class,
                int64_t v);
 
-uint64_t ctf_bitfield_unsigned_read(struct stream_pos *pos,
-                       const struct type_class_bitfield *bitfield_class);
-int64_t ctf_bitfield_signed_read(struct stream_pos *pos,
-                       const struct type_class_bitfield *bitfield_class);
-void ctf_bitfield_unsigned_write(struct stream_pos *pos,
-                       const struct type_class_bitfield *bitfield_class,
-                       uint64_t v);
-void ctf_bitfield_signed_write(struct stream_pos *pos,
-                       const struct type_class_bitfield *bitfield_class,
-                       int64_t v);
-
 double ctf_double_read(struct stream_pos *pos,
                        const struct type_class_float *src);
 void ctf_double_write(struct stream_pos *pos,
index 539197299a37811ef02f5db6484f3065fc528331..5909ce39f0bf3599ea720829d15cf3f050a449ff 100644 (file)
@@ -40,17 +40,6 @@ struct format {
                          const struct type_class_integer *int_class,
                          int64_t v);
 
-       uint64_t (*bitfield_unsigned_read)(struct stream_pos *pos,
-                       const struct type_class_bitfield *bitfield_class);
-       int64_t (*bitfield_signed_read)(struct stream_pos *pos,
-                       const struct type_class_bitfield *bitfield_class);
-       void (*bitfield_unsigned_write)(struct stream_pos *pos,
-                       const struct type_class_bitfield *bitfield_class,
-                       uint64_t v);
-       void (*bitfield_signed_write)(struct stream_pos *pos,
-                       const struct type_class_bitfield *bitfield_class,
-                       int64_t v);
-
        void (*float_copy)(struct stream_pos *dest,
                           struct stream_pos *src,
                           const struct type_class_float *src);
index 3c66563f075822da814e5359ae1687c77981f608..305d553d700d9a8a9588f22bac9c02580b603791 100644 (file)
@@ -93,27 +93,23 @@ struct type_class {
        void (*free)(struct type_class *type_class);
 };
 
-struct type_class_integer {
-       struct type_class p;
-       size_t len;             /* length, in bits. */
-       int byte_order;         /* byte order */
-       int signedness;
-};
-
 /*
  * Because we address in bits, bitfields end up being exactly the same as
  * integers, except that their read/write functions must be able to deal with
  * read/write non aligned on CHAR_BIT.
  */
-struct type_class_bitfield {
-       struct type_class_integer p;
+struct type_class_integer {
+       struct type_class p;
+       size_t len;             /* length, in bits. */
+       int byte_order;         /* byte order */
+       int signedness;
 };
 
 struct type_class_float {
        struct type_class p;
-       struct bitfield_class *sign;
-       struct bitfield_class *mantissa;
-       struct bitfield_class *exp;
+       struct int_class *sign;
+       struct int_class *mantissa;
+       struct int_class *exp;
        int byte_order;
        /* TODO: we might want to express more info about NaN, +inf and -inf */
 };
@@ -124,7 +120,7 @@ struct enum_table {
 };
 
 struct type_class_enum {
-       struct type_class_bitfield p;   /* inherit from bitfield */
+       struct type_class_int p;        /* inherit from integer */
        struct enum_table table;
 };
 
@@ -148,12 +144,6 @@ struct type_class_integer *integer_type_new(const char *name,
                                            size_t alignment);
 void integer_type_free(struct type_class_integer *int_class);
 
-struct type_class_bitfield *bitfield_type_new(const char *name,
-                                             size_t len, int byte_order,
-                                             int signedness,
-                                             size_t alignment);
-void bitfield_type_free(struct type_class_bitfield *bitfield_class);
-
 /*
  * mantissa_len is the length of the number of bytes represented by the mantissa
  * (e.g. result of DBL_MANT_DIG). It includes the leading 1.
diff --git a/types/bitfield.c b/types/bitfield.c
deleted file mode 100644 (file)
index 6977487..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * BabelTrace - Bitfield Type Converter
- *
- * 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 <babeltrace/compiler.h>
-#include <babeltrace/types.h>
-#include <stdint.h>
-
-size_t bitfield_copy(struct stream_pos *dest, const struct format *fdest, 
-                    struct stream_pos *src, const struct format *fsrc,
-                    const struct type_class *type_class)
-{
-       struct type_class_bitfield *bitfield_class =
-               container_of(type_class, struct type_class_bitfield, p);
-       struct type_class_integer *int_class = &bitfield_class->p;
-
-       if (!int_class->signedness) {
-               uint64_t v;
-
-               v = fsrc->bitfield_unsigned_read(src, bitfield_class);
-               return fdest->bitfield_unsigned_write(dest, bitfield_class, v);
-       } else {
-               int64_t v;
-
-               v = fsrc->bitfield_signed_read(src, bitfield_class);
-               return fdest->bitfield_signed_write(dest, bitfield_class, v);
-       }
-}
-
-void bitfield_type_free(struct type_class_bitfield *bitfield_class)
-{
-       g_free(bitfield_class);
-}
-
-static void _bitfield_type_free(struct type_class *type_class)
-{
-       struct type_class_bitfield *bitfield_class =
-               container_of(type_class, struct type_class_bitfield, p);
-       bitfield_type_free(bitfield_class);
-}
-
-struct type_class_bitfield *bitfield_type_new(const char *name,
-                                             size_t len, int byte_order,
-                                             int signedness,
-                                             size_t alignment)
-{
-       struct type_class_bitfield *bitfield_class;
-       struct type_class_integer *int_class;
-       int ret;
-
-       bitfield_class = g_new(struct type_class_bitfield, 1);
-       int_class = &bitfield_class->p;
-       int_class->p.name = g_quark_from_string(name);
-       int_class->p.alignment = alignment;
-       int_class->p.copy = bitfield_copy;
-       int_class->p.free = _bitfield_type_free;
-       int_class->len = len;
-       int_class->byte_order = byte_order;
-       int_class->signedness = signedness;
-       if (int_class->p.name) {
-               ret = ctf_register_type(&int_class->p);
-               if (ret) {
-                       g_free(bitfield_class);
-                       return NULL;
-               }
-       }
-       return bitfield_class;
-}
index 354603c44176dc989d9a5b66b082d997b81ac766..8e8ef694fc4100c865dc0df5cfb7d211be9f90dc 100644 (file)
@@ -172,8 +172,7 @@ size_t enum_copy(unsigned char *dest, const struct format *fdest,
 {
        struct type_class_enum *enum_class =
                container_of(type_class, struct type_class_enum, p);
-       struct type_class_bitfield *bitfield_class = &enum_class->p;
-       struct type_class_integer *int_class = &bitfield_class->p;
+       struct type_class_integer *int_class = &enum_class->p;
        GQuark v;
 
        v = fsrc->enum_read(src, enum_class)
@@ -200,18 +199,16 @@ struct type_class_enum *enum_type_new(const char *name,
                                      int signedness,
                                      size_t alignment)
 {
-       struct type_class_bitfield *bitfield_class;
        struct type_class_integer *int_class;
        int ret;
 
-       enum_class = g_new(struct type_class_bitfield, 1);
+       enum_class = g_new(struct type_class_enum, 1);
        enum_class->table.value_to_quark = g_hash_table(enum_val_hash,
                                                        enum_val_equal);
        enum_class->table.quark_to_value = g_hash_table_new_full(g_direct_hash,
                                                        g_direct_equal,
                                                        NULL, enum_val_free);
-       bitfield_class = &enum_class->p;
-       int_class = &bitfield_class->p;
+       int_class = &enum_class->p;
        int_class->p.name = g_quark_from_string(name);
        int_class->p.alignment = alignment;
        int_class->p.copy = enum_copy;
index 5c2e7f8d2a99c06648035a25adce79facd815502..266f7579da0c37de05eb43b9218ca31c839f7a35 100644 (file)
@@ -56,7 +56,6 @@ struct type_class_float *float_type_new(const char *name,
                                        size_t alignment)
 {
        struct type_class_float *float_class;
-       struct type_class_bitfield *bitfield_class;
        struct type_class_integer *int_class;
        struct type_class *type_class;
        int ret;
@@ -70,16 +69,16 @@ struct type_class_float *float_type_new(const char *name,
        type_class->free = _float_type_free;
        float_class->byte_order = byte_order;
 
-       float_class->sign = bitfield_type_new(NULL, 1,
-                                             byte_order, false, 1);
+       float_class->sign = integer_type_new(NULL, 1,
+                                            byte_order, false, 1);
        if (!float_class->mantissa)
                goto error_sign;
-       float_class->mantissa = bitfield_type_new(NULL, mantissa_len - 1,
-                                                 byte_order, false, 1);
+       float_class->mantissa = integer_type_new(NULL, mantissa_len - 1,
+                                                byte_order, false, 1);
        if (!float_class->mantissa)
                goto error_mantissa;
-       float_class->exp = bitfield_type_new(NULL, exp_len,
-                                            byte_order, true, 1);
+       float_class->exp = integer_type_new(NULL, exp_len,
+                                           byte_order, true, 1);
        if (!float_class->exp)
                goto error_exp;
 
@@ -91,11 +90,11 @@ struct type_class_float *float_type_new(const char *name,
        return float_class;
 
 error_register:
-       bitfield_type_free(float_class->exp);
+       integer_type_free(float_class->exp);
 error_exp:
-       bitfield_type_free(float_class->mantissa);
+       integer_type_free(float_class->mantissa);
 error_mantissa:
-       bitfield_type_free(float_class->sign);
+       integer_type_free(float_class->sign);
 error_sign:
        g_free(float_class);
        return NULL;
This page took 0.03337 seconds and 4 git commands to generate.