* 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>
/*
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 {
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;
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;
}
/* 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 = {
.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;
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 = {
.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;
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;
}