summaryrefslogtreecommitdiff
path: root/core/cortex-m/task.c
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2015-09-19 10:48:19 -0700
committerchrome-bot <chrome-bot@chromium.org>2015-09-21 01:13:54 -0700
commit1d8fcfcd0d1b93d04ea5adcb980ffac38bd3d140 (patch)
tree0eb4927a778fa1ff4899c1738ecfafefaf487622 /core/cortex-m/task.c
parentdbfb5c1deeb6ee54663baaee6052849b8cba5bd5 (diff)
downloadchrome-ec-1d8fcfcd0d1b93d04ea5adcb980ffac38bd3d140.tar.gz
common: Add __fls function
Returns the most significant bit set. Replace 31 - __builtin_clz(x), so x must be different from 0. Use get_next_bit when not on the performance path, on performance path set the bit field just after reading it. BRANCH=smaug BUG=none TEST=compile, check Ryu still works. Change-Id: Ie1a4cda4188f45b4bf92d0549d5c8fb401a30e5d Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/301300
Diffstat (limited to 'core/cortex-m/task.c')
-rw-r--r--core/cortex-m/task.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/core/cortex-m/task.c b/core/cortex-m/task.c
index f7fbfded19..510e4cba32 100644
--- a/core/cortex-m/task.c
+++ b/core/cortex-m/task.c
@@ -266,7 +266,7 @@ void svc_handler(int desched, task_id_t resched)
tasks_ready |= 1 << resched;
ASSERT(tasks_ready);
- next = __task_id_to_ptr(31 - __builtin_clz(tasks_ready));
+ next = __task_id_to_ptr(__fls(tasks_ready));
#ifdef CONFIG_TASK_PROFILING
/* Track time in interrupts */
@@ -536,11 +536,11 @@ void mutex_unlock(struct mutex *mtx)
: "r" (&mtx->lock), "r" (&mtx->waiters), "r" (0)
: "cc");
while (waiters) {
- task_id_t id = 31 - __builtin_clz(waiters);
+ task_id_t id = __fls(waiters);
+ waiters &= ~(1 << id);
/* Somebody is waiting on the mutex */
task_set_event(id, TASK_EVENT_MUTEX, 0);
- waiters &= ~(1 << id);
}
/* Ensure no event is remaining from mutex wake-up */