summaryrefslogtreecommitdiffstats
path: root/scilab/modules/core
diff options
context:
space:
mode:
authorSylvestre Ledru <sylvestre.ledru@scilab.org>2010-03-23 16:18:58 +0100
committerSylvestre Ledru <sylvestre.ledru@scilab.org>2010-03-23 16:18:58 +0100
commita02dc8cd4d70fc46c3fea20e98293b035ce5979e (patch)
tree8408782e776f01103237d0f4ba242c1e133473f5 /scilab/modules/core
parent1a602260d1f08d2bd08cd3c2ed45ff57df882af7 (diff)
downloadscilab-a02dc8cd4d70fc46c3fea20e98293b035ce5979e.zip
scilab-a02dc8cd4d70fc46c3fea20e98293b035ce5979e.tar.gz
Coding style + TODO comment + indentation
Diffstat (limited to 'scilab/modules/core')
-rw-r--r--scilab/modules/core/src/cpp/namstr.cpp140
-rw-r--r--scilab/modules/core/src/cpp/search_functions.cpp26
-rw-r--r--scilab/modules/core/src/cpp/unrolled_algorithms.hxx216
3 files changed, 269 insertions, 113 deletions
diff --git a/scilab/modules/core/src/cpp/namstr.cpp b/scilab/modules/core/src/cpp/namstr.cpp
index 8eae972..d356963 100644
--- a/scilab/modules/core/src/cpp/namstr.cpp
+++ b/scilab/modules/core/src/cpp/namstr.cpp
@@ -1,16 +1,29 @@
1/*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2010 - DIGITEO - Bernard HUGUENEY
4 *
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10 *
11 */
1#include "machine.h" // C2F 12#include "machine.h" // C2F
2#include "stack-def.h" // nsiz, nlgh 13#include "stack-def.h" // nsiz, nlgh
3 14
4extern "C" { 15extern "C"
5 void C2F(namstr)(int* id, int* str, int* n, char* job); 16{
17 void C2F(namstr)(int* id, int* str, int* n, char* job);
6} 18}
7 19
8namespace{ 20namespace
9 int const blank=40; 21{
10 int const one_blank= (blank<<24); 22 int const blank=40; /* @TOD: What is 40 */
11 int const two_blanks= one_blank + (blank<<16); 23 int const one_blank= (blank<<24);
12 int const three_blanks= two_blanks + (blank<<8); 24 int const two_blanks= one_blank + (blank<<16);
13 int const four_blanks= three_blanks + blank; 25 int const three_blanks= two_blanks + (blank<<8);
26 int const four_blanks= three_blanks + blank;
14} 27}
15 28
16/* 29/*
@@ -26,49 +39,72 @@ namespace{
26 * 39 *
27 * TODO: now that function search has been ported to C++, should expose a saner API that would not require strlen call nor a job arg. 40 * TODO: now that function search has been ported to C++, should expose a saner API that would not require strlen call nor a job arg.
28 */ 41 */
29void C2F(namstr)(int* id,int* str, int* n, char* job){ 42void C2F(namstr)(int* id,int* str, int* n, char* job)
30 if(*job) { // id -> str 43{
31 unsigned int i1(0); 44 if(*job) // id -> str
32 for(unsigned int j= 0; j != nsiz; ++j, i1+=4) { 45 {
33 int id_j(id[j]); 46
34 for(unsigned int i(i1); i!=i1+4; ++i, id_j>>=8) { 47 unsigned int i1(0);
35 int ch((id_j & 0x80) ? (id_j |0xffffff00) : (id_j & 0xff)); 48
36 if(ch == blank) { 49 for(unsigned int j= 0; j != nsiz; ++j, i1 += 4) /* @TODO: add comment */
37 *n= i; 50 {
38 return; 51 int id_j(id[j]);
52 for(unsigned int i(i1); i!=i1+4; ++i, id_j >>= 8) /* @TODO: add comment */
53 {
54 int ch((id_j & 0x80) ? (id_j |0xffffff00) : (id_j & 0xff));
55/* @TODO: add comment: what is 0x80 0xffffff00 0xff */
56 if(ch == blank)
57 {
58 *n = i;
59 return;
60 }
61 id_j += 128;
62 str[i]= ch;
63 }
64 }
65
66 *n= nlgh;
67
68 }
69 else
70 { // str -> id
71 // n (<= nsiz*4 = nlgh) int in str packed into id
72 unsigned int j;
73 unsigned const int full_ids((*n)>>2); /* @TODO: add comment: 2 ?*/
74
75 for(j= 0; j!=full_ids; ++j)
76 {
77 id[j]= str[4*j+0] +(str[4*j+1]<<8)+(str[4*j+2]<<16)+(str[4*j+3]<<24); /* @TODO: add comment */
78 }
79 if(j!= nsiz)
80 {
81 switch((*n)&0x3) /* @TODO: add comment */
82 {
83 case 3:
84 {
85 id[j]= one_blank + (str[4*j+2] << 16) + (str[4*j+1] << 8) + str[4*j + 0]; /* @TODO: add comment */
86 ++j;
87 break;
88 }
89 case 2:
90 {
91 id[j]= two_blanks + (str[4*j+1]<<8) + str[4*j+0]; /* @TODO: add comment */
92 ++j;
93 break;
94 }
95 case 1:
96 {
97 id[j]= three_blanks + str[4*j+0]; /* @TODO: add comment */
98 ++j;
99 break;
100 }
101 }
102
103 for(;j != nsiz; ++j) /* @TODO: add comment */
104 {
105 id[j]= four_blanks;
106 }
107 }
39 } 108 }
40 id_j+=128; 109 return;
41 str[i]= ch;
42 }
43 }
44 *n= nlgh;
45 }else { // str -> id
46 // n (<= nsiz*4 = nlgh) int in str packed into id
47 unsigned int j;
48 unsigned const int full_ids((*n)>>2);
49 for(j= 0; j!=full_ids; ++j) {
50 id[j]= str[4*j+0] +(str[4*j+1]<<8)+(str[4*j+2]<<16)+(str[4*j+3]<<24);
51 }
52 if(j!= nsiz) {
53 switch((*n)&0x3) {
54 case 3: {
55 id[j]= one_blank +(str[4*j+2]<<16)+(str[4*j+1]<<8)+str[4*j+0];
56 ++j;
57 break;
58 }
59 case 2: {
60 id[j]= two_blanks + (str[4*j+1]<<8) + str[4*j+0];
61 ++j;
62 break;
63 }
64 case 1: {
65 id[j]= three_blanks + str[4*j+0];
66 ++j;
67 break;
68 }
69 }
70 for(;j != nsiz;++j) { id[j]= four_blanks; }
71 }
72 }
73 return;
74} 110}
diff --git a/scilab/modules/core/src/cpp/search_functions.cpp b/scilab/modules/core/src/cpp/search_functions.cpp
index 2ba2cae..d6339c3 100644
--- a/scilab/modules/core/src/cpp/search_functions.cpp
+++ b/scilab/modules/core/src/cpp/search_functions.cpp
@@ -1,3 +1,15 @@
1/*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2010 - DIGITEO - Bernard HUGUENEY
4 *
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10 *
11 */
12
1#include <cstdlib> 13#include <cstdlib>
2#include <algorithm> 14#include <algorithm>
3#include "unrolled_algorithms.hxx" 15#include "unrolled_algorithms.hxx"
@@ -54,20 +66,20 @@ void C2F(siflibs)(int* id, int* k_ptr, int* istr, int* lbibn_ptr, int* nbibn_ptr
54 66
55 if (istk_ptr[il] == sci_lib) 67 if (istk_ptr[il] == sci_lib)
56 { 68 {
57 nbibn=istk_ptr[il+1]; 69 nbibn = istk_ptr[il+1];
58 lbibn=il+2; 70 lbibn = il+2;
59 il+= nbibn+2; 71 il += nbibn+2;
60 ilp=il+1; 72 ilp = il+1;
61 ip=std::max(1, id_char(id)-9); 73 ip = std::max(1, id_char(id)-9);
62 if (ip <= nclas) 74 if (ip <= nclas)
63 { 75 {
64 76
65 int n=istk_ptr[ilp+ip] -istk_ptr[ilp+ip-1]; 77 int n = istk_ptr[ilp+ip] -istk_ptr[ilp+ip-1];
66 if (n != 0) 78 if (n != 0)
67 { 79 {
68 int iln= ilp+nclas+1+(istk_ptr[ilp+ip-1]-1)*nsiz; 80 int iln= ilp+nclas+1+(istk_ptr[ilp+ip-1]-1)*nsiz;
69 81
70 for (int i= 1; i<=n; ++i, iln+= nsiz) 82 for (int i = 1; i<=n; ++i, iln+= nsiz)
71 { 83 {
72 if(eq_n<nsiz>(id, istk_ptr+iln)) 84 if(eq_n<nsiz>(id, istk_ptr+iln))
73 { // 39 85 { // 39
diff --git a/scilab/modules/core/src/cpp/unrolled_algorithms.hxx b/scilab/modules/core/src/cpp/unrolled_algorithms.hxx
index 8bac872..d1c8b6b 100644
--- a/scilab/modules/core/src/cpp/unrolled_algorithms.hxx
+++ b/scilab/modules/core/src/cpp/unrolled_algorithms.hxx
@@ -14,67 +14,175 @@
14#define UNROLLED_ALGORITHMS_HXX 14#define UNROLLED_ALGORITHMS_HXX
15 15
16namespace { 16namespace {
17 /* 17 /*
18 * generic template unrolling for small vectors 18 * generic template unrolling for small vectors
19 */ 19 */
20 20
21 template<typename It1, typename It2, int N> struct eq_n_t { 21/**
22 bool operator()(It1 i1, It2 i2) const { 22 * @TODO add comment
23 return (*i1 == *i2) && eq_n_t<It1, It2, N-1>()(++i1, ++i2) ; 23 *
24 } 24 * @param
25 }; 25 * @return <ReturnValue>
26 template<typename It1, typename It2> struct eq_n_t<It1, It2, 0> { 26 */
27 bool operator()(It1 i1, It2 i2) const { 27 template<typename It1, typename It2, int N> struct eq_n_t
28 return true ; 28 {
29 } 29 bool operator()(It1 i1, It2 i2) const
30 }; 30 {
31 template<int N, typename It1, typename It2> bool eq_n(It1 i1, It2 i2) { 31 return (*i1 == *i2) && eq_n_t<It1, It2, N-1>()(++i1, ++i2) ;
32 return eq_n_t<It1, It2, N>()(i1, i2); 32 }
33 } 33 };
34 // ensure most efficient inlining irrespectively of optimization compiler options for ids of nsiz=6 ints
35 template<> bool eq_n<6,int const*, int const*>(int const* id1, int const* id2) {
36 return (id1[0]==id2[0]) && (id1[1]==id2[1]) && (id1[2]==id2[2]) && (id1[3]==id2[3]) && (id1[4]==id2[4]) && (id1[5]==id2[5]);
37 }
38
39 template<> bool eq_n<6,int const*, int*>(int const* id1, int* id2) {
40 return (id1[0]==id2[0]) && (id1[1]==id2[1]) && (id1[2]==id2[2]) && (id1[3]==id2[3]) && (id1[4]==id2[4]) && (id1[5]==id2[5]);
41 }
42 template<> bool eq_n<6,int*, int const*>(int* id1, int const* id2) {
43 return (id1[0]==id2[0]) && (id1[1]==id2[1]) && (id1[2]==id2[2]) && (id1[3]==id2[3]) && (id1[4]==id2[4]) && (id1[5]==id2[5]);
44 }
45 template<> bool eq_n<6,int*, int*>(int* id1, int* id2) {
46 return (id1[0]==id2[0]) && (id1[1]==id2[1]) && (id1[2]==id2[2]) && (id1[3]==id2[3]) && (id1[4]==id2[4]) && (id1[5]==id2[5]);
47 }
48 34
49 template<typename It1, typename It2, int N> struct less_n_t { 35/**
50 bool operator()(It1 i1, It2 i2) const { 36 * @TODO add comment
51 return (*i1<*i2) ? true : ( (*i1>*i2) ? false : less_n_t<It1, It2, N-1>()(++i1, ++i2)); 37 *
38 * @param
39 * @return <ReturnValue>
40 */
41 template<typename It1, typename It2> struct eq_n_t<It1, It2, 0> {
42 bool operator()(It1 i1, It2 i2) const {
43 return true ;
44 }
45 };
46
47/**
48 * @TODO add comment
49 *
50 * @param i1
51 * @param i2
52 * @return <ReturnValue>
53 */
54 template<int N, typename It1, typename It2> bool eq_n(It1 i1, It2 i2) {
55 return eq_n_t<It1, It2, N>()(i1, i2);
56 }
57
58/**
59 * ensure most efficient inlining irrespectively of optimization compiler options for ids of nsiz=6 ints
60 *
61 * @param id1
62 * @param id2
63 */
64 template<> bool eq_n<6,int const*, int const*>(int const* id1, int const* id2) {
65 return (id1[0]==id2[0]) && (id1[1]==id2[1]) && (id1[2]==id2[2]) && (id1[3]==id2[3]) && (id1[4]==id2[4]) && (id1[5]==id2[5]);
66 }
67
68/**
69 * @TODO add comment
70 *
71 * @param id1
72 * @param id2
73 */
74 template<> bool eq_n<6,int const*, int*>(int const* id1, int* id2)
75 {
76 return (id1[0]==id2[0]) && (id1[1]==id2[1]) && (id1[2]==id2[2]) && (id1[3]==id2[3]) && (id1[4]==id2[4]) && (id1[5]==id2[5]);
52 } 77 }
53 }; 78
54 template<typename It1, typename It2> struct less_n_t<It1, It2, 0> { 79/**
55 bool operator()(It1 i1, It2 i2) const { 80 * @TODO add comment
56 return false ; 81 *
82 * @param id1
83 * @param id2
84 */
85 template<> bool eq_n<6,int*, int const*>(int* id1, int const* id2)
86 {
87 return (id1[0]==id2[0]) && (id1[1]==id2[1]) && (id1[2]==id2[2]) && (id1[3]==id2[3]) && (id1[4]==id2[4]) && (id1[5]==id2[5]);
57 } 88 }
58 };
59 89
60 template<int N, typename It1, typename It2> bool less_n(It1 i1, It2 i2) {
61 return less_n_t<It1, It2, N>()(i1, i2);
62 }
63 90
64 template<typename In, typename Out, int N> struct copy_n_t { 91/**
65 Out operator()(In in, Out out) const { 92 * @TODO add comment
66 *out= *in; 93 *
67 return copy_n_t<In, Out, N-1>()(++in, ++out); 94 * @param id1
68 } 95 * @param id2
69 }; 96 */
70 template<typename In, typename Out> struct copy_n_t<In, Out, 0> { 97 template<> bool eq_n<6,int*, int*>(int* id1, int* id2)
71 Out operator()(In, Out out) const { 98 {
72 return out; 99 return (id1[0]==id2[0]) && (id1[1]==id2[1]) && (id1[2]==id2[2]) && (id1[3]==id2[3]) && (id1[4]==id2[4]) && (id1[5]==id2[5]);
73 } 100 }
74 }; 101
75 template<int N, typename In, typename Out> Out copy_n(In in, Out out) { 102/**
76 return copy_n_t<In, Out, N>()(in, out); 103 * @TODO add comment
77 } 104 *
105 * @param i1
106 * @param i2
107 * @return <ReturnValue>
108 */
109 template<typename It1, typename It2, int N> struct less_n_t
110 {
111 bool operator()(It1 i1, It2 i2) const
112 {
113 return (*i1<*i2) ? true : ( (*i1>*i2) ? false : less_n_t<It1, It2, N-1>()(++i1, ++i2));
114 }
115 };
116
117/**
118 * @TODO add comment
119 *
120 * @param i1
121 * @param i2
122 * @return <ReturnValue>
123 */
124 template<typename It1, typename It2> struct less_n_t<It1, It2, 0>
125 {
126 bool operator()(It1 i1, It2 i2) const
127 {
128 return false ;
129 }
130 };
131
132/**
133 * @TODO add comment
134 *
135 * @param i1
136 * @param i2
137 * @return <ReturnValue>
138 */
139 template<int N, typename It1, typename It2> bool less_n(It1 i1, It2 i2)
140 {
141 return less_n_t<It1, It2, N>()(i1, i2);
142 }
143
144/**
145 * @TODO add comment
146 *
147 * @param in
148 * @param out
149 * @return <ReturnValue>
150 */
151 template<typename In, typename Out, int N> struct copy_n_t
152 {
153 Out operator()(In in, Out out) const
154 {
155 *out= *in;
156 return copy_n_t<In, Out, N-1>()(++in, ++out);
157 }
158 };
159
160/**
161 * @TODO add comment
162 *
163 * @param in
164 * @param out
165 * @return <ReturnValue>
166 */
167 template<typename In, typename Out> struct copy_n_t<In, Out, 0>
168 {
169 Out operator()(In, Out out) const
170 {
171 return out;
172 }
173 };
174
175/**
176 * @TODO add comment
177 *
178 * @param in
179 * @param out
180 * @return <ReturnValue>
181 */
182 template<int N, typename In, typename Out> Out copy_n(In in, Out out)
183 {
184 return copy_n_t<In, Out, N>()(in, out);
185 }
78 186
79} 187}
80#endif 188#endif