~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to macros/sci2for/%x2for.sci

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function [stk,nwrk,txt,top]=%x2for(nwrk)
 
2
// multiplications 
 
3
//!
 
4
// Copyright INRIA
 
5
 
 
6
s2=stk(top);s1=stk(top-1);
 
7
txt1=[]
 
8
if s1(3)<>s2(3) then
 
9
  if s1(3)=='0' then 
 
10
    [s1,nwrk,txt1]=typconv(s1,nwrk,'1'),
 
11
  else
 
12
    [s2,nwrk,txt1]=typconv(s2,nwrk,'1'),
 
13
  end
 
14
end
 
15
[s1,te1,t1,m1,n1]=s1(1:5);
 
16
[s2,te2,t2,m2,n2]=s2(1:5);
 
17
it1=prod(size(s1))-1;it2=prod(size(s2))-1
 
18
if t1<>t2 then
 
19
  if t2=='0' then t2='1',end
 
20
end
 
21
//
 
22
if m1=='1'&n1=='1'&m2=='1'&n2=='1' then // cas scalaire
 
23
  select it1+2*it2
 
24
  case 0 then
 
25
     if te2=='2' then s2='('+s2+')',end
 
26
     if te1=='2' then s1='('+s1+')',end
 
27
     stk=list(mulf(s1,s2),'1',t2,m1,n1)
 
28
  case 1 then
 
29
     if te1=='2' then s1(1)='('+s1(1)+')',s1(2)='('+s1(2)+')',   end
 
30
     if te2=='2' then s2='('+s2+')',end
 
31
     stk=list([mulf(s1(1),s2(1)),mulf(s1(2),s2(1))],'1',t2,m1,n1)
 
32
  case 2 then
 
33
     if te2=='2' then s2(1)='('+s2(1)+')',s2(2)='('+s2(2)+')',   end
 
34
     if te1=='2' then s1='('+s1+')',end
 
35
     stk=list([mulf(s1(1),s2(1)),mulf(s1(1),s2(2))],'1',t2,m1,n1)
 
36
  case 3 then
 
37
     if te1=='2' then s1(1)='('+s1(1)+')',s1(2)='('+s1(2)+')',   end
 
38
     if te2=='2' then s2(1)='('+s2(1)+')',s2(2)='('+s2(2)+')',   end
 
39
     stk=list([subf(mulf(s1(1),s2(1)),mulf(s1(2),s2(2))),..
 
40
               addf(mulf(s1(1),s2(2)),mulf(s1(2),s2(1))) ],'1',t2,m1,n1)
 
41
  end
 
42
  txt=[txt1;txt]
 
43
  top=top-1
 
44
  return
 
45
end 
 
46
if m1=='1'&n1=='1' then
 
47
  mn2=mulf(m2,n2)
 
48
  select it1+2*it2
 
49
  case 0 then
 
50
  [out,nwrk,txt]=outname(nwrk,t2,m2,n2)
 
51
  if out<>s2 then
 
52
    txt=[txt;gencall(['dcopy',mn2,s2,'1',out,'1'])]
 
53
  end
 
54
  txt=[txt;gencall(['dscal',mn2,s1,out,'1'])]
 
55
  if ~isnum(s1)&op(2)==s1 then
 
56
    txt=[txt;gencall(['dcopy',mn2,out,'1',s1,'1'])]
 
57
    out=s1
 
58
  end
 
59
  stk=list(out,'-1',t2,m2,n2)
 
60
  case 1 then
 
61
    [outr,nwrk,txt]=outname(nwrk,t2,m2,n2)
 
62
    if part(outr,1:4)<>'work' then
 
63
      outi=outr+'_i'
 
64
      outr=outr+'_r'
 
65
    else
 
66
      [outi,nwrk,txt]=outname(nwrk,t2,m2,n2)
 
67
    end
 
68
    txt=[txt;
 
69
         gencall(['dcopy',mn2,s2,'1',outr,'1']);
 
70
         gencall(['dcopy',mn2,s2,'1',outi,'1']);
 
71
         gencall(['dscal',mn2,s1(1),outr,'1']);
 
72
         gencall(['dscal',mn2,s1(2),outi,'1'])];
 
73
    stk=list([outr,outi],'-1',t2,m2,n2)
 
74
  case 2 then
 
75
    [outr,nwrk,txt]=outname(nwrk,t2,m2,n2)
 
76
    if part(outr,1:4)<>'work' then
 
77
      outi=outr+'_i'
 
78
      outr=outr+'_r'
 
79
    else
 
80
     [outi,nwrk,txt]=outname(nwrk,t2,m2,n2)
 
81
    end
 
82
    txt=[txt;
 
83
         gencall(['dcopy',mn2,s2(1),'1',outr,'1']);
 
84
         gencall(['dcopy',mn2,s2(2),'1',outi,'1']);
 
85
         gencall(['dscal',mn2,s1,outr,'1']);
 
86
         gencall(['dscal',mn2,s1,outi,'1'])];
 
87
    stk=list([outr,outi],'-1',t2,m2,n2)
 
88
  case 3 then
 
89
    [outr,nwrk,txt]=outname(nwrk,t2,m2,n2)
 
90
    if part(outr,1:4)<>'work' then
 
91
      outi=outr+'_i'
 
92
      outr=outr+'_r'
 
93
    else
 
94
      [outi,nwrk,txt]=outname(nwrk,t2,m2,n2)
 
95
    end
 
96
    txt=[txt;
 
97
         gencall(['dcopy',mn2,s2(1),'1',outr,'1']);
 
98
         gencall(['dcopy',mn2,s2(2),'1',outi,'1']);
 
99
         gencall(['wscal',mn2,s1(1),s1(2),outr,outi,'1'])];
 
100
  stk=list([outr,outi],'-1',t2,m2,n2)
 
101
  end
 
102
  txt=[txt1;txt]
 
103
  top=top-1
 
104
  return
 
105
end 
 
106
if m2=='1'&n2=='1' then
 
107
  mn1=mulf(m1,n1)
 
108
  select it1*2*it2
 
109
  case 0 then
 
110
    [out,nwrk,txt]=outname(nwrk,t2,m1,n1)
 
111
    if out<>s1 then txt=[txt;gencall(['dcopy',mn1,s1,'1',out,'1'])], end
 
112
    txt=[txt;gencall(['dscal',mn1,s2,out,'1'])]
 
113
    if ~isnum(s2)&op(2)==s2 then
 
114
      txt=[txt;gencall(['dcopy',mn1,out,'1',s2,'1'])]
 
115
      out=s2
 
116
    end
 
117
    stk=list(out,'-1',t2,m1,n1)
 
118
  case 1 then
 
119
    [outr,nwrk,txt]=outname(nwrk,t1,m1,n1)
 
120
    if part(outr,1:4)<>'work' then
 
121
      outi=outr+'_i'
 
122
      outr=outr+'_r'
 
123
    else
 
124
      [outi,nwrk,txt]=outname(nwrk,t2,m2,n2)
 
125
    end
 
126
    txt=[txt;
 
127
         gencall(['dcopy',mn1,s1(1),'1',outr,'1']);
 
128
         gencall(['dcopy',mn1,s1(2),'1',outi,'1']);
 
129
         gencall(['dscal',mn1,s2,outr,'1']);
 
130
         gencall(['dscal',mn1,s2,outi,'1'])];
 
131
    stk=list([outr,outi],'-1',t2,m1,n1)
 
132
  case 2 then
 
133
    [outr,nwrk,txt]=outname(nwrk,t1,m1,n1)
 
134
    if part(outr,1:4)<>'work' then
 
135
      outi=outr+'_i'
 
136
      outr=outr+'_r'
 
137
    else
 
138
      [outi,nwrk,txt]=outname(nwrk,t2,m2,n2)
 
139
    end
 
140
    txt=[txt;
 
141
         gencall(['dcopy',mn1,s1,'1',outr,'1']);
 
142
         gencall(['dcopy',mn1,s1,'1',outi,'1']);
 
143
         gencall(['dscal',mn1,s2(1),outr,'1']);
 
144
         gencall(['dscal',mn1,s2(2),outi,'1'])];
 
145
    stk=list([outr,outi],'-1',t2,m1,n1)
 
146
  case 3 then
 
147
    [outr,nwrk,txt]=outname(nwrk,t1,m1,n1)
 
148
    if part(outr,1:4)<>'work' then
 
149
      outi=outr+'_i'
 
150
      outr=outr+'_r'
 
151
    else
 
152
      [outi,nwrk,txt]=outname(nwrk,t2,m2,n2)
 
153
    end
 
154
    txt=[txt;
 
155
         gencall(['dcopy',mn1,s1(1),'1',outr,'1']);
 
156
         gencall(['dcopy',mn1,s1(2),'1',outi,'1']);
 
157
         gencall(['wscal',mn1,s2(1),s2(2),outr,outi,'1'])]
 
158
    stk=list([outr,outi],'-1',t2,m1,n1)
 
159
  end
 
160
  txt=[txt1;txt]
 
161
  top=top-1
 
162
  return
 
163
end 
 
164
  select it1+2*it2
 
165
  case 0 then
 
166
    [out,nwrk,txt]=outname(nwrk,t2,m1,n2,[s1,s2])
 
167
    txt=[txt;
 
168
         gencall(['dcopy',mulf(m1,n2),s1,'1',out,'1'])
 
169
         gencall(['dvmul',mulf(m1,n2),s2,'1',out,'1'])]
 
170
    stk=list(out,'-1',t2,m1,n2)
 
171
  case 1 then
 
172
    [outr,nwrk,txt]=outname(nwrk,t2,m1,n2,[s1,s2])
 
173
    [outi,nwrk,txt]=outname(nwrk,t2,m1,n2,[s1,s2])
 
174
    txt=[txt;
 
175
         gencall(['dcopy',mulf(m1,n2),s1(1),'1',outr,'1'])
 
176
         gencall(['dcopy',mulf(m1,n2),s1(2),'1',outi,'1'])
 
177
         gencall(['dvmul',mulf(m1,n2),s2(1),'1',outr,'1'])
 
178
         gencall(['dvmul',mulf(m1,n2),s2(1),'1',outi,'1'])]
 
179
    stk=list([outr,outi],'-1',t2,m1,n2)
 
180
  case 2 then
 
181
    [outr,nwrk,txt]=outname(nwrk,t2,m1,n2,[s1,s2])
 
182
    [outi,nwrk,txt]=outname(nwrk,t2,m1,n2,[s1,s2])
 
183
    txt=[txt;
 
184
         gencall(['dcopy',mulf(m1,n2),s2(1),'1',outr,'1'])
 
185
         gencall(['dcopy',mulf(m1,n2),s2(2),'1',outi,'1'])
 
186
         gencall(['dvmul',mulf(m1,n2),s1(1),'1',outr,'1'])
 
187
         gencall(['dvmul',mulf(m1,n2),s1(1),'1',outi,'1'])]
 
188
    stk=list([outr,outi],'-1',t2,m1,n2)
 
189
  case 3 then
 
190
    [outr,nwrk,txt]=outname(nwrk,t2,m1,n2,[s1,s2])
 
191
    [outi,nwrk,txt]=outname(nwrk,t2,m1,n2,[s1,s2])
 
192
    txt=[txt;
 
193
         gencall(['dcopy',mulf(m1,n2),s1(1),'1',outr,'1'])
 
194
         gencall(['dcopy',mulf(m1,n2),s1(2),'1',outi,'1'])
 
195
         gencall(['wvmul',mulf(m1,n2),s2(1),s2(2),'1',outr,outi,'1'])]
 
196
    stk=list([outr,outi],'-1',t2,m1,n2)
 
197
  end
 
198
  txt=[txt1;txt]
 
199
  top=top-1
 
200
  return
 
201
endfunction