Commit bdacf57b authored by Zach Fredin's avatar Zach Fredin

added pi benchmark. updated rules.mk for -O3 optimization flag.

parent 0d5053d9
##
## This file is part of the libopencm3 project.
##
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
##
## This library is free software: you can redistribute it and/or modify
## it under the terms of the GNU Lesser General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with this library. If not, see <http://www.gnu.org/licenses/>.
##
BINARY = pi
LDSCRIPT = ../../stm32f412xExG.ld
include ../Makefile.include
## pi calculation test
This test follows the standard [CBA pi benchmark](https://gitlab.cba.mit.edu/pub/pi). Instead of setting up a real-time clock and computing the FLOPS on-board and reporting via serial terminal, I added a few GPIO toggles to flip a pin immediately prior to and after the pi calculation `for` loop. I also reduced the iteration count to 1,000,000 to reduce the wait time for the test. I then set the MDO3024 to 4 s/div capture and watched the GPIO pin in single-shot mode:
![pi capture](pi_capture.png)
The measurement shows a total calculation time of 12.91 s, including a [for these purposes] negligible delay to toggle the GPIOs. The FPU is set up with flags `-mfloat-abi=hard -mfpu=fpv4-sp-d16`, while the compiler includes `-O3`. Based on the pi benchmark calculation rate of 5 FLOPS per cycle iteration, this test suggests the STM32F412 is running at (5 * 1E6) / (12.91) = 0.387 MFLOPS. At the current 84 MHz clock speed, this suggests the pi calculation is taking (8.4E7) / (1E6 / 12.91) = 1084 clock cycles per iteration. This is a few orders of magnitude high, suggesting the FPU isn't cooperating.
/*
* pi.c
* Neil Gershenfeld 2/6/11
* STM32F412 port Zach Fredin 10/8/2019
* pi calculation benchmark
* pi = 3.14159265358979323846
*/
/*
#include <stdio.h>
#include <time.h>
#define NPTS 1000000000
void main() {
int i;
double a,b,c,pi,dt,mflops;
struct timespec tstart,tend;
clock_gettime(CLOCK_REALTIME,&tstart);
a = 0.5;
b = 0.75;
c = 0.25;
pi = 0;
pi = 0;
for (i = 1; i <= NPTS; ++i)
pi += a/((i-b)*(i-c));
clock_gettime(CLOCK_REALTIME,&tend);
dt = (tend.tv_sec+tend.tv_nsec/1e9)-(tstart.tv_sec+tstart.tv_nsec/1e9);
mflops = NPTS*5.0/(dt*1e6);
printf("NPTS = %d, pi = %f\n",NPTS,pi);
printf("time = %f, estimated MFlops = %f\n",dt,mflops);
}
*/
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
#define NPTS 1000000
static void clock_setup(void){
//no built-in libopencm3 support for a 100 MHz clock
rcc_clock_setup_pll(&rcc_hsi_configs[RCC_CLOCK_3V3_84MHZ]);
}
static void gpio_setup(void)
{
rcc_periph_clock_enable(RCC_GPIOB);
rcc_periph_clock_enable(RCC_GPIOD);
gpio_mode_setup(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO7);
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO5);
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO6);
}
int main(void) {
clock_setup();
gpio_setup();
int i;
volatile double a,b,c,pi;
a = 0.5;
b = 0.75;
c = 0.25;
pi = 0;
gpio_set(GPIOB, GPIO7);
gpio_set(GPIOD, GPIO5);
for (i = 1; i <= NPTS; ++i) {
pi += a/((i-b)*(i-c));
}
gpio_clear(GPIOD, GPIO5);
gpio_clear(GPIOB, GPIO7);
while(1) {
}
}
pi.o: pi.c ../../libopencm3//include/libopencm3/stm32/rcc.h \
../../libopencm3//include/libopencm3/cm3/common.h \
/usr/lib/gcc/arm-none-eabi/7.3.1/include/stdint.h \
/usr/arm-none-eabi/include/stdint.h \
/usr/arm-none-eabi/include/machine/_default_types.h \
/usr/arm-none-eabi/include/sys/features.h \
/usr/arm-none-eabi/include/_newlib_version.h \
/usr/arm-none-eabi/include/sys/_intsup.h \
/usr/arm-none-eabi/include/sys/_stdint.h \
/usr/lib/gcc/arm-none-eabi/7.3.1/include/stdbool.h \
../../libopencm3//include/libopencm3/stm32/memorymap.h \
../../libopencm3//include/libopencm3/stm32/f4/memorymap.h \
../../libopencm3//include/libopencm3/cm3/memorymap.h \
../../libopencm3//include/libopencm3/stm32/f4/rcc.h \
../../libopencm3//include/libopencm3/stm32/pwr.h \
../../libopencm3//include/libopencm3/stm32/f4/pwr.h \
../../libopencm3//include/libopencm3/stm32/common/pwr_common_v1.h \
../../libopencm3//include/libopencm3/stm32/common/rcc_common_all.h \
../../libopencm3//include/libopencm3/stm32/gpio.h \
../../libopencm3//include/libopencm3/stm32/f4/gpio.h \
../../libopencm3//include/libopencm3/stm32/common/gpio_common_f24.h \
../../libopencm3//include/libopencm3/stm32/common/gpio_common_f234.h \
../../libopencm3//include/libopencm3/stm32/common/gpio_common_all.h
This diff is collapsed.
......@@ -42,7 +42,7 @@ STFLASH = $(shell which st-flash)
STYLECHECK := /checkpatch.pl
STYLECHECKFLAGS := --no-tree -f --terse --mailback
STYLECHECKFILES := $(shell find . -name '*.[ch]')
OPT := -Os
OPT := -O3
DEBUG := -ggdb3
CSTD ?= -std=c99
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment