Skip to content

Commit

Permalink
revert app change
Browse files Browse the repository at this point in the history
  • Loading branch information
davideschiavone committed Sep 25, 2024
1 parent 695edb6 commit 850461c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 70 deletions.
18 changes: 1 addition & 17 deletions sw/applications/example_asm/add.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 9 additions & 31 deletions sw/applications/example_asm/main.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#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
Expand All @@ -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;
}
29 changes: 7 additions & 22 deletions sw/applications/example_asm/multiply.S
Original file line number Diff line number Diff line change
@@ -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
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

0 comments on commit 850461c

Please sign in to comment.