STM32f4 performance

Gast #3192203
Lesenswert?

Ich habe mich seit einige Zeit gefragt wie schnell den Cortex-M4 
(STM32F4) wirklich ist. Deaswegen, habe ich den Quelltext von

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/DM00047230.pdf

genommen, compiliert mit gcc -O3, und auf meiner Discovery Platine es 
laufen gelassen. Für ein 320x240 8 bit bild mit 120 Itertionen braucht 
es 257 ms.

arm-none-eabi-gcc obj/src/main.o obj/src/rcc.o obj/src/discovery.o 
obj/src/discovery_ex.o obj/src/startup_stm32f4xx.o -lm 
-Wl,-Map=obj/STM32F4.map,--cref -Wl,--gc-sections -Tsrc/stm32_flash.ld 
-mcpu=cortex-m4 -mthumb -mfloat-abi=softfp -mfpu=fpv4-sp-d16 --output 
obj/STM32F4.elf

GenerateJulia_fpu(320, 240, 160, 120, 120, (uint8_t *) 0x20000000);

(Der Stack liegt bei 0x10010000)

ich habe gedacht daß der M4 ein bischen flotter war... mir kommt 
irgendwie langsam vor.
Gast #3192205
Lesenswert?

Das hat gefehlt...

arm-none-eabi-gcc -c -Isrc -O3 -std=gnu99 -gdwarf-2 -ffunction-sections 
-fdata-sections -Wall -Wa,-adhlns=obj/main.lst 
-fsingle-precision-constant -mcpu=cortex-m4 -mthumb -mfloat-abi=softfp 
-mfpu=fpv4-sp-d16 -MMD -MP -MF obj/main.d src/main.c -o obj/src/main.o
Gast #3192274
Lesenswert?

Nein, es ist nur für die "Calling Convention", nicht für emu:

VFP hardware floating-point support using the soft-float ABI. This is 
selected by the -mfloat-abi=softfp option. When you select this variant, 
the compiler generates VFP floating-point instructions, but the 
resulting code uses the same call and return conventions as code 
compiled with software floating point.

Der FPU wird benutzt dank: -mfpu=fpv4-sp-d16 :)
Gast #3192281
Lesenswert?

Ein bisschen Code
1
src/main.c    **** void GenerateJulia_fpu(uint16_t size_x, uint16_t size_y, uint16_t offset_x, uint16_t offset_y, uint
2
  36:src/main.c    **** {
3
  27                  .loc 1 36 0
4
  28                  .cfi_startproc
5
  29                  @ args = 8, pretend = 0, frame = 0
6
  30                  @ frame_needed = 0, uses_anonymous_args = 0
7
  31                  @ link register save eliminated.
8
  32                .LVL0:
9
  33 0000 30B4         push  {r4, r5}
10
  34                .LCFI0:
11
  35                  .cfi_def_cfa_offset 8
12
  36                  .cfi_offset 5, -4
13
  37                  .cfi_offset 4, -8
14
  37:src/main.c    **** float tmp1, tmp2;
15
  38:src/main.c    **** float num_real, num_img;
16
  39:src/main.c    **** float radius, fofs_y, fofs_x, fzoom;
17
  40:src/main.c    **** const float rlimit = 4.0f;
18
  41:src/main.c    **** uint8_t i;
19
  42:src/main.c    **** uint16_t x,y;
20
  43:src/main.c    **** #define ITERATION 128
21
  44:src/main.c    **** #define IMG_CONSTANT 0.001f
22
  45:src/main.c    **** #define REAL_CONSTANT 0.285f
23
  46:src/main.c    **** 
24
  47:src/main.c    ****   fofs_y = (float)offset_y;
25
  38                  .loc 1 47 0
26
  39 0002 01EE103A     fmsr  s2, r3  @ int
27
  36:src/main.c    **** {
28
  40                  .loc 1 36 0
29
  41 0006 BDF80840     ldrh  r4, [sp, #8]
30
  48:src/main.c    ****   fofs_x = (float)offset_x;
31
  42                  .loc 1 48 0
32
  43 000a 07EE102A     fmsr  s14, r2  @ int
33
  36:src/main.c    **** {
34
  44                  .loc 1 36 0
35
  45 000e 01EE904A     fmsr  s3, r4  @ int
36
  47:src/main.c    ****   fofs_y = (float)offset_y;
37
  46                  .loc 1 47 0
38
  47 0012 B8EE412A     fuitos  s4, s2
39
  48                .LVL1:
40
  49                  .loc 1 48 0
41
  50 0016 F8EE472A     fuitos  s5, s14
42
  51                .LVL2:
43
  49:src/main.c    ****   fzoom = (float) zoom;
44
  50:src/main.c    ****   for (y=0; y<size_y; y++)
45
  52                  .loc 1 50 0
46
  53 001a 0029         cmp  r1, #0
47
  54 001c 44D0         beq  .L1
48
  35:src/main.c    **** void GenerateJulia_fpu(uint16_t size_x, uint16_t size_y, uint16_t offset_x, uint16_t offset_y, uint
49
  55                  .loc 1 35 0
50
  56 001e 039C         ldr  r4, [sp, #12]
51
  57                .LVL3:
52
  51:src/main.c    ****   {
53
  52:src/main.c    ****     for (x=0; x<size_x; x++)
54
  53:src/main.c    ****     {
55
  54:src/main.c    ****       num_real = (float)y - fofs_y;
56
  55:src/main.c    ****       num_real = num_real / zoom;
57
  56:src/main.c    ****       num_img = (float)x - fofs_x;
58
  57:src/main.c    ****       num_img = num_img / zoom;
59
  58:src/main.c    ****       i=0;
60
  59:src/main.c    ****       radius = 0.0f;
61
  60:src/main.c    ****       while ((i<ITERATION-1) && (radius < rlimit))
62
  61:src/main.c    ****       {
63
  62:src/main.c    ****         tmp1 = num_real * num_real;
64
  63:src/main.c    ****         tmp2 = num_img * num_img;
65
  64:src/main.c    ****         num_img = 2*num_real*num_img + IMG_CONSTANT;
66
  58                  .loc 1 64 0
67
  59 0020 DFED224A     flds  s9, .L11
68
  65:src/main.c    ****         num_real = tmp1 - tmp2 + REAL_CONSTANT;
69
  60                  .loc 1 65 0
70
  61 0024 9FED225A     flds  s10, .L11+4
71
  50:src/main.c    ****   for (y=0; y<size_y; y++)
72
  62                  .loc 1 50 0
73
  63 0028 0025         movs  r5, #0
74
  60:src/main.c    ****       while ((i<ITERATION-1) && (radius < rlimit))
75
  64                  .loc 1 60 0
76
  65 002a B1EE004A     fconsts  s8, #16
77
  66                .LVL4:
78
  67                .L3:
79
  52:src/main.c    ****     for (x=0; x<size_x; x++)
80
  68                  .loc 1 52 0 discriminator 1
81
  69 002e B0B3         cbz  r0, .L7
82
  52:src/main.c    ****     for (x=0; x<size_x; x++)
83
  70                  .loc 1 52 0 is_stmt 0
84
  71 0030 07EE105A     fmsr  s14, r5  @ int
85
  72 0034 F8EE477A     fuitos  s15, s14
86
  73 0038 F8EEE13A     fsitos  s7, s3
87
  74 003c 77EEC27A     fsubs  s15, s15, s4
88
  75 0040 0022         movs  r2, #0
89
  76 0042 87EEA33A     fdivs  s6, s15, s7
90
  77 0046 1346         mov  r3, r2
Persönliche Seite #3192894
Lesenswert?

War das nicht das Beispielprogramm, mit dem ST den 
Geschwindigkeitsgewinn durch die FPU demonstriert? Ich glaube dazu gibt 
es ein Video von ST.

Aber ich nehme mal an in der ST-Demonstration wurde der Code einmal mit 
Soft- und Hard-FPU kompiliert. Ist klar, dass man die Soft-FPU da 
vergessen kann. Aber interessant wäre zu wissen wie der Unterschied 
zwischen optimierter Fixed-Point Implementierung und FPU-Implementierung 
wäre.
Gast #3200825
Lesenswert?

Die 5 WS sind pflicht (P 62, DM00031020.pdf) aber der ART soll extra 
initialisiert... ich sehe im Code daß kein spur von Prefetch/Caches 
gibt... Ich werde es machen un neuen Tests durchlaufen lassen.

Danke!

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren