Skip to content

Commit b996955

Browse files
ioannisgnashif
authored andcommitted
arch: arm: optimize _size_to_mpu_rasr_size function
This commit optimizes _size_to_mpu_rasr_size(.) in the ARMv7-M MPU driver, so it makes use of a single _builtin_clz() function call, instead of two. Signed-off-by: Ioannis Glaropoulos <[email protected]>
1 parent 4cc2866 commit b996955

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

arch/arm/core/cortex_m/mpu/arm_mpu.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ static inline u32_t _get_region_attr(u32_t xn, u32_t ap, u32_t tex,
103103
/**
104104
* This internal function converts the region size to
105105
* the SIZE field value of MPU_RASR.
106+
*
107+
* Note: If size is not a power-of-two, it is rounded-up to the next
108+
* power-of-two value, and the returned SIZE field value corresponds
109+
* to that power-of-two value.
106110
*/
107111
static inline u32_t _size_to_mpu_rasr_size(u32_t size)
108112
{
@@ -120,8 +124,8 @@ static inline u32_t _size_to_mpu_rasr_size(u32_t size)
120124
return REGION_4G;
121125
}
122126

123-
size = 1 << (32 - __builtin_clz(size - 1));
124-
return (32 - __builtin_clz(size) - 2) << 1;
127+
return ((32 - __builtin_clz(size - 1) - 2 + 1) << MPU_RASR_SIZE_Pos) &
128+
MPU_RASR_SIZE_Msk;
125129
}
126130

127131
/**

0 commit comments

Comments
 (0)