refactoring fixes

This commit is contained in:
Blaise Tine
2020-04-14 19:39:59 -04:00
parent 22c8da7490
commit 12dc4d6874
624 changed files with 600 additions and 28528 deletions

View File

@@ -0,0 +1,41 @@
LIB_PATH = ../../runtime
COMP = /home/fares/dev/riscv-gnu-toolchain-vector/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 = /home/fares/dev/riscv-gnu-toolchain-vector/drops/bin/riscv32-unknown-elf-objdump
CPY = /home/fares/dev/riscv-gnu-toolchain-vector/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_VEC = vx_vec.s
LIBS = /home/fares/dev/riscv-gnu-toolchain-vector/drops/riscv32-unknown-elf/lib/libc.a /home/fares/dev/riscv-gnu-toolchain-vector/drops/riscv32-unknown-elf/lib/libstdc++.a -static-libgcc -lgcc
VX_MAIN = vx_vector_main
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_VEC) $(VX_FIO) $(NEWLIB) $(VX_INT) $(VX_IO) $(VX_API) $(VX_MAIN).c $(LIBS) -Iinclude -o $(VX_MAIN).elf
run:
../../simX/obj_dir/Vcache_simX -E -a rv32i --core vx_vector_main.hex -s -b 1> emulator.debug

View File

@@ -0,0 +1,30 @@
.type vx_vec_test, @function
.global vx_vec_test
vx_vec_test:
li a1, 7
sw a1, 0(a0)
ret
# slli a0, a0, 2
# add a0, a0, a3
# vmv.v.x vv0, a2
# # vsplat4 vv0, a2
# stripmine_loop:
# vlb4 vv1, (a1)
# vcmpez4 vp0, vv1
# !vp0 vlw4 vv1, (a3)
# !vp0 vlw4 vv2, (a4)
# !vp0 vfma4 vv1, vv0, vv1, vv2
# !vp0 vsw4 vv1, (a4)
# addi a1, a1, 4
# addi a3, a3, 16
# addi a4, a4, 16
# bleu a3, a0, stripmine_loop
# handle edge cases
# when (n % 4) != 0 ...

View File

@@ -0,0 +1,32 @@
#include "../../runtime/intrinsics/vx_intrinsics.h"
#include "vx_vec.h"
int main()
{
vx_tmc(1);
// int * a = malloc(4);
// int * b = malloc(4);
// int * c = malloc(4);
int * a = malloc(4);
*a = 5;
printf("Value of a: %d\n", *a);
vx_vec_test(a);
printf("Value of a: %d\n", *a);
// for (int i = 0; i < 4; i++)
// {
// if (c[i] != (a[i] + b[i]))
// {
// printf("Fail\n");
// break;
// }
// }
vx_tmc(0);
}

View File

@@ -0,0 +1,91 @@
#include <stdio.h>
#include <stdlib.h>
#include "../../runtime/intrinsics/vx_intrinsics.h"
#include "vx_vec.h"
int main()
{
vx_tmc(1);
#if 0
# 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
#endif
#if 1
int n = 5;
int *a = (int*)malloc(sizeof(int) * n); //{1, 1, 1, 1, 1};
int *b = (int*)malloc(sizeof(int) * n); //{1, 1, 1, 1, 1};
int *c = (int*)malloc(sizeof(int) * n); //{1, 1, 1, 1, 1};
for(int i = 0; i < n; ++i)
{
a[i] = b[i] = c[i] = 1;
}
for(int i = 0; i < n; ++i) printf("%d, ", a[i]);
printf("\n");
// for(int i = 0; i < n; ++i) printf("%d, ", b[i]);
// printf("\n");
// for(int i = 0; i < n; ++i) printf("%d, ", c[i]);
int *d;
*d = 1;
vx_vec_test(n, d, b, c);
printf("(after: n = %d, %d)\n", n, *d);
for(int i = 0; i < n; ++i) printf("%d, ", a[i]);
// printf("\n");
// for(int i = 0; i < n; ++i) printf("%d, ", b[i]);
// printf("\n");
// for(int i = 0; i < n; ++i) printf("%d, ", c[i]);
#endif
#if 0
int * a = malloc(sizeof(int) * 10);
for(int i = 0; i < 10; ++i) a[i] = 5;
for(int i = 0; i < 10; ++i)
printf("%d, ", a[i]);
vx_vec_test(a);
//vx_vec_test(2, a, a, a);
printf("after--------\n");
for(int i = 0; i < 10; ++i)
printf("%d, ", a[i]);
#endif
#if 0
int n = 5;
int *a = (int*)malloc(sizeof(int) * 5); //{1, 1, 1, 1, 1};
int *b = (int*)malloc(sizeof(int) * 5); //{1, 1, 1, 1, 1};
int *c = (int*)malloc(sizeof(int) * 5); //{1, 1, 1, 1, 1};
for(int i = 0; i < n; ++i)
{
a[i] = 1;
b[i] = 1;
c[i] = 0;
}
printf("Value of a: %d, b: %d, c: %d, n: %d\n", a[0], b[0], c[0], n);
vx_vec_test(n, a, b, c);
printf("Value of a: %d, b: %d, c: %d, n: %d\n", a[0], b[0], c[0], n);
#endif
// for (int i = 0; i < 4; i++)
// {
// if (c[i] != (a[i] + b[i]))
// {
// printf("Fail\n");
// break;
// }
// }
vx_tmc(0);
}

View File

@@ -0,0 +1,15 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
void vx_vec_test(int n, int* a, int* b, int* c); //vvaddint32
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,23 @@
.type vx_vec_test, @function
.global vx_vec_test
vx_vec_test:
# 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
vsetvli t0, a0, e32 # Set vector length based on 32-bit vectors
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, vx_vec_test # Loop back
ret # Finished

View File

@@ -0,0 +1,27 @@
#include "../../runtime/intrinsics/vx_intrinsics.h"
#include "vx_vec.h"
int main()
{
vx_tmc(1);
printf("----------------hello!!! \n");
int n = 8;
int *a = (int*)malloc(sizeof(int) * n); //{1, 1, 1, 1, 1};
int *b = (int*)malloc(sizeof(int) * n); //{1, 1, 1, 1, 1};
int *c = (int*)malloc(sizeof(int) * n); //{1, 1, 1, 1, 1};
printf("hello!!! \n");
for(int i = 0; i < n; ++i)
{
a[i] = b[i] = c[i] = 1;
}
vx_vec_test(n, a, b, c);
for(int i = 0; i < n; ++i)
printf("%d ", c[i]);
vx_tmc(0);
}

View File

@@ -0,0 +1,29 @@
#include "../../runtime/intrinsics/vx_intrinsics.h"
#include "vx_vec.h"
int main()
{
vx_tmc(1);
printf("Hello\n");
int n = 64;
int *a = (int*)malloc(sizeof(int) * n); //{1, 1, 1, 1, 1};
int *b = (int*)malloc(sizeof(int) * n); //{1, 1, 1, 1, 1};
int *c = (int*)malloc(sizeof(int) * n); //{1, 1, 1, 1, 1};
for(int i = 0; i < n; ++i)
{
a[i] = b[i] = c[i] = 1;
}
vx_vec_test(n, a, b, c);
for (int i = 0; i < n; ++i)
{
printf("a[%d]=%d, b[%d]=%d, c[%d]=%d\n", i, a[i], i, b[i], i, c[i]);
}
vx_tmc(0);
}