OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [coremark/] [core_matrix.c] - Diff between revs 355 and 406

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 355 Rev 406
Line 45... Line 45...
#define matrix_clip(x,y) ((y) ? (x) & 0x0ff : (x) & 0x0ffff)
#define matrix_clip(x,y) ((y) ? (x) & 0x0ff : (x) & 0x0ffff)
#define matrix_big(x) (0xf000 | (x))
#define matrix_big(x) (0xf000 | (x))
#define bit_extract(x,from,to) (((x)>>(from)) & (~(0xffffffff << (to))))
#define bit_extract(x,from,to) (((x)>>(from)) & (~(0xffffffff << (to))))
 
 
#if CORE_DEBUG
#if CORE_DEBUG
void printmat(MATDAT *A, ee_u32 N, char *name) {
void printmat(MATDAT * A, ee_u32 N, char *name)
 
{
        ee_u32 i,j;
        ee_u32 i,j;
        ee_printf("Matrix %s [%dx%d]:\n",name,N,N);
        ee_printf("Matrix %s [%dx%d]:\n",name,N,N);
        for (i=0; i<N; i++) {
        for (i=0; i<N; i++) {
                for (j=0; j<N; j++) {
                for (j=0; j<N; j++) {
                        if (j!=0)
                        if (j!=0)
Line 57... Line 58...
                        ee_printf("%d",A[i*N+j]);
                        ee_printf("%d",A[i*N+j]);
                }
                }
                ee_printf("\n");
                ee_printf("\n");
        }
        }
}
}
void printmatC(MATRES *C, ee_u32 N, char *name) {
 
 
void printmatC(MATRES * C, ee_u32 N, char *name)
 
{
        ee_u32 i,j;
        ee_u32 i,j;
        ee_printf("Matrix %s [%dx%d]:\n",name,N,N);
        ee_printf("Matrix %s [%dx%d]:\n",name,N,N);
        for (i=0; i<N; i++) {
        for (i=0; i<N; i++) {
                for (j=0; j<N; j++) {
                for (j=0; j<N; j++) {
                        if (j!=0)
                        if (j!=0)
Line 76... Line 79...
        Benchmark function
        Benchmark function
 
 
        Iterate <matrix_test> N times,
        Iterate <matrix_test> N times,
        changing the matrix values slightly by a constant amount each time.
        changing the matrix values slightly by a constant amount each time.
*/
*/
ee_u16 core_bench_matrix(mat_params *p, ee_s16 seed, ee_u16 crc) {
ee_u16 core_bench_matrix(mat_params * p, ee_s16 seed, ee_u16 crc)
 
{
        ee_u32 N=p->N;
        ee_u32 N=p->N;
        MATRES *C=p->C;
        MATRES *C=p->C;
        MATDAT *A=p->A;
        MATDAT *A=p->A;
        MATDAT *B=p->B;
        MATDAT *B=p->B;
        MATDAT val=(MATDAT)seed;
        MATDAT val=(MATDAT)seed;
Line 112... Line 116...
        4 - Multiply a matrix by a matrix.
        4 - Multiply a matrix by a matrix.
        5 - Add a constant value to all elements of a matrix.
        5 - Add a constant value to all elements of a matrix.
 
 
        After the last step, matrix A is back to original contents.
        After the last step, matrix A is back to original contents.
*/
*/
ee_s16 matrix_test(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B, MATDAT val) {
ee_s16 matrix_test(ee_u32 N, MATRES * C, MATDAT * A, MATDAT * B, MATDAT val)
 
{
        ee_u16 crc=0;
        ee_u16 crc=0;
        MATDAT clipval=matrix_big(val);
        MATDAT clipval=matrix_big(val);
 
 
        matrix_add_const(N,A,val); /* make sure data changes  */
        matrix_add_const(N,A,val); /* make sure data changes  */
#if CORE_DEBUG
#if CORE_DEBUG
Line 141... Line 146...
        crc=crc16(matrix_sum(N,C,clipval),crc);
        crc=crc16(matrix_sum(N,C,clipval),crc);
#if CORE_DEBUG
#if CORE_DEBUG
        printmatC(C,N,"matrix_mul_matrix_bitextract");
        printmatC(C,N,"matrix_mul_matrix_bitextract");
#endif
#endif
 
 
        matrix_add_const(N,A,-val); /* return matrix to initial value */
        matrix_add_const(N, A, -val);   /* return matrix to initial value */
        return crc;
        return crc;
}
}
 
 
/* Function : matrix_init
/* Function : matrix_init
        Initialize the memory block for matrix benchmarking.
        Initialize the memory block for matrix benchmarking.
Line 160... Line 165...
        Matrix dimensions.
        Matrix dimensions.
 
 
        Note:
        Note:
        The seed parameter MUST be supplied from a source that cannot be determined at compile time
        The seed parameter MUST be supplied from a source that cannot be determined at compile time
*/
*/
ee_u32 core_init_matrix(ee_u32 blksize, void *memblk, ee_s32 seed, mat_params *p) {
ee_u32 core_init_matrix(ee_u32 blksize, void *memblk, ee_s32 seed,
 
                        mat_params * p)
 
{
        ee_u32 N=0;
        ee_u32 N=0;
        MATDAT *A;
        MATDAT *A;
        MATDAT *B;
        MATDAT *B;
        ee_s32 order=1;
        ee_s32 order=1;
        MATDAT val;
        MATDAT val;
Line 211... Line 218...
        As long as this value is under the parameter clipval,
        As long as this value is under the parameter clipval,
        add 1 to the result if the element is bigger then the previous.
        add 1 to the result if the element is bigger then the previous.
 
 
        Otherwise, reset the accumulator and add 10 to the result.
        Otherwise, reset the accumulator and add 10 to the result.
*/
*/
ee_s16 matrix_sum(ee_u32 N, MATRES *C, MATDAT clipval) {
ee_s16 matrix_sum(ee_u32 N, MATRES * C, MATDAT clipval)
 
{
        MATRES tmp=0,prev=0,cur=0;
        MATRES tmp=0,prev=0,cur=0;
        ee_s16 ret=0;
        ee_s16 ret=0;
        ee_u32 i,j;
        ee_u32 i,j;
        for (i=0; i<N; i++) {
        for (i=0; i<N; i++) {
                for (j=0; j<N; j++) {
                for (j=0; j<N; j++) {
Line 235... Line 243...
 
 
/* Function: matrix_mul_const
/* Function: matrix_mul_const
        Multiply a matrix by a constant.
        Multiply a matrix by a constant.
        This could be used as a scaler for instance.
        This could be used as a scaler for instance.
*/
*/
void matrix_mul_const(ee_u32 N, MATRES *C, MATDAT *A, MATDAT val) {
void matrix_mul_const(ee_u32 N, MATRES * C, MATDAT * A, MATDAT val)
 
{
        ee_u32 i,j;
        ee_u32 i,j;
        for (i=0; i<N; i++) {
        for (i=0; i<N; i++) {
                for (j=0; j<N; j++) {
                for (j=0; j<N; j++) {
                        C[i*N+j]=(MATRES)A[i*N+j] * (MATRES)val;
                        C[i*N+j]=(MATRES)A[i*N+j] * (MATRES)val;
                }
                }
Line 247... Line 256...
}
}
 
 
/* Function: matrix_add_const
/* Function: matrix_add_const
        Add a constant value to all elements of a matrix.
        Add a constant value to all elements of a matrix.
*/
*/
void matrix_add_const(ee_u32 N, MATDAT *A, MATDAT val) {
void matrix_add_const(ee_u32 N, MATDAT * A, MATDAT val)
 
{
        ee_u32 i,j;
        ee_u32 i,j;
        for (i=0; i<N; i++) {
        for (i=0; i<N; i++) {
                for (j=0; j<N; j++) {
                for (j=0; j<N; j++) {
                        A[i*N+j] += val;
                        A[i*N+j] += val;
                }
                }
Line 260... Line 270...
 
 
/* Function: matrix_mul_vect
/* Function: matrix_mul_vect
        Multiply a matrix by a vector.
        Multiply a matrix by a vector.
        This is common in many simple filters (e.g. fir where a vector of coefficients is applied to the matrix.)
        This is common in many simple filters (e.g. fir where a vector of coefficients is applied to the matrix.)
*/
*/
void matrix_mul_vect(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B) {
void matrix_mul_vect(ee_u32 N, MATRES * C, MATDAT * A, MATDAT * B)
 
{
        ee_u32 i,j;
        ee_u32 i,j;
        for (i=0; i<N; i++) {
        for (i=0; i<N; i++) {
                C[i]=0;
                C[i]=0;
                for (j=0; j<N; j++) {
                for (j=0; j<N; j++) {
                        C[i]+=(MATRES)A[i*N+j] * (MATRES)B[j];
                        C[i]+=(MATRES)A[i*N+j] * (MATRES)B[j];
Line 274... Line 285...
 
 
/* Function: matrix_mul_matrix
/* Function: matrix_mul_matrix
        Multiply a matrix by a matrix.
        Multiply a matrix by a matrix.
        Basic code is used in many algorithms, mostly with minor changes such as scaling.
        Basic code is used in many algorithms, mostly with minor changes such as scaling.
*/
*/
void matrix_mul_matrix(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B) {
void matrix_mul_matrix(ee_u32 N, MATRES * C, MATDAT * A, MATDAT * B)
 
{
        ee_u32 i,j,k;
        ee_u32 i,j,k;
        for (i=0; i<N; i++) {
        for (i=0; i<N; i++) {
                for (j=0; j<N; j++) {
                for (j=0; j<N; j++) {
                        C[i*N+j]=0;
                        C[i*N+j]=0;
                        for(k=0;k<N;k++)
                        for (k = 0; k < N; k++) {
                        {
                                C[i * N + j] +=
                                C[i*N+j]+=(MATRES)A[i*N+k] * (MATRES)B[k*N+j];
                                    (MATRES) A[i * N + k] * (MATRES) B[k * N +
 
                                                                       j];
                        }
                        }
                }
                }
        }
        }
}
}
 
 
/* Function: matrix_mul_matrix_bitextract
/* Function: matrix_mul_matrix_bitextract
        Multiply a matrix by a matrix, and extract some bits from the result.
        Multiply a matrix by a matrix, and extract some bits from the result.
        Basic code is used in many algorithms, mostly with minor changes such as scaling.
        Basic code is used in many algorithms, mostly with minor changes such as scaling.
*/
*/
void matrix_mul_matrix_bitextract(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B) {
void matrix_mul_matrix_bitextract(ee_u32 N, MATRES * C, MATDAT * A, MATDAT * B)
 
{
        ee_u32 i,j,k;
        ee_u32 i,j,k;
        for (i=0; i<N; i++) {
        for (i=0; i<N; i++) {
                for (j=0; j<N; j++) {
                for (j=0; j<N; j++) {
                        C[i*N+j]=0;
                        C[i*N+j]=0;
                        for(k=0;k<N;k++)
                        for (k = 0; k < N; k++) {
                        {
                                MATRES tmp =
                                MATRES tmp=(MATRES)A[i*N+k] * (MATRES)B[k*N+j];
                                    (MATRES) A[i * N + k] * (MATRES) B[k * N +
                                C[i*N+j]+=bit_extract(tmp,2,4)*bit_extract(tmp,5,7);
                                                                       j];
 
                                C[i * N + j] +=
 
                                    bit_extract(tmp, 2, 4) * bit_extract(tmp, 5,
 
                                                                         7);
                        }
                        }
                }
                }
        }
        }
}
}
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.