view test/ps2.c @ 684:6e2f1e7f9fc3

*** empty log message ***
author kono
date Tue, 02 Oct 2007 21:18:12 +0900
parents fe0a971a6666
children c2c709727221
line wrap: on
line source

#ifndef INLINE
#define INLINE
#endif

int printf(const char *,...);
void bzero(void *b, unsigned int len);


int align100 ;
int align101 __attribute__((aligned (16)));
int align102 __attribute__((aligned (8)));
char align103;
char align104;
int align105;
int align106 __attribute__((aligned (8)));

void *aligns[] = {
    &align100,
    &align101,
    &align102,
    &align103,
    &align104,
    &align105,
    &align106,
};

void *aligns1[] = {
    &align100,
    &align101,
    &align102,
    &align103,
    &align104,
    &align105,
    &align106
};


typedef float        ps2_vu0_fmatrix[4][4] __attribute__((aligned (16)));
typedef ps2_vu0_fmatrix FMATRIX;

typedef float        ps2_vu0_fmatrix1[4][4];
typedef ps2_vu0_fmatrix1 FMATRIX1;

typedef struct objNode {
    void* object;
    void (*mtd)(struct objNode*);
    void (*draw)(struct objNode*, FMATRIX, FMATRIX);
    struct objNode *next;
    struct objNode *parent;
    struct objNode *child;
} ObjNode, *ObjNodePtr;

INLINE void  draw(ObjNode *this, FMATRIX m, FMATRIX n)
{
    printf("work %g ",m[1][1]);
    printf("base %g\n",n[1][1]);
    m[1][1] += -0.7;
    n[1][1] += 0.7;
}

ObjNode c = {
    0, 0, draw, 0, 0, 0
};

ObjNode p = {
    0, 0, draw, &c, 0, &c
};


INLINE void
graphic_ObjNode_draw( ObjNode *this, FMATRIX base )
{
    FMATRIX work;
    bzero(&work,sizeof(work)); work[1][1] = 0.33;

    if(!this) return;
    if(this->mtd)  this->mtd( this );
    if(this->draw) this->draw( this, work, base );
    printf("offset draw %d\n",((char*)(&this->draw) - ((char*)&this->object)));
    printf("offset next %d\n",((char*)(&this->next) - ((char*)&this->object)));

    if(this->child) graphic_ObjNode_draw( this->child, work );
    if(this->next)  graphic_ObjNode_draw( this->next,  base );
    return;
}


INLINE void  ps2_vu0_unit_matrix(ps2_vu0_fmatrix m)
{
    printf("%g\n",m[1][1]);
    m[1][1] = -0.5;
}


#define mod16(a) (((int)(&a))%16)

int
align16(int i, FMATRIX a, FMATRIX b) {
   FMATRIX m;
   FMATRIX n;
   int k = i;
   FMATRIX o;
   if (i==0) return i;
#ifdef OFFSET
   printf("offset %d\n",((char*)a) - ((char*)(&m)));
#endif
   printf("%d %d %d\n",mod16(m),mod16(n),mod16(o));
   align16(i-1,m,n);
   return k;
}

int
align16_1(int i, FMATRIX1 a, FMATRIX1 b) {
   FMATRIX1 m;
   FMATRIX1 n;
   int k = i;
   FMATRIX1 o;
   if (i==0) return i;
#ifdef OFFSET
   printf("offset %d\n",((char*)a) - ((char*)(&m)));
#endif
   printf("%d %d %d\n",mod16(m),mod16(n),mod16(o));
   align16_1(i-1,m,n);
   return k;
}


int
main(int ac, char *av[])
{
    FMATRIX m;
    int i;
    int aligned = 10;

    m[1][1] = 0.5;
    ps2_vu0_unit_matrix(m);
    printf("%g %d\n",m[1][1],aligned);
    align16(2,m,m);
    align16_1(2,m,m);
    graphic_ObjNode_draw( &p, m);

    printf("sizeof(aligns)==%d %d\n",
	sizeof(aligns),sizeof(aligns1));
    printf("sizeof(aligns)/sizeof(void *)==%d\n",
	sizeof(aligns)/sizeof(void *));

    for(i=0;i<sizeof(aligns)/sizeof(void *);i++) {
	printf("align10%d %d\n",i,mod16(aligns[i]));
    }

}


/* end */