Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

ARM CM3: use a general register for MSR

Posted by Samuel Tardieu on March 22, 2009
The code for portSET_INTERRUPT_MASK() and portCLEAR_INTERRUPT_MASK() of the GCC ARM CM3 port hardcodes the use of the r0 register as the intermediate value to use as "msr basepri, r0". Any general register can be used here, and sometimes letting GCC choose leads to a shorter and faster code.

By using respectively

__asm volatile("msr basepri,%0" : : "r"(configMAX_SYSCALL_INTERRUPT_PRIORITY));

and

_asm volatile("msr basepri,%0" : : "r"(0));

we can only get better code: in the worst case, we get the equivalent two instructions, in the best case, the compiler knows that rconfigMAX_SYSCALL_INTERRUPT_PRIORITY/0 is already loaded into a register at this point and will use it. Also, it decreases the register pressure on r0 by allowing the use of a different register should it lead to a better code.

For example, vPortExitCritical will then get compiled as

1488: 4a03 ldr r2, [pc, #12] (1498 <vPortExitCritical+0x10>)
148a: 6813 ldr r3, [r2, #0]
148c: 3b01 subs r3, #1
148e: 6013 str r3, [r2, #0]
1490: b90b cbnz r3, 1496 <vPortExitCritical+0xe>
1492: f383 8811 msr BASEPRI, r3
1496: 4770 bx lr

Here, at address 1492, the compiler knows that r3 (which contains the uxCriticalNesting value) is necessarily 0 and uses it instead of reloading the constant 0 into another register.

RE: ARM CM3: use a general register for MSR

Posted by Richard on March 22, 2009
Very good post - thanks for sharing.

Regards.

RE: ARM CM3: use a general register for MSR

Posted by Samuel Tardieu on March 24, 2009
Richard,

any chance to get this change applied to the SVN repository?

(I'm already using it in my local copy, I just want to make sure it doesn't get forgotten)

Sam

RE: ARM CM3: use a general register for MSR

Posted by Richard on March 24, 2009
Can you add it to the feature request tracker in SourceForge please. That way it won't get forgotten.

Regards.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists