summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorNamyoon Woo <namyoon@chromium.org>2019-04-17 12:54:48 -0700
committerCommit Bot <commit-bot@chromium.org>2019-08-02 17:47:47 +0000
commit7893aa27fe69ead0ad53b91edbe48af8d691b204 (patch)
tree40afab6aeb7ccf0bbc164f52a85044b60381f316 /common
parente77a5b00a40e6c43a4f04346cb5128f7055d1d50 (diff)
downloadchrome-ec-7893aa27fe69ead0ad53b91edbe48af8d691b204.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> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1719555 Reviewed-by: Edward Hill <ecgh@chromium.org> Tested-by: Edward Hill <ecgh@chromium.org> Commit-Queue: Edward Hill <ecgh@chromium.org>
Diffstat (limited to 'common')
-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);
}