circular_queue.hh (13487:ed055875261d) circular_queue.hh (13796:ca1eed45ebe5)
1/*
2 * Copyright (c) 2017-2018 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 92 unchanged lines hidden (view full) ---

101 {
102 return (op1 + op2) % size;
103 }
104
105 /** General modular subtraction. */
106 static uint32_t
107 moduloSub(uint32_t op1, uint32_t op2, uint32_t size)
108 {
1/*
2 * Copyright (c) 2017-2018 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 92 unchanged lines hidden (view full) ---

101 {
102 return (op1 + op2) % size;
103 }
104
105 /** General modular subtraction. */
106 static uint32_t
107 moduloSub(uint32_t op1, uint32_t op2, uint32_t size)
108 {
109 int ret = (uint32_t)(op1 - op2) % size;
109 int32_t ret = sub(op1, op2, size);
110 return ret >= 0 ? ret : ret + size;
111 }
112
110 return ret >= 0 ? ret : ret + size;
111 }
112
113 static int32_t
114 sub(uint32_t op1, uint32_t op2, uint32_t size)
115 {
116 if (op1 > op2)
117 return (op1 - op2) % size;
118 else
119 return -((op2 - op1) % size);
120 }
121
113 void increase(uint32_t& v, size_t delta = 1)
114 {
115 v = moduloAdd(v, delta, _capacity);
116 }
117
118 void decrease(uint32_t& v)
119 {
120 v = (v ? v : _capacity) - 1;

--- 229 unchanged lines hidden (view full) ---

350 }
351
352 /** Difference operator.
353 * that + ret == this
354 */
355 difference_type operator-(const iterator& that)
356 {
357 /* If a is already at the end, we can safely return 0. */
122 void increase(uint32_t& v, size_t delta = 1)
123 {
124 v = moduloAdd(v, delta, _capacity);
125 }
126
127 void decrease(uint32_t& v)
128 {
129 v = (v ? v : _capacity) - 1;

--- 229 unchanged lines hidden (view full) ---

359 }
360
361 /** Difference operator.
362 * that + ret == this
363 */
364 difference_type operator-(const iterator& that)
365 {
366 /* If a is already at the end, we can safely return 0. */
358 auto ret = _cq->moduloSub(this->_idx, that._idx);
367 auto ret = _cq->sub(this->_idx, that._idx, _cq->capacity());
359
368
360 if (ret == 0 && this->_round != that._round) {
361 ret += this->_round * _cq->capacity();
369 if (this->_round != that._round) {
370 ret += ((this->_round - that._round) * _cq->capacity());
362 }
363 return ret;
364 }
365
366 /** Index operator.
367 * The use of * tests for dereferenceability.
368 */
369 template<typename Idx>

--- 274 unchanged lines hidden ---
371 }
372 return ret;
373 }
374
375 /** Index operator.
376 * The use of * tests for dereferenceability.
377 */
378 template<typename Idx>

--- 274 unchanged lines hidden ---