projects
/
fio.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update documentation
[fio.git]
/
lib
/
lfsr.c
diff --git
a/lib/lfsr.c
b/lib/lfsr.c
index 927b2a10cdeeefc4441a9b7aa720677b6939a9be..0c0072ccb39b15e970eeb6bd92342b67a85cd8bb 100644
(file)
--- a/
lib/lfsr.c
+++ b/
lib/lfsr.c
@@
-2,6
+2,7
@@
#include <math.h>
#include "lfsr.h"
#include <math.h>
#include "lfsr.h"
+#include "../compiler/compiler.h"
/*
* LFSR taps retrieved from:
/*
* LFSR taps retrieved from:
@@
-10,7
+11,7
@@
* The memory overhead of the following tap table should be relatively small,
* no more than 400 bytes.
*/
* The memory overhead of the following tap table should be relatively small,
* no more than 400 bytes.
*/
-static uint8_t taps[64][FIO_MAX_TAPS] =
+static uint8_t
lfsr_
taps[64][FIO_MAX_TAPS] =
{
{0}, {0}, {0}, //LFSRs with less that 3-bits cannot exist
{3, 2}, //Tap position for 3-bit LFSR
{
{0}, {0}, {0}, //LFSRs with less that 3-bits cannot exist
{3, 2}, //Tap position for 3-bit LFSR
@@
-123,7
+124,7
@@
static inline void __lfsr_next(struct fio_lfsr *fl, unsigned int spin)
* c. Check if the calculated value exceeds the desirable range. In this case,
* go back to b, else return.
*/
* c. Check if the calculated value exceeds the desirable range. In this case,
* go back to b, else return.
*/
-int lfsr_next(struct fio_lfsr *fl, uint64_t *off
, uint64_t last
)
+int lfsr_next(struct fio_lfsr *fl, uint64_t *off)
{
if (fl->num_vals++ > fl->max_val)
return 1;
{
if (fl->num_vals++ > fl->max_val)
return 1;
@@
-132,11
+133,9
@@
int lfsr_next(struct fio_lfsr *fl, uint64_t *off, uint64_t last)
if (fl->cycle_length && !--fl->cycle_length) {
__lfsr_next(fl, fl->spin + 1);
fl->cycle_length = fl->cached_cycle_length;
if (fl->cycle_length && !--fl->cycle_length) {
__lfsr_next(fl, fl->spin + 1);
fl->cycle_length = fl->cached_cycle_length;
- goto check;
- }
- __lfsr_next(fl, fl->spin);
-check: ;
- } while (fl->last_val > fl->max_val);
+ } else
+ __lfsr_next(fl, fl->spin);
+ } while (fio_unlikely(fl->last_val > fl->max_val));
*off = fl->last_val;
return 0;
*off = fl->last_val;
return 0;
@@
-159,12
+158,12
@@
static uint8_t *find_lfsr(uint64_t size)
/*
* For an LFSR, there is always a prohibited state (all ones).
/*
* For an LFSR, there is always a prohibited state (all ones).
- * Thus, if we need to find the proper LFSR for our size, we must
take that
- * into account.
+ * Thus, if we need to find the proper LFSR for our size, we must
+ *
take that
into account.
*/
for (i = 3; i < 64; i++)
if ((1UL << i) > size)
*/
for (i = 3; i < 64; i++)
if ((1UL << i) > size)
- return taps[i];
+ return
lfsr_
taps[i];
return NULL;
}
return NULL;
}
@@
-187,7
+186,7
@@
static uint8_t *find_lfsr(uint64_t size)
* Thus, [1] is equivalent to (y * i) % (spin + 1) == 0;
* Also, the cycle's length will be (x * i) + (y * i) / (spin + 1)
*/
* Thus, [1] is equivalent to (y * i) % (spin + 1) == 0;
* Also, the cycle's length will be (x * i) + (y * i) / (spin + 1)
*/
-int prepare_spin(struct fio_lfsr *fl, unsigned int spin)
+
static
int prepare_spin(struct fio_lfsr *fl, unsigned int spin)
{
uint64_t max = (fl->cached_bit << 1) - 1;
uint64_t x, y;
{
uint64_t max = (fl->cached_bit << 1) - 1;
uint64_t x, y;
@@
-235,15
+234,15
@@
int lfsr_reset(struct fio_lfsr *fl, unsigned long seed)
int lfsr_init(struct fio_lfsr *fl, uint64_t nums, unsigned long seed,
unsigned int spin)
{
int lfsr_init(struct fio_lfsr *fl, uint64_t nums, unsigned long seed,
unsigned int spin)
{
- uint8_t *
lfsr_
taps;
+ uint8_t *taps;
-
lfsr_
taps = find_lfsr(nums);
- if (!
lfsr_
taps)
+ taps = find_lfsr(nums);
+ if (!taps)
return 1;
fl->max_val = nums - 1;
return 1;
fl->max_val = nums - 1;
- fl->xormask = lfsr_create_xormask(
lfsr_
taps);
- fl->cached_bit = 1UL << (
lfsr_
taps[0] - 1);
+ fl->xormask = lfsr_create_xormask(taps);
+ fl->cached_bit = 1UL << (taps[0] - 1);
if (prepare_spin(fl, spin))
return 1;
if (prepare_spin(fl, spin))
return 1;