summaryrefslogtreecommitdiffstats
path: root/scilab/modules/core
diff options
context:
space:
mode:
authorBernard HUGUENEY <bernard.hugueney@scilab.org>2010-03-19 14:44:25 +0100
committerBernard HUGUENEY <bernard.hugueney@scilab.org>2010-03-19 14:44:25 +0100
commit473bcba8ff387bc72ca0ba92973b203b19bdecab (patch)
tree8c26c59ccaa61ea1559ea5056e799db2aefc288f /scilab/modules/core
parentbf02fa2487f6b1a4bb8bf8f270c81a86f4468f2c (diff)
downloadscilab-473bcba8ff387bc72ca0ba92973b203b19bdecab.zip
scilab-473bcba8ff387bc72ca0ba92973b203b19bdecab.tar.gz
partial rewrite (only the most perf sensitive loops) of funs_ in c++ (search_functions.cpp).
1°) paves the way for inlinin of eqid 2°) do not convert whole id -> name if not needed TODO: add endianness handling in upper_char and id_char
Diffstat (limited to 'scilab/modules/core')
-rw-r--r--scilab/modules/core/Makefile.am3
-rw-r--r--scilab/modules/core/src/cpp/search_functions.cpp107
-rw-r--r--scilab/modules/core/src/fortran/funs.f83
3 files changed, 128 insertions, 65 deletions
diff --git a/scilab/modules/core/Makefile.am b/scilab/modules/core/Makefile.am
index a4a0dcc..5b04324 100644
--- a/scilab/modules/core/Makefile.am
+++ b/scilab/modules/core/Makefile.am
@@ -86,7 +86,8 @@ src/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 89src/cpp/namstr.cpp \
90src/cpp/search_functions.cpp
90 91
91if USE_DYNAMIC_STACK 92if USE_DYNAMIC_STACK
92CORE_C_SOURCES += src/c/scimem64.c 93CORE_C_SOURCES += src/c/scimem64.c
diff --git a/scilab/modules/core/src/cpp/search_functions.cpp b/scilab/modules/core/src/cpp/search_functions.cpp
new file mode 100644
index 0000000..ab84e4a4
--- /dev/null
+++ b/scilab/modules/core/src/cpp/search_functions.cpp
@@ -0,0 +1,107 @@
1#include <cstdlib>
2#include <algorithm>
3extern "C" {
4#include "stack-c.h"
5#include "stack-def.h" /* C2F(basbrk) */
6#include "intmacr2tree.h" /*#define idstk(x,y) (C2F(vstk).idstk+(x-1)+(y-1)*nsiz) */
7int C2F(eqid)(int const*x, int const*y);
8void C2F(siflibs)(int* id, int* k_ptr, int* istr, int* lbibn, int* nbibn, int* ilp, int* nn, int* should_return);
9void C2F(sivars)(int* id, int* should_return);
10void C2F(namstr)(int* id, int* str, int* n, char const* job);
11}
12
13namespace {
14 char const f_true= 1;
15 char const f_false=0;
16 int const percent= 56;
17 int const nclas= 29;
18 char const from_id=1;
19
20 int upper_char(int id){ return std::abs((int)((id & 0x80) ? (id |0xffffff00) : (id & 0xff))); }
21
22 int id_char(int const* id){
23 int ch(upper_char(*id));
24 if(ch == percent){
25 ch= upper_char((*id)>>8);
26 }
27 return ch;
28 }
29}
30
31void C2F(siflibs)(int* id, int* k_ptr, int* istr, int* lbibn_ptr, int* nbibn_ptr, int* ilp_ptr, int* nn_ptr, int* should_return){
32 static int const* const lstk_ptr = (int*)C2F(vstk).lstk-1;
33 static int const* const istk_ptr = ((int*)C2F(stack).Stk)-1;
34 *should_return= f_false;
35 int k, ilp, nbibn, lbibn;
36 for(k= Bot-1; k < C2F(vstk).isiz; ++k){
37 int il=iadr(lstk_ptr[k]);
38 int ip;
39 if(istk_ptr[il] == sci_lib){
40 nbibn=istk_ptr[il+1];
41 lbibn=il+2;
42 il+= nbibn+2;
43 ilp=il+1;
44 ip=std::max(1, id_char(id)-9);
45 if(ip <= nclas){
46 int n=istk_ptr[ilp+ip] -istk_ptr[ilp+ip-1];
47 if(n != 0){
48 int iln= ilp+nclas+1+(istk_ptr[ilp+ip-1]-1)*nsiz;
49 for(int i= 1; i<=n; ++i, iln+= nsiz){
50 if(C2F(eqid)(id, istk_ptr+iln)){ // 39
51 if((Fin == -1) || (Fin == -3)){
52 C2F(com).fun= k;
53 Fin= i;
54 *should_return= f_true;
55 return;
56 }
57 Fin= i;
58 if(C2F(errgst).err1 != 0){
59 C2F(com).fun= Fin= 0;
60 *should_return= f_true;
61 return;
62 }
63 C2F(namstr)(id,istr, nn_ptr, &from_id);
64 *k_ptr= k;
65 *lbibn_ptr= lbibn;
66 *nbibn_ptr= nbibn;
67 *ilp_ptr= ilp;
68 *should_return= f_false;
69 return;
70 }
71 }
72 }
73
74 }
75
76 }
77
78 }
79 C2F(com).fun= Fin= 0;
80 *should_return= f_true;
81 return;
82}
83
84
85void C2F(sivars)(int* id, int* should_return){
86 int* const lstk_ptr = (int*)C2F(vstk).lstk-1;
87
88 int k;
89 // idstk(x,y) (C2F(vstk).idstk+(x-1)+(y-1)*nsiz)
90 int* id_addr=C2F(vstk).idstk;
91 for( *should_return= f_false, k= Bot-1, id_addr+=(k-1)*nsiz
92 ; k <= C2F(vstk).isiz && !C2F(eqid)(id_addr, id); ++k, id_addr+=nsiz){
93 }
94 if( k <= C2F(vstk).isiz ){// eq_id
95 int il=lstk_ptr[k];//iadr()
96 il<<=1;
97 ++il;
98 if((*istk(il)!=sci_u_function) &&(*istk(il)!=sci_c_function)) {
99 C2F(com).fun= Fin= 0;
100 *should_return= f_true;
101 }
102 C2F(com).fun= -1;
103 Fin= k;
104 *should_return= f_true;
105 }
106 return; // *should_return= f_false;
107}
diff --git a/scilab/modules/core/src/fortran/funs.f b/scilab/modules/core/src/fortran/funs.f
index 137d960..e979568 100644
--- a/scilab/modules/core/src/fortran/funs.f
+++ b/scilab/modules/core/src/fortran/funs.f
@@ -1,10 +1,10 @@
1c Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 1c Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2c Copyright (C) INRIA 2c Copyright (C) INRIA
3c 3c
4c This file must be used under the terms of the CeCILL. 4c This file must be used under the terms of the CeCILL.
5c This source file is licensed as described in the file COPYING, which 5c This source file is licensed as described in the file COPYING, which
6c you should have received as part of this distribution. The terms 6c you should have received as part of this distribution. The terms
7c are also available at 7c are also available at
8c http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt 8c http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
9 9
10 subroutine funs(id) 10 subroutine funs(id)
@@ -15,18 +15,19 @@ c ====================================================================
15 parameter (nz1=nsiz-1,nz2=nsiz-2) 15 parameter (nz1=nsiz-1,nz2=nsiz-2)
16 integer id(nsiz),istr(nlgh) 16 integer id(nsiz),istr(nlgh)
17c 17c
18 logical eqid,cresmat 18 logical cresmat
19 integer srhs,percen,fptr,slhs,r 19 integer srhs,percen,fptr,slhs,r
20 integer iadr 20 integer iadr
21 logical toreturn
21 data nclas/29/,percen/56/ 22 data nclas/29/,percen/56/
22c 23c
23 iadr(l)=l+l-1 24 iadr(l)=l+l-1
24c 25c
25c look only in scilab code function libraries 26c look only in scilab code function libraries
26 if(fin.eq.-3) goto 35 27 if(fin.eq.-3) goto 35
27 if(fin.eq.-4) goto 30 28 if(fin.eq.-4) goto 30
28c 29c
29c 30c
30 if (comp(1).ne.0) then 31 if (comp(1).ne.0) then
31c if compilation mode skip primitive functions 32c if compilation mode skip primitive functions
32 fin=0 33 fin=0
@@ -45,66 +46,24 @@ c look for name in primitive functions
45 fin = mod(fptr,1000) 46 fin = mod(fptr,1000)
46 endif 47 endif
47 return 48 return
48c 49c
49c is a scilab code function already loaded in the variables stack 50c is a scilab code function already loaded in the variables stack
50 30 k=bot-1 51 30 call sivars(id, toreturn)
51 31 k=k+1 52 if(toreturn) then
52 if(k.gt.isiz) goto 35
53 if(.not.eqid(idstk(1,k),id)) goto 31
54 il=iadr(lstk(k))
55c modif 1.3 SS
56 if(istk(il).ne.11.and.istk(il).ne.13) then
57 fin=0
58 fun=0
59 return 53 return
60 endif 54 endif
61 fin=k 55c
62 fun=-1
63 return
64c
65c look in scilab code function libraries 56c look in scilab code function libraries
66 35 k=bot-1 57 35 call siflibs(id, k, istr, lbibn, nbibn, ilp, nn, toreturn)
67 36 k=k+1 58 if(toreturn) then
68 if(k.ge.isiz) then
69 fin=0
70 fun=0
71 return 59 return
72 endif 60 endif
73 il=iadr(lstk(k)) 61c
74 if(istk(il).ne.14) goto 36 62c
75 nbibn=istk(il+1) 63
76 lbibn=il+2 64c
77 il=lbibn+nbibn
78 ilp=il+1
79 call namstr(id,istr,nn,1)
80 ip=abs(istr(1))
81 if(ip.eq.percen) ip=abs(istr(2))
82 ip=max(1,ip-9)
83 if(ip.gt.nclas) goto 36
84 n=istk(ilp+ip)-istk(ilp+ip-1)
85 if(n.eq.0) goto 36
86 iln=ilp+nclas+1+(istk(ilp+ip-1)-1)*nsiz
87 do 37 l=1,n
88 if(eqid(id,istk(iln))) goto 39
89 iln=iln+nsiz
90 37 continue
91 goto 36
92c
93c
94 39 if(fin.ne.-1.and.fin.ne.-3) goto 40
95 fun=k
96 fin=l
97 return
98c
99 40 fin=l
100 if(err1.ne.0) then
101 fun=0
102 fin=0
103 return
104 endif
105c
106c load it in the variables stack 65c load it in the variables stack
107 66
108c create a variable with the bin file path 67c create a variable with the bin file path
109 n=nbibn 68 n=nbibn
110c get name and its length 69c get name and its length
@@ -115,7 +74,7 @@ c get name and its length
115c path 74c path
116 call icopy(nbibn,istk(lbibn),1,istk(ilp),1) 75 call icopy(nbibn,istk(lbibn),1,istk(ilp),1)
117c name 76c name
118 call icopy(nn,istr,1,istk(ilp+nbibn),1) 77 call icopy(nn,istr,1,istk(ilp+nbibn),1)
119c extension 78c extension
120 call cvstr(4,istk(ilp+nbibn+nn),'.bin',0) 79 call cvstr(4,istk(ilp+nbibn+nn),'.bin',0)
121c load variables stored in the given file 80c load variables stored in the given file
@@ -157,7 +116,3 @@ c . requested varible not loaded
157 return 116 return
158c 117c
159 end 118 end
160
161
162
163