-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: John Sanpe <[email protected]>
- Loading branch information
Showing
6 changed files
with
160 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
# Copyright(c) 2023 ffashion <[email protected]> | ||
# | ||
|
||
add_executable(benchmark main.c crc.c rbtree.c) | ||
add_executable(benchmark main.c mpi.c crc.c rbtree.c) | ||
target_link_libraries(benchmark ${CMAKE_PROJECT_NAME}) | ||
target_link_libraries(benchmark bfdev) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
/* | ||
* Copyright(c) 2021-2022 John Sanpe <[email protected]> | ||
*/ | ||
|
||
#ifndef _MAIN_H_ | ||
#define _MAIN_H_ | ||
|
||
#include "py32f0xx_hal.h" | ||
|
||
extern UART_HandleTypeDef huart1; | ||
extern IWDG_HandleTypeDef hiwgd; | ||
|
||
static inline void | ||
iwdg_touch(void) | ||
{ | ||
HAL_IWDG_Refresh(&hiwgd); | ||
} | ||
|
||
#endif /* */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
/* | ||
* Copyright(c) 2023 John Sanpe <[email protected]> | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include <errno.h> | ||
#include <bfdev.h> | ||
|
||
#include "main.h" | ||
#include "py32f0xx_hal.h" | ||
|
||
#define TEST_LEN 100 | ||
#define TEST_SIZE (TEST_LEN / 4 + 1) | ||
#define TEST_LOOP (TEST_LEN / 1.39793 + 1) | ||
|
||
int mpi_benchmark(void) | ||
{ | ||
uint32_t start, time; | ||
bfdev_mpi_t *vw, *vs, *vv, *vq; | ||
unsigned int k; | ||
int retval; | ||
|
||
if (!((vw = bfdev_mpi_create(NULL)) && | ||
(vs = bfdev_mpi_create(NULL)) && | ||
(vv = bfdev_mpi_create(NULL)) && | ||
(vq = bfdev_mpi_create(NULL)))) | ||
return -ENOMEM; | ||
|
||
bfdev_log_notice("Generate bignum: %u\n", TEST_SIZE); | ||
if ((retval = bfdev_mpi_set(vw, 16 * 5)) || | ||
(retval = bfdev_mpi_set(vv, 239 * 4)) || | ||
(retval = bfdev_mpi_set(vq, 10000))) | ||
return retval; | ||
|
||
for (k = 0; k < TEST_SIZE; ++k) { | ||
if ((retval = bfdev_mpi_mul(vw, vw, vq)) || | ||
(retval = bfdev_mpi_mul(vv, vv, vq))) | ||
return retval; | ||
|
||
iwdg_touch(); | ||
} | ||
|
||
bfdev_log_notice("Calculate PI %d:\n", TEST_LEN); | ||
start = HAL_GetTick(); | ||
for (k = 1; k <= TEST_LOOP; ++k) { | ||
if ((retval = bfdev_mpi_divi(vw, vw, vw, 25)) || | ||
(retval = bfdev_mpi_divi(vv, vv, vv, 239 * 239)) || | ||
(retval = bfdev_mpi_sub(vq, vw, vv)) || | ||
(retval = bfdev_mpi_divi(vq, vq, vq, 2 * k - 1))) | ||
return retval; | ||
|
||
if (k & 1) | ||
retval = bfdev_mpi_add(vs, vs, vq); | ||
else | ||
retval = bfdev_mpi_sub(vs, vs, vq); | ||
|
||
if (retval) | ||
return retval; | ||
|
||
iwdg_touch(); | ||
} | ||
|
||
time = HAL_GetTick() - start; | ||
bfdev_log_notice("Total time: %lu.%lus\n", time / 1000, time % 1000); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters