GCC inline a optimalizace
Jaroslav Buchta
jaroslav.buchta na hascomp.cz
Sobota Srpen 13 09:36:09 CEST 2016
Sypu si popel na hlavu, v prokladanem vypisu jsou prehazeny adresy a to
jsem si nevsimnul, pokud je vypis jen ASM vypada to OK
08000454 push {r7}
08000456 add r7, sp, #0
08000458 mov.w r0, #95 ; 0x5f
0800045C msr BASEPRI, r0
08000460 ldr r3, [pc, #60] ; (0x80004a0 <SysTick_Handler+76>)
08000462 ldr r3, [r3, #0]
08000464 adds r2, r3, #1
08000466 ldr r3, [pc, #56] ; (0x80004a0 <SysTick_Handler+76>)
08000468 str r2, [r3, #0]
0800046A ldr r3, [pc, #56] ; (0x80004a4 <SysTick_Handler+80>)
0800046C ldrd r2, r3, [r3]
08000470 adds r2, #1
08000472 adc.w r3, r3, #0
08000476 ldr r1, [pc, #44] ; (0x80004a4 <SysTick_Handler+80>)
08000478 strd r2, r3, [r1]
0800047C ldr r3, [pc, #32] ; (0x80004a0 <SysTick_Handler+76>)
0800047E ldr r3, [r3, #0]
08000480 subs r2, r3, #1
08000482 ldr r3, [pc, #28] ; (0x80004a0 <SysTick_Handler+76>)
08000484 str r2, [r3, #0]
08000486 ldr r3, [pc, #24] ; (0x80004a0 <SysTick_Handler+76>)
08000488 ldr r3, [r3, #0]
0800048A cmp r3, #0
0800048C bne.n 0x8000496 <SysTick_Handler+66>
0800048E mov.w r0, #0
08000492 msr BASEPRI, r0
08000496 mov sp, r7
08000498 ldr.w r7, [sp], #4
0800049C bx lr
Volatile u funkce jde ale nesmi pak byt void, ale chova se to stejne.
Dne 13.08.2016 v 9:05 Zdeněk Aster napsal(a):
> pujde dat ?
>
> inline void volatile EnterCritical() __attribute__( ( always_inline ) );
>
>
> Zdenek Aster
>
> ---------- Původní zpráva ----------
> Od: Jaroslav Buchta <jaroslav.buchta na hascomp.cz>
> Komu: HW-news <hw-list na list.hw.cz>
> Datum: 13. 8. 2016 7:47:28
> Předmět: GCC inline a optimalizace
>
>
> Zdravim,
>
> nevim jak donutit compiler, aby mi neprehazel posloupnost operaci v
> nasledujici funkci
>
> inline void EnterCritical() __attribute__( ( always_inline ) );
> inline void ExitCritical() __attribute__( ( always_inline ) );
>
>
> inline void EnterCritical()
> {
> __asm volatile
> (
> " mov r0, %0 \n"
> " msr basepri, r0 \n"
> ::"i"(CRITICAL_INT_PRIORITY):"r0"
> );
> criticalNesting++;
> }
>
> inline void ExitCritical()
> {
> criticalNesting--;
> if( criticalNesting == 0 )
> {
> __asm volatile
> (
> " mov r0, #0 \n"
> " msr basepri, r0 \n"
> :::"r0"
> );
> }
>
> }
>
>
> volatile uint64_t sysTicksCounter;
>
> void SysTick_Handler(void)
> {
> EnterCritical();
> sysTicksCounter++;
> ExitCritical();
> }
>
> Ma nekdo tip jak na to? Takhle z toho vypadne toto v asm:
>
>
> 08000458 mov.w r0, #95 ; 0x5f
> 0800045C msr BASEPRI, r0
> (56) (
> (57) " mov r0, %0 \n"
> (58) " msr basepri, r0 \n"
> (59) ::"i"(CRITICAL_INT_PRIORITY):"r0"
> (60) );
> (61) criticalNesting++;
> 08000460 ldr r3, [pc, #60] ; (0x80004a0 <SysTick_Handler+76>)
> 08000462 ldr r3, [r3, #0]
> 08000464 adds r2, r3, #1
> 08000466 ldr r3, [pc, #56] ; (0x80004a0 <SysTick_Handler+76>)
> 08000468 str r2, [r3, #0]
> (62) }
> (63)
> (64) inline void ExitCritical()
> (65) {
> (66) criticalNesting--;
> 0800047C ldr r3, [pc, #32] ; (0x80004a0 <SysTick_Handler+76>)
> 0800047E ldr r3, [r3, #0]
> 08000480 subs r2, r3, #1
> 08000482 ldr r3, [pc, #28] ; (0x80004a0 <SysTick_Handler+76>)
> 08000484 str r2, [r3, #0]
> (67) if( criticalNesting == 0 )
> 08000486 ldr r3, [pc, #24] ; (0x80004a0 <SysTick_Handler+76>)
> 08000488 ldr r3, [r3, #0]
> 0800048A cmp r3, #0
> 0800048C bne.n 0x8000496 <SysTick_Handler+66>
> (68) {
> (69) __asm volatile
> 0800048E mov.w r0, #0
> 08000492 msr BASEPRI, r0
> (70) (
> (71) " mov r0, #0 \n"
> (72) " msr basepri, r0 \n"
> (73) :::"r0"
> (74) );
> (75) }
> (76)
> (77) }
> (78)
> (79) volatile uint64_t sysTicksCounter;
> (80)
> (81) void SysTick_Handler(void)
> (82) {
> 08000454 push {r7}
> 08000456 add r7, sp, #0
> (83) EnterCritical();
> (84) sysTicksCounter++;
> 0800046A ldr r3, [pc, #56] ; (0x80004a4 <SysTick_Handler+80>)
> 0800046C ldrd r2, r3, [r3]
> 08000470 adds r2, #1
> 08000472 adc.w r3, r3, #0
> 08000476 ldr r1, [pc, #44] ; (0x80004a4 <SysTick_Handler+80>)
> 08000478 strd r2, r3, [r1]
> (85) ExitCritical();
> (86) }
> 08000496 mov sp, r7
> 08000498 ldr.w r7, [sp], #4
> 0800049C bx lr
> 0800049E nop
> 080004A0 lsls r4, r1, #17
> 080004A2 movs r0, #0
> 080004A4 lsls r0, r2, #17
> 080004A6 movs r0, #0
>
>
> -> cili to provede omezeni preruseni, zrusi omezeni a teprve potom
> provede increment ktery ma byt samozrejme mezi tim...
>
> _______________________________________________
> HW-list mailing list - sponsored by www.HW.cz
> Hw-list na list.hw.cz
> http://list.hw.cz/mailman/listinfo/hw-list
>
>
>
> _______________________________________________
> HW-list mailing list - sponsored by www.HW.cz
> Hw-list na list.hw.cz
> http://list.hw.cz/mailman/listinfo/hw-list
------------- další část ---------------
HTML příloha byla odstraněna...
URL: <http://list.hw.cz/pipermail/hw-list/attachments/20160813/129f3662/attachment.html>
Další informace o konferenci Hw-list