source: soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc1.c

Last change on this file was 822, checked in by meunier, 10 years ago

In rosenfeld:

  • Updated nrio0, nrio1, nrio2, nrio1f, nrio2f, nrio1x, nrbool1, nrbool2 and nralloc1 in the nrc2 lib in order to use macro-typed functions
  • Updated the simulation script to include performance evaluation with random images, and a script to generate graphs
  • Updated the clock.h to use 64-bit integers, which potentially breaks the printing on the giet
File size: 6.0 KB
Line 
1/* ------------------ */
2/* --- nralloc1.c --- */
3/* ------------------ */
4
5/*
6 * Copyright (c) 2000-2014, Lionel Lacassagne, All rights reserved
7 * Univ Paris Sud XI, CNRS
8 *
9 * Distributed under the Boost Software License, Version 1.0
10 * see accompanying file LICENSE.txt or copy it at
11 * http://www.boost.org/LICENSE_1_0.txt
12 */
13
14/*
15 * this code is based on the "Numerical Recipes in C 2nd edition" nrutil.c nrutil.h files from
16 * William H. Press, Saul A. Teukolsky, William T. Vetterling, Brian P. Flannery
17 *
18 * The original code is not-copyrighted.
19 * The original routines are placed into the public domain
20 * (see Appendix B: utility routines, pp 964)
21 * for more information, visit http://www.nr.com
22*/
23
24/*
25* 2002/06/11 ajout des fonctions endline
26*/
27#include <stdio.h>
28#include <stddef.h>
29#include <stdlib.h>
30#include <malloc.h>
31#include <stdint.h>
32
33#include "nrc_os_config.h"
34#include "mypredef.h"
35#include "nrtype.h"
36#include "nrdef.h"
37#include "nrmacro.h"
38#include "nrkernel.h"
39
40#include "nralloc1.h"
41
42
43
44#undef type_vector
45#define type_vector(t) \
46t * short_name(t,,vector)(int32_t nl, int32_t nh) \
47{ \
48 t * v; \
49 v = malloc((nh - nl + 1 + NR_END) * sizeof(t)); \
50 if (v == NULL) { \
51 nrerror("*** Error: allocation failure in %s\n", __func__); \
52 } \
53 return v - nl + NR_END; \
54}
55
56type_vector(int8_t);
57type_vector(uint8_t);
58type_vector(int16_t);
59type_vector(uint16_t);
60type_vector(int32_t);
61type_vector(uint32_t);
62type_vector(int64_t);
63type_vector(uint64_t);
64type_vector(float);
65type_vector(double);
66type_vector(void_p);
67type_vector(rgb8);
68type_vector(rgbx8);
69type_vector(rgb32);
70
71
72
73#undef type_vector0
74#define type_vector0(t) \
75t * short_name(t,,vector0)(int32_t nl, int32_t nh) \
76{ \
77 t * v; \
78 v = calloc((nh - nl + 1 + NR_END), sizeof(t)); \
79 if (v == NULL) { \
80 nrerror("*** Error: allocation failure in %s\n", __func__); \
81 } \
82 return v - nl + NR_END; \
83}
84
85type_vector0(int8_t);
86type_vector0(uint8_t);
87type_vector0(int16_t);
88type_vector0(uint16_t);
89type_vector0(int32_t);
90type_vector0(uint32_t);
91type_vector0(int64_t);
92type_vector0(uint64_t);
93type_vector0(float);
94type_vector0(double);
95type_vector0(void_p);
96type_vector0(rgb8);
97type_vector0(rgbx8);
98type_vector0(rgb32);
99
100
101#undef realloc_type_vector
102#define realloc_type_vector(t) \
103t * short_name(t,realloc_,vector)(t * v, int32_t nl, int32_t nh) \
104{ \
105 v += nl; \
106 v -= NR_END; \
107 v = realloc(v, (nh - nl + 1 + NR_END) * sizeof(t)); \
108 if (v == NULL) { \
109 nrerror("*** Error: allocation failure in %s\n", __func__); \
110 } \
111 return v - nl + NR_END; \
112}
113
114
115realloc_type_vector(int8_t);
116realloc_type_vector(uint8_t);
117realloc_type_vector(int16_t);
118realloc_type_vector(uint16_t);
119realloc_type_vector(int32_t);
120realloc_type_vector(uint32_t);
121realloc_type_vector(int64_t);
122realloc_type_vector(uint64_t);
123realloc_type_vector(float);
124realloc_type_vector(double);
125realloc_type_vector(void_p);
126realloc_type_vector(rgb8);
127realloc_type_vector(rgbx8);
128realloc_type_vector(rgb32);
129
130
131#undef free_type_vector
132#define free_type_vector(t) \
133void short_name(t,free_,vector)(t * v, long nl, long nh) \
134{ \
135 free((FREE_ARG) (v + nl - NR_END)); \
136}
137
138free_type_vector(int8_t);
139free_type_vector(uint8_t);
140free_type_vector(int16_t);
141free_type_vector(uint16_t);
142free_type_vector(int32_t);
143free_type_vector(uint32_t);
144free_type_vector(int64_t);
145free_type_vector(uint64_t);
146free_type_vector(float);
147free_type_vector(double);
148free_type_vector(void_p);
149free_type_vector(rgb8);
150free_type_vector(rgbx8);
151free_type_vector(rgb32);
152
153
154
155
156#if TARGET_OS == GIETVM
157#undef remote_type_vector
158#define remote_type_vector(t) \
159t * short_name(t,remote_,vector)(int32_t nl, int32_t nh, int32_t x, int32_t y) \
160{ \
161 t * v; \
162 v = remote_malloc((nh - nl + 1 + NR_END) * sizeof(t), x, y); \
163 if (v == NULL) { \
164 nrerror("*** Error: allocation failure in %s\n", __func__); \
165 } \
166 return v - nl + NR_END; \
167}
168
169remote_type_vector(int8_t);
170remote_type_vector(uint8_t);
171remote_type_vector(int16_t);
172remote_type_vector(uint16_t);
173remote_type_vector(int32_t);
174remote_type_vector(uint32_t);
175remote_type_vector(int64_t);
176remote_type_vector(uint64_t);
177remote_type_vector(float);
178remote_type_vector(double);
179remote_type_vector(void_p);
180remote_type_vector(rgb8);
181remote_type_vector(rgbx8);
182remote_type_vector(rgb32);
183
184#endif
185
186// Local Variables:
187// tab-width: 4
188// c-basic-offset: 4
189// c-file-offsets:((innamespace . 0)(inline-open . 0))
190// indent-tabs-mode: nil
191// End:
192
193// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
194
Note: See TracBrowser for help on using the repository browser.