OpenCores
URL https://opencores.org/ocsvn/neorv32/neorv32/trunk

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [example/] [bitmanip_test/] [main.c] - Diff between revs 64 and 65

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 64 Rev 65
Line 76... Line 76...
 
 
  // 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, ho hw flow control
  neorv32_uart_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.
 
 
  // inform the user if you are actually executing this
  // inform the user if you are actually executing this
  neorv32_uart_printf("ERROR! Program has not been compiled. Use >>make USER_FLAGS+=-DRUN_CHECK clean_all exe<< to compile it.\n");
  neorv32_uart0_printf("ERROR! Program has not been compiled. Use >>make USER_FLAGS+=-DRUN_CHECK clean_all exe<< to compile it.\n");
 
 
  return 1;
  return 1;
#endif
#endif
 
 
  // intro
  // intro
  neorv32_uart_printf("NEORV32 'Zbb' Bit-Manipulation Extension Test\n\n");
  neorv32_uart0_printf("NEORV32 'Zbb' Bit-Manipulation Extension 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 Zbb extension is implemented at all
  if ((NEORV32_SYSINFO.CPU & (1<<SYSINFO_CPU_ZBB)) == 0) {
  if ((NEORV32_SYSINFO.CPU & (1<<SYSINFO_CPU_ZBB)) == 0) {
    neorv32_uart_print("Error! <Zbb> extension not synthesized!\n");
    neorv32_uart0_print("Error! <Zbb> extension not synthesized!\n");
    return 1;
    return 1;
  }
  }
 
 
  neorv32_uart_printf("Starting Zbb bit-manipulation extension tests (%i test cases per instruction)...\n", num_tests);
  neorv32_uart0_printf("Starting Zbb bit-manipulation extension tests (%i test cases per instruction)...\n", num_tests);
 
 
  // ANDN
  // ANDN
  neorv32_uart_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++) {
    opa = xorshift32();
    opa = xorshift32();
    opb = xorshift32();
    opb = xorshift32();
    res_sw = riscv_emulate_andn(opa, opb);
    res_sw = riscv_emulate_andn(opa, opb);
Line 115... Line 115...
    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);
 
 
  // ORN
  // ORN
  neorv32_uart_printf("\nORN:\n");
  neorv32_uart0_printf("\nORN:\n");
  err_cnt = 0;
  err_cnt = 0;
  for (i=0;i<num_tests; i++) {
  for (i=0;i<num_tests; i++) {
    opa = xorshift32();
    opa = xorshift32();
    opb = xorshift32();
    opb = xorshift32();
    res_sw = riscv_emulate_orn(opa, opb);
    res_sw = riscv_emulate_orn(opa, opb);
Line 127... Line 127...
    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);
 
 
  // XNOR
  // XNOR
  neorv32_uart_printf("\nXNOR:\n");
  neorv32_uart0_printf("\nXNOR:\n");
  err_cnt = 0;
  err_cnt = 0;
  for (i=0;i<num_tests; i++) {
  for (i=0;i<num_tests; i++) {
    opa = xorshift32();
    opa = xorshift32();
    opb = xorshift32();
    opb = xorshift32();
    res_sw = riscv_emulate_xnor(opa, opb);
    res_sw = riscv_emulate_xnor(opa, opb);
Line 141... Line 141...
  print_report(err_cnt, num_tests);
  print_report(err_cnt, num_tests);
 
 
 
 
 
 
  // CLZ
  // CLZ
  neorv32_uart_printf("\nCLZ:\n");
  neorv32_uart0_printf("\nCLZ:\n");
  err_cnt = 0;
  err_cnt = 0;
  for (i=0;i<num_tests; i++) {
  for (i=0;i<num_tests; i++) {
    opa = xorshift32();
    opa = xorshift32();
    res_sw = riscv_emulate_clz(opa);
    res_sw = riscv_emulate_clz(opa);
    res_hw = riscv_intrinsic_clz(opa);
    res_hw = riscv_intrinsic_clz(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);
 
 
  // CTZ
  // CTZ
  neorv32_uart_printf("\nCTZ:\n");
  neorv32_uart0_printf("\nCTZ:\n");
  err_cnt = 0;
  err_cnt = 0;
  for (i=0;i<num_tests; i++) {
  for (i=0;i<num_tests; i++) {
    opa = xorshift32();
    opa = xorshift32();
    res_sw = riscv_emulate_ctz(opa);
    res_sw = riscv_emulate_ctz(opa);
    res_hw = riscv_intrinsic_ctz(opa);
    res_hw = riscv_intrinsic_ctz(opa);
Line 165... Line 165...
  print_report(err_cnt, num_tests);
  print_report(err_cnt, num_tests);
 
 
 
 
 
 
  // CPOP
  // CPOP
  neorv32_uart_printf("\nCPOP:\n");
  neorv32_uart0_printf("\nCPOP:\n");
  err_cnt = 0;
  err_cnt = 0;
  for (i=0;i<num_tests; i++) {
  for (i=0;i<num_tests; i++) {
    opa = xorshift32();
    opa = xorshift32();
    res_sw = riscv_emulate_cpop(opa);
    res_sw = riscv_emulate_cpop(opa);
    res_hw = riscv_intrinsic_cpop(opa);
    res_hw = riscv_intrinsic_cpop(opa);
Line 178... Line 178...
  print_report(err_cnt, num_tests);
  print_report(err_cnt, num_tests);
 
 
 
 
 
 
  // MAX
  // MAX
  neorv32_uart_printf("\nMAX:\n");
  neorv32_uart0_printf("\nMAX:\n");
  err_cnt = 0;
  err_cnt = 0;
  for (i=0;i<num_tests; i++) {
  for (i=0;i<num_tests; i++) {
    opa = xorshift32();
    opa = xorshift32();
    opb = xorshift32();
    opb = xorshift32();
    res_sw = riscv_emulate_max(opa, opb);
    res_sw = riscv_emulate_max(opa, opb);
Line 190... Line 190...
    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);
 
 
  // MAXU
  // MAXU
  neorv32_uart_printf("\nMAXU:\n");
  neorv32_uart0_printf("\nMAXU:\n");
  err_cnt = 0;
  err_cnt = 0;
  for (i=0;i<num_tests; i++) {
  for (i=0;i<num_tests; i++) {
    opa = xorshift32();
    opa = xorshift32();
    opb = xorshift32();
    opb = xorshift32();
    res_sw = riscv_emulate_maxu(opa, opb);
    res_sw = riscv_emulate_maxu(opa, opb);
Line 202... Line 202...
    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);
 
 
  // MIN
  // MIN
  neorv32_uart_printf("\nMIN:\n");
  neorv32_uart0_printf("\nMIN:\n");
  err_cnt = 0;
  err_cnt = 0;
  for (i=0;i<num_tests; i++) {
  for (i=0;i<num_tests; i++) {
    opa = xorshift32();
    opa = xorshift32();
    opb = xorshift32();
    opb = xorshift32();
    res_sw = riscv_emulate_min(opa, opb);
    res_sw = riscv_emulate_min(opa, opb);
Line 214... Line 214...
    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);
 
 
  // MINU
  // MINU
  neorv32_uart_printf("\nMINU:\n");
  neorv32_uart0_printf("\nMINU:\n");
  err_cnt = 0;
  err_cnt = 0;
  for (i=0;i<num_tests; i++) {
  for (i=0;i<num_tests; i++) {
    opa = xorshift32();
    opa = xorshift32();
    opb = xorshift32();
    opb = xorshift32();
    res_sw = riscv_emulate_minu(opa, opb);
    res_sw = riscv_emulate_minu(opa, opb);
Line 228... Line 228...
  print_report(err_cnt, num_tests);
  print_report(err_cnt, num_tests);
 
 
 
 
 
 
  // SEXT.B
  // SEXT.B
  neorv32_uart_printf("\nSEXT.B:\n");
  neorv32_uart0_printf("\nSEXT.B:\n");
  err_cnt = 0;
  err_cnt = 0;
  for (i=0;i<num_tests; i++) {
  for (i=0;i<num_tests; i++) {
    opa = xorshift32();
    opa = xorshift32();
    res_sw = riscv_emulate_sextb(opa);
    res_sw = riscv_emulate_sextb(opa);
    res_hw = riscv_intrinsic_sextb(opa);
    res_hw = riscv_intrinsic_sextb(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);
 
 
  // SEXT.H
  // SEXT.H
  neorv32_uart_printf("\nSEXT.H:\n");
  neorv32_uart0_printf("\nSEXT.H:\n");
  err_cnt = 0;
  err_cnt = 0;
  for (i=0;i<num_tests; i++) {
  for (i=0;i<num_tests; i++) {
    opa = xorshift32();
    opa = xorshift32();
    res_sw = riscv_emulate_sexth(opa);
    res_sw = riscv_emulate_sexth(opa);
    res_hw = riscv_intrinsic_sexth(opa);
    res_hw = riscv_intrinsic_sexth(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);
 
 
  // ZEXT.H
  // ZEXT.H
  neorv32_uart_printf("\nZEXT.H:\n");
  neorv32_uart0_printf("\nZEXT.H:\n");
  err_cnt = 0;
  err_cnt = 0;
  for (i=0;i<num_tests; i++) {
  for (i=0;i<num_tests; i++) {
    opa = xorshift32();
    opa = xorshift32();
    res_sw = riscv_emulate_zexth(opa);
    res_sw = riscv_emulate_zexth(opa);
    res_hw = riscv_intrinsic_zexth(opa);
    res_hw = riscv_intrinsic_zexth(opa);
Line 263... Line 263...
  print_report(err_cnt, num_tests);
  print_report(err_cnt, num_tests);
 
 
 
 
 
 
  // ROL
  // ROL
  neorv32_uart_printf("\nROL:\n");
  neorv32_uart0_printf("\nROL:\n");
  err_cnt = 0;
  err_cnt = 0;
  for (i=0;i<num_tests; i++) {
  for (i=0;i<num_tests; i++) {
    opa = xorshift32();
    opa = xorshift32();
    opb = xorshift32();
    opb = xorshift32();
    res_sw = riscv_emulate_rol(opa, opb);
    res_sw = riscv_emulate_rol(opa, opb);
Line 275... Line 275...
    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);
 
 
  // ROR
  // ROR
  neorv32_uart_printf("\nROR:\n");
  neorv32_uart0_printf("\nROR:\n");
  err_cnt = 0;
  err_cnt = 0;
  for (i=0;i<num_tests; i++) {
  for (i=0;i<num_tests; i++) {
    opa = xorshift32();
    opa = xorshift32();
    opb = xorshift32();
    opb = xorshift32();
    res_sw = riscv_emulate_ror(opa, opb);
    res_sw = riscv_emulate_ror(opa, opb);
Line 287... Line 287...
    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);
 
 
  // RORI
  // RORI
  neorv32_uart_printf("\nRORI (imm=20):\n"); // FIXME: static immediate
  neorv32_uart0_printf("\nRORI (imm=20):\n"); // FIXME: static immediate
  err_cnt = 0;
  err_cnt = 0;
  for (i=0;i<num_tests; i++) {
  for (i=0;i<num_tests; i++) {
    opa = xorshift32();
    opa = xorshift32();
    res_sw = riscv_emulate_ror(opa, 20);
    res_sw = riscv_emulate_ror(opa, 20);
    res_hw = riscv_intrinsic_rori20(opa);
    res_hw = riscv_intrinsic_rori20(opa);
Line 300... Line 300...
  print_report(err_cnt, num_tests);
  print_report(err_cnt, num_tests);
 
 
 
 
 
 
  // ORC.B
  // ORC.B
  neorv32_uart_printf("\nORCB:\n");
  neorv32_uart0_printf("\nORCB:\n");
  err_cnt = 0;
  err_cnt = 0;
  for (i=0;i<num_tests; i++) {
  for (i=0;i<num_tests; i++) {
    opa = xorshift32();
    opa = xorshift32();
    res_sw = riscv_emulate_orcb(opa);
    res_sw = riscv_emulate_orcb(opa);
    res_hw = riscv_intrinsic_orcb(opa);
    res_hw = riscv_intrinsic_orcb(opa);
Line 313... Line 313...
  print_report(err_cnt, num_tests);
  print_report(err_cnt, num_tests);
 
 
 
 
 
 
  // REV8
  // REV8
  neorv32_uart_printf("\nREV8:\n");
  neorv32_uart0_printf("\nREV8:\n");
  err_cnt = 0;
  err_cnt = 0;
  for (i=0;i<num_tests; i++) {
  for (i=0;i<num_tests; i++) {
    opa = xorshift32();
    opa = xorshift32();
    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);
 
 
 
 
  neorv32_uart_printf("\nBit manipulation extension tests done.\n");
  neorv32_uart0_printf("\nBit manipulation extension tests done.\n");
 
 
  return 0;
  return 0;
}
}
 
 
 
 
Line 360... Line 360...
 * @return zero if results are equal.
 * @return zero if results are equal.
 **************************************************************************/
 **************************************************************************/
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) {
 
 
  if (ref != res) {
  if (ref != res) {
    neorv32_uart_printf("%u: opa = 0x%x, opb = 0x%x : ref = 0x%x vs res = 0x%x ", num, opa, opb, ref, res);
    neorv32_uart0_printf("%u: opa = 0x%x, opb = 0x%x : ref = 0x%x vs res = 0x%x ", num, opa, opb, ref, res);
    neorv32_uart_printf("%c[1m[FAILED]%c[0m\n", 27, 27);
    neorv32_uart0_printf("%c[1m[FAILED]%c[0m\n", 27, 27);
    return 1;
    return 1;
  }
  }
  else {
  else {
    return 0;
    return 0;
  }
  }
Line 378... Line 378...
 * @param[in] num_err Number or errors in this test.
 * @param[in] num_err Number or errors in this test.
 * @param[in] num_tests Total number of conducted tests.
 * @param[in] num_tests Total number of conducted tests.
 **************************************************************************/
 **************************************************************************/
void print_report(int num_err, int num_tests) {
void print_report(int num_err, int num_tests) {
 
 
  neorv32_uart_printf("Errors: %i/%i ", num_err, num_tests);
  neorv32_uart0_printf("Errors: %i/%i ", num_err, num_tests);
 
 
  if (num_err == 0) {
  if (num_err == 0) {
    neorv32_uart_printf("%c[1m[ok]%c[0m\n", 27, 27);
    neorv32_uart0_printf("%c[1m[ok]%c[0m\n", 27, 27);
  }
  }
  else {
  else {
    neorv32_uart_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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.