project tests refactoring
This commit is contained in:
40
tests/vector/vecadd/Makefile
Normal file
40
tests/vector/vecadd/Makefile
Normal file
@@ -0,0 +1,40 @@
|
||||
LIB_PATH = ../../../runtime
|
||||
|
||||
COMP = /nethome/ekim79/riscv-gnu-toolchain/drops/bin/riscv32-unknown-elf-gcc
|
||||
|
||||
CC_FLAGS = -ffreestanding -O0 -Wl,--gc-sections -nostartfiles -nostdlib -nostartfiles -nodefaultlibs -Wl,-Bstatic,-T,$(LIB_PATH)/startup/vx_link.ld -march=rv32imv -mabi=ilp32
|
||||
|
||||
DMP = /nethome/ekim79/riscv-gnu-toolchain/drops/bin/riscv32-unknown-elf-objdump
|
||||
CPY = /nethome/ekim79/riscv-gnu-toolchain/drops/bin/riscv32-unknown-elf-objcopy
|
||||
|
||||
# VX_STR = ../../startup/vx_start.S
|
||||
|
||||
NEWLIB = $(LIB_PATH)/newlib/newlib.c
|
||||
VX_STR = $(LIB_PATH)/startup/vx_start.S
|
||||
VX_INT = $(LIB_PATH)/intrinsics/vx_intrinsics.S
|
||||
VX_IO = $(LIB_PATH)/io/vx_io.S $(LIB_PATH)/io/vx_io.c
|
||||
VX_API = $(LIB_PATH)/vx_api/vx_api.c
|
||||
VX_FIO = $(LIB_PATH)/fileio/fileio.S
|
||||
VX_VEC1 = vx_vec_vvaddint32.s
|
||||
#VX_VEC2 = vx_vec_saxpy.s #float --> int
|
||||
#VX_VEC3 = vx_vec_sgemm.s #float --> int
|
||||
#VX_VEC4 = vx_vec_vsadd.s
|
||||
#VX_VEC5 = vx_vec_memcpy.s
|
||||
LIBS = /nethome/ekim79/riscv-gnu-toolchain/drops/riscv32-unknown-elf/lib/libc.a /nethome/ekim79/riscv-gnu-toolchain/drops/riscv32-unknown-elf/lib/libstdc++.a -static-libgcc -lgcc
|
||||
|
||||
VX_MAIN = vx_vec_vecadd
|
||||
|
||||
all: HEX DUMP ELF
|
||||
|
||||
DUMP: ELF
|
||||
$(DMP) -D $(VX_MAIN).elf > $(VX_MAIN).dump
|
||||
|
||||
HEX: ELF
|
||||
$(CPY) -O ihex $(VX_MAIN).elf $(VX_MAIN).hex
|
||||
|
||||
ELF:
|
||||
$(COMP) $(CC_FLAGS) $(VX_STR) $(VX_VEC1) $(VX_FIO) $(NEWLIB) $(VX_INT) $(VX_IO) $(VX_API) $(VX_MAIN).c $(LIBS) -Iinclude -o $(VX_MAIN).elf
|
||||
# $(COMP) $(CC_FLAGS) $(VX_STR) $(VX_VEC2) $(VX_FIO) $(NEWLIB) $(VX_INT) $(VX_IO) $(VX_API) $(VX_MAIN).c $(LIBS) -Iinclude -o $(VX_MAIN).elf
|
||||
# $(COMP) $(CC_FLAGS) $(VX_STR) $(VX_VEC3) $(VX_FIO) $(NEWLIB) $(VX_INT) $(VX_IO) $(VX_API) $(VX_MAIN).c $(LIBS) -Iinclude -o $(VX_MAIN).elf
|
||||
# $(COMP) $(CC_FLAGS) $(VX_STR) $(VX_VEC4) $(VX_FIO) $(NEWLIB) $(VX_INT) $(VX_IO) $(VX_API) $(VX_MAIN).c $(LIBS) -Iinclude -o $(VX_MAIN).elf
|
||||
# $(COMP) $(CC_FLAGS) $(VX_STR) $(VX_VEC5) $(VX_FIO) $(NEWLIB) $(VX_INT) $(VX_IO) $(VX_API) $(VX_MAIN).c $(LIBS) -Iinclude -o $(VX_MAIN).elf~
|
||||
57
tests/vector/vecadd/vx_vec_vecadd.c
Normal file
57
tests/vector/vecadd/vx_vec_vecadd.c
Normal file
@@ -0,0 +1,57 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "../../../runtime/intrinsics/vx_intrinsics.h"
|
||||
#include "vx_vec_vecadd.h"
|
||||
|
||||
//---------------------------------------------------------------
|
||||
/* vvaddint32
|
||||
* # vector-vector add routine of 32-bit integers
|
||||
* # void vvaddint32(size_t n, const int*x, const int*y, int*z)
|
||||
* # { for (size_t i=0; i<n; i++) { z[i]=x[i]+y[i]; } } */
|
||||
//---------------------------------------------------------------
|
||||
|
||||
int main()
|
||||
{
|
||||
vx_tmc(1);
|
||||
|
||||
int n = 4; //SIZE
|
||||
|
||||
int *a = (int*)malloc(sizeof(int) * n);
|
||||
int *b = (int*)malloc(sizeof(int) * n);
|
||||
int *c = (int*)malloc(sizeof(int) * n);
|
||||
|
||||
// Initialize values for array members.
|
||||
for (int i = 0; i < n; ++i) {
|
||||
a[i] = i * 2 + 0;
|
||||
b[i] = i * 2 + 1;
|
||||
c[i] = 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
printf("vvaddint...\na[%d]: ", n);
|
||||
for(int i = 0; i < n; ++i) printf("%d ", a[i]);
|
||||
printf("\nb[%d]: ", n);
|
||||
for(int i = 0; i < n; ++i) printf("%d ", b[i]);
|
||||
printf("\nc[%d] = a[%d] + b[%d]: ", n, n, n);
|
||||
for(int i = 0; i < n; ++i) printf("%d ", c[i]);
|
||||
#endif
|
||||
|
||||
vx_vec_vvaddint32(n, a, b, c);
|
||||
|
||||
for(int i = 0; i < n; ++i)
|
||||
{
|
||||
if(c[i] != (a[i]+b[i]))
|
||||
{
|
||||
printf("\n<vddint32> FAILED at <index: %d>! \n", i);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
printf("\nPASSED.......................... <vddint32> \n");
|
||||
|
||||
free(a); free(b); free(c);
|
||||
|
||||
vx_tmc(0);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
86984
tests/vector/vecadd/vx_vec_vecadd.dump
Normal file
86984
tests/vector/vecadd/vx_vec_vecadd.dump
Normal file
File diff suppressed because it is too large
Load Diff
17
tests/vector/vecadd/vx_vec_vecadd.h
Normal file
17
tests/vector/vecadd/vx_vec_vecadd.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void vx_vec_vvaddint32(int n, int* a, int* b, int *c);
|
||||
//void vx_vec_vsadd(int n, int* a, int scalar);
|
||||
//void vx_vec_memcpy(int* a, int* b, int n);
|
||||
//void vx_vec_saxpy(int n, int scalar, int* a, int* b);
|
||||
//void vx_vec_sgemm_nn(int n, int m, int k, int* a1, int lda, int* b1, int ldb, int* c1, int ldc);
|
||||
//void vx_vec_sgemm_nn(int n, int m, int k, int* a1, int* b1, int* c1);
|
||||
//void vx_vec_sgemm_nn(int n, int* a1, int* b1, int* c1);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
22
tests/vector/vecadd/vx_vec_vvaddint32.s
Normal file
22
tests/vector/vecadd/vx_vec_vvaddint32.s
Normal file
@@ -0,0 +1,22 @@
|
||||
.type vx_vec_vvaddi32, @function
|
||||
.global vx_vec_vvaddint32
|
||||
# vector-vector add routine of 32-bit integers
|
||||
# void vvaddint32(size_t n, const int*x, const int*y, int*z)
|
||||
# { for (size_t i=0; i<n; i++) { z[i]=x[i]+y[i]; } }
|
||||
#
|
||||
# a0 = n, a1 = x, a2 = y, a3 = z
|
||||
# Non-vector instructions are indented
|
||||
vx_vec_vvaddint32:
|
||||
vsetvli t0, a0, e32 # Set vector length based on 32-bit vectors
|
||||
loop:
|
||||
vlw.v v0, (a1) # Get first vector
|
||||
sub a0, a0, t0 # Decrement number done
|
||||
slli t0, t0, 2 # Multiply number done by 4 bytes
|
||||
add a1, a1, t0 # Bump pointer
|
||||
vlw.v v1, (a2) # Get second vector
|
||||
add a2, a2, t0 # Bump pointer
|
||||
vadd.vv v2, v0, v1 # Sum vectors
|
||||
vsw.v v2, (a3) # Store result
|
||||
add a3, a3, t0 # Bump pointer
|
||||
bnez a0, loop # Loop back
|
||||
ret # Finished
|
||||
Reference in New Issue
Block a user