summaryrefslogtreecommitdiff
path: root/common/queue.c
diff options
context:
space:
mode:
authorNamyoon Woo <namyoon@chromium.org>2019-04-17 12:54:48 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-05-02 21:02:52 -0700
commit8e8dd8a8e4a0556b67f2ceed6b0fe1547989d924 (patch)
tree94d57fdffce3c138813fcc38cd84f3fd674df880 /common/queue.c
parent781170c47b6078e1f9588d2b3fa1c23d208b0e88 (diff)
downloadchrome-ec-8e8dd8a8e4a0556b67f2ceed6b0fe1547989d924.tar.gz
cr50: add buffer_units_mask member into struct queue
"q->buffer_units - 1" is performed many times to wrap head and/or tail. It should be calculated once. BUG=None BRANCH=cr50 TEST=None Change-Id: I9714147d5a97afd7aaba00d31a8b10bad50d0942 Signed-off-by: Namyoon Woo <namyoon@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1572444 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Diffstat (limited to 'common/queue.c')
-rw-r--r--common/queue.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/common/queue.c b/common/queue.c
index 67934ca74e..584d0fbdfa 100644
--- a/common/queue.c
+++ b/common/queue.c
@@ -70,8 +70,8 @@ int queue_is_full(struct queue const *q)
struct queue_chunk queue_get_write_chunk(struct queue const *q)
{
- size_t head = q->state->head & (q->buffer_units - 1);
- size_t tail = q->state->tail & (q->buffer_units - 1);
+ size_t head = q->state->head & q->buffer_units_mask;
+ size_t tail = q->state->tail & q->buffer_units_mask;
size_t last = (queue_is_full(q) ? tail : /* Full */
((tail < head) ? head : /* Wrapped */
q->buffer_units)); /* Normal | Empty */
@@ -84,8 +84,8 @@ struct queue_chunk queue_get_write_chunk(struct queue const *q)
struct queue_chunk queue_get_read_chunk(struct queue const *q)
{
- size_t head = q->state->head & (q->buffer_units - 1);
- size_t tail = q->state->tail & (q->buffer_units - 1);
+ size_t head = q->state->head & q->buffer_units_mask;
+ size_t tail = q->state->tail & q->buffer_units_mask;
size_t last = (queue_is_empty(q) ? head : /* Empty */
((head < tail) ? tail : /* Normal */
q->buffer_units)); /* Wrapped | Full */
@@ -120,7 +120,7 @@ size_t queue_advance_tail(struct queue const *q, size_t count)
size_t queue_add_unit(struct queue const *q, const void *src)
{
- size_t tail = q->state->tail & (q->buffer_units - 1);
+ size_t tail = q->state->tail & q->buffer_units_mask;
if (queue_space(q) == 0)
return 0;
@@ -146,7 +146,7 @@ size_t queue_add_memcpy(struct queue const *q,
size_t n))
{
size_t transfer = MIN(count, queue_space(q));
- size_t tail = q->state->tail & (q->buffer_units - 1);
+ size_t tail = q->state->tail & q->buffer_units_mask;
size_t first = MIN(transfer, q->buffer_units - tail);
memcpy(q->buffer + tail * q->unit_bytes,
@@ -183,7 +183,7 @@ static void queue_read_safe(struct queue const *q,
size_t queue_remove_unit(struct queue const *q, void *dest)
{
- size_t head = q->state->head & (q->buffer_units - 1);
+ size_t head = q->state->head & q->buffer_units_mask;
if (queue_count(q) == 0)
return 0;
@@ -209,7 +209,7 @@ size_t queue_remove_memcpy(struct queue const *q,
size_t n))
{
size_t transfer = MIN(count, queue_count(q));
- size_t head = q->state->head & (q->buffer_units - 1);
+ size_t head = q->state->head & q->buffer_units_mask;
queue_read_safe(q, dest, head, transfer, memcpy);
@@ -236,7 +236,7 @@ size_t queue_peek_memcpy(struct queue const *q,
size_t transfer = MIN(count, available - i);
if (i < available) {
- size_t head = (q->state->head + i) & (q->buffer_units - 1);
+ size_t head = (q->state->head + i) & q->buffer_units_mask;
queue_read_safe(q, dest, head, transfer, memcpy);
}