annotate test/ps2.c @ 684:6e2f1e7f9fc3

*** empty log message ***
author kono
date Tue, 02 Oct 2007 21:18:12 +0900
parents fe0a971a6666
children c2c709727221
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
642
e9622935a621 *** empty log message ***
kono
parents: 638
diff changeset
1 #ifndef INLINE
e9622935a621 *** empty log message ***
kono
parents: 638
diff changeset
2 #define INLINE
e9622935a621 *** empty log message ***
kono
parents: 638
diff changeset
3 #endif
637
140b65f8ff03 ARRAY argument in fuction
kono
parents:
diff changeset
4
140b65f8ff03 ARRAY argument in fuction
kono
parents:
diff changeset
5 int printf(const char *,...);
646
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
6 void bzero(void *b, unsigned int len);
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
7
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
8
649
f1d71563a46a array size fix
kono
parents: 648
diff changeset
9 int align100 ;
f1d71563a46a array size fix
kono
parents: 648
diff changeset
10 int align101 __attribute__((aligned (16)));
f1d71563a46a array size fix
kono
parents: 648
diff changeset
11 int align102 __attribute__((aligned (8)));
f1d71563a46a array size fix
kono
parents: 648
diff changeset
12 char align103;
f1d71563a46a array size fix
kono
parents: 648
diff changeset
13 char align104;
f1d71563a46a array size fix
kono
parents: 648
diff changeset
14 int align105;
f1d71563a46a array size fix
kono
parents: 648
diff changeset
15 int align106 __attribute__((aligned (8)));
f1d71563a46a array size fix
kono
parents: 648
diff changeset
16
f1d71563a46a array size fix
kono
parents: 648
diff changeset
17 void *aligns[] = {
f1d71563a46a array size fix
kono
parents: 648
diff changeset
18 &align100,
f1d71563a46a array size fix
kono
parents: 648
diff changeset
19 &align101,
f1d71563a46a array size fix
kono
parents: 648
diff changeset
20 &align102,
f1d71563a46a array size fix
kono
parents: 648
diff changeset
21 &align103,
f1d71563a46a array size fix
kono
parents: 648
diff changeset
22 &align104,
f1d71563a46a array size fix
kono
parents: 648
diff changeset
23 &align105,
f1d71563a46a array size fix
kono
parents: 648
diff changeset
24 &align106,
f1d71563a46a array size fix
kono
parents: 648
diff changeset
25 };
f1d71563a46a array size fix
kono
parents: 648
diff changeset
26
f1d71563a46a array size fix
kono
parents: 648
diff changeset
27 void *aligns1[] = {
f1d71563a46a array size fix
kono
parents: 648
diff changeset
28 &align100,
f1d71563a46a array size fix
kono
parents: 648
diff changeset
29 &align101,
f1d71563a46a array size fix
kono
parents: 648
diff changeset
30 &align102,
f1d71563a46a array size fix
kono
parents: 648
diff changeset
31 &align103,
f1d71563a46a array size fix
kono
parents: 648
diff changeset
32 &align104,
f1d71563a46a array size fix
kono
parents: 648
diff changeset
33 &align105,
f1d71563a46a array size fix
kono
parents: 648
diff changeset
34 &align106
f1d71563a46a array size fix
kono
parents: 648
diff changeset
35 };
f1d71563a46a array size fix
kono
parents: 648
diff changeset
36
637
140b65f8ff03 ARRAY argument in fuction
kono
parents:
diff changeset
37
140b65f8ff03 ARRAY argument in fuction
kono
parents:
diff changeset
38 typedef float ps2_vu0_fmatrix[4][4] __attribute__((aligned (16)));
140b65f8ff03 ARRAY argument in fuction
kono
parents:
diff changeset
39 typedef ps2_vu0_fmatrix FMATRIX;
140b65f8ff03 ARRAY argument in fuction
kono
parents:
diff changeset
40
647
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
41 typedef float ps2_vu0_fmatrix1[4][4];
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
42 typedef ps2_vu0_fmatrix1 FMATRIX1;
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
43
646
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
44 typedef struct objNode {
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
45 void* object;
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
46 void (*mtd)(struct objNode*);
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
47 void (*draw)(struct objNode*, FMATRIX, FMATRIX);
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
48 struct objNode *next;
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
49 struct objNode *parent;
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
50 struct objNode *child;
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
51 } ObjNode, *ObjNodePtr;
637
140b65f8ff03 ARRAY argument in fuction
kono
parents:
diff changeset
52
646
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
53 INLINE void draw(ObjNode *this, FMATRIX m, FMATRIX n)
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
54 {
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
55 printf("work %g ",m[1][1]);
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
56 printf("base %g\n",n[1][1]);
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
57 m[1][1] += -0.7;
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
58 n[1][1] += 0.7;
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
59 }
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
60
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
61 ObjNode c = {
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
62 0, 0, draw, 0, 0, 0
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
63 };
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
64
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
65 ObjNode p = {
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
66 0, 0, draw, &c, 0, &c
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
67 };
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
68
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
69
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
70 INLINE void
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
71 graphic_ObjNode_draw( ObjNode *this, FMATRIX base )
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
72 {
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
73 FMATRIX work;
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
74 bzero(&work,sizeof(work)); work[1][1] = 0.33;
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
75
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
76 if(!this) return;
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
77 if(this->mtd) this->mtd( this );
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
78 if(this->draw) this->draw( this, work, base );
650
fe0a971a6666 fix alignment in struct
kono
parents: 649
diff changeset
79 printf("offset draw %d\n",((char*)(&this->draw) - ((char*)&this->object)));
fe0a971a6666 fix alignment in struct
kono
parents: 649
diff changeset
80 printf("offset next %d\n",((char*)(&this->next) - ((char*)&this->object)));
646
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
81
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
82 if(this->child) graphic_ObjNode_draw( this->child, work );
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
83 if(this->next) graphic_ObjNode_draw( this->next, base );
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
84 return;
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
85 }
637
140b65f8ff03 ARRAY argument in fuction
kono
parents:
diff changeset
86
140b65f8ff03 ARRAY argument in fuction
kono
parents:
diff changeset
87
642
e9622935a621 *** empty log message ***
kono
parents: 638
diff changeset
88 INLINE void ps2_vu0_unit_matrix(ps2_vu0_fmatrix m)
637
140b65f8ff03 ARRAY argument in fuction
kono
parents:
diff changeset
89 {
140b65f8ff03 ARRAY argument in fuction
kono
parents:
diff changeset
90 printf("%g\n",m[1][1]);
638
35014112c01d multi dimentional array in functional arugments.
kono
parents: 637
diff changeset
91 m[1][1] = -0.5;
637
140b65f8ff03 ARRAY argument in fuction
kono
parents:
diff changeset
92 }
140b65f8ff03 ARRAY argument in fuction
kono
parents:
diff changeset
93
646
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
94
647
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
95 #define mod16(a) (((int)(&a))%16)
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
96
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
97 int
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
98 align16(int i, FMATRIX a, FMATRIX b) {
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
99 FMATRIX m;
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
100 FMATRIX n;
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
101 int k = i;
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
102 FMATRIX o;
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
103 if (i==0) return i;
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
104 #ifdef OFFSET
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
105 printf("offset %d\n",((char*)a) - ((char*)(&m)));
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
106 #endif
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
107 printf("%d %d %d\n",mod16(m),mod16(n),mod16(o));
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
108 align16(i-1,m,n);
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
109 return k;
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
110 }
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
111
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
112 int
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
113 align16_1(int i, FMATRIX1 a, FMATRIX1 b) {
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
114 FMATRIX1 m;
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
115 FMATRIX1 n;
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
116 int k = i;
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
117 FMATRIX1 o;
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
118 if (i==0) return i;
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
119 #ifdef OFFSET
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
120 printf("offset %d\n",((char*)a) - ((char*)(&m)));
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
121 #endif
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
122 printf("%d %d %d\n",mod16(m),mod16(n),mod16(o));
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
123 align16_1(i-1,m,n);
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
124 return k;
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
125 }
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
126
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
127
637
140b65f8ff03 ARRAY argument in fuction
kono
parents:
diff changeset
128 int
140b65f8ff03 ARRAY argument in fuction
kono
parents:
diff changeset
129 main(int ac, char *av[])
140b65f8ff03 ARRAY argument in fuction
kono
parents:
diff changeset
130 {
140b65f8ff03 ARRAY argument in fuction
kono
parents:
diff changeset
131 FMATRIX m;
649
f1d71563a46a array size fix
kono
parents: 648
diff changeset
132 int i;
648
234bc5f79a11 alignement attribute (working)
kono
parents: 647
diff changeset
133 int aligned = 10;
637
140b65f8ff03 ARRAY argument in fuction
kono
parents:
diff changeset
134
140b65f8ff03 ARRAY argument in fuction
kono
parents:
diff changeset
135 m[1][1] = 0.5;
140b65f8ff03 ARRAY argument in fuction
kono
parents:
diff changeset
136 ps2_vu0_unit_matrix(m);
648
234bc5f79a11 alignement attribute (working)
kono
parents: 647
diff changeset
137 printf("%g %d\n",m[1][1],aligned);
647
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
138 align16(2,m,m);
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
139 align16_1(2,m,m);
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
140 graphic_ObjNode_draw( &p, m);
649
f1d71563a46a array size fix
kono
parents: 648
diff changeset
141
f1d71563a46a array size fix
kono
parents: 648
diff changeset
142 printf("sizeof(aligns)==%d %d\n",
f1d71563a46a array size fix
kono
parents: 648
diff changeset
143 sizeof(aligns),sizeof(aligns1));
f1d71563a46a array size fix
kono
parents: 648
diff changeset
144 printf("sizeof(aligns)/sizeof(void *)==%d\n",
f1d71563a46a array size fix
kono
parents: 648
diff changeset
145 sizeof(aligns)/sizeof(void *));
f1d71563a46a array size fix
kono
parents: 648
diff changeset
146
f1d71563a46a array size fix
kono
parents: 648
diff changeset
147 for(i=0;i<sizeof(aligns)/sizeof(void *);i++) {
f1d71563a46a array size fix
kono
parents: 648
diff changeset
148 printf("align10%d %d\n",i,mod16(aligns[i]));
f1d71563a46a array size fix
kono
parents: 648
diff changeset
149 }
f1d71563a46a array size fix
kono
parents: 648
diff changeset
150
637
140b65f8ff03 ARRAY argument in fuction
kono
parents:
diff changeset
151 }
646
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
152
647
fe23fe842b82 *** empty log message ***
kono
parents: 646
diff changeset
153
646
0d7baf338fc2 array argument continue...
kono
parents: 642
diff changeset
154 /* end */