source: trunk/platforms/caba-ring-vcache2_memcache-mipsel/soft/main.c @ 3

Last change on this file since 3 was 3, checked in by nipo, 14 years ago

Import platforms

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to "Author Date Id Rev URL Revision"
  • Property svn:mime-type set to text/plain
File size: 7.4 KB
Line 
1#include "system.h"
2#include "stdio.h"
3#include "stdlib.h"
4
5
6#include "../segmentation.h"
7
8#define NPROCS 4
9#define SIZE 100
10#define SORT_TYPE 1
11
12volatile int lock=0;
13volatile int compteur=NPROCS;
14volatile int nprocs=NPROCS;
15
16// 100 elements
17unsigned int gQSortNum0[100] = {
18  251,  24, 113, 170, 215,  60,  83,  30, 115,  48, 169, 210,  49,  92, 101,  58,  21, 184, 225,   6,
19  199, 244, 227, 146,  99,  96,  25, 222,  65, 140, 213,  22, 219, 136, 175, 182,  73,  36, 141, 190,
20   83, 112, 137, 114, 175, 188, 187, 102,  53, 168, 193, 154, 167, 172,   3, 242,  67,  64, 144, 137,
21  142, 175, 188,  69, 102,  53, 168, 193, 102,  89, 172, 253, 242,  67, 192,   7,  62, 159,  20, 181,
22  182, 187, 216, 207,  22, 105, 132, 109, 162, 205,  16, 151,  18, 113, 228,  37,   6,  85,   8, 161
23};
24
25unsigned int SortArr0[2*(SIZE)];
26
27void SORT(int *base, int n, int size, int (*compar) (),int type);
28void QSORT(int *base, int n, int size, int (*compar) ());
29void simple_sort(int *base, int n, int size, int (*compar) ());
30void insertion_sort(int *base, int n, int size, int (*compar) ());
31void bubble_sort(int *base, int n, int size, int (*compar) ());
32int compare(int *n1, int *n2)
33{
34  return (*((unsigned int *) n1) - *((unsigned int *) n2));
35}
36
37int main()
38{
39/* -------------------------------------------------- */
40        // define the page table entry
41        uint32_t * ptd_table;
42        ptd_table = (uint32_t *)PTD_ADDR;
43
44        ptd_table[2] = 0xC0040403;      // PTD for instruction   
45        ptd_table[4] = 0xC0040402;      // PTD for tty
46
47        ptd_table[128] = 0x8D000080;    // PTE for data ram
48        ptd_table[1024] = 0x8D800400;   // PTE for exception
49       
50        // tty pte
51        uint32_t * pte_table;
52        pte_table = (uint32_t *)PTE_ADDR;
53        pte_table[0] = 0x85000000;      //tty no global
54        pte_table[1] = 0x000C0200;      //tty no global
55
56        // instruction pte
57        uint32_t * ipte_table;
58        ipte_table = (uint32_t *)IPTE_ADDR;
59        ipte_table[0] = 0x8B000000;
60        ipte_table[1] = 0x00000400;
61
62        puts("Page table are defined! \n");
63
64        // context switch and tlb mode change
65        set_cp2(0, 0, 0x00020200);      // context switch
66        set_cp2(1, 0, 0xf);             // TLB enable
67        puts("Context switch(TLB flush) and TLB enable!\n");
68
69        set_cp2(2, 0, 0);
70        puts("icache flush done!\n");
71
72        set_cp2(3, 0, 0);
73        puts("dcache flush done!\n");
74
75        // cache inval
76        //set_cp2(6, 0, 0x004000a4);
77        set_cp2(6, 0, 0x004000c4);
78        puts("icache invalidation test good :-)\n");
79        set_cp2(7, 0, 0x00800000);
80        puts("dcache invalidation test good :-) \n");
81
82        // tlb inval
83        puts("TLB invalidation test begin: \n");
84        set_cp2(4, 0, 0x00400000);
85        puts("itlb invalidation test good :-) \n");
86        set_cp2(5, 0, 0x00800000);
87        puts("dtlb invalidation test good :-) \n");
88
89/* -------------------------------------------------- */
90  register int p;
91
92  p=procnum();
93
94  puts("Hello from processor ");
95  putchar(p+'0');
96  putchar('\n');
97
98
99  int i;
100  int j;
101  int temp;
102
103  if(p+1 <= nprocs){
104        for(i=1 ; i <= 8 ; i++ ){
105        puts("Memory copy \n");
106        memcpy(SortArr0+p*(SIZE), gQSortNum0 + ( (4*(p+1)*i) % 32) ,SIZE);
107       
108        puts("Sort... \n");
109        SORT((int *) (SortArr0+p*(SIZE)), (int) SIZE, sizeof(unsigned int), compare,SORT_TYPE);
110        for (j = 1; j < SIZE; j++)
111        {
112                if (SortArr0[p*(SIZE)+j] < SortArr0[p*(SIZE) + j - 1])
113                {
114                        puts("ucbqsort: failed\n");
115                        while(1);
116                }
117
118        }
119        puts("ucbqsort: success\n");
120        }
121  }
122 
123
124  if(p+1 <= nprocs){
125        lock_lock(&lock);
126        compteur--;
127        if(!compteur){
128                putchar('\n');
129                puti(temp);
130                putchar('\n');
131        }
132        lock_unlock(&lock);
133  }
134
135  while(1);
136}
137
138static int (*qcmp) ();
139static int qsz;
140static int thresh;
141static int mthresh;
142static void qst(int *, int *);
143void QSORT(base, n, size, compar)
144     int *base;
145     int n;
146     int size;
147     int (*compar) ();
148{
149  register int c, *i, *j, *lo, *hi;
150  int *min, *max;
151  if (n <= 1)
152    return;
153  qsz = size;
154  qcmp = compar;
155  thresh = 4;
156  mthresh = 6;
157  max = base + n;
158  if (n >= 4)
159    {
160      qst(base, max);
161      hi = base + thresh;
162    }
163  else
164    {
165      hi = max;
166    }
167
168  puts("Quick sort done... \n");
169
170  for (j = lo = base; (lo ++) < hi;)
171    if ((*qcmp) (j, lo) > 0)
172      j = lo;
173  if (j != base)
174    {
175      for (i = base, hi = base + 1; i < hi;)
176        {
177          c = *j;
178          *j++ = *i;
179          *i++ = c;
180        }
181
182    }
183  for (min = base; (hi = min ++) < max;)
184    {
185      while ((*qcmp) (hi --, min) > 0)
186        ;
187      if ((hi ++) != min)
188        {
189          for (lo = min + 1; --lo >= min;)
190            {
191              c = *lo;
192              for (i = j = lo; (j --) >= hi; i = j)
193                *i = *j;
194              *i = c;
195            }
196
197        }
198    }
199
200}
201
202
203void simple_sort(base, n, size, compar)
204     int *base;
205     int n;
206     int size;
207     int (*compar) ();
208{
209  register int c, *i, *j, *lo, p, *k;
210  int *max;
211  if (n <= 1)
212    return;
213  qsz = size;
214  qcmp = compar;
215  max = base + n;
216  puts("Selection Sort\n");
217  p=procnum();
218//  k=4;
219  for(j = base; j < max ; j++){
220    lo=j;
221    c=(*lo);
222    for(i = j; i < max ; i++){
223        asm("   nop             \n"); //1
224      if( c-(*i) > 0){
225        lo=i;
226        c=(*lo);
227      }
228      asm("     nop             \n"); // 1
229    }
230    *lo = *j;
231    *j = c;
232  }
233}
234
235void insertion_sort(base, n, size, compar)
236     int *base;
237     int n;
238     int size;
239     int (*compar) ();
240{
241  register int c, *i, *j,p;
242  int *max;
243  if (n <= 1)
244    return;
245  qsz = size;
246  qcmp = compar;
247  max = base + n;
248  puts("Insertion Sort\n");
249  p=procnum();
250  for(j = base; j < max-1 ; j++){
251    for(i = j; i < max-1 ; i++){
252      if( (*i)-(*(i+1)) > 0){
253        c = *i;
254        *i = *(i+1);
255        *(i+1)=c;
256      }
257    }
258  }
259}
260
261
262void bubble_sort(base, n, size, compar)
263     int *base;
264     int n;
265     int size;
266     int (*compar) ();
267{
268  register int c, *i;
269  register int b_swap=1;
270  int *max;
271  if (n <= 1)
272    return;
273  qsz = size;
274  qcmp = compar;
275  max = base + n;
276  puts("Bubble Sort\n");
277  while(b_swap){
278    b_swap=0;
279    for(i = base; i < max-1 ; i++){
280      if( (*i)-(*(i+1)) > 0){
281        b_swap=1;
282        c = *i;
283        *i = *(i+1);
284        *(i+1)=c;
285      }
286    }
287  }
288}
289
290static
291void qst(base, max)
292     int *base, *max;
293{
294  register int c, *i, *j, *jj;
295  register int ii;
296  int *mid, *tmp;
297  int lo, hi;
298  lo = max - base;
299  do
300    {
301      mid = i = base + 1 * ((lo / qsz) >> 1);
302      if (lo >= mthresh)
303        {
304          j = ((*qcmp) ((jj = base), i) > 0 ? jj : i);
305          if ((*qcmp) (j, (tmp = max - 1)) > 0)
306            {
307              j = (j == jj ? i : jj);
308              if ((*qcmp) (j, tmp) < 0)
309                j = tmp;
310            }
311
312          if (j != i)
313            {
314              ii = 1;
315              do
316                {
317                  c = *i;
318                  *i++ = *j;
319                  *j++ = c;
320                }
321
322              while (--ii);
323            }
324
325        }
326      for (i = base, j = max - 1;;)
327        {
328          while (i < mid && (*qcmp) (i, mid) <= 0)
329            i ++;
330          while (j > mid)
331            {
332              if ((*qcmp) (mid, j) <= 0)
333                {
334                  j --;
335                  continue;
336                }
337
338              tmp = i + 1;
339              if (i == mid)
340                {
341                  mid = jj = j;
342                }
343              else
344                {
345                  jj = j;
346                  j --;
347                }
348
349              goto swap;
350            }
351
352          if (i == mid)
353            {
354              break;
355            }
356          else
357            {
358              jj = mid;
359              tmp = mid = i;
360              j --;
361            }
362
363        swap:
364          ii = 1;
365          do
366            {
367              c = *i;
368              *i++ = *jj;
369              *jj++ = c;
370            }
371
372          while (--ii);
373          i = tmp;
374        }
375
376      i = (j = mid) + 1;
377      if ((lo = j - base) <= (hi = max - i))
378        {
379          if (lo >= thresh)
380            qst(base, j);
381          base = i;
382          lo = hi;
383        }
384      else
385        {
386          if (hi >= thresh)
387            qst(i, max);
388          max = j;
389        }
390
391    }
392  while (lo >= thresh);
393}
394
395void SORT(int *base, int n, int size, int (*compar) (),int type){
396  switch(type){
397  case 0:
398    QSORT(base, n, size, compar);
399    break;
400  case 1:
401    simple_sort(base, n, size, compar);
402    break;
403  case 2:
404    insertion_sort(base, n, size, compar);
405    break;
406  case 3:
407    bubble_sort(base, n, size, compar);
408    break;
409  default:
410    break;
411  }
412
413}
414
415
Note: See TracBrowser for help on using the repository browser.