diff mbox

[10/28] vmstate: introduce float32 arrays

Message ID 783ca638dcf9eadd75cbb2e81059a019b21c8389.1319658750.git.quintela@redhat.com
State New
Headers show

Commit Message

Juan Quintela Oct. 26, 2011, 8:16 p.m. UTC
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/hw.h  |    5 +++++
 savevm.c |   30 ++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/hw/hw.h b/hw/hw.h
index 0f0200a..014cdc1 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -354,6 +354,8 @@  extern const VMStateInfo vmstate_info_uint16;
 extern const VMStateInfo vmstate_info_uint32;
 extern const VMStateInfo vmstate_info_uint64;

+extern const VMStateInfo vmstate_info_float32;
+
 extern const VMStateInfo vmstate_info_timer;
 extern const VMStateInfo vmstate_info_ptimer;
 extern const VMStateInfo vmstate_info_buffer;
@@ -875,6 +877,9 @@  extern const VMStateDescription vmstate_hid_ptr_device;
 #define VMSTATE_INT64_ARRAY(_f, _s, _n)                               \
     VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0)

+#define VMSTATE_FLOAT32_ARRAY(_f, _s, _n)                             \
+    VMSTATE_ARRAY(_f, _s, _n, 0, vmstate_info_float32, float32)
+
 #define VMSTATE_BUFFER_V(_f, _s, _v)                                  \
     VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f)))

diff --git a/savevm.c b/savevm.c
index 557eba4..cd0178c 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1027,6 +1027,36 @@  const VMStateInfo vmstate_info_uint16_equal = {
     .put  = put_uint16,
 };

+/* 32 bit float */
+
+typedef union {
+    float32 f;
+    uint32_t i;
+} VMStateFloat32;
+
+static int get_float32(QEMUFile *f, void *pv, size_t size)
+{
+    float32 *v = pv;
+    VMStateFloat32 u;
+    qemu_get_be32s(f, &u.i);
+    *v = u.f;
+    return 0;
+}
+
+static void put_float32(QEMUFile *f, void *pv, size_t size)
+{
+    float32 *v = pv;
+    VMStateFloat32 u;
+    u.f = *v;
+    qemu_put_be32s(f, &u.i);
+}
+
+const VMStateInfo vmstate_info_float32 = {
+    .name = "float32",
+    .get  = get_float32,
+    .put  = put_float32,
+};
+
 /* timers  */

 static int get_timer(QEMUFile *f, void *pv, size_t size)