Skip to content

Commit 9a79718

Browse files
committed
ARMv7-M: FPU Register optimization
Improvement to the ARMv7-M port: FPU registers only saved/restored on context switch if they've been used by the task.
1 parent 0ab86bd commit 9a79718

File tree

9 files changed

+83
-290
lines changed

9 files changed

+83
-290
lines changed

Ports/ARM-Cortex-M/ARMv7-M/ARM/os_cpu.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,6 @@ void OS_CPU_SysTickInitFreq(CPU_INT32U cpu_freq);
157157
void OS_CPU_SysTickHandler (void);
158158
void OS_CPU_PendSVHandler (void);
159159

160-
#if (OS_CPU_ARM_FP_EN > 0u)
161-
void OS_CPU_FP_Reg_Push (CPU_STK *stkPtr);
162-
void OS_CPU_FP_Reg_Pop (CPU_STK *stkPtr);
163-
#endif
164-
165160

166161
/*
167162
*********************************************************************************************************

Ports/ARM-Cortex-M/ARMv7-M/ARM/os_cpu_a.asm

Lines changed: 20 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@
5050
EXPORT OSIntCtxSw
5151
EXPORT OS_CPU_PendSVHandler
5252

53-
IF {FPU} != "SoftVFP"
54-
EXPORT OS_CPU_FP_Reg_Push
55-
EXPORT OS_CPU_FP_Reg_Pop
56-
ENDIF
57-
5853

5954
;********************************************************************************************************
6055
; EQUATES
@@ -76,55 +71,6 @@ NVIC_PENDSVSET EQU 0x10000000 ; Value to trigg
7671
AREA CODE, CODE, READONLY
7772

7873

79-
;********************************************************************************************************
80-
; FLOATING POINT REGISTERS PUSH
81-
; void OS_CPU_FP_Reg_Push (CPU_STK *stkPtr)
82-
;
83-
; Note(s) : 1) This function saves S16-S31 registers of the Floating Point Unit.
84-
;
85-
; 2) Pseudo-code is:
86-
; a) Push remaining FPU regs S16-S31 on process stack;
87-
; b) Update OSTCBCurPtr->StkPtr;
88-
;********************************************************************************************************
89-
90-
IF {FPU} != "SoftVFP"
91-
92-
OS_CPU_FP_Reg_Push
93-
MRS R1, PSP ; PSP is process stack pointer
94-
CBZ R1, OS_CPU_FP_nosave ; Skip FP register save the first time
95-
96-
VSTMDB R0!, {S16-S31}
97-
LDR R1, =OSTCBCurPtr
98-
LDR R2, [R1]
99-
STR R0, [R2]
100-
OS_CPU_FP_nosave
101-
BX LR
102-
103-
ENDIF
104-
105-
106-
;********************************************************************************************************
107-
; FLOATING POINT REGISTERS POP
108-
; void OS_CPU_FP_Reg_Pop (CPU_STK *stkPtr)
109-
;
110-
; Note(s) : 1) This function restores S16-S31 of the Floating Point Unit.
111-
;
112-
; 2) Pseudo-code is:
113-
; a) Restore regs S16-S31 of new process stack;
114-
; b) Update OSTCBHighRdyPtr->StkPtr pointer of new proces stack;
115-
;********************************************************************************************************
116-
117-
IF {FPU} != "SoftVFP"
118-
119-
OS_CPU_FP_Reg_Pop
120-
VLDMIA R0!, {S16-S31}
121-
LDR R1, =OSTCBHighRdyPtr
122-
LDR R2, [R1]
123-
STR R0, [R2]
124-
BX LR
125-
126-
ENDIF
127-
12874

12975
;********************************************************************************************************
13076
; START MULTITASKING
@@ -177,6 +123,7 @@ OSStartHighRdy
177123

178124
MRS R0, CONTROL
179125
ORR R0, R0, #2
126+
BIC R0, R0, #4 ; Clear FPCA bit to indicate FPU is not in use
180127
MSR CONTROL, R0
181128
ISB ; Sync instruction stream
182129

@@ -265,6 +212,13 @@ OS_CPU_PendSVHandler
265212
CPSIE I
266213

267214
MRS R0, PSP ; PSP is process stack pointer
215+
IF {FPU} != "SoftVFP"
216+
; Push high vfp registers if the task is using the FPU context
217+
TST R14, #0x10
218+
IT EQ
219+
VSTMDBEQ R0!, {S16-S31}
220+
ENDIF
221+
268222
STMFD R0!, {R4-R11, R14} ; Save remaining regs r4-11, R14 on process stack
269223

270224
MOV32 R5, OSTCBCurPtr ; OSTCBCurPtr->StkPtr = SP;
@@ -287,10 +241,22 @@ OS_CPU_PendSVHandler
287241
ORR LR, R4, #0x04 ; Ensure exception return uses process stack
288242
LDR R0, [R2] ; R0 is new process SP; SP = OSTCBHighRdyPtr->StkPtr;
289243
LDMFD R0!, {R4-R11, R14} ; Restore r4-11, R14 from new process stack
244+
245+
IF {FPU} != "SoftVFP"
246+
; Pop the high vfp registers if the next task is using the FPU context
247+
TST R14, #0x10
248+
IT EQ
249+
VLDMIAEQ R0!, {S16-S31}
250+
ENDIF
251+
290252
MSR PSP, R0 ; Load PSP with new process SP
291253

292254
MOV32 R2, #0 ; Restore BASEPRI priority level to 0
255+
CPSID I ; Cortex-M7 errata notice. See Note #5
293256
MSR BASEPRI, R2
257+
DSB
258+
ISB
259+
CPSIE I
294260
BX LR ; Exception return will restore remaining context
295261

296262
ALIGN ; Removes warning[A1581W]: added <no_padbytes> of padding at <address>

Ports/ARM-Cortex-M/ARMv7-M/CCS/os_cpu.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,6 @@ void OS_CPU_SysTickInitFreq(CPU_INT32U cpu_freq);
157157
void OS_CPU_SysTickHandler (void);
158158
void OS_CPU_PendSVHandler (void);
159159

160-
#if (OS_CPU_ARM_FP_EN > 0u)
161-
void OS_CPU_FP_Reg_Push (CPU_STK *stkPtr);
162-
void OS_CPU_FP_Reg_Pop (CPU_STK *stkPtr);
163-
#endif
164-
165160

166161
/*
167162
*********************************************************************************************************

Ports/ARM-Cortex-M/ARMv7-M/CCS/os_cpu_a.asm

Lines changed: 20 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ OS_KA_BASEPRI_BoundaryAddr: .word OS_KA_BASEPRI_Boundary
5959
.global OSIntCtxSw
6060
.global OS_CPU_PendSVHandler
6161

62-
.if __TI_VFP_SUPPORT__
63-
.global OS_CPU_FP_Reg_Push
64-
.global OS_CPU_FP_Reg_Pop
65-
.endif
66-
6762

6863
;********************************************************************************************************
6964
; EQUATES
@@ -84,59 +79,6 @@ NVIC_PENDSVSET: .word 0x10000000 ; Value to trigg
8479
.thumb
8580

8681

87-
;********************************************************************************************************
88-
; FLOATING POINT REGISTERS PUSH
89-
; void OS_CPU_FP_Reg_Push (CPU_STK *stkPtr)
90-
;
91-
; Note(s) : 1) This function saves S16-S31 registers of the Floating Point Unit.
92-
;
93-
; 2) Pseudo-code is:
94-
; a) Push remaining FPU regs S16-S31 on process stack;
95-
; b) Update OSTCBCurPtr->StkPtr;
96-
;********************************************************************************************************
97-
98-
.if __TI_VFP_SUPPORT__
99-
.asmfunc
100-
OS_CPU_FP_Reg_Push:
101-
MRS R1, PSP ; PSP is process stack pointer
102-
CBZ R1, OS_CPU_FP_nosave ; Skip FP register save the first time
103-
104-
VSTMDB R0!, {S16-S31}
105-
LDR R1, OSTCBCurPtrAddr
106-
LDR R2, [R1]
107-
STR R0, [R2]
108-
.endasmfunc
109-
110-
.asmfunc
111-
OS_CPU_FP_nosave:
112-
BX LR
113-
.endasmfunc
114-
.endif
115-
116-
117-
;********************************************************************************************************
118-
; FLOATING POINT REGISTERS POP
119-
; void OS_CPU_FP_Reg_Pop (CPU_STK *stkPtr)
120-
;
121-
; Note(s) : 1) This function restores S16-S31 of the Floating Point Unit.
122-
;
123-
; 2) Pseudo-code is:
124-
; a) Restore regs S16-S31 of new process stack;
125-
; b) Update OSTCBHighRdyPtr->StkPtr pointer of new proces stack;
126-
;********************************************************************************************************
127-
128-
.if __TI_VFP_SUPPORT__
129-
.asmfunc
130-
OS_CPU_FP_Reg_Pop:
131-
VLDMIA R0!, {S16-S31}
132-
LDR R1, OSTCBHighRdyPtrAddr
133-
LDR R2, [R1]
134-
STR R0, [R2]
135-
BX LR
136-
.endasmfunc
137-
.endif
138-
139-
14082
;********************************************************************************************************
14183
; START MULTITASKING
14284
; void OSStartHighRdy(void)
@@ -189,6 +131,7 @@ OSStartHighRdy:
189131

190132
MRS R0, CONTROL
191133
ORR R0, R0, #2
134+
BIC R0, R0, #4 ; Clear FPCA bit to indicate FPU is not in use
192135
MSR CONTROL, R0
193136
ISB ; Sync instruction stream
194137

@@ -281,6 +224,13 @@ OS_CPU_PendSVHandler:
281224
CPSIE I
282225

283226
MRS R0, PSP ; PSP is process stack pointer
227+
.if __TI_VFP_SUPPORT__
228+
; Push high vfp registers if the task is using the FPU context
229+
TST R14, #0x10
230+
IT EQ
231+
VSTMDBEQ R0!, {S16-S31}
232+
.endif
233+
284234
STMFD R0!, {R4-R11, R14} ; Save remaining regs r4-11, R14 on process stack
285235

286236
LDR R5, OSTCBCurPtrAddr ; OSTCBCurPtr->StkPtr = SP;
@@ -303,10 +253,22 @@ OS_CPU_PendSVHandler:
303253
ORR LR, R4, #0x04 ; Ensure exception return uses process stack
304254
LDR R0, [R2] ; R0 is new process SP; SP = OSTCBHighRdyPtr->StkPtr;
305255
LDMFD R0!, {R4-R11, R14} ; Restore r4-11, R14 from new process stack
256+
257+
.if __TI_VFP_SUPPORT__
258+
; Pop the high vfp registers if the next task is using the FPU context
259+
TST R14, #0x10
260+
IT EQ
261+
VLDMIAEQ R0!, {S16-S31}
262+
.endif
263+
306264
MSR PSP, R0 ; Load PSP with new process SP
307265

308266
MOV R2, #0 ; Restore BASEPRI priority level to 0
267+
CPSID I ; Cortex-M7 errata notice. See Note #5
309268
MSR BASEPRI, R2
269+
DSB
270+
ISB
271+
CPSIE I
310272
BX LR ; Exception return will restore remaining context
311273
.endasmfunc
312274

Ports/ARM-Cortex-M/ARMv7-M/GNU/os_cpu.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,6 @@ void OS_CPU_SysTickInitFreq(CPU_INT32U cpu_freq);
157157
void OS_CPU_SysTickHandler (void);
158158
void OS_CPU_PendSVHandler (void);
159159

160-
#if (OS_CPU_ARM_FP_EN > 0u)
161-
void OS_CPU_FP_Reg_Push (CPU_STK *stkPtr);
162-
void OS_CPU_FP_Reg_Pop (CPU_STK *stkPtr);
163-
#endif
164-
165160

166161
/*
167162
*********************************************************************************************************

Ports/ARM-Cortex-M/ARMv7-M/GNU/os_cpu_a.S

Lines changed: 23 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
@
1717
@ ARMv7-M Port
1818
@
19+
@ File : os_cpu_a.asm
20+
@ Version : V3.08.00
21+
@********************************************************************************************************
1922
@ For : ARMv7-M Cortex-M
2023
@ Mode : Thumb-2 ISA
2124
@ Toolchain : GNU C Compiler
@@ -46,10 +49,6 @@
4649
.global OSIntCtxSw
4750
.global OS_CPU_PendSVHandler
4851

49-
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
50-
.global OS_CPU_FP_Reg_Push
51-
.global OS_CPU_FP_Reg_Pop
52-
#endif
5352

5453

5554
@********************************************************************************************************
@@ -72,56 +71,6 @@
7271
.syntax unified
7372

7473

75-
@********************************************************************************************************
76-
@ FLOATING POINT REGISTERS PUSH
77-
@ void OS_CPU_FP_Reg_Push (CPU_STK *stkPtr)
78-
@
79-
@ Note(s) : 1) This function saves S16-S31 registers of the Floating Point Unit.
80-
@
81-
@ 2) Pseudo-code is:
82-
@ a) Push remaining FPU regs S16-S31 on process stack;
83-
@ b) Update OSTCBCurPtr->StkPtr;
84-
@********************************************************************************************************
85-
86-
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
87-
88-
.thumb_func
89-
OS_CPU_FP_Reg_Push:
90-
MRS R1, PSP @ PSP is process stack pointer
91-
CBZ R1, OS_CPU_FP_nosave @ Skip FP register save the first time
92-
93-
VSTMDB R0!, {S16-S31}
94-
LDR R1, =OSTCBCurPtr
95-
LDR R2, [R1]
96-
STR R0, [R2]
97-
OS_CPU_FP_nosave:
98-
BX LR
99-
#endif
100-
101-
102-
@********************************************************************************************************
103-
@ FLOATING POINT REGISTERS POP
104-
@ void OS_CPU_FP_Reg_Pop (CPU_STK *stkPtr)
105-
@
106-
@ Note(s) : 1) This function restores S16-S31 of the Floating Point Unit.
107-
@
108-
@ 2) Pseudo-code is:
109-
@ a) Restore regs S16-S31 of new process stack;
110-
@ b) Update OSTCBHighRdyPtr->StkPtr pointer of new proces stack;
111-
@********************************************************************************************************
112-
113-
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
114-
115-
.thumb_func
116-
OS_CPU_FP_Reg_Pop:
117-
VLDMIA R0!, {S16-S31}
118-
LDR R1, =OSTCBHighRdyPtr
119-
LDR R2, [R1]
120-
STR R0, [R2]
121-
BX LR
122-
#endif
123-
124-
12574
@********************************************************************************************************
12675
@ START MULTITASKING
12776
@ void OSStartHighRdy(void)
@@ -182,6 +131,7 @@ OSStartHighRdy:
182131

183132
MRS R0, CONTROL
184133
ORR R0, R0, #2
134+
BIC R0, R0, #4 @ Clear FPCA bit to indicate FPU is not in use
185135
MSR CONTROL, R0
186136
ISB @ Sync instruction stream
187137

@@ -273,6 +223,13 @@ OS_CPU_PendSVHandler:
273223
CPSIE I
274224

275225
MRS R0, PSP @ PSP is process stack pointer
226+
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
227+
@ Push high vfp registers if the task is using the FPU context
228+
TST R14, #0x10
229+
IT EQ
230+
VSTMDBEQ R0!, {S16-S31}
231+
#endif
232+
276233
STMFD R0!, {R4-R11, R14} @ Save remaining regs r4-11, R14 on process stack
277234

278235
MOVW R5, #:lower16:OSTCBCurPtr @ OSTCBCurPtr->StkPtr = SP;
@@ -299,10 +256,22 @@ OS_CPU_PendSVHandler:
299256
ORR LR, R4, #0x04 @ Ensure exception return uses process stack
300257
LDR R0, [R2] @ R0 is new process SP; SP = OSTCBHighRdyPtr->StkPtr;
301258
LDMFD R0!, {R4-R11, R14} @ Restore r4-11, R14 from new process stack
259+
260+
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
261+
@ Pop the high vfp registers if the next task is using the FPU context
262+
TST R14, #0x10
263+
IT EQ
264+
VLDMIAEQ R0!, {S16-S31}
265+
#endif
266+
302267
MSR PSP, R0 @ Load PSP with new process SP
303268

304269
MOV R2, #0 @ Restore BASEPRI priority level to 0
270+
CPSID I @ Cortex-M7 errata notice. See Note #5
305271
MSR BASEPRI, R2
272+
DSB
273+
ISB
274+
CPSIE I
306275
BX LR @ Exception return will restore remaining context
307276

308277
.end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy