commit 12d96a3a84f92ed2941815a2d56dfa8cad37eb19
parent 651ab6843fc93d8540ef55c9dd65c13fa6c14e20
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 1 Apr 2015 09:38:07 +0200
Add the built-in smc_float type
Diffstat:
4 files changed, 164 insertions(+), 5 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -54,8 +54,8 @@ set(VERSION_MINOR 0)
set(VERSION_PATCH 0)
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
-set(SMC_FILES_SRC smc_device.c)
-set(SMC_FILES_INC smc.h smc_device_c.h)
+set(SMC_FILES_SRC smc_device.c smc_type.c)
+set(SMC_FILES_INC smc.h smc_device_c.h smc_type_c.h)
# Prepend each file in the `SMC_FILES_<SRC|INC>' list by `SMC_SOURCE_DIR'
rcmake_prepend_path(SMC_FILES_SRC ${SMC_SOURCE_DIR})
diff --git a/src/smc.h b/src/smc.h
@@ -59,9 +59,7 @@ struct mem_allocator;
/* Generic type descriptor */
struct smc_type {
void* (*create)(struct mem_allocator* allocator);
- void (*destroy)(void* data);
- void (*copy)(void* dst, const void* src);
- void (*copy_and_release)(void* dst, void* src);
+ void (*destroy)(struct mem_allocator* allocator, void* data);
void (*set)(void* result, const void* value);
void (*zero)(void* result);
@@ -77,6 +75,9 @@ struct smc_estimator; /* Estimator of an integrator */
BEGIN_DECLS
+/* Pre-declared SMC types */
+extern const struct smc_type smc_float;
+
/*******************************************************************************
* API deinition
******************************************************************************/
diff --git a/src/smc_type.c b/src/smc_type.c
@@ -0,0 +1,107 @@
+/* Copyright (C) |Meso|Star> 2015 (contact@meso-star.com)
+ *
+ * This software is a computer program whose purpose is to manage the
+ * statistical estimation of a function.
+ *
+ * This software is governed by the CeCILL license under French law and
+ * abiding by the rules of distribution of free software. You can use,
+ * modify and/or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms. */
+
+#include "smc.h"
+#include <rsys/mem_allocator.h>
+
+/*******************************************************************************
+ * SMC float definition
+ ******************************************************************************/
+static void*
+smc_float_create(struct mem_allocator* allocator)
+{
+ ASSERT(allocator);
+ return MEM_ALLOC(allocator, sizeof(float));
+}
+
+static void
+smc_float_destroy(struct mem_allocator* allocator, void* data)
+{
+ ASSERT(data);
+ MEM_FREE(allocator, data);
+}
+
+static void
+smc_float_set(void* result, const void* value)
+{
+ ASSERT(result && value);
+ *(float*)result = *(const float*)value;
+}
+
+static void
+smc_float_zero(void* result)
+{
+ ASSERT(result);
+ *(float*)result = 0;
+}
+
+static void
+smc_float_add(void* result, const void* op0, const void* op1)
+{
+ ASSERT(result && op0 && op1);
+ *(float*)result = *(const float*)op0 + *(const float*)op1;
+}
+
+static void
+smc_float_sub(void* result, const void* op0, const void* op1)
+{
+ ASSERT(result && op0 && op1);
+ *(float*)result = *(const float*)op0 - *(const float*)op1;
+}
+
+static void
+smc_float_mul(void* result, const void* op0, const void* op1)
+{
+ ASSERT(result && op0 && op1);
+ *(float*)result = *(const float*)op0 * *(const float*)op1;
+}
+
+static void
+smc_float_divi(void* result, const void* op0, const unsigned long op1)
+{
+ ASSERT(result && op0 && op1);
+ *(float*)result = (float)((double)(*(const float*)op0) / (double)op1);
+}
+
+/*******************************************************************************
+ * Exported constant
+ ******************************************************************************/
+const struct smc_type smc_float = {
+ smc_float_create,
+ smc_float_destroy,
+ smc_float_set,
+ smc_float_zero,
+ smc_float_add,
+ smc_float_sub,
+ smc_float_mul,
+ smc_float_divi
+};
+
diff --git a/src/smc_type_c.h b/src/smc_type_c.h
@@ -0,0 +1,51 @@
+/* Copyright (C) |Meso|Star> 2015 (contact@meso-star.com)
+ *
+ * This software is a computer program whose purpose is to manage the
+ * statistical estimation of a function.
+ *
+ * This software is governed by the CeCILL license under French law and
+ * abiding by the rules of distribution of free software. You can use,
+ * modify and/or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms. */
+
+#ifndef SMC_TYPE_C_H
+#define SMC_TYPE_C_H
+
+#include "smc.h"
+
+static INLINE char
+check_type(const struct smc_type* type)
+{
+ return type->create != NULL
+ && type->destroy != NULL
+ && type->set != NULL
+ && type->zero != NULL
+ && type->add != NULL
+ && type->sub != NULL
+ && type->mul != NULL
+ && type->divi != NULL;
+}
+
+#endif /* SMC_TYPE_C_H */
+