From 850461c15c9accffe89dbe9cd5cabed241344f36 Mon Sep 17 00:00:00 2001 From: davide schiavone Date: Wed, 25 Sep 2024 18:02:27 +0200 Subject: [PATCH] revert app change --- sw/applications/example_asm/add.s | 18 +----------- sw/applications/example_asm/main.c | 40 ++++++-------------------- sw/applications/example_asm/multiply.S | 29 +++++-------------- 3 files changed, 17 insertions(+), 70 deletions(-) diff --git a/sw/applications/example_asm/add.s b/sw/applications/example_asm/add.s index 62d59eb40..2e61b29ac 100644 --- a/sw/applications/example_asm/add.s +++ b/sw/applications/example_asm/add.s @@ -2,21 +2,5 @@ .globl add_asm_function add_asm_function: - flw f0,0(a0) - flw f1,0(a1) - #check if it gets executed in a branch shadow - li t0, 100 - loop1: - fadd.s fa0, f0, f1 # Add the values in a0 and a1, store the result in a0 - fadd.s fa0, fa0, f1 # Add the values in a0 and a1, store the result in a0 - fadd.s fa0, fa0, f1 # Add the values in a0 and a1, store the result in a0 - fadd.s fa0, fa0, f1 # Add the values in a0 and a1, store the result in a0 - fadd.s fa0, fa0, f1 # Add the values in a0 and a1, store the result in a0 - fadd.s fa0, fa0, f1 # Add the values in a0 and a1, store the result in a0 - fadd.s fa0, fa0, f1 # Add the values in a0 and a1, store the result in a0 - fadd.s fa0, fa0, f1 # Add the values in a0 and a1, store the result in a0 - fadd.s fa0, fa0, f1 # Add the values in a0 and a1, store the result in a0 - fadd.s fa0, fa0, f1 # Add the values in a0 and a1, store the result in a0 - addi t0,t0,-1 - bnez t0, loop1 + add a0, a0, a1 # Add the values in a0 and a1, store the result in a0 ret # Return from the function \ No newline at end of file diff --git a/sw/applications/example_asm/main.c b/sw/applications/example_asm/main.c index aa0462aed..48ca9c9e5 100644 --- a/sw/applications/example_asm/main.c +++ b/sw/applications/example_asm/main.c @@ -1,11 +1,7 @@ #include #include #include "constants.h" -#include "csr.h" #include "x-heep.h" -#include "timer_sdk.h" - -#define FS_INITIAL 0x01 /* By default, printfs are activated for FPGA and disabled for simulation. */ #define PRINTF_IN_FPGA 1 @@ -19,35 +15,17 @@ #define PRINTF(...) #endif -void __attribute__((aligned(4), interrupt)) handler_irq_timer(void) { - timer_arm_stop(); - timer_irq_clear(); - return; -} - -extern float add_asm_function(float* a, float* b); -extern float add_asm_function2(float* a, float* b); +extern int add_asm_function(int a, int b); +extern int mul_by_const_asm_function( int a); int main() { + int num1 = 10; + int num2 = 20; + int sum = add_asm_function(num1, num2); + int mul = mul_by_const_asm_function(num2); - //enable FP operations - CSR_SET_BITS(CSR_REG_MSTATUS, (FS_INITIAL << 13)); - CSR_SET_BITS(CSR_REG_MSTATUS, 0x8); - // Set mie.MEIE bit to one to enable machine-level external interrupts - const uint32_t mask = 1 << 7; - CSR_SET_BITS(CSR_REG_MIE, mask); - - timer_init(); - timer_irq_enable(); - timer_arm_start(4); - - float num1 = 10.0; - float num2 = 20.0; - float sum = add_asm_function2(&num1, &num2); -// int mul = mul_by_const_asm_function(num2); - -// PRINTF("%d+%d=%d\n", num1, num2, sum); -// PRINTF("%d*%d=%d\n", num2, MULTIPLY_CONSTANT, mul ); + PRINTF("%d+%d=%d\n", num1, num2, sum); + PRINTF("%d*%d=%d\n", num2, MULTIPLY_CONSTANT, mul ); - return (sum == num1+num2) ? EXIT_SUCCESS : EXIT_FAILURE; + return (sum == num1+num2) && (mul == num2*MULTIPLY_CONSTANT) ? EXIT_SUCCESS : EXIT_FAILURE; } \ No newline at end of file diff --git a/sw/applications/example_asm/multiply.S b/sw/applications/example_asm/multiply.S index db828935f..7130f4886 100644 --- a/sw/applications/example_asm/multiply.S +++ b/sw/applications/example_asm/multiply.S @@ -1,24 +1,9 @@ +#include "constants.h" + .section .text - .globl add_asm_function2 + .globl mul_by_const_asm_function -add_asm_function2: - flw f0,0(a0) - flw f1,0(a1) - #check if it gets executed in a branch shadow - cv.starti 0, start_loop - cv.endi 0, end_loop - cv.counti 0, 100 - start_loop: - .balign 4 - fadd.s fa0, f0, f1 # Add the values in a0 and a1, store the result in a0 - fadd.s fa0, fa0, f1 # Add the values in a0 and a1, store the result in a0 - fadd.s fa0, fa0, f1 # Add the values in a0 and a1, store the result in a0 - fadd.s fa0, fa0, f1 # Add the values in a0 and a1, store the result in a0 - fadd.s fa0, fa0, f1 # Add the values in a0 and a1, store the result in a0 - fadd.s fa0, fa0, f1 # Add the values in a0 and a1, store the result in a0 - fadd.s fa0, fa0, f1 # Add the values in a0 and a1, store the result in a0 - fadd.s fa0, fa0, f1 # Add the values in a0 and a1, store the result in a0 - fadd.s fa0, fa0, f1 # Add the values in a0 and a1, store the result in a0 - fadd.s fa0, fa0, f1 # Add the values in a0 and a1, store the result in a0 - end_loop: - ret # Return from the function \ No newline at end of file +mul_by_const_asm_function: + li t0, MULTIPLY_CONSTANT # Load the constant into temporary register t0 + mul a0, a0, t0 # Multiply the value in a0 by the constant in t0 + ret # Return from the function \ No newline at end of file