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

Last change on this file was 821, checked in by meunier, 8 years ago
  • Added several versions of rosenfeld: { SLOW, FAST } x { FEATURES, NO_FEATURES }
  • Added native linux compilation support
  • Added a script to check results natively
  • Started to refactor nrc code
File size: 3.8 KB
Line 
1/* ------------------ */
2/* --- nrarith2.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#include <stdio.h>
15#include <stddef.h>
16#include <stdlib.h>
17#include <malloc.h>
18#include <math.h> // fabs
19
20#include "nrc_os_config.h"
21#include "mypredef.h"
22#include "nrtype.h"
23#include "nrdef.h"
24#include "nrmacro.h"
25#include "nrkernel.h"
26
27
28#undef addcnz_type_matrix
29#define addcnz_type_matrix(t) \
30void short_name(t,addcnz_,matrix)(t ** src, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t cte, t ** dst) \
31{                                              \
32        t * Xi;                                    \
33    t * Yi;                                    \
34        for (int32_t i = nrl; i <= nrh; i++) {     \
35                Xi = src[i];                           \
36                Yi = dst[i];                           \
37                for (int32_t j = ncl; j <= nch; j++) { \
38                        if (Xi[j] != 0) {                  \
39                                Yi[j] = Xi[j] + cte;           \
40            }                                  \
41                        else {                             \
42                                Yi[j] = Xi[j];                 \
43            }                                  \
44                }                                      \
45        }                                          \
46}
47
48addcnz_type_matrix(int8_t);
49addcnz_type_matrix(uint8_t);
50addcnz_type_matrix(int16_t);
51addcnz_type_matrix(uint16_t);
52addcnz_type_matrix(int32_t);
53addcnz_type_matrix(uint32_t);
54addcnz_type_matrix(int64_t);
55addcnz_type_matrix(uint64_t);
56addcnz_type_matrix(float);
57addcnz_type_matrix(double);
58
59
60#undef addandc_type_matrix
61#define addandc_type_matrix(t) \
62void short_name(t,addandc_,matrix)(t ** src, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t cte, t ** dst) \
63{                                              \
64        t * Xi;                                    \
65    t * Yi;                                    \
66        for (int32_t i = nrl; i <= nrh; i++) {     \
67                Xi = src[i];                           \
68                Yi = dst[i];                           \
69                for (int32_t j = ncl; j <= nch; j++) { \
70                        if (Xi[j] != 0) {                  \
71                Yi[j] = Xi[j] + cte;           \
72            }                                  \
73                }                                      \
74        }                                          \
75}
76
77addandc_type_matrix(int8_t);
78addandc_type_matrix(uint8_t);
79addandc_type_matrix(int16_t);
80addandc_type_matrix(uint16_t);
81addandc_type_matrix(int32_t);
82addandc_type_matrix(uint32_t);
83addandc_type_matrix(int64_t);
84addandc_type_matrix(uint64_t);
85addandc_type_matrix(float);
86addandc_type_matrix(double);
87
88
89#undef sum_type_matrix
90#define sum_type_matrix(t,rt) \
91rt short_name(t,sum_,matrix)(t ** m, int32_t nrl, int32_t nrh,int32_t ncl, int32_t nch) \
92{                                              \
93        rt s = 0;                                  \
94        t * Xi;                                    \
95        for (int32_t i = nrl; i <= nrh; i++) {     \
96                Xi = m[i];                             \
97                for (int32_t j = ncl; j <= nch; j++) { \
98                        s += Xi[j];                        \
99                }                                      \
100    }                                          \
101    return s;                                  \
102}
103
104
105sum_type_matrix(int8_t, int32_t);
106sum_type_matrix(uint8_t, uint32_t);
107sum_type_matrix(int16_t, int32_t);
108sum_type_matrix(uint16_t, uint32_t);
109sum_type_matrix(int32_t, int64_t);
110sum_type_matrix(uint32_t, uint64_t);
111sum_type_matrix(int64_t, int64_t);
112sum_type_matrix(uint64_t, uint64_t);
113sum_type_matrix(float, float);
114sum_type_matrix(double, double);
115
116
117// Local Variables:
118// tab-width: 4
119// c-basic-offset: 4
120// c-file-offsets:((innamespace . 0)(inline-open . 0))
121// indent-tabs-mode: nil
122// End:
123
124// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
125
Note: See TracBrowser for help on using the repository browser.