Commit 5a4f3383 authored by Marc's avatar Marc
Browse files

new grayscale test and changes to mat_mul

parent 29360044
......@@ -55,18 +55,59 @@ simd_mask: simd_mask_test.c bin_change
sparc-gaisler-elf-objdump -d simd_mask_test.o > simd_mask_test.dump
mat_mul: mat_mul.o
$(XCC) $(XCFLAGS) mat_mul.o -o mat_mul.exe
mat_mul: mat_mul.c
$(XCC) $(XCFLAGS) -D N=$(par1) -c $<
$(XCC) $(XCFLAGS) mat_mul.o -o mat_mul.exe
sparc-gaisler-elf-objcopy -O srec --gap-fill 0 mat_mul.exe mat_mul.srec
cp mat_mul.srec $(CURRENT_DIR)/test.srec
sparc-gaisler-elf-objdump -d mat_mul.o > mat_mul.dump
mat_mul_simd: mat_mul_simd.o bin_change
grayscale: grayscale.c arrays.h image256.h
$(XCC) $(XCFLAGS) -D N=$(par1) -c $<
$(XCC) $(XCFLAGS) grayscale.o -o grayscale.exe
sparc-gaisler-elf-objcopy -O srec --gap-fill 0 grayscale.exe grayscale.srec
cp grayscale.srec $(CURRENT_DIR)/test.srec
sparc-gaisler-elf-objdump -d grayscale.o > grayscale.dump
grayscale_simd: grayscale_simd.c arrays.h image256.h
$(XCC) $(XCFLAGS) -D N=$(par1) -c $<
$(XCC) $(XCFLAGS) grayscale_simd.o -o grayscale_simd.exe
sparc-gaisler-elf-objcopy -O srec --gap-fill 0 grayscale_simd.exe tmp.grayscale_simd.srec
./bin_change tmp.grayscale_simd.srec grayscale_simd.list grayscale_simd.srec 83320001
cp grayscale_simd.srec $(CURRENT_DIR)/test.srec
sparc-gaisler-elf-objdump -d grayscale_simd.o > grayscale_simd.dump
mat_mul_int: mat_mul_int.c
$(XCC) $(XCFLAGS) -D N=$(par1) -c $<
$(XCC) $(XCFLAGS) mat_mul_int.o -o mat_mul_int.exe
sparc-gaisler-elf-objcopy -O srec --gap-fill 0 mat_mul_int.exe mat_mul_int.srec
cp mat_mul_int.srec $(CURRENT_DIR)/test.srec
sparc-gaisler-elf-objdump -d mat_mul_int.o > mat_mul_int.dump
mat_mul_simd: mat_mul_simd.c bin_change
$(XCC) $(XCFLAGS) -D N=$(par1) -c mat_mul_simd.c
$(XCC) $(XCFLAGS) mat_mul_simd.o -o mat_mul_simd.exe
sparc-gaisler-elf-objcopy -O srec --gap-fill 0 mat_mul_simd.exe tmp.mat_mul_simd.srec
./bin_change tmp.mat_mul_simd.srec mat_mul_simd.list mat_mul_simd.srec 925A0009
./bin_change tmp.mat_mul_simd.srec mat_mul_simd.list tmp2.mat_mul_simd.srec 925A0009
./bin_change tmp2.mat_mul_simd.srec mat_mul_simd32.list3 mat_mul_simd.srec 92020009
cp mat_mul_simd.srec $(CURRENT_DIR)/test.srec
sparc-gaisler-elf-objdump -d mat_mul_simd.o > mat_mul_simd.dump
mat_mul_simd4: mat_mul_simd4.o bin_change
$(XCC) $(XCFLAGS) mat_mul_simd4.o -o mat_mul_simd4.exe
sparc-gaisler-elf-objcopy -O srec --gap-fill 0 mat_mul_simd4.exe tmp.mat_mul_simd4.srec
./bin_change tmp.mat_mul_simd4.srec mat_mul_simd4.list mat_mul_simd4.srec 925A0009
cp mat_mul_simd4.srec $(CURRENT_DIR)/test.srec
sparc-gaisler-elf-objdump -d mat_mul_simd4.o > mat_mul_simd4.dump
mat_mul_simd32: mat_mul_simd32.o bin_change
$(XCC) $(XCFLAGS) mat_mul_simd32.o -o mat_mul_simd32.exe
sparc-gaisler-elf-objcopy -O srec --gap-fill 0 mat_mul_simd32.exe tmp.mat_mul_simd32.srec
./bin_change tmp.mat_mul_simd32.srec mat_mul_simd32.list tmp2.mat_mul_simd32.srec 925A0009
./bin_change tmp2.mat_mul_simd32.srec mat_mul_simd32.list2 tmp3.mat_mul_simd32.srec 84784001
./bin_change tmp3.mat_mul_simd32.srec mat_mul_simd32.list3 mat_mul_simd32.srec 92020009
cp mat_mul_simd32.srec $(CURRENT_DIR)/test.srec
sparc-gaisler-elf-objdump -d mat_mul_simd32.o > mat_mul_simd32.dump
clean:
rm -f *.exe *.o *.dump bin_change make.x tmp.*
rm -f *.exe *.o *.dump bin_change make.x tmp*.*
#include "image256.h"
#ifndef N
#define N 2
#endif
#if N == 2
#define IMAGE_ARRAY 255,0,0,255,255,255,0,255,255,255,0,255,255,0,0,255
#elif N == 4
#define IMAGE_ARRAY 255,255,255,255,255,0,0,255,255,0,0,255,255,255,255,255,255,0,0,255,255,178,127,255,0,19,127,255,255,255,255,255,255,255,255,255,0,19,127,255,255,216,0,255,0,19,127,255,255,255,255,255,127,51,0,255,0,19,127,255,127,51,0,255
#elif N == 8
#define IMAGE_ARRAY 66,165,245,255,66,165,245,255,66,165,245,255,66,165,245,255,66,165,245,255,66,165,245,255,66,165,245,255,66,165,245,255,66,165,245,255,66,165,245,255,248,187,208,255,248,187,208,255,248,187,208,255,248,187,208,255,66,165,245,255,66,165,245,255,66,165,245,255,248,187,208,255,248,187,208,255,248,187,208,255,248,187,208,255,248,187,208,255,248,187,208,255,66,165,245,255,66,165,245,255,244,143,177,255,248,187,208,255,0,0,0,255,248,187,208,255,0,0,0,255,248,187,208,255,66,165,245,255,244,143,177,255,248,187,208,255,248,187,208,255,26,35,126,255,248,187,208,255,26,35,126,255,248,187,208,255,244,143,177,255,244,143,177,255,244,143,177,255,240,98,146,255,248,187,208,255,248,187,208,255,248,187,208,255,240,98,146,255,244,143,177,255,66,165,245,255,173,20,87,255,244,143,177,255,244,143,177,255,248,187,208,255,248,187,208,255,173,20,87,255,66,165,245,255,76,175,80,255,173,20,87,255,194,24,91,255,194,24,91,255,76,175,80,255,173,20,87,255,194,24,91,255,76,175,80,255
#else
#define IMAGE_ARRAY IMAGE256
#endif
#include <stdio.h>
#include <stdlib.h>
#include "arrays.h"
#ifndef N
#define N 2
#endif
void init(unsigned char a[N][N][4]){
for (int i = 0; i<N; i++)
for (int j = 0; j<N; j++){
a[i][j][0] = rand()%255;
a[i][j][1] = rand()%255;
a[i][j][2] = rand()%255;
a[i][j][3] = 255;
}
}
unsigned char shift_and_add(unsigned char r, unsigned char g, unsigned char b){
unsigned char ret;
ret = (r>>2) + (g>>2) + (b>>2);
return ret;
}
void grayscale(unsigned char src[N][N][4], unsigned char dst[N][N][3]){
unsigned char color;
for (int i = 0; i<N; i++)
for (int j = 0; j<N; j++){
color = shift_and_add(src[i][j][0], src[i][j][1], src[i][j][2]);
dst[i][j][0] = color;
dst[i][j][1] = color;
dst[i][j][2] = color;
}
}
void print(unsigned char src[N][N][3]) {
printf("P3\n%d %d\n255\n",N,N);
for (int i = 0; i<N; i++){
for (int j = 0; j<N; j++){
printf("%d %d %d ", src[i][j][0], src[i][j][1], src[i][j][2]);
}
printf("\n");
}
}
int main(){
unsigned char source[N][N][4] = {IMAGE_ARRAY};
unsigned char dest[N][N][3];
//init(source);
grayscale(source, dest);
print(dest);
}
This source diff could not be displayed because it is too large. You can view the blob instead.
#include <stdio.h>
#include <stdlib.h>
#include "arrays.h"
#ifndef N
#define N 2
#endif
void init(unsigned char a[N][N][4]){
for (int i = 0; i<N; i++)
for (int j = 0; j<N; j++){
a[i][j][0] = rand()%255;
a[i][j][1] = rand()%255;
a[i][j][2] = rand()%255;
a[i][j][3] = 255;
}
}
int b = 0xfcfcfc7f;
int shift_and_add(int a){
int r;
asm("srl %1, %0, %0"
: "=r"(r)
: "r"(a), "0"(b));
return r;
}
void grayscale(unsigned char src[N][N][4], unsigned char dst[N][N][3]){
unsigned char color;
for (int i = 0; i<N; i++)
for (int j = 0; j<N; j++){
color = shift_and_add(*((int *) &src[i][j][0]));
dst[i][j][0] = color;
dst[i][j][1] = color;
dst[i][j][2] = color;
}
}
void print(unsigned char src[N][N][3]) {
printf("P3\n%d %d\n255\n",N,N);
for (int i = 0; i<N; i++){
for (int j = 0; j<N; j++){
printf("%d %d %d ", src[i][j][0], src[i][j][1], src[i][j][2]);
}
printf("\n");
}
}
int main(){
unsigned char source[N][N][4] = {IMAGE_ARRAY};
unsigned char dest[N][N][3];
//init(source);
grayscale(source, dest);
print(dest);
}
This diff is collapsed.
This diff is collapsed.
......@@ -3,17 +3,33 @@
#include <string.h>
#include <stdlib.h>
#define min(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })
#ifndef N
#define N 4
#endif
int computeCell(int a, int b){
int r;
asm("smul %1, %0, %0"
: "=r"(r)
: "r"(a), "0"(b));
//printf("a: %d\nb: %d\nr: %d\n",a,b,r);
return r;
return min(r, 255);
}
int computeSum(int a, int b) {
int r;
//sum sum a b
asm("add %1, %0, %0"
: "=r"(r)
: "r"(a), "0"(b));
return min(r, 255);
}
int main()
......@@ -23,6 +39,7 @@ int main()
unsigned char A[N][N], B[N][N], C[N][N];
srand(N);
for(int i=0; i<N; i++)
for(int j=0; j<N; j++) {
A[i][j] = rand()%10;
......@@ -30,14 +47,24 @@ int main()
}
int sum = 0;
int aux;
puts("TEST BEGIN");
asm("nop");
asm("srl %i0, %o1, %g2");
asm("nop");
for(int i=0; i<N; i++)
for(int j=0; j<N; j++){
for(int k=0; k<N; k++){
sum += computeCell(A[i][k],B[k][j]);
aux = computeCell(A[i][k],B[k][j]);
sum = computeSum(sum, aux);
}
C[i][j] = sum;
sum = 0;
}
asm("nop");
asm("srl %i0, %o1, %g2");
asm("nop");
puts("TEST END");
pos += sprintf(&string[pos],"A:\n");
for(int i=0; i<N; i++){
......@@ -61,5 +88,5 @@ int main()
}
puts(string);
puts("END OF TEST");
puts("END OF SIMULATION");
}
This diff is collapsed.
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#ifndef N
#define N 4
#endif
int computeCell(int a, int b){
int r;
asm("smul %1, %0, %0"
: "=r"(r)
: "r"(a), "0"(b));
//printf("a: %d\nb: %d\nr: %d\n",a,b,r);
return r;
}
int computeSum(int a, int b) {
int r;
//sum sum a b
asm("add %1, %0, %0"
: "=r"(r)
: "r"(a), "0"(b));
return r;
}
int main()
{
char string[3*(3+(6*N*N+N))];
int pos = 0;
unsigned int A[N][N], B[N][N], C[N][N];
srand(N);
for(int i=0; i<N; i++)
for(int j=0; j<N; j++) {
A[i][j] = rand()%10;
B[i][j] = rand()%10;
}
int sum = 0;
int aux;
puts("TEST BEGIN");
asm("nop");
asm("srl %i0, %o1, %g2");
asm("nop");
for(int i=0; i<N; i++)
for(int j=0; j<N; j++){
for(int k=0; k<N; k++){
aux = computeCell(A[i][k],B[k][j]);
sum = computeSum(sum, aux);
}
C[i][j] = sum;
sum = 0;
}
asm("nop");
asm("srl %i0, %o1, %g2");
asm("nop");
puts("TEST END");
pos += sprintf(&string[pos],"A:\n");
for(int i=0; i<N; i++){
for(int j=0; j<N; j++)
pos+=sprintf(&string[pos],"%d ", A[i][j]);
pos+=sprintf(&string[pos],"\n");
}
pos += sprintf(&string[pos],"B:\n");
for(int i=0; i<N; i++){
for(int j=0; j<N; j++)
pos+=sprintf(&string[pos],"%d ", B[i][j]);
pos+=sprintf(&string[pos],"\n");
}
pos += sprintf(&string[pos],"C:\n");
for(int i=0; i<N; i++){
for(int j=0; j<N; j++)
pos+=sprintf(&string[pos],"%d ", C[i][j]);
pos+=sprintf(&string[pos],"\n");
}
puts(string);
puts("END OF SIMULATION");
}
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -3,7 +3,9 @@
#include <string.h>
#include <stdlib.h>
#define N 4
#ifndef N
#define N 8
#endif
int computeCell(int a, int b){
int r;
......@@ -15,6 +17,15 @@ int computeCell(int a, int b){
return r;
}
int computeSum(int a, int b) {
int r;
//sum sum a b
asm("add %1, %0, %0"
: "=r"(r)
: "r"(a), "0"(b));
return r;
}
int main()
{
char string[3*(3+(6*N*N+N))];
......@@ -22,7 +33,6 @@ int main()
unsigned char A[N][N], B[N][N], C[N][N];
srand(N);
puts("TEST BEGIN");
for(int i=0; i<N; i++)
for(int j=0; j<N; j++) {
......@@ -31,12 +41,25 @@ int main()
}
int sum = 0;
int aux;
puts("TEST BEGIN");
asm("nop");
asm("srl %i0, %o1, %g2");
asm("nop");
for(int i=0; i<N; i++)
for(int j=0; j<N; j++){
sum += computeCell(*((int *) &A[i][0]),*((int *) &B[j][0]));
for(int k=0; k<N/4; k++){
aux = computeCell(*((int *) &A[i][k*4]),*((int *) &B[j][k*4]));
sum = computeSum(aux, sum);
}
C[i][j] = sum;
sum = 0;
}
asm("nop");
asm("srl %i0, %o1, %g2");
asm("nop");
puts("TEST END");
pos += sprintf(&string[pos],"A:\n");
for(int i=0; i<N; i++){
......@@ -60,5 +83,5 @@ int main()
}
puts(string);
puts("END OF TEST");
puts("END OF SIMULATION");
}
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#define N 32
int computeCell(int a, int b){
int r;
//usmul usum a b
asm("smul %1, %0, %0"
: "=r"(r)
: "r"(a), "0"(b));
// printf("cell\na: %#010x\nb: %#010x\nr: %#010x\n",a,b,r);
return r;
}
int computeCell2(unsigned char A[N][N], unsigned char B[N][N], int i, int j, int base){
int r;
//set ac_be = 0001
asm("sdiv %g1, %g1, %g2");
for(int k=0; k<4; k++)
r = computeCell(*((int *) &A[i][base+k*4]),*((int *) &B[j][base+k*4]));
// printf("r: %#010x\n",r);
return r;
}
int computeSum(int a, int b) {
int r;
//sum sum a b
asm("add %1, %0, %0"
: "=r"(r)
: "r"(a), "0"(b));
return r;
}
int main()
{
char string[3*(3+(6*N*N+N))];
int pos = 0;
unsigned char A[N][N], B[N][N], C[N][N];
srand(N);
for(int i=0; i<N; i++)
for(int j=0; j<N; j++) {
A[i][j] = rand()%10;
B[j][i] = rand()%10;
}
int sum1 = 0;
int sum2 = 0;
int aux;
puts("TEST BEGIN");
asm("nop");
asm("srl %i0, %o1, %g2");
asm("nop");
for(int i=0; i<N; i++)
for(int j=0; j<N; j++){
sum1 = computeCell2(A, B, i, j, 0);
sum2 = computeCell2(A, B, i, j, 4);
aux = computeSum(sum1, sum2);
//printf("sum: %#010x\n",aux);
C[i][j] = aux;
}
asm("nop");
asm("srl %i0, %o1, %g2");
asm("nop");
puts("TEST END");
pos += sprintf(&string[pos],"A:\n");
for(int i=0; i<N; i++){
for(int j=0; j<N; j++)
pos+=sprintf(&string[pos],"%d ", A[i][j]);
pos+=sprintf(&string[pos],"\n");
}
pos += sprintf(&string[pos],"B:\n");
for(int j=0; j<N; j++){
for(int i=0; i<N; i++)
pos+=sprintf(&string[pos],"%d ", B[i][j]);
pos+=sprintf(&string[pos],"\n");
}
pos += sprintf(&string[pos],"C:\n");
for(int i=0; i<N; i++){
for(int j=0; j<N; j++)
pos+=sprintf(&string[pos],"%d ", C[i][j]);
pos+=sprintf(&string[pos],"\n");
}
puts(string);
puts("END OF SIMULATION");
}
This source diff could not be displayed because it is too large. You can view the blob instead.
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#define N 4
int computeCell(int a, int b){
int r;
asm("smul %1, %0, %0"
: "=r"(r)
: "r"(a), "0"(b));
//printf("a: %#010x\nb: %#010x\nr: %#010x\n",a,b,r);
return r;
}
int main()
{
char string[3*(3+(6*N*N+N))];
int pos = 0;
unsigned char A[N][N], B[N][N], C[N][N];
srand(N);
for(int i=0; i<N; i++)
for(int j=0; j<N; j++) {
A[i][j] = rand()%10;
B[j][i] = rand()%10;
}
puts("TEST BEGIN");
asm("nop");
asm("srl %i0, %o1, %g2");
asm("nop");
for(int i=0; i<N; i++)
for(int j=0; j<N; j++){
C[i][j] = computeCell(*((int *) &A[i][0]),*((int *) &B[j][0]));
}
asm("nop");
asm("srl %i0, %o1, %g2");
asm("nop");
puts("TEST END");
pos += sprintf(&string[pos],"A:\n");
for(int i=0; i<N; i++){
for(int j=0; j<N;