Line 1... |
Line 1... |
// #################################################################################################
|
// #################################################################################################
|
// # << NEORV32 - RISC-V Bit-Manipulation 'B' Extension Test Program >> #
|
// # << NEORV32 - RISC-V Bit-Manipulation 'B' Extension Test Program >> #
|
// # ********************************************************************************************* #
|
// # ********************************************************************************************* #
|
// # BSD 3-Clause License #
|
// # BSD 3-Clause License #
|
// # #
|
// # #
|
// # Copyright (c) 2021, Stephan Nolting. All rights reserved. #
|
// # Copyright (c) 2022, Stephan Nolting. All rights reserved. #
|
// # #
|
// # #
|
// # Redistribution and use in source and binary forms, with or without modification, are #
|
// # Redistribution and use in source and binary forms, with or without modification, are #
|
// # permitted provided that the following conditions are met: #
|
// # permitted provided that the following conditions are met: #
|
// # #
|
// # #
|
// # 1. Redistributions of source code must retain the above copyright notice, this list of #
|
// # 1. Redistributions of source code must retain the above copyright notice, this list of #
|
Line 49... |
Line 49... |
/**@{*/
|
/**@{*/
|
/** UART BAUD rate */
|
/** UART BAUD rate */
|
#define BAUD_RATE (19200)
|
#define BAUD_RATE (19200)
|
//** Number of test cases for each instruction */
|
//** Number of test cases for each instruction */
|
#define NUM_TEST_CASES (1000000)
|
#define NUM_TEST_CASES (1000000)
|
|
//** Enable Zbb tests when 1 */
|
|
#define ENABLE_ZBB (1)
|
|
//** Enable Zba tests when 1 */
|
|
#define ENABLE_ZBA (1)
|
|
//** Enable Zbs tests when 1 */
|
|
#define ENABLE_ZBS (1)
|
|
//** Enable Zbc tests when 1 */
|
|
#define ENABLE_ZBC (1)
|
/**@}*/
|
/**@}*/
|
|
|
|
|
// Prototypes
|
// Prototypes
|
uint32_t xorshift32(void);
|
uint32_t xorshift32(void);
|
uint32_t check_result(uint32_t num, uint32_t opa, uint32_t opb, uint32_t ref, uint32_t res);
|
uint32_t check_result(uint32_t num, uint32_t opa, uint32_t opb, uint32_t ref, uint32_t res);
|
void print_report(int num_err, int num_tests);
|
void print_report(int num_err, int num_tests);
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Main function; test all available operations of the NEORV32 'Zbb' extensions
|
* Main function; test all available operations of the NEORV32 'B' extension
|
* using bit manipulation intrinsics and software-only reference functions (emulation).
|
* using bit manipulation intrinsics and software-only reference functions (emulation).
|
*
|
*
|
* @note This program requires the bit-manipulation CPU extension.
|
* @note This program requires the bit-manipulation CPU extension.
|
*
|
*
|
* @return Irrelevant.
|
* @return Irrelevant.
|
Line 75... |
Line 83... |
const uint32_t num_tests = (int)NUM_TEST_CASES;
|
const uint32_t num_tests = (int)NUM_TEST_CASES;
|
|
|
// capture all exceptions and give debug info via UART
|
// capture all exceptions and give debug info via UART
|
neorv32_rte_setup();
|
neorv32_rte_setup();
|
|
|
// init UART at default baud rate, no parity bits, ho hw flow control
|
// init UART at default baud rate, no parity bits, no hw flow control
|
neorv32_uart0_setup(BAUD_RATE, PARITY_NONE, FLOW_CONTROL_NONE);
|
neorv32_uart0_setup(BAUD_RATE, PARITY_NONE, FLOW_CONTROL_NONE);
|
|
|
// Disable compilation by default
|
// Disable compilation by default
|
#ifndef RUN_CHECK
|
#ifndef RUN_CHECK
|
#warning Program HAS NOT BEEN COMPILED! Use >>make USER_FLAGS+=-DRUN_CHECK clean_all exe<< to compile it.
|
#warning Program HAS NOT BEEN COMPILED! Use >>make USER_FLAGS+=-DRUN_CHECK clean_all exe<< to compile it.
|
Line 89... |
Line 97... |
|
|
return 1;
|
return 1;
|
#endif
|
#endif
|
|
|
// intro
|
// intro
|
neorv32_uart0_printf("NEORV32 Bit-Manipulation Extension Test (Zba, Zbb)\n\n");
|
neorv32_uart0_printf("<<< NEORV32 Bit-Manipulation Extension ('B') Test >>>\n\n");
|
|
|
// check available hardware extensions and compare with compiler flags
|
// check available hardware extensions and compare with compiler flags
|
neorv32_rte_check_isa(0); // silent = 0 -> show message if isa mismatch
|
neorv32_rte_check_isa(0); // silent = 0 -> show message if isa mismatch
|
|
|
// check if Zbb extension is implemented at all
|
// check if B extension is implemented at all
|
if ((neorv32_cpu_csr_read(CSR_MISA) & (1<<CSR_MISA_B)) == 0) {
|
if ((neorv32_cpu_csr_read(CSR_MISA) & (1<<CSR_MISA_B)) == 0) {
|
neorv32_uart0_print("Error! <B> extension not synthesized!\n");
|
neorv32_uart0_print("Error! B extension not synthesized!\n");
|
return 1;
|
return 1;
|
}
|
}
|
|
|
neorv32_uart0_printf("Starting bit-manipulation extension tests (%i test cases per instruction)...\n\n", num_tests);
|
neorv32_uart0_printf("Starting bit-manipulation extension tests (%i test cases per instruction)...\n\n", num_tests);
|
|
|
neorv32_uart0_printf("-----------------------------------------\n");
|
#if (ENABLE_ZBB != 0)
|
|
neorv32_uart0_printf("--------------------------------------------\n");
|
neorv32_uart0_printf("Zbb - Basic bit-manipulation instructions\n");
|
neorv32_uart0_printf("Zbb - Basic bit-manipulation instructions\n");
|
neorv32_uart0_printf("-----------------------------------------\n");
|
neorv32_uart0_printf("--------------------------------------------\n");
|
|
|
// ANDN
|
// ANDN
|
neorv32_uart0_printf("\nANDN:\n");
|
neorv32_uart0_printf("\nANDN:\n");
|
err_cnt = 0;
|
err_cnt = 0;
|
for (i=0;i<num_tests; i++) {
|
for (i=0;i<num_tests; i++) {
|
Line 326... |
Line 335... |
res_sw = riscv_emulate_rev8(opa);
|
res_sw = riscv_emulate_rev8(opa);
|
res_hw = riscv_intrinsic_rev8(opa);
|
res_hw = riscv_intrinsic_rev8(opa);
|
err_cnt += check_result(i, opa, 0, res_sw, res_hw);
|
err_cnt += check_result(i, opa, 0, res_sw, res_hw);
|
}
|
}
|
print_report(err_cnt, num_tests);
|
print_report(err_cnt, num_tests);
|
|
#endif
|
|
|
|
|
|
#if (ENABLE_ZBA != 0)
|
neorv32_uart0_printf("\n\n");
|
neorv32_uart0_printf("\n\n");
|
neorv32_uart0_printf("-----------------------------------------\n");
|
neorv32_uart0_printf("--------------------------------------------\n");
|
neorv32_uart0_printf("Zba - Address generation instructions\n");
|
neorv32_uart0_printf("Zba - Address-generation instructions\n");
|
neorv32_uart0_printf("-----------------------------------------\n");
|
neorv32_uart0_printf("--------------------------------------------\n");
|
|
|
// SH1ADD
|
// SH1ADD
|
neorv32_uart0_printf("\nSH1ADD:\n");
|
neorv32_uart0_printf("\nSH1ADD:\n");
|
err_cnt = 0;
|
err_cnt = 0;
|
for (i=0;i<num_tests; i++) {
|
for (i=0;i<num_tests; i++) {
|
Line 368... |
Line 378... |
res_sw = riscv_emulate_sh3add(opa, opb);
|
res_sw = riscv_emulate_sh3add(opa, opb);
|
res_hw = riscv_intrinsic_sh3add(opa, opb);
|
res_hw = riscv_intrinsic_sh3add(opa, opb);
|
err_cnt += check_result(i, opa, opb, res_sw, res_hw);
|
err_cnt += check_result(i, opa, opb, res_sw, res_hw);
|
}
|
}
|
print_report(err_cnt, num_tests);
|
print_report(err_cnt, num_tests);
|
|
#endif
|
|
|
|
|
|
#if (ENABLE_ZBS != 0)
|
|
neorv32_uart0_printf("\n\n");
|
|
neorv32_uart0_printf("--------------------------------------------\n");
|
|
neorv32_uart0_printf("Zbs - Single-bit instructions\n");
|
|
neorv32_uart0_printf("--------------------------------------------\n");
|
|
|
|
// BCLR
|
|
neorv32_uart0_printf("\nBCLR:\n");
|
|
err_cnt = 0;
|
|
for (i=0;i<num_tests; i++) {
|
|
opa = xorshift32();
|
|
opb = xorshift32();
|
|
res_sw = riscv_emulate_bclr(opa, opb);
|
|
res_hw = riscv_intrinsic_bclr(opa, opb);
|
|
err_cnt += check_result(i, opa, opb, res_sw, res_hw);
|
|
}
|
|
print_report(err_cnt, num_tests);
|
|
|
|
// BCLRI
|
|
neorv32_uart0_printf("\nBCLRI (imm=20):\n"); // FIXME: static immediate
|
|
err_cnt = 0;
|
|
for (i=0;i<num_tests; i++) {
|
|
opa = xorshift32();
|
|
res_sw = riscv_emulate_bclr(opa, 20);
|
|
res_hw = riscv_intrinsic_bclri20(opa);
|
|
err_cnt += check_result(i, opa, opb, res_sw, res_hw);
|
|
}
|
|
print_report(err_cnt, num_tests);
|
|
|
|
|
|
|
|
// BEXT
|
|
neorv32_uart0_printf("\nBEXT:\n");
|
|
err_cnt = 0;
|
|
for (i=0;i<num_tests; i++) {
|
|
opa = xorshift32();
|
|
opb = xorshift32();
|
|
res_sw = riscv_emulate_bext(opa, opb);
|
|
res_hw = riscv_intrinsic_bext(opa, opb);
|
|
err_cnt += check_result(i, opa, opb, res_sw, res_hw);
|
|
}
|
|
print_report(err_cnt, num_tests);
|
|
|
|
// BEXTI
|
|
neorv32_uart0_printf("\nBEXTI (imm=20):\n"); // FIXME: static immediate
|
|
err_cnt = 0;
|
|
for (i=0;i<num_tests; i++) {
|
|
opa = xorshift32();
|
|
res_sw = riscv_emulate_bext(opa, 20);
|
|
res_hw = riscv_intrinsic_bexti20(opa);
|
|
err_cnt += check_result(i, opa, opb, res_sw, res_hw);
|
|
}
|
|
print_report(err_cnt, num_tests);
|
|
|
|
|
|
|
|
// BINV
|
|
neorv32_uart0_printf("\nBINV:\n");
|
|
err_cnt = 0;
|
|
for (i=0;i<num_tests; i++) {
|
|
opa = xorshift32();
|
|
opb = xorshift32();
|
|
res_sw = riscv_emulate_binv(opa, opb);
|
|
res_hw = riscv_intrinsic_binv(opa, opb);
|
|
err_cnt += check_result(i, opa, opb, res_sw, res_hw);
|
|
}
|
|
print_report(err_cnt, num_tests);
|
|
|
|
// BINVI
|
|
neorv32_uart0_printf("\nBINVI (imm=20):\n"); // FIXME: static immediate
|
|
err_cnt = 0;
|
|
for (i=0;i<num_tests; i++) {
|
|
opa = xorshift32();
|
|
res_sw = riscv_emulate_binv(opa, 20);
|
|
res_hw = riscv_intrinsic_binvi20(opa);
|
|
err_cnt += check_result(i, opa, opb, res_sw, res_hw);
|
|
}
|
|
print_report(err_cnt, num_tests);
|
|
|
|
|
neorv32_uart0_printf("\nBit manipulation extension tests done.\n");
|
|
|
|
|
// BSET
|
|
neorv32_uart0_printf("\nBSET:\n");
|
|
err_cnt = 0;
|
|
for (i=0;i<num_tests; i++) {
|
|
opa = xorshift32();
|
|
opb = xorshift32();
|
|
res_sw = riscv_emulate_bset(opa, opb);
|
|
res_hw = riscv_intrinsic_bset(opa, opb);
|
|
err_cnt += check_result(i, opa, opb, res_sw, res_hw);
|
|
}
|
|
print_report(err_cnt, num_tests);
|
|
|
|
// BSETI
|
|
neorv32_uart0_printf("\nBSETI (imm=20):\n"); // FIXME: static immediate
|
|
err_cnt = 0;
|
|
for (i=0;i<num_tests; i++) {
|
|
opa = xorshift32();
|
|
res_sw = riscv_emulate_bset(opa, 20);
|
|
res_hw = riscv_intrinsic_bseti20(opa);
|
|
err_cnt += check_result(i, opa, opb, res_sw, res_hw);
|
|
}
|
|
print_report(err_cnt, num_tests);
|
|
#endif
|
|
|
|
|
|
#if (ENABLE_ZBC != 0)
|
|
neorv32_uart0_printf("\n\n");
|
|
neorv32_uart0_printf("--------------------------------------------\n");
|
|
neorv32_uart0_printf("Zbc - Carry-less multiplication instructions\n");
|
|
neorv32_uart0_printf("--------------------------------------------\n");
|
|
|
|
neorv32_uart0_printf("\nNOTE: The emulation functions will take quite some time to execute.\n");
|
|
|
|
// CLMUL
|
|
neorv32_uart0_printf("\nCLMUL:\n");
|
|
err_cnt = 0;
|
|
for (i=0;i<num_tests; i++) {
|
|
opa = xorshift32();
|
|
opb = xorshift32();
|
|
res_sw = riscv_emulate_clmul(opa, opb);
|
|
res_hw = riscv_intrinsic_clmul(opa, opb);
|
|
err_cnt += check_result(i, opa, opb, res_sw, res_hw);
|
|
}
|
|
print_report(err_cnt, num_tests);
|
|
|
|
// CLMULH
|
|
neorv32_uart0_printf("\nCLMULH:\n");
|
|
err_cnt = 0;
|
|
for (i=0;i<num_tests; i++) {
|
|
opa = xorshift32();
|
|
opb = xorshift32();
|
|
res_sw = riscv_emulate_clmulh(opa, opb);
|
|
res_hw = riscv_intrinsic_clmulh(opa, opb);
|
|
err_cnt += check_result(i, opa, opb, res_sw, res_hw);
|
|
}
|
|
print_report(err_cnt, num_tests);
|
|
|
|
// CLMULR
|
|
neorv32_uart0_printf("\nCLMULR:\n");
|
|
err_cnt = 0;
|
|
for (i=0;i<num_tests; i++) {
|
|
opa = xorshift32();
|
|
opb = xorshift32();
|
|
res_sw = riscv_emulate_clmulr(opa, opb);
|
|
res_hw = riscv_intrinsic_clmulr(opa, opb);
|
|
err_cnt += check_result(i, opa, opb, res_sw, res_hw);
|
|
}
|
|
print_report(err_cnt, num_tests);
|
|
#endif
|
|
|
|
|
|
neorv32_uart0_printf("\n\nB extension tests completed.\n");
|
return 0;
|
return 0;
|
}
|
}
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Pseudo-Random Number Generator (to generate test vectors).
|
* Pseudo-Random Number Generator (to generate deterministic test vectors).
|
*
|
*
|
* @return Random data (32-bit).
|
* @return Random data (32-bit).
|
**************************************************************************/
|
**************************************************************************/
|
uint32_t xorshift32(void) {
|
uint32_t xorshift32(void) {
|
|
|
Line 434... |
Line 596... |
else {
|
else {
|
neorv32_uart0_printf("%c[1m[FAILED]%c[0m\n", 27, 27);
|
neorv32_uart0_printf("%c[1m[FAILED]%c[0m\n", 27, 27);
|
}
|
}
|
}
|
}
|
|
|
No newline at end of file
|
No newline at end of file
|
|
|
|
/**********************************************************************//**
|
|
* "after-main" handler that is executed after the application's
|
|
* main function returns (called by crt0.S start-up code)
|
|
**************************************************************************/
|
|
int __neorv32_crt0_after_main(int32_t return_code) {
|
|
|
|
if (return_code) {
|
|
neorv32_uart0_printf("\n<RTE> main function returned with exit code (%i) </RTE>\n", return_code);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
No newline at end of file
|
No newline at end of file
|