dol: initial dol commit
[jump.git] / dol / src / dol / visitor / cell / lib / spu / dolSupport.h
1 #ifndef DOLSUPPORT_H\r
2 #define DOLSUPPORT_H\r
3 \r
4 #include <stdio.h>\r
5 \r
6 #include "dol.h"\r
7 #include "../pt/pt.h"\r
8 #include "proc_wrapper.h"\r
9 \r
10 #include "Fifo.h"\r
11 #include "WindowedFifo.h"\r
12 \r
13 \r
14 typedef struct _process_data {\r
15     int lc;\r
16     proc_wrapper *wrapper;\r
17 } process_data;\r
18 \r
19 \r
20 #define DOL_read(port, buf, size, process) \\r
21     PT_WAIT_UNTIL((pt*)(p->wptr), read(port, buf, size, process) == size);\r
22 \r
23 #define DOL_write(port, buf, size, process) \\r
24     PT_WAIT_UNTIL((pt*)(p->wptr), write(port, buf, size, process) == size);\r
25 \r
26 #define DOL_reserve(port, buf, size, process) \\r
27         PT_WAIT_UNTIL((pt*)(p->wptr), reserve(port, (void**)buf, size, process) == size);\r
28 \r
29         //should stall only if the return size is 0!!! (but how, one has to give a return value...)\r
30 \r
31 #define DOL_release(port, process) \\r
32         release(port, process);\r
33 \r
34 #define DOL_capture(port, buf, size, process) \\r
35         PT_WAIT_UNTIL((pt*)(p->wptr), capture(port, (void**)buf, size, process) == size);\r
36 \r
37         //should stall only if the return size is 0!!! (but how, one has to give a return value...)\r
38 \r
39 #define DOL_consume(port, process) \\r
40         consume(port, process);\r
41 \r
42 \r
43 void DOL_detach(DOLProcess* p);\r
44 \r
45 unsigned write(void* fifo, void* buf, unsigned len, DOLProcess* p);\r
46 \r
47 unsigned read(void* fifo, void* buf, unsigned len, DOLProcess* p);\r
48 \r
49 unsigned reserve(void* fifo, void** destination, unsigned len, DOLProcess* p);\r
50 \r
51 void release(void* fifo, DOLProcess* p);\r
52 \r
53 unsigned capture(void* fifo, void** destination, unsigned len, DOLProcess* p);\r
54 \r
55 void consume(void* fifo, DOLProcess* p);\r
56 \r
57 \r
58 //macros to deal with iterated ports\r
59 /**\r
60  * macro to create a variable to store a port name\r
61  *\r
62  * @param name name of the variable\r
63  */\r
64 #define CREATEPORTVAR(name) static Fifo *name\r
65 \r
66 /**\r
67  * Create the port name of an iterated port based on its basename and the\r
68  * given indices.\r
69  *\r
70  * @param port buffer where the result is stored (created using\r
71  *             CREATEPORTVAR)\r
72  * @param base basename of the port\r
73  * @param number_of_indices number of dimensions of the port\r
74  * @param index_range_pairs index and range values for each dimension\r
75  */\r
76 \r
77 #define CREATEPORT(port, base, number_of_indices, index_range_pairs...) \\r
78   createPort((void**)(&port), base, number_of_indices, index_range_pairs)\r
79 \r
80 #define GETINDEX(dimension) \\r
81   static_cast<proc_wrapper *>((static_cast<process_data *>(p->wptr))->wrapper)->getIndex(dimension)\r
82 \r
83 void createPort(void** port, void* base, int number_of_indices, int index0, int range0);\r
84 void createPort(void** port, void* base, int number_of_indices, int index0, int range0, int index1, int range1);\r
85 void createPort(void** port, void* base, int number_of_indices, int index0, int range0, int index1, int range1, int index2, int range2);\r
86 void createPort(void** port, void* base, int number_of_indices, int index0, int range0, int index1, int range1, int index2, int range2, int index3, int range3);\r
87 \r
88 #endif\r