3 #include "multicoreruntime.h"
4 #include "runtime_arch.h"
6 inline void initialization() {
9 inline void initCommunication() {
11 if (corenum < NUMCORES) {
14 raw_user_interrupts_on();
19 inline void fakeExecution() {
20 // handle communications
30 #endif // #ifdef USEIO
34 inline void terminate() {
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();
43 // transfer an object to targetcore
45 void transferObject(struct transObjInfo * transObj) {
46 void * obj = transObj->objptr;
47 int type=((int *)obj)[0];
48 int targetcore = transObj->targetcore;
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;
56 struct ___Object___ * newobj = (struct ___Object___ *)obj;
58 calCoords(corenum, &self_x, &self_y);
59 calCoords(targetcore, &target_x, &target_y);
61 // Build the message header
62 msgHdr = construct_dyn_hdr(0, msgsize, 0, // msgsize word sent.
65 // start sending msg, set sand msg flag
68 BAMBOO_DEBUGPRINT(0xbbbb);
69 BAMBOO_DEBUGPRINT(0xb000 + targetcore); // targetcore
77 BAMBOO_DEBUGPRINT_REG(msgsize);
81 BAMBOO_DEBUGPRINT_REG(obj);
83 for(i = 0; i < transObj->length; ++i) {
84 int taskindex = transObj->queues[2*i];
85 int paramindex = transObj->queues[2*i+1];
88 BAMBOO_DEBUGPRINT_REG(taskindex);
92 BAMBOO_DEBUGPRINT_REG(paramindex);
96 BAMBOO_DEBUGPRINT(0xffff);
98 // end of sending this msg, set sand msg flag 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
110 // Build the message header
111 msgHdr = construct_dyn_hdr(0, outmsgleft, 0, // msgsize word sent.
116 BAMBOO_DEBUGPRINT(0xbbbb);
117 BAMBOO_DEBUGPRINT(0xb000 + target); // targetcore
119 while(outmsgleft-- > 0) {
120 gdn_send(outmsgdata[outmsgindex++]);
122 BAMBOO_DEBUGPRINT_REG(outmsgdata[outmsgindex - 1]);
126 BAMBOO_DEBUGPRINT(0xffff);
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) {
134 outmsgindex = outmsglast = 0;
135 isMsgHanging = false;
137 BAMBOO_CLOSE_CRITICAL_SECTION_MSG();
141 inline void send_msg_1 (int targetcore, int n0) {
144 int self_y, self_x, target_y, target_x;
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);
151 // mark to start sending the msg
153 // Build the message header
154 msgHdr = construct_dyn_hdr(0, msglength, 0, // msgsize word sent.
157 gdn_send(msgHdr); // Send the message header
159 BAMBOO_DEBUGPRINT(0xbbbb);
160 BAMBOO_DEBUGPRINT(0xb000 + targetcore); // targetcore
164 BAMBOO_DEBUGPRINT(n0);
165 BAMBOO_DEBUGPRINT(0xffff);
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
178 // Build the message header
179 msgHdr = construct_dyn_hdr(0, outmsgleft, 0, // msgsize word sent.
184 BAMBOO_DEBUGPRINT(0xbbbb);
185 BAMBOO_DEBUGPRINT(0xb000 + target); // targetcore
187 while(outmsgleft-- > 0) {
188 gdn_send(outmsgdata[outmsgindex++]);
190 BAMBOO_DEBUGPRINT_REG(outmsgdata[outmsgindex - 1]);
194 BAMBOO_DEBUGPRINT(0xffff);
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) {
202 outmsgindex = outmsglast = 0;
203 isMsgHanging = false;
205 BAMBOO_CLOSE_CRITICAL_SECTION_MSG();
209 inline void send_msg_2 (int targetcore, int n0, int n1) {
212 int self_y, self_x, target_y, target_x;
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);
219 // mark to start sending the msg
221 // Build the message header
222 msgHdr = construct_dyn_hdr(0, msglength, 0, // msgsize word sent.
225 gdn_send(msgHdr); // Send the message header
227 BAMBOO_DEBUGPRINT(0xbbbb);
228 BAMBOO_DEBUGPRINT(0xb000 + targetcore); // targetcore
232 BAMBOO_DEBUGPRINT(n0);
236 BAMBOO_DEBUGPRINT(n1);
237 BAMBOO_DEBUGPRINT(0xffff);
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
250 // Build the message header
251 msgHdr = construct_dyn_hdr(0, outmsgleft, 0, // msgsize word sent.
256 BAMBOO_DEBUGPRINT(0xbbbb);
257 BAMBOO_DEBUGPRINT(0xb000 + target); // targetcore
259 while(outmsgleft-- > 0) {
260 gdn_send(outmsgdata[outmsgindex++]);
262 BAMBOO_DEBUGPRINT_REG(outmsgdata[outmsgindex - 1]);
266 BAMBOO_DEBUGPRINT(0xffff);
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) {
274 outmsgindex = outmsglast = 0;
275 isMsgHanging = false;
277 BAMBOO_CLOSE_CRITICAL_SECTION_MSG();
281 inline void send_msg_3 (int targetcore, int n0, int n1, int n2) {
284 int self_y, self_x, target_y, target_x;
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);
291 // mark to start sending the msg
293 // Build the message header
294 msgHdr = construct_dyn_hdr(0, msglength, 0, // msgsize word sent.
297 gdn_send(msgHdr); // Send the message header
299 BAMBOO_DEBUGPRINT(0xbbbb);
300 BAMBOO_DEBUGPRINT(0xb000 + targetcore); // targetcore
304 BAMBOO_DEBUGPRINT(n0);
308 BAMBOO_DEBUGPRINT(n1);
312 BAMBOO_DEBUGPRINT(n2);
313 BAMBOO_DEBUGPRINT(0xffff);
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
326 // Build the message header
327 msgHdr = construct_dyn_hdr(0, outmsgleft, 0, // msgsize word sent.
332 BAMBOO_DEBUGPRINT(0xbbbb);
333 BAMBOO_DEBUGPRINT(0xb000 + target); // targetcore
335 while(outmsgleft-- > 0) {
336 gdn_send(outmsgdata[outmsgindex++]);
338 BAMBOO_DEBUGPRINT_REG(outmsgdata[outmsgindex - 1]);
342 BAMBOO_DEBUGPRINT(0xffff);
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) {
350 outmsgindex = outmsglast = 0;
351 isMsgHanging = false;
353 BAMBOO_CLOSE_CRITICAL_SECTION_MSG();
357 inline void send_msg_4 (int targetcore, int n0, int n1, int n2, int n3) {
360 int self_y, self_x, target_y, target_x;
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);
367 // mark to start sending the msg
369 // Build the message header
370 msgHdr = construct_dyn_hdr(0, msglength, 0, // msgsize word sent.
373 gdn_send(msgHdr); // Send the message header
375 BAMBOO_DEBUGPRINT(0xbbbb);
376 BAMBOO_DEBUGPRINT(0xb000 + targetcore); // targetcore
380 BAMBOO_DEBUGPRINT(n0);
384 BAMBOO_DEBUGPRINT(n1);
388 BAMBOO_DEBUGPRINT(n2);
392 BAMBOO_DEBUGPRINT(n3);
393 BAMBOO_DEBUGPRINT(0xffff);
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
406 // Build the message header
407 msgHdr = construct_dyn_hdr(0, outmsgleft, 0, // msgsize word sent.
412 BAMBOO_DEBUGPRINT(0xbbbb);
413 BAMBOO_DEBUGPRINT(0xb000 + target); // targetcore
415 while(outmsgleft-- > 0) {
416 gdn_send(outmsgdata[outmsgindex++]);
418 BAMBOO_DEBUGPRINT_REG(outmsgdata[outmsgindex - 1]);
422 BAMBOO_DEBUGPRINT(0xffff);
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) {
430 outmsgindex = outmsglast = 0;
431 isMsgHanging = false;
433 BAMBOO_CLOSE_CRITICAL_SECTION_MSG();
437 inline void send_msg_5 (int targetcore, int n0, int n1, int n2, int n3, int n4) {
440 int self_y, self_x, target_y, target_x;
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);
447 // mark to start sending the msg
449 // Build the message header
450 msgHdr = construct_dyn_hdr(0, msglength, 0, // msgsize word sent.
453 gdn_send(msgHdr); // Send the message header
455 BAMBOO_DEBUGPRINT(0xbbbb);
456 BAMBOO_DEBUGPRINT(0xb000 + targetcore); // targetcore
460 BAMBOO_DEBUGPRINT(n0);
464 BAMBOO_DEBUGPRINT(n1);
468 BAMBOO_DEBUGPRINT(n2);
472 BAMBOO_DEBUGPRINT(n3);
476 BAMBOO_DEBUGPRINT(n4);
477 BAMBOO_DEBUGPRINT(0xffff);
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
490 // Build the message header
491 msgHdr = construct_dyn_hdr(0, outmsgleft, 0, // msgsize word sent.
496 BAMBOO_DEBUGPRINT(0xbbbb);
497 BAMBOO_DEBUGPRINT(0xb000 + target); // targetcore
499 while(outmsgleft-- > 0) {
500 gdn_send(outmsgdata[outmsgindex++]);
502 BAMBOO_DEBUGPRINT_REG(outmsgdata[outmsgindex - 1]);
506 BAMBOO_DEBUGPRINT(0xffff);
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) {
514 outmsgindex = outmsglast = 0;
515 isMsgHanging = false;
517 BAMBOO_CLOSE_CRITICAL_SECTION_MSG();
521 inline void send_msg_6 (int targetcore, int n0, int n1, int n2, int n3, int n4, int n5) {
524 int self_y, self_x, target_y, target_x;
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);
531 // mark to start sending the msg
533 // Build the message header
534 msgHdr = construct_dyn_hdr(0, msglength, 0, // msgsize word sent.
537 gdn_send(msgHdr); // Send the message header
539 BAMBOO_DEBUGPRINT(0xbbbb);
540 BAMBOO_DEBUGPRINT(0xb000 + targetcore); // targetcore
544 BAMBOO_DEBUGPRINT(n0);
548 BAMBOO_DEBUGPRINT(n1);
552 BAMBOO_DEBUGPRINT(n2);
556 BAMBOO_DEBUGPRINT(n3);
560 BAMBOO_DEBUGPRINT(n4);
564 BAMBOO_DEBUGPRINT(n5);
565 BAMBOO_DEBUGPRINT(0xffff);
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
578 // Build the message header
579 msgHdr = construct_dyn_hdr(0, outmsgleft, 0, // msgsize word sent.
584 BAMBOO_DEBUGPRINT(0xbbbb);
585 BAMBOO_DEBUGPRINT(0xb000 + target); // targetcore
587 while(outmsgleft-- > 0) {
588 gdn_send(outmsgdata[outmsgindex++]);
590 BAMBOO_DEBUGPRINT_REG(outmsgdata[outmsgindex - 1]);
594 BAMBOO_DEBUGPRINT(0xffff);
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) {
602 outmsgindex = outmsglast = 0;
603 isMsgHanging = false;
605 BAMBOO_CLOSE_CRITICAL_SECTION_MSG();
609 inline void cache_msg_2 (int targetcore, int n0, int n1) {
612 BAMBOO_DEBUGPRINT(0xdede);
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;
623 inline void cache_msg_3 (int targetcore, int n0, int n1, int n2) {
626 BAMBOO_DEBUGPRINT(0xdede);
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;
638 inline void cache_msg_4 (int targetcore, int n0, int n1, int n2, int n3) {
641 BAMBOO_DEBUGPRINT(0xdede);
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;
654 inline void cache_msg_6 (int targetcore, int n0, int n1, int n2, int n3, int n4, int n5) {
657 BAMBOO_DEBUGPRINT(0xdede);
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;
672 inline int receiveMsg() {
673 if(gdn_input_avail() == 0) {
675 if(corenum < NUMCORES) {
676 BAMBOO_DEBUGPRINT(0xd001);
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;
690 BAMBOO_DEBUGPRINT(0xcccc);
692 while((gdn_input_avail() != 0) && (msgdataindex < msglength)) {
693 msgdata[msgdataindex] = gdn_receive();
694 if(msgdataindex == 0) {
695 if(msgdata[0] > 0xc) {
697 } else if (msgdata[0] == 0xc) {
699 } else if(msgdata[0] > 8) {
701 } else if(msgdata[0] == 8) {
703 } else if(msgdata[0] > 5) {
705 } else if (msgdata[0] > 2) {
707 } else if (msgdata[0] == 2) {
709 } else if (msgdata[0] > 0) {
712 } else if((msgdataindex == 1) && (msgdata[0] == 0)) {
713 msglength = msgdata[msgdataindex];
716 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex]);
721 BAMBOO_DEBUGPRINT(0xffff);
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;
739 inline void profileTaskEnd() {
740 if(!taskInfoOverflow) {
741 taskInfoArray[taskInfoIndex]->endTime = raw_get_cycle();
743 if(taskInfoIndex == TASKINFOLENGTH) {
744 taskInfoOverflow = true;
748 #endif // #ifdef PROFILE
750 #endif // #ifdef TASK