summaryrefslogtreecommitdiffstats
path: root/scilab/modules/core
diff options
context:
space:
mode:
authorBernard HUGUENEY <bernard.hugueney@scilab.org>2010-03-19 14:27:09 +0100
committerBernard HUGUENEY <bernard.hugueney@scilab.org>2010-03-19 14:27:09 +0100
commitbf02fa2487f6b1a4bb8bf8f270c81a86f4468f2c (patch)
tree5b48cb4125c610bc8ca6d9c7d09ca81f098ecdb3 /scilab/modules/core
parent345d3322fde02e10ff2f7b06052e3b1b4749872d (diff)
downloadscilab-bf02fa2487f6b1a4bb8bf8f270c81a86f4468f2c.zip
scilab-bf02fa2487f6b1a4bb8bf8f270c81a86f4468f2c.tar.gz
c++ rewrite of namstr.f, replacing artihmetic operation with bitwise operations.
TODO add endianness check in configure TODO provide a more efficient C++ API for C++ client code (hashtable_core et al.)
Diffstat (limited to 'scilab/modules/core')
-rw-r--r--scilab/modules/core/Makefile.am6
-rw-r--r--scilab/modules/core/src/cpp/namstr.cpp74
2 files changed, 77 insertions, 3 deletions
diff --git a/scilab/modules/core/Makefile.am b/scilab/modules/core/Makefile.am
index 9493e29..a4a0dcc 100644
--- a/scilab/modules/core/Makefile.am
+++ b/scilab/modules/core/Makefile.am
@@ -85,7 +85,8 @@ src/c/funcprot.c \
85src/c/eqid.c \ 85src/c/eqid.c \
86src/c/dynamic_tclsci.c 86src/c/dynamic_tclsci.c
87 87
88CORE_CPP_SOURCES = src/cpp/hashtable_core.cpp 88CORE_CPP_SOURCES = src/cpp/hashtable_core.cpp \
89src/cpp/namstr.cpp
89 90
90if USE_DYNAMIC_STACK 91if USE_DYNAMIC_STACK
91CORE_C_SOURCES += src/c/scimem64.c 92CORE_C_SOURCES += src/c/scimem64.c
@@ -137,7 +138,6 @@ src/fortran/allops.f \
137src/fortran/mname.f \ 138src/fortran/mname.f \
138src/fortran/command.f \ 139src/fortran/command.f \
139src/fortran/ref2val.f \ 140src/fortran/ref2val.f \
140src/fortran/namstr.f \
141src/fortran/stack.f \ 141src/fortran/stack.f \
142src/fortran/isbrk.f \ 142src/fortran/isbrk.f \
143src/fortran/majmin.f \ 143src/fortran/majmin.f \
@@ -297,7 +297,7 @@ libscicore_la_CPPFLAGS = -I$(srcdir)/includes/ \
297 -I$(srcdir)/src/c/ \ 297 -I$(srcdir)/src/c/ \
298 -I$(srcdir)/src/cpp/ \ 298 -I$(srcdir)/src/cpp/ \
299 -I$(top_srcdir)/modules/dynamic_link/includes \ 299 -I$(top_srcdir)/modules/dynamic_link/includes \
300 -I$(top_srcdir)/libs/MALLOC/includes/ 300 -I$(top_srcdir)/libs/MALLOC/includes/
301 301
302# Used by sci_getdebuginfo: 302# Used by sci_getdebuginfo:
303if TCLTK 303if TCLTK
diff --git a/scilab/modules/core/src/cpp/namstr.cpp b/scilab/modules/core/src/cpp/namstr.cpp
new file mode 100644
index 0000000..8eae972
--- /dev/null
+++ b/scilab/modules/core/src/cpp/namstr.cpp
@@ -0,0 +1,74 @@
1#include "machine.h" // C2F
2#include "stack-def.h" // nsiz, nlgh
3
4extern "C" {
5 void C2F(namstr)(int* id, int* str, int* n, char* job);
6}
7
8namespace{
9 int const blank=40;
10 int const one_blank= (blank<<24);
11 int const two_blanks= one_blank + (blank<<16);
12 int const three_blanks= two_blanks + (blank<<8);
13 int const four_blanks= three_blanks + blank;
14}
15
16/*
17 * convert id (array of nsiz ints) <-> str (array of n <= nlgh=4*nsiz ints)
18 * each element of str is stored in 8 bits of an id. The reming bytes (after n)
19 * are filled with blanks.
20 *
21 *
22 * @param id contains the id of nsiz ints
23 * @param str contains the string of nlgh ints
24 * @param n contains the address of the (int) length of the string input for str->id, output for id->str
25 * @param job 0 => str->id, id-> str otherwise
26 *
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.
28 */
29void C2F(namstr)(int* id,int* str, int* n, char* job){
30 if(*job) { // id -> str
31 unsigned int i1(0);
32 for(unsigned int j= 0; j != nsiz; ++j, i1+=4) {
33 int id_j(id[j]);
34 for(unsigned int i(i1); i!=i1+4; ++i, id_j>>=8) {
35 int ch((id_j & 0x80) ? (id_j |0xffffff00) : (id_j & 0xff));
36 if(ch == blank) {
37 *n= i;
38 return;
39 }
40 id_j+=128;
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}