Skip to content

Commit 90edd94

Browse files
committed
[MSVC-MingW] Use generic C code for implementing task selection
This generic version simplifies building and any modern compiler should be able to handle the conversion to the assembler instruction.
1 parent b4b91bc commit 90edd94

File tree

1 file changed

+8
-31
lines changed

1 file changed

+8
-31
lines changed

portable/MSVC-MingW/portmacro.h

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ void vPortExitCritical( void );
124124
#endif
125125

126126
/*-----------------------------------------------------------*/
127-
128127
#if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
129128

130129
/* Check the configuration. */
@@ -135,36 +134,14 @@ void vPortExitCritical( void );
135134
/* Store/clear the ready priorities in a bit map. */
136135
#define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( ( ( UBaseType_t ) 1 ) << ( uxPriority ) )
137136
#define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( ( ( UBaseType_t ) 1 ) << ( uxPriority ) )
138-
139-
#ifdef __GNUC__
140-
141-
#define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) \
142-
__asm volatile ( "bsr %1, %0\n\t" \
143-
: "=r" ( uxTopPriority ) \
144-
: "rm" ( uxReadyPriorities ) \
145-
: "cc" )
146-
147-
#else /* __GNUC__ */
148-
149-
/* BitScanReverse returns the bit position of the most significant '1'
150-
* in the word. */
151-
#if defined( __x86_64__ ) || defined( _M_X64 )
152-
153-
#define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) \
154-
do \
155-
{ \
156-
DWORD ulTopPriority; \
157-
_BitScanReverse64( &ulTopPriority, ( uxReadyPriorities ) ); \
158-
uxTopPriority = ulTopPriority; \
159-
} while( 0 )
160-
161-
#else /* #if defined( __x86_64__ ) || defined( _M_X64 ) */
162-
163-
#define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) _BitScanReverse( ( DWORD * ) &( uxTopPriority ), ( uxReadyPriorities ) )
164-
165-
#endif /* #if defined( __x86_64__ ) || defined( _M_X64 ) */
166-
167-
#endif /* __GNUC__ */
137+
#define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) \
138+
do { \
139+
unsigned i = sizeof(UBaseType_t) * 8 - 1; \
140+
while ((uxReadyPriorities & ((UBaseType_t)1 << i)) == 0) { \
141+
i--; \
142+
} \
143+
uxTopPriority = i; \
144+
} while( 0 )
168145

169146
#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
170147

0 commit comments

Comments
 (0)