35 lines
625 B
C
35 lines
625 B
C
#include <math.h>
|
|
#include <stdint.h>
|
|
#include <riscv_vector.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#define N 32
|
|
|
|
// Use 'aligned' to help the autovectorizer
|
|
_Float16 a[N] __attribute__((aligned(16)));
|
|
float b[N] __attribute__((aligned(16)));
|
|
|
|
static inline uint64_t read_cycles() {
|
|
uint64_t start;
|
|
asm volatile ("rdcycle %0" : "=r"(start));
|
|
return start;
|
|
}
|
|
|
|
void benchmark() {
|
|
read_cycles();
|
|
for (int i = 0; i < N; i++) {
|
|
b[i] = (float)a[i];
|
|
}
|
|
read_cycles();
|
|
|
|
read_cycles();
|
|
for (int i = 0; i < N; i++) {
|
|
a[i] = (_Float16)b[i];
|
|
}
|
|
read_cycles();
|
|
}
|
|
|
|
int main() {
|
|
benchmark();
|
|
}
|