| #include "test_vector.h" | |
| #include <springbok.h> | |
| #define MSTATUS_VS 0x00000600 | |
| #define enable_vec() \ | |
| do { \ | |
| __asm__ volatile("csrs mstatus, %[bits];" ::[bits] "r"( \ | |
| MSTATUS_VS & (MSTATUS_VS >> 1))); \ | |
| } while (0); | |
| uint32_t get_vtype(uint8_t vsew, uint8_t vlmul, bool tail_agnostic, | |
| bool mask_agnostic) { | |
| return (vlmul & 0x7) | (vsew & 0x7) << 3 | (tail_agnostic & 0x1) << 6 | | |
| (mask_agnostic & 0x1) << 7; | |
| } | |
| uint32_t get_vtype_e8(uint8_t vlmul, bool tail_agnostic, bool mask_agnostic) { | |
| uint8_t vsew = 0; | |
| return get_vtype(vsew, vlmul, tail_agnostic, mask_agnostic); | |
| } | |
| uint32_t get_vtype_e16(uint8_t vlmul, bool tail_agnostic, bool mask_agnostic) { | |
| uint8_t vsew = 1; | |
| return get_vtype(vsew, vlmul, tail_agnostic, mask_agnostic); | |
| } | |
| uint32_t get_vtype_e32(uint8_t vlmul, bool tail_agnostic, bool mask_agnostic) { | |
| uint8_t vsew = 2; | |
| return get_vtype(vsew, vlmul, tail_agnostic, mask_agnostic); | |
| } | |
| uint32_t get_vtype_e64(uint8_t vlmul, bool tail_agnostic, bool mask_agnostic) { | |
| uint8_t vsew = 3; | |
| return get_vtype(vsew, vlmul, tail_agnostic, mask_agnostic); | |
| } | |
| int main(void) { | |
| LOG_INFO("Hello test_vector.c"); | |
| LOG_INFO("Built at: " __DATE__ ", " __TIME__); | |
| uint32_t misa; | |
| __asm__ volatile("csrr %0, misa" : "=r"(misa)); | |
| LOG_INFO("MISA: 0x%08x", (unsigned int)misa); | |
| uint32_t mstatus; | |
| __asm__ volatile("csrr %0, mstatus" : "=r"(mstatus)); | |
| LOG_INFO("BEFORE MSTATUS: 0x%08x", (unsigned int)mstatus); | |
| enable_vec(); | |
| __asm__ volatile("csrr %0, mstatus" : "=r"(mstatus)); | |
| LOG_INFO("AFTER MSTATUS: 0x%08x", (unsigned int)mstatus); | |
| uint32_t vlenb; | |
| __asm__ volatile("csrr %0, vlenb" : "=r"(vlenb)); | |
| LOG_INFO("VLENB: 0x%08x, VLEN: %u", (unsigned int)vlenb, vlenb << 3); | |
| assert(test_vector()); | |
| LOG_INFO("test_main done."); | |
| return 0; | |
| } |