Subversion Repositories tendra.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    Copyright (c) 1993 Open Software Foundation, Inc.
3
 
4
 
5
    All Rights Reserved
6
 
7
 
8
    Permission to use, copy, modify, and distribute this software
9
    and its documentation for any purpose and without fee is hereby
10
    granted, provided that the above copyright notice appears in all
11
    copies and that both the copyright notice and this permission
12
    notice appear in supporting documentation.
13
 
14
 
15
    OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING
16
    ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17
    PARTICULAR PURPOSE.
18
 
19
 
20
    IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
21
    CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
22
    LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
23
    NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
24
    WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25
*/
26
 
27
/*
28
    		 Crown Copyright (c) 1997
29
 
30
    This TenDRA(r) Computer Program is subject to Copyright
31
    owned by the United Kingdom Secretary of State for Defence
32
    acting through the Defence Evaluation and Research Agency
33
    (DERA).  It is made available to Recipients with a
34
    royalty-free licence for its use, reproduction, transfer
35
    to other parties and amendment for any purpose not excluding
36
    product development provided that any such use et cetera
37
    shall be deemed to be acceptance of the following conditions:-
38
 
39
        (1) Its Recipients shall ensure that this Notice is
40
        reproduced upon any copies or amended versions of it;
41
 
42
        (2) Any amended version of it shall be clearly marked to
43
        show both the nature of and the organisation responsible
44
        for the relevant amendment or amendments;
45
 
46
        (3) Its onward transfer from a recipient to another
47
        party shall be deemed to be that party's acceptance of
48
        these conditions;
49
 
50
        (4) DERA gives no warranty or assurance as to its
51
        quality or suitability for any purpose and DERA accepts
52
        no liability whatsoever in relation to any use to which
53
        it may be put.
54
*/
55
 
56
 
57
 
58
/**********************************************************************
59
$Author: release $
60
$Date: 1998/02/04 15:48:58 $
61
$Revision: 1.2 $
62
$Log: mem_copy.c,v $
63
 * Revision 1.2  1998/02/04  15:48:58  release
64
 * Added OSF copyright message.
65
 *
66
 * Revision 1.1.1.1  1998/01/17  15:55:57  release
67
 * First version to be checked into rolling release.
68
 *
69
 * Revision 1.2  1996/10/04  16:02:34  pwe
70
 * add banners and mod for PWE ownership
71
 *
72
**********************************************************************/
73
 
74
 
75
#include "config.h"
76
#include "memtdf.h"
77
#include "codegen.h"
78
#include "comment.h"
79
#include "myassert.h"
80
#include "mem_copy.h"
81
 
82
 
83
#define MAX_BYTE_COPY 80
84
 
85
void static_memory_copy PROTO_N ((reg_from,reg_to,number_of_bytes)) PROTO_T ( int reg_from X int reg_to X int number_of_bytes)
86
{
87
  baseoff from;
88
  baseoff to;
89
  int bytes;
90
  int words;
91
  int i;
92
  COMMENT3("memory copy of %d bytes from R_%d to R_%d",number_of_bytes,reg_from,reg_to);
93
  ASSERT(number_of_bytes >=0);
94
  if(reg_from == reg_to || number_of_bytes==0 )
95
  {
96
    /* Nothing to do */
97
    return;
98
  }
99
  words = number_of_bytes/4;
100
  bytes = number_of_bytes - (words *4);
101
 
102
  from.base = reg_from;
103
  from.offset = 0;
104
  to.base = reg_to;
105
  to.offset = 0;  
106
 
107
  if(number_of_bytes <= MAX_BYTE_COPY)
108
  {
109
    /* copy the words */
110
    for(i=0;i<words;i++)
111
    {
112
      ld_ro_ins(i_l,from,R_TMP0);comment(NIL);
113
      st_ro_ins(i_st,R_TMP0,to);comment(NIL);
114
      from.offset += 4;
115
      to.offset += 4;
116
    }
117
    /* copy the bytes */
118
    for(i=0;i<bytes;i++)
119
    {
120
      ld_ro_ins(i_lbz,from,R_TMP0);comment(NIL);
121
      st_ro_ins(i_stb,R_TMP0,to);comment(NIL);
122
      from.offset +=1;
123
      to.offset +=1;
124
    }
125
  }
126
  else
127
  {
128
    if(words >0)
129
    {
130
      /* dynamically copy */
131
      int loop = new_label();
132
      from.base = reg_from;
133
      from.offset = 4;
134
      to.base = reg_to;
135
      to.offset = 4;
136
      rir_ins(i_a,reg_from,-4,reg_from);
137
      rir_ins(i_a,reg_to,-4,reg_to);
138
      ld_const_ins(words,R_TMP0);
139
      mt_ins(i_mtctr,R_TMP0);
140
      set_label(loop);
141
      ld_ro_ins(i_lu,from,R_TMP0);comment(NIL);
142
      st_ro_ins(i_stu,R_TMP0,to);comment(NIL);
143
      uncond_ins(i_bdn,loop);
144
      rir_ins(i_a,reg_from,4,reg_from);
145
      rir_ins(i_a,reg_to,4,reg_to);
146
    }
147
    from.base = reg_from;
148
    from.offset = 0;
149
    to.base = reg_to;
150
    to.offset =0;
151
    for(i=0;i<bytes;i++)
152
    {
153
      ld_ro_ins(i_lbz,from,R_TMP0);comment(NIL);
154
      st_ro_ins(i_stb,R_TMP0,to);comment(NIL);
155
      from.offset +=1;
156
      to.offset +=1;
157
    }
158
 
159
    /* restore the pointers to their initial values */
160
    if(words>0)
161
    {
162
      rir_ins(i_a,reg_from,-4 * words,reg_from);
163
      rir_ins(i_a,reg_to,-4 * words,reg_to);
164
    }
165
  }
166
  return;
167
}
168
void reverse_static_memory_copy PROTO_N ((reg_from,reg_to,number_of_bytes)) PROTO_T (int reg_from X int reg_to X int number_of_bytes)
169
{
170
  int bytes;
171
  int words;
172
  int r;
173
  baseoff from;
174
  baseoff to;
175
  int offset;
176
 
177
  from.base = reg_from;
178
  to.base = reg_to;
179
 
180
  COMMENT("reverse static memory copy");
181
 
182
  words = number_of_bytes/4;
183
  bytes = number_of_bytes - (4*words);
184
 
185
  offset = number_of_bytes;
186
  for(r = 0;r<bytes;r++)
187
  {
188
    offset -=1;
189
    from.offset =offset;
190
    to.offset = offset;
191
    ld_ro_ins(i_lbz,from,R_TMP0);comment(NIL);
192
    st_ro_ins(i_stb,R_TMP0,to);comment(NIL);
193
  }
194
  for(r = 0;r<words;r++)
195
  {
196
    offset -=4;
197
    from.offset =offset;
198
    to.offset = offset;
199
    ld_ro_ins(i_l,from,R_TMP0);comment(NIL);
200
    st_ro_ins(i_st,R_TMP0,to);comment(NIL);
201
  }
202
  ASSERT(offset ==0);
203
  return;
204
}
205
 
206
void dynamic_byte_memory_copy PROTO_N ((reg_from,reg_to,reg_size)) PROTO_T (int reg_from X int reg_to X int reg_size)
207
{
208
  /* reg_size contains the number of bytes to copy */
209
  int zero = new_label();
210
  int loop = new_label();
211
  int creg = next_creg();
212
  baseoff from;
213
  baseoff to;
214
  COMMENT3("dynamic copy (byte at a time) from R_%d ro R_%d using no of bytes in R_%d",reg_from,reg_to,reg_size);
215
 
216
  cmp_ri_ins(i_cmp,reg_size,0,creg);
217
  bc_ins(i_beq,creg,zero,UNLIKELY_TO_JUMP);
218
  from.base = reg_from;
219
  from.offset =1;
220
  to.base = reg_to;
221
  to.offset =1;
222
 
223
  rir_ins(i_a,reg_from,-1,reg_from);
224
  rir_ins(i_a,reg_to,-1,reg_to);
225
 
226
  mt_ins(i_mtctr,reg_size);
227
 
228
  set_label(loop);
229
  ld_ro_ins(i_lbzu,from,R_TMP0);comment(NIL);
230
  st_ro_ins(i_stbu,R_TMP0,to);comment(NIL);
231
  uncond_ins(i_bdn,loop);
232
 
233
  rir_ins(i_a,reg_from,1,reg_from);
234
  rir_ins(i_a,reg_to,1,reg_to);
235
  set_label(zero);
236
 
237
  /* reg_from goes to reg_from + reg_size */
238
  /* reg_to goes to reg_to + reg_size */
239
  return;
240
}
241
void reverse_dynamic_byte_memory_copy PROTO_N ((reg_from,reg_to,reg_size)) PROTO_T (int reg_from X int reg_to X int reg_size )
242
{
243
  /* reg_size contains the number of bytes to copy */
244
  int zero = new_label();
245
  int loop = new_label();
246
  int creg = next_creg();
247
  baseoff from;
248
  baseoff to;
249
  COMMENT3("reverse dynamic copy (byte at a time) from R_%d ro R_%d using no of bytes in R_%d",reg_from,reg_to,reg_size);
250
  cmp_ri_ins(i_cmp,reg_size,0,creg);
251
  bc_ins(i_beq,creg,zero,UNLIKELY_TO_JUMP);
252
  from.base = reg_from;
253
  from.offset = -1;
254
  to.base = reg_to;
255
  to.offset = -1;
256
  rrr_ins(i_a,reg_from,reg_size,reg_from);
257
  rrr_ins(i_a,reg_to,reg_size,reg_to);
258
  mt_ins(i_mtctr,reg_size);
259
  set_label(loop);
260
  ld_ro_ins(i_lbzu,from,R_TMP0);comment(NIL);
261
  st_ro_ins(i_stbu,R_TMP0,to);comment(NIL);
262
  uncond_ins(i_bdn,loop);
263
 
264
  set_label(zero);
265
 
266
  return;
267
}
268
 
269
void dynamic_word_memory_copy PROTO_N ((reg_from,reg_to,reg_size)) PROTO_T (int reg_from X int reg_to X int reg_size)
270
{
271
  /* reg_size contains the number of bytes to copy */
272
  /* however in this case we do it word at a time */
273
  int zero = new_label();
274
  int loop = new_label();
275
  int creg = next_creg();
276
  baseoff from;
277
  baseoff to;
278
  COMMENT3("dynamic copy (word at a time) from R_%d ro R_%d using no of bytes in R_%d",reg_from,reg_to,reg_size);
279
  cmp_ri_ins(i_cmp,reg_size,0,creg);
280
  bc_ins(i_beq,creg,zero,UNLIKELY_TO_JUMP);
281
  from.base = reg_from;
282
  from.offset =4;
283
  to.base = reg_to;
284
  to.offset =4;
285
 
286
  rir_ins(i_a,reg_from,-4,reg_from);
287
  rir_ins(i_a,reg_to,-4,reg_to);
288
 
289
  rir_ins(i_sr,reg_size,2,R_TMP0);
290
  mt_ins(i_mtctr,R_TMP0);
291
 
292
  set_label(loop);
293
  ld_ro_ins(i_lu,from,R_TMP0);comment(NIL);
294
  st_ro_ins(i_stu,R_TMP0,to);comment(NIL);
295
  uncond_ins(i_bdn,loop);
296
 
297
  rir_ins(i_a,reg_from,4,reg_from);
298
  rir_ins(i_a,reg_to,4,reg_to);
299
  set_label(zero);
300
 
301
  /* reg_from goes to reg_from + reg_size */
302
  /* reg_to goes to reg_to + reg_size */
303
  return;
304
}
305
void reverse_dynamic_word_memory_copy PROTO_N ((reg_from,reg_to,reg_size)) PROTO_T (int reg_from X int reg_to X int reg_size )
306
{
307
  int zero = new_label();
308
  int loop = new_label();
309
  int creg = next_creg();
310
  baseoff from;
311
  baseoff to;
312
  COMMENT3("reverse dynamic copy (word at a time) from R_%d ro R_%d using no of bytes in R_%d",reg_from,reg_to,reg_size);
313
  cmp_ri_ins(i_cmp,reg_size,0,creg);
314
  bc_ins(i_beq,creg,zero,UNLIKELY_TO_JUMP);
315
  from.base = reg_from;
316
  from.offset = -4;
317
  to.base = reg_to;
318
  to.offset = -4;
319
  rrr_ins(i_a,reg_from,reg_size,reg_from);
320
  rrr_ins(i_a,reg_to,reg_size,reg_to);
321
  rir_ins(i_sr,reg_size,2,R_TMP0);
322
  mt_ins(i_mtctr,R_TMP0);
323
 
324
  set_label(loop);
325
  ld_ro_ins(i_lu,from,R_TMP0);comment(NIL);
326
  st_ro_ins(i_stu,R_TMP0,to);comment(NIL);
327
  uncond_ins(i_bdn,loop);
328
 
329
  set_label(zero);
330
 
331
  /* reg_from and reg_to are unchanged */
332
  return;
333
}