reorganize multicore version runtime codes for easy support of new platforms
[IRC.git] / Robust / src / Runtime / RAW / task_arch.c
1 #ifdef TASK
2 #include "runtime.h"
3 #include "multicoreruntime.h"
4 #include "runtime_arch.h"
5
6 inline void initialization() {
7 } // initialization()
8
9 inline void initCommunication() {
10 #ifdef INTERRUPT
11   if (corenum < NUMCORES) {
12     // set up interrupts
13     setup_ints();
14     raw_user_interrupts_on();
15   }
16 #endif
17 }
18
19 inline void fakeExecution() {
20   // handle communications
21   while(true) {
22           receiveObject();
23   }
24 }
25
26 #ifdef USEIO
27 int main(void) {
28 #else
29 void begin() {
30 #endif // #ifdef USEIO
31   run(NULL);
32 }
33
34 inline void terminate() {
35         raw_test_done(1);
36 }
37
38 // helper function to compute the coordinates of a core from the core number
39 #define calCoords(core_num, coordX, coordY) \
40   *(coordX) = (core_num) % raw_get_array_size_x();\
41   *(coordY) = core_num / raw_get_array_size_x();
42
43 // transfer an object to targetcore
44 // format: object
45 void transferObject(struct transObjInfo * transObj) {
46   void * obj = transObj->objptr;
47   int type=((int *)obj)[0];
48   int targetcore = transObj->targetcore;  
49
50   unsigned msgHdr;
51   int self_y, self_x, target_y, target_x;
52   // for 32 bit machine, the size of fixed part is always 3 words
53   int msgsize = 3 + transObj->length * 2;
54   int i = 0;
55
56   struct ___Object___ * newobj = (struct ___Object___ *)obj;
57
58   calCoords(corenum, &self_x, &self_y);
59   calCoords(targetcore, &target_x, &target_y);
60   isMsgSending = true;
61   // Build the message header
62   msgHdr = construct_dyn_hdr(0, msgsize, 0,             // msgsize word sent.
63                              self_y, self_x,
64                              target_y, target_x);
65   // start sending msg, set sand msg flag
66   gdn_send(msgHdr);                     
67 #ifdef DEBUG
68   BAMBOO_DEBUGPRINT(0xbbbb);
69   BAMBOO_DEBUGPRINT(0xb000 + targetcore);       // targetcore
70 #endif
71   gdn_send(0);
72 #ifdef DEBUG
73   BAMBOO_DEBUGPRINT(0);
74 #endif
75   gdn_send(msgsize);
76 #ifdef DEBUG
77   BAMBOO_DEBUGPRINT_REG(msgsize);
78 #endif
79   gdn_send((int)obj);
80 #ifdef DEBUG
81   BAMBOO_DEBUGPRINT_REG(obj);
82 #endif
83   for(i = 0; i < transObj->length; ++i) {
84     int taskindex = transObj->queues[2*i];
85     int paramindex = transObj->queues[2*i+1];
86     gdn_send(taskindex);
87 #ifdef DEBUG
88     BAMBOO_DEBUGPRINT_REG(taskindex);
89 #endif
90     gdn_send(paramindex);
91 #ifdef DEBUG
92     BAMBOO_DEBUGPRINT_REG(paramindex);
93 #endif
94   }
95 #ifdef DEBUG
96   BAMBOO_DEBUGPRINT(0xffff);
97 #endif
98   // end of sending this msg, set sand msg flag false
99   isMsgSending = false;
100   ++(self_numsendobjs);
101   // check if there are pending msgs
102   while(isMsgHanging) {
103           // get the msg from outmsgdata[]
104           // length + target + msg
105           outmsgleft = outmsgdata[outmsgindex++];
106           int target = outmsgdata[outmsgindex++];
107           calCoords(target, &target_x, &target_y);
108           // mark to start sending the msg
109           isMsgSending = true;
110           // Build the message header
111           msgHdr = construct_dyn_hdr(0, outmsgleft, 0,                        // msgsize word sent.
112                                  self_y, self_x,
113                                  target_y, target_x);
114           gdn_send(msgHdr);                           
115 #ifdef DEBUG
116           BAMBOO_DEBUGPRINT(0xbbbb);
117           BAMBOO_DEBUGPRINT(0xb000 + target);             // targetcore
118 #endif
119           while(outmsgleft-- > 0) {
120                   gdn_send(outmsgdata[outmsgindex++]);
121 #ifdef DEBUG
122                   BAMBOO_DEBUGPRINT_REG(outmsgdata[outmsgindex - 1]);
123 #endif
124           }
125 #ifdef DEBUG
126           BAMBOO_DEBUGPRINT(0xffff);
127 #endif
128           // mark to end sending the msg
129           isMsgSending = false;
130           BAMBOO_START_CRITICAL_SECTION_MSG();
131           // check if there are still msg hanging
132           if(outmsgindex == outmsglast) {
133                   // no more msgs
134                   outmsgindex = outmsglast = 0;
135                   isMsgHanging = false;
136           }
137           BAMBOO_CLOSE_CRITICAL_SECTION_MSG();
138   }
139 }
140
141 inline void send_msg_1 (int targetcore, int n0) {
142   // send this msg
143   unsigned msgHdr;
144   int self_y, self_x, target_y, target_x;
145   msglength = 1;
146
147   // get the x-coord and y-coord of the target core
148   calCoords(corenum, &self_x, &self_y);
149   calCoords(targetcore, &target_x, &target_y);
150
151   // mark to start sending the msg
152   isMsgSending = true;
153   // Build the message header
154   msgHdr = construct_dyn_hdr(0, msglength, 0,             // msgsize word sent.
155                              self_y, self_x,
156                              target_y, target_x);
157   gdn_send(msgHdr);                     // Send the message header
158 #ifdef DEBUG
159   BAMBOO_DEBUGPRINT(0xbbbb);
160   BAMBOO_DEBUGPRINT(0xb000 + targetcore);       // targetcore
161 #endif
162   gdn_send(n0);
163 #ifdef DEBUG
164   BAMBOO_DEBUGPRINT(n0);
165   BAMBOO_DEBUGPRINT(0xffff);
166 #endif
167   // mark to end sending the msg
168   isMsgSending = false;
169   // check if there are pending msgs
170   while(isMsgHanging) {
171           // get the msg from outmsgdata[]
172           // length + target + msg
173           outmsgleft = outmsgdata[outmsgindex++];
174           int target = outmsgdata[outmsgindex++];
175           calCoords(target, &target_x, &target_y);
176           // mark to start sending the msg
177           isMsgSending = true;
178           // Build the message header
179           msgHdr = construct_dyn_hdr(0, outmsgleft, 0,                        // msgsize word sent.
180                                  self_y, self_x,
181                                  target_y, target_x);
182           gdn_send(msgHdr);                           
183 #ifdef DEBUG
184           BAMBOO_DEBUGPRINT(0xbbbb);
185           BAMBOO_DEBUGPRINT(0xb000 + target);             // targetcore
186 #endif
187           while(outmsgleft-- > 0) {
188                   gdn_send(outmsgdata[outmsgindex++]);
189 #ifdef DEBUG
190                   BAMBOO_DEBUGPRINT_REG(outmsgdata[outmsgindex - 1]);
191 #endif
192           }
193 #ifdef DEBUG
194           BAMBOO_DEBUGPRINT(0xffff);
195 #endif
196           // mark to end sending the msg
197           isMsgSending = false;
198           BAMBOO_START_CRITICAL_SECTION_MSG();
199           // check if there are still msg hanging
200           if(outmsgindex == outmsglast) {
201                   // no more msgs
202                   outmsgindex = outmsglast = 0;
203                   isMsgHanging = false;
204           }
205           BAMBOO_CLOSE_CRITICAL_SECTION_MSG();
206   }
207 }
208
209 inline void send_msg_2 (int targetcore, int n0, int n1) {
210   // send this msg
211   unsigned msgHdr;
212   int self_y, self_x, target_y, target_x;
213   msglength = 2;
214
215   // get the x-coord and y-coord of the target core
216   calCoords(corenum, &self_x, &self_y);
217   calCoords(targetcore, &target_x, &target_y);
218
219   // mark to start sending the msg
220   isMsgSending = true;
221   // Build the message header
222   msgHdr = construct_dyn_hdr(0, msglength, 0,             // msgsize word sent.
223                              self_y, self_x,
224                              target_y, target_x);
225   gdn_send(msgHdr);                     // Send the message header
226 #ifdef DEBUG
227   BAMBOO_DEBUGPRINT(0xbbbb);
228   BAMBOO_DEBUGPRINT(0xb000 + targetcore);       // targetcore
229 #endif
230   gdn_send(n0);
231 #ifdef DEBUG
232   BAMBOO_DEBUGPRINT(n0);
233 #endif
234   gdn_send(n1);
235 #ifdef DEBUG
236   BAMBOO_DEBUGPRINT(n1);
237   BAMBOO_DEBUGPRINT(0xffff);
238 #endif
239   // mark to end sending the msg
240   isMsgSending = false;
241   // check if there are pending msgs
242   while(isMsgHanging) {
243           // get the msg from outmsgdata[]
244           // length + target + msg
245           outmsgleft = outmsgdata[outmsgindex++];
246           int target = outmsgdata[outmsgindex++];
247           calCoords(target, &target_x, &target_y);
248           // mark to start sending the msg
249           isMsgSending = true;
250           // Build the message header
251           msgHdr = construct_dyn_hdr(0, outmsgleft, 0,                        // msgsize word sent.
252                                  self_y, self_x,
253                                  target_y, target_x);
254           gdn_send(msgHdr);                           
255 #ifdef DEBUG
256           BAMBOO_DEBUGPRINT(0xbbbb);
257           BAMBOO_DEBUGPRINT(0xb000 + target);             // targetcore
258 #endif
259           while(outmsgleft-- > 0) {
260                   gdn_send(outmsgdata[outmsgindex++]);
261 #ifdef DEBUG
262                   BAMBOO_DEBUGPRINT_REG(outmsgdata[outmsgindex - 1]);
263 #endif
264           }
265 #ifdef DEBUG
266           BAMBOO_DEBUGPRINT(0xffff);
267 #endif
268           // mark to end sending the msg
269           isMsgSending = false;
270           BAMBOO_START_CRITICAL_SECTION_MSG();
271           // check if there are still msg hanging
272           if(outmsgindex == outmsglast) {
273                   // no more msgs
274                   outmsgindex = outmsglast = 0;
275                   isMsgHanging = false;
276           }
277           BAMBOO_CLOSE_CRITICAL_SECTION_MSG();
278   }
279 }
280
281 inline void send_msg_3 (int targetcore, int n0, int n1, int n2) {
282   // send this msg
283   unsigned msgHdr;
284   int self_y, self_x, target_y, target_x;
285   msglength = 3;
286
287   // get the x-coord and y-coord of the target core
288   calCoords(corenum, &self_x, &self_y);
289   calCoords(targetcore, &target_x, &target_y);
290
291   // mark to start sending the msg
292   isMsgSending = true;
293   // Build the message header
294   msgHdr = construct_dyn_hdr(0, msglength, 0,             // msgsize word sent.
295                              self_y, self_x,
296                              target_y, target_x);
297   gdn_send(msgHdr);                     // Send the message header
298 #ifdef DEBUG
299   BAMBOO_DEBUGPRINT(0xbbbb);
300   BAMBOO_DEBUGPRINT(0xb000 + targetcore);       // targetcore
301 #endif
302   gdn_send(n0);
303 #ifdef DEBUG
304   BAMBOO_DEBUGPRINT(n0);
305 #endif
306   gdn_send(n1);
307 #ifdef DEBUG
308   BAMBOO_DEBUGPRINT(n1);
309 #endif
310   gdn_send(n2);
311 #ifdef DEBUG
312   BAMBOO_DEBUGPRINT(n2);
313   BAMBOO_DEBUGPRINT(0xffff);
314 #endif
315   // mark to end sending the msg
316   isMsgSending = false;
317   // check if there are pending msgs
318   while(isMsgHanging) {
319           // get the msg from outmsgdata[]
320           // length + target + msg
321           outmsgleft = outmsgdata[outmsgindex++];
322           int target = outmsgdata[outmsgindex++];
323           calCoords(target, &target_x, &target_y);
324           // mark to start sending the msg
325           isMsgSending = true;
326           // Build the message header
327           msgHdr = construct_dyn_hdr(0, outmsgleft, 0,                        // msgsize word sent.
328                                  self_y, self_x,
329                                  target_y, target_x);
330           gdn_send(msgHdr);                           
331 #ifdef DEBUG
332           BAMBOO_DEBUGPRINT(0xbbbb);
333           BAMBOO_DEBUGPRINT(0xb000 + target);             // targetcore
334 #endif
335           while(outmsgleft-- > 0) {
336                   gdn_send(outmsgdata[outmsgindex++]);
337 #ifdef DEBUG
338                   BAMBOO_DEBUGPRINT_REG(outmsgdata[outmsgindex - 1]);
339 #endif
340           }
341 #ifdef DEBUG
342           BAMBOO_DEBUGPRINT(0xffff);
343 #endif
344           // mark to end sending the msg
345           isMsgSending = false;
346           BAMBOO_START_CRITICAL_SECTION_MSG();
347           // check if there are still msg hanging
348           if(outmsgindex == outmsglast) {
349                   // no more msgs
350                   outmsgindex = outmsglast = 0;
351                   isMsgHanging = false;
352           }
353           BAMBOO_CLOSE_CRITICAL_SECTION_MSG();
354   }
355 }
356
357 inline void send_msg_4 (int targetcore, int n0, int n1, int n2, int n3) {
358   // send this msg
359   unsigned msgHdr;
360   int self_y, self_x, target_y, target_x;
361   msglength = 4;
362
363   // get the x-coord and y-coord of the target core
364   calCoords(corenum, &self_x, &self_y);
365   calCoords(targetcore, &target_x, &target_y);
366
367   // mark to start sending the msg
368   isMsgSending = true;
369   // Build the message header
370   msgHdr = construct_dyn_hdr(0, msglength, 0,             // msgsize word sent.
371                              self_y, self_x,
372                              target_y, target_x);
373   gdn_send(msgHdr);                     // Send the message header
374 #ifdef DEBUG
375   BAMBOO_DEBUGPRINT(0xbbbb);
376   BAMBOO_DEBUGPRINT(0xb000 + targetcore);       // targetcore
377 #endif
378   gdn_send(n0);
379 #ifdef DEBUG
380   BAMBOO_DEBUGPRINT(n0);
381 #endif
382   gdn_send(n1);
383 #ifdef DEBUG
384   BAMBOO_DEBUGPRINT(n1);
385 #endif
386   gdn_send(n2);
387 #ifdef DEBUG
388   BAMBOO_DEBUGPRINT(n2);
389 #endif
390   gdn_send(n3);
391 #ifdef DEBUG
392   BAMBOO_DEBUGPRINT(n3);
393   BAMBOO_DEBUGPRINT(0xffff);
394 #endif
395   // mark to end sending the msg
396   isMsgSending = false;
397   // check if there are pending msgs
398   while(isMsgHanging) {
399           // get the msg from outmsgdata[]
400           // length + target + msg
401           outmsgleft = outmsgdata[outmsgindex++];
402           int target = outmsgdata[outmsgindex++];
403           calCoords(target, &target_x, &target_y);
404           // mark to start sending the msg
405           isMsgSending = true;
406           // Build the message header
407           msgHdr = construct_dyn_hdr(0, outmsgleft, 0,                        // msgsize word sent.
408                                  self_y, self_x,
409                                  target_y, target_x);
410           gdn_send(msgHdr);                           
411 #ifdef DEBUG
412           BAMBOO_DEBUGPRINT(0xbbbb);
413           BAMBOO_DEBUGPRINT(0xb000 + target);             // targetcore
414 #endif
415           while(outmsgleft-- > 0) {
416                   gdn_send(outmsgdata[outmsgindex++]);
417 #ifdef DEBUG
418                   BAMBOO_DEBUGPRINT_REG(outmsgdata[outmsgindex - 1]);
419 #endif
420           }
421 #ifdef DEBUG
422           BAMBOO_DEBUGPRINT(0xffff);
423 #endif
424           // mark to end sending the msg
425           isMsgSending = false;
426           BAMBOO_START_CRITICAL_SECTION_MSG();
427           // check if there are still msg hanging
428           if(outmsgindex == outmsglast) {
429                   // no more msgs
430                   outmsgindex = outmsglast = 0;
431                   isMsgHanging = false;
432           }
433           BAMBOO_CLOSE_CRITICAL_SECTION_MSG();
434   }
435 }
436
437 inline void send_msg_5 (int targetcore, int n0, int n1, int n2, int n3, int n4) {
438   // send this msg
439   unsigned msgHdr;
440   int self_y, self_x, target_y, target_x;
441   msglength = 5;
442
443   // get the x-coord and y-coord of the target core
444   calCoords(corenum, &self_x, &self_y);
445   calCoords(targetcore, &target_x, &target_y);
446
447   // mark to start sending the msg
448   isMsgSending = true;
449   // Build the message header
450   msgHdr = construct_dyn_hdr(0, msglength, 0,             // msgsize word sent.
451                              self_y, self_x,
452                              target_y, target_x);
453   gdn_send(msgHdr);                     // Send the message header
454 #ifdef DEBUG
455   BAMBOO_DEBUGPRINT(0xbbbb);
456   BAMBOO_DEBUGPRINT(0xb000 + targetcore);       // targetcore
457 #endif
458   gdn_send(n0);
459 #ifdef DEBUG
460   BAMBOO_DEBUGPRINT(n0);
461 #endif
462   gdn_send(n1);
463 #ifdef DEBUG
464   BAMBOO_DEBUGPRINT(n1);
465 #endif
466   gdn_send(n2);
467 #ifdef DEBUG
468   BAMBOO_DEBUGPRINT(n2);
469 #endif
470   gdn_send(n3);
471 #ifdef DEBUG
472   BAMBOO_DEBUGPRINT(n3);
473 #endif
474   gdn_send(n4);
475 #ifdef DEBUG
476   BAMBOO_DEBUGPRINT(n4);
477   BAMBOO_DEBUGPRINT(0xffff);
478 #endif
479   // mark to end sending the msg
480   isMsgSending = false;
481   // check if there are pending msgs
482   while(isMsgHanging) {
483           // get the msg from outmsgdata[]
484           // length + target + msg
485           outmsgleft = outmsgdata[outmsgindex++];
486           int target = outmsgdata[outmsgindex++];
487           calCoords(target, &target_x, &target_y);
488           // mark to start sending the msg
489           isMsgSending = true;
490           // Build the message header
491           msgHdr = construct_dyn_hdr(0, outmsgleft, 0,                        // msgsize word sent.
492                                  self_y, self_x,
493                                  target_y, target_x);
494           gdn_send(msgHdr);                           
495 #ifdef DEBUG
496           BAMBOO_DEBUGPRINT(0xbbbb);
497           BAMBOO_DEBUGPRINT(0xb000 + target);             // targetcore
498 #endif
499           while(outmsgleft-- > 0) {
500                   gdn_send(outmsgdata[outmsgindex++]);
501 #ifdef DEBUG
502                   BAMBOO_DEBUGPRINT_REG(outmsgdata[outmsgindex - 1]);
503 #endif
504           }
505 #ifdef DEBUG
506           BAMBOO_DEBUGPRINT(0xffff);
507 #endif
508           // mark to end sending the msg
509           isMsgSending = false;
510           BAMBOO_START_CRITICAL_SECTION_MSG();
511           // check if there are still msg hanging
512           if(outmsgindex == outmsglast) {
513                   // no more msgs
514                   outmsgindex = outmsglast = 0;
515                   isMsgHanging = false;
516           }
517           BAMBOO_CLOSE_CRITICAL_SECTION_MSG();
518   }
519 }
520
521 inline void send_msg_6 (int targetcore, int n0, int n1, int n2, int n3, int n4, int n5) {
522   // send this msg
523   unsigned msgHdr;
524   int self_y, self_x, target_y, target_x;
525   msglength = 6;
526
527   // get the x-coord and y-coord of the target core
528   calCoords(corenum, &self_x, &self_y);
529   calCoords(targetcore, &target_x, &target_y);
530
531   // mark to start sending the msg
532   isMsgSending = true;
533   // Build the message header
534   msgHdr = construct_dyn_hdr(0, msglength, 0,             // msgsize word sent.
535                              self_y, self_x,
536                              target_y, target_x);
537   gdn_send(msgHdr);                     // Send the message header
538 #ifdef DEBUG
539   BAMBOO_DEBUGPRINT(0xbbbb);
540   BAMBOO_DEBUGPRINT(0xb000 + targetcore);       // targetcore
541 #endif
542   gdn_send(n0);
543 #ifdef DEBUG
544   BAMBOO_DEBUGPRINT(n0);
545 #endif
546   gdn_send(n1);
547 #ifdef DEBUG
548   BAMBOO_DEBUGPRINT(n1);
549 #endif
550   gdn_send(n2);
551 #ifdef DEBUG
552   BAMBOO_DEBUGPRINT(n2);
553 #endif
554   gdn_send(n3);
555 #ifdef DEBUG
556   BAMBOO_DEBUGPRINT(n3);
557 #endif
558   gdn_send(n4);
559 #ifdef DEBUG
560   BAMBOO_DEBUGPRINT(n4);
561 #endif
562   gdn_send(n5);
563 #ifdef DEBUG
564   BAMBOO_DEBUGPRINT(n5);
565   BAMBOO_DEBUGPRINT(0xffff);
566 #endif
567   // mark to end sending the msg
568   isMsgSending = false;
569   // check if there are pending msgs
570   while(isMsgHanging) {
571           // get the msg from outmsgdata[]
572           // length + target + msg
573           outmsgleft = outmsgdata[outmsgindex++];
574           int target = outmsgdata[outmsgindex++];
575           calCoords(target, &target_x, &target_y);
576           // mark to start sending the msg
577           isMsgSending = true;
578           // Build the message header
579           msgHdr = construct_dyn_hdr(0, outmsgleft, 0,                        // msgsize word sent.
580                                  self_y, self_x,
581                                  target_y, target_x);
582           gdn_send(msgHdr);                           
583 #ifdef DEBUG
584           BAMBOO_DEBUGPRINT(0xbbbb);
585           BAMBOO_DEBUGPRINT(0xb000 + target);             // targetcore
586 #endif
587           while(outmsgleft-- > 0) {
588                   gdn_send(outmsgdata[outmsgindex++]);
589 #ifdef DEBUG
590                   BAMBOO_DEBUGPRINT_REG(outmsgdata[outmsgindex - 1]);
591 #endif
592           }
593 #ifdef DEBUG
594           BAMBOO_DEBUGPRINT(0xffff);
595 #endif
596           // mark to end sending the msg
597           isMsgSending = false;
598           BAMBOO_START_CRITICAL_SECTION_MSG();
599           // check if there are still msg hanging
600           if(outmsgindex == outmsglast) {
601                   // no more msgs
602                   outmsgindex = outmsglast = 0;
603                   isMsgHanging = false;
604           }
605           BAMBOO_CLOSE_CRITICAL_SECTION_MSG();
606   }
607 }
608
609 inline void cache_msg_2 (int targetcore, int n0, int n1) {
610   // cache this msg
611 #ifdef DEBUG
612   BAMBOO_DEBUGPRINT(0xdede);
613 #endif
614   isMsgHanging = true;
615   // cache the msg in outmsgdata and send it later
616   // msglength + target core + msg
617   outmsgdata[outmsglast++] = 2;
618   outmsgdata[outmsglast++] = targetcore;
619   outmsgdata[outmsglast++] = n0;
620   outmsgdata[outmsglast++] = n1;
621 }
622
623 inline void cache_msg_3 (int targetcore, int n0, int n1, int n2) {
624   // cache this msg
625 #ifdef DEBUG
626   BAMBOO_DEBUGPRINT(0xdede);
627 #endif
628   isMsgHanging = true;
629   // cache the msg in outmsgdata and send it later
630   // msglength + target core + msg
631   outmsgdata[outmsglast++] = 3;
632   outmsgdata[outmsglast++] = targetcore;
633   outmsgdata[outmsglast++] = n0;
634   outmsgdata[outmsglast++] = n1;
635   outmsgdata[outmsglast++] = n2;
636 }
637
638 inline void cache_msg_4 (int targetcore, int n0, int n1, int n2, int n3) {
639   // cache this msg
640 #ifdef DEBUG
641   BAMBOO_DEBUGPRINT(0xdede);
642 #endif
643   isMsgHanging = true;
644   // cache the msg in outmsgdata and send it later
645   // msglength + target core + msg
646   outmsgdata[outmsglast++] = 4;
647   outmsgdata[outmsglast++] = targetcore;
648   outmsgdata[outmsglast++] = n0;
649   outmsgdata[outmsglast++] = n1;
650   outmsgdata[outmsglast++] = n2;
651   outmsgdata[outmsglast++] = n3;
652 }
653
654 inline void cache_msg_6 (int targetcore, int n0, int n1, int n2, int n3, int n4, int n5) {
655   // cache this msg
656 #ifdef DEBUG
657   BAMBOO_DEBUGPRINT(0xdede);
658 #endif
659   isMsgHanging = true;
660   // cache the msg in outmsgdata and send it later
661   // msglength + target core + msg
662   outmsgdata[outmsglast++] = 6;
663   outmsgdata[outmsglast++] = targetcore;
664   outmsgdata[outmsglast++] = n0;
665   outmsgdata[outmsglast++] = n1;
666   outmsgdata[outmsglast++] = n2;
667   outmsgdata[outmsglast++] = n3;
668   outmsgdata[outmsglast++] = n4;
669   outmsgdata[outmsglast++] = n5;
670 }
671
672 inline int receiveMsg() {
673   if(gdn_input_avail() == 0) {
674 #ifdef DEBUG
675     if(corenum < NUMCORES) {
676       BAMBOO_DEBUGPRINT(0xd001);
677     }
678 #endif
679     return -1;
680   }
681 #ifdef PROFILE
682   /*if(isInterrupt && (!interruptInfoOverflow)) {
683      // BAMBOO_DEBUGPRINT(0xffff);
684      interruptInfoArray[interruptInfoIndex] = RUNMALLOC_I(sizeof(struct interrupt_info));
685      interruptInfoArray[interruptInfoIndex]->startTime = raw_get_cycle();
686      interruptInfoArray[interruptInfoIndex]->endTime = -1;
687      }*/
688 #endif
689 #ifdef DEBUG
690   BAMBOO_DEBUGPRINT(0xcccc);
691 #endif
692   while((gdn_input_avail() != 0) && (msgdataindex < msglength)) {
693     msgdata[msgdataindex] = gdn_receive();
694     if(msgdataindex == 0) {
695                 if(msgdata[0] > 0xc) {
696                         msglength = 3;
697                 } else if (msgdata[0] == 0xc) {
698                         msglength = 1;
699                 } else if(msgdata[0] > 8) {
700                         msglength = 4;
701                 } else if(msgdata[0] == 8) {
702                         msglength = 6;
703                 } else if(msgdata[0] > 5) {
704                         msglength = 2;
705                 } else if (msgdata[0] > 2) {
706                         msglength = 4;
707                 } else if (msgdata[0] == 2) {
708                         msglength = 5;
709                 } else if (msgdata[0] > 0) {
710                         msglength = 4;
711                 }
712     } else if((msgdataindex == 1) && (msgdata[0] == 0)) {
713       msglength = msgdata[msgdataindex];
714     }
715 #ifdef DEBUG
716     BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex]);
717 #endif
718     msgdataindex++;
719   }
720 #ifdef DEBUG
721   BAMBOO_DEBUGPRINT(0xffff);
722 #endif
723   return msgdataindex;
724 }
725
726 #ifdef PROFILE
727 inline void profileTaskStart(char * taskname) {
728   if(!taskInfoOverflow) {
729           TaskInfo* taskInfo = RUNMALLOC(sizeof(struct task_info));
730           taskInfoArray[taskInfoIndex] = taskInfo;
731           taskInfo->taskName = taskname;
732           taskInfo->startTime = raw_get_cycle();
733           taskInfo->endTime = -1;
734           taskInfo->exitIndex = -1;
735           taskInfo->newObjs = NULL;
736   }
737 }
738
739 inline void profileTaskEnd() {
740   if(!taskInfoOverflow) {
741           taskInfoArray[taskInfoIndex]->endTime = raw_get_cycle();
742           taskInfoIndex++;
743           if(taskInfoIndex == TASKINFOLENGTH) {
744                   taskInfoOverflow = true;
745           }
746   }
747 }
748 #endif  // #ifdef PROFILE
749
750 #endif // #ifdef TASK