ny88 wrote on Wednesday, July 18, 2007:
Posiont:
In Function void vTaskSwitchContext( void ), FreeRTOS 4.3.1, at line 1864
: listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopReadyPriority ] ) ).
Problem:
Because listGET_OWNER_OF_NEXT_ENTRY is a macro by defined, the compilers can rarely optimize its parameters. They only replace them simply. I have tested it as below.
A partial Solution:
change " listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopReadyPriority ] ) );"
to "
xList* ppp=&( pxReadyTasksLists[ uxTopReadyPriority ] );
listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, ppp );
"
Test:
Condition: ATMega323, WinAVR20070525, AVR Studio4.13 simulation mode Frequence = 4MHz, makefile: OPT = s, configUSE_TRACE_FACILITY == 0.
Result:
(1) listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopReadyPriority ] ) ):
asm:
1420: listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopReadyPriority ] ) );
+00000100: 91200079 LDS R18,0x0079 Load direct from data space
+00000102: 91800079 LDS R24,0x0079 Load direct from data space
+00000104: 2799 CLR R25 Clear Register
+00000105: 01FC MOVW R30,R24 Copy register pair
+00000106: E0A3 LDI R26,0x03 Load immediate
+00000107: 0FEE LSL R30 Logical Shift Left
+00000108: 1FFF ROL R31 Rotate Left Through Carry
+00000109: 95AA DEC R26 Decrement
+0000010A: F7E1 BRNE PC-0x03 Branch if not equal
+0000010B: 0FE8 ADD R30,R24 Add without carry
+0000010C: 1FF9 ADC R31,R25 Add with carry
+0000010D: 58E1 SUBI R30,0x81 Subtract immediate
+0000010E: 4FFF SBCI R31,0xFF Subtract immediate with carry
+0000010F: 8001 LDD R0,Z+1 Load indirect with displacement
+00000110: 81F2 LDD R31,Z+2 Load indirect with displacement
+00000111: 2DE0 MOV R30,R0 Copy register
+00000112: 8182 LDD R24,Z+2 Load indirect with displacement
+00000113: 8193 LDD R25,Z+3 Load indirect with displacement
+00000114: 2733 CLR R19 Clear Register
+00000115: 01F9 MOVW R30,R18 Copy register pair
+00000116: E073 LDI R23,0x03 Load immediate
+00000117: 0FEE LSL R30 Logical Shift Left
+00000118: 1FFF ROL R31 Rotate Left Through Carry
+00000119: 957A DEC R23 Decrement
+0000011A: F7E1 BRNE PC-0x03 Branch if not equal
+0000011B: 0FE2 ADD R30,R18 Add without carry
+0000011C: 1FF3 ADC R31,R19 Add with carry
+0000011D: 58E1 SUBI R30,0x81 Subtract immediate
+0000011E: 4FFF SBCI R31,0xFF Subtract immediate with carry
+0000011F: 8392 STD Z+2,R25 Store indirect with displacement
+00000120: 8381 STD Z+1,R24 Store indirect with displacement
+00000121: 91800079 LDS R24,0x0079 Load direct from data space
+00000123: 91200079 LDS R18,0x0079 Load direct from data space
+00000125: 9F24 MUL R18,R20 Multiply unsigned
+00000126: 0190 MOVW R18,R0 Copy register pair
+00000127: 2411 CLR R1 Clear Register
+00000128: 572E SUBI R18,0x7E Subtract immediate
+00000129: 4F3F SBCI R19,0xFF Subtract immediate with carry
+0000012A: 2799 CLR R25 Clear Register
+0000012B: 01FC MOVW R30,R24 Copy register pair
+0000012C: E063 LDI R22,0x03 Load immediate
+0000012D: 0FEE LSL R30 Logical Shift Left
+0000012E: 1FFF ROL R31 Rotate Left Through Carry
+0000012F: 956A DEC R22 Decrement
+00000130: F7E1 BRNE PC-0x03 Branch if not equal
+00000131: 0FE8 ADD R30,R24 Add without carry
+00000132: 1FF9 ADC R31,R25 Add with carry
+00000133: 58E1 SUBI R30,0x81 Subtract immediate
+00000134: 4FFF SBCI R31,0xFF Subtract immediate with carry
+00000135: 8181 LDD R24,Z+1 Load indirect with displacement
+00000136: 8192 LDD R25,Z+2 Load indirect with displacement
+00000137: 1782 CP R24,R18 Compare
+00000138: 0793 CPC R25,R19 Compare with carry
+00000139: F509 BRNE PC+0x22 Branch if not equal
+0000013A: 91200079 LDS R18,0x0079 Load direct from data space
+0000013C: 91800079 LDS R24,0x0079 Load direct from data space
+0000013E: 2799 CLR R25 Clear Register
+0000013F: 01FC MOVW R30,R24 Copy register pair
+00000140: E053 LDI R21,0x03 Load immediate
+00000141: 0FEE LSL R30 Logical Shift Left
+00000142: 1FFF ROL R31 Rotate Left Through Carry
+00000143: 955A DEC R21 Decrement
+00000144: F7E1 BRNE PC-0x03 Branch if not equal
+00000145: 0FE8 ADD R30,R24 Add without carry
+00000146: 1FF9 ADC R31,R25 Add with carry
+00000147: 58E1 SUBI R30,0x81 Subtract immediate
+00000148: 4FFF SBCI R31,0xFF Subtract immediate with carry
+00000149: 8001 LDD R0,Z+1 Load indirect with displacement
+0000014A: 81F2 LDD R31,Z+2 Load indirect with displacement
+0000014B: 2DE0 MOV R30,R0 Copy register
+0000014C: 8182 LDD R24,Z+2 Load indirect with displacement
+0000014D: 8193 LDD R25,Z+3 Load indirect with displacement
+0000014E: 2733 CLR R19 Clear Register
+0000014F: 01F9 MOVW R30,R18 Copy register pair
+00000150: E043 LDI R20,0x03 Load immediate
+00000151: 0FEE LSL R30 Logical Shift Left
+00000152: 1FFF ROL R31 Rotate Left Through Carry
+00000153: 954A DEC R20 Decrement
+00000154: F7E1 BRNE PC-0x03 Branch if not equal
+00000155: 0FE2 ADD R30,R18 Add without carry
+00000156: 1FF3 ADC R31,R19 Add with carry
+00000157: 58E1 SUBI R30,0x81 Subtract immediate
+00000158: 4FFF SBCI R31,0xFF Subtract immediate with carry
+00000159: 8392 STD Z+2,R25 Store indirect with displacement
+0000015A: 8381 STD Z+1,R24 Store indirect with displacement
+0000015B: 91800079 LDS R24,0x0079 Load direct from data space
+0000015D: 2799 CLR R25 Clear Register
+0000015E: 01FC MOVW R30,R24 Copy register pair
+0000015F: E023 LDI R18,0x03 Load immediate
+00000160: 0FEE LSL R30 Logical Shift Left
+00000161: 1FFF ROL R31 Rotate Left Through Carry
+00000162: 952A DEC R18 Decrement
+00000163: F7E1 BRNE PC-0x03 Branch if not equal
+00000164: 0FE8 ADD R30,R24 Add without carry
+00000165: 1FF9 ADC R31,R25 Add with carry
+00000166: 58E1 SUBI R30,0x81 Subtract immediate
+00000167: 4FFF SBCI R31,0xFF Subtract immediate with carry
+00000168: 8001 LDD R0,Z+1 Load indirect with displacement
+00000169: 81F2 LDD R31,Z+2 Load indirect with displacement
+0000016A: 2DE0 MOV R30,R0 Copy register
+0000016B: 8186 LDD R24,Z+6 Load indirect with displacement
+0000016C: 8197 LDD R25,Z+7 Load indirect with displacement
+0000016D: 93900073 STS 0x0073,R25 Store direct to data space
+0000016F: 93800072 STS 0x0072,R24 Store direct to data space
+00000171: 9508 RET Subroutine return
time: ~= 49us
(2) xList* ppp=&( pxReadyTasksLists[ uxTopReadyPriority ] );
listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, ppp );
1422: xList* ppp=&( pxReadyTasksLists[ uxTopReadyPriority ] );
+00000102: 91800079 LDS R24,0x0079 Load direct from data space
+00000104: 9F89 MUL R24,R25 Multiply unsigned
+00000105: 01D0 MOVW R26,R0 Copy register pair
+00000106: 2411 CLR R1 Clear Register
+00000107: 58A1 SUBI R26,0x81 Subtract immediate
+00000108: 4FBF SBCI R27,0xFF Subtract immediate with carry
1423: listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, ppp );
+00000109: 01ED MOVW R28,R26 Copy register pair
+0000010A: 81E9 LDD R30,Y+1 Load indirect with displacement
+0000010B: 81FA LDD R31,Y+2 Load indirect with displacement
+0000010C: 8002 LDD R0,Z+2 Load indirect with displacement
+0000010D: 81F3 LDD R31,Z+3 Load indirect with displacement
+0000010E: 2DE0 MOV R30,R0 Copy register
+0000010F: 83FA STD Y+2,R31 Store indirect with displacement
+00000110: 83E9 STD Y+1,R30 Store indirect with displacement
+00000111: 01CD MOVW R24,R26 Copy register pair
+00000112: 9603 ADIW R24,0x03 Add immediate to word
+00000113: 17E8 CP R30,R24 Compare
+00000114: 07F9 CPC R31,R25 Compare with carry
+00000115: F421 BRNE PC+0x05 Branch if not equal
+00000116: 8182 LDD R24,Z+2 Load indirect with displacement
+00000117: 8193 LDD R25,Z+3 Load indirect with displacement
+00000118: 839A STD Y+2,R25 Store indirect with displacement
+00000119: 8389 STD Y+1,R24 Store indirect with displacement
+0000011A: 01ED MOVW R28,R26 Copy register pair
+0000011B: 81E9 LDD R30,Y+1 Load indirect with displacement
+0000011C: 81FA LDD R31,Y+2 Load indirect with displacement
+0000011D: 8186 LDD R24,Z+6 Load indirect with displacement
+0000011E: 8197 LDD R25,Z+7 Load indirect with displacement
+0000011F: 93900073 STS 0x0073,R25 Store direct to data space
+00000121: 93800072 STS 0x0072,R24 Store direct to data space
+00000123: 91DF POP R29 Pop register from stack
+00000124: 91CF POP R28 Pop register from stack
+00000125: 9508 RET Subroutine return
time: ~= 14us
End:
Be careful to use a function defined by #define. "Maybe" to implement it with a true function is better in this case. There are some other places like this flaws, please correct it in next version.
B.R.