Replaced lfs_swap16/swap32/sswap16/etc with a macro
Seems the best way to do this in standard C.
No code changes:
code stack
before: 33886 2560
after: 33886 (+0.0%) 2560 (+0.0%)
This commit is contained in:
@@ -2921,7 +2921,7 @@ trunk:;
|
|||||||
&alt, &weight,
|
&alt, &weight,
|
||||||
p[0].alt, p[0].weight,
|
p[0].alt, p[0].weight,
|
||||||
lower_rid, upper_rid);
|
lower_rid, upper_rid);
|
||||||
lfs_swap32(&jump, &branch_);
|
LFS_SWAP(lfs_size_t, &jump, &branch_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// should've taken red alt? needs a flip
|
// should've taken red alt? needs a flip
|
||||||
@@ -2935,9 +2935,9 @@ trunk:;
|
|||||||
p[0].alt, p[0].weight,
|
p[0].alt, p[0].weight,
|
||||||
lower_rid, upper_rid,
|
lower_rid, upper_rid,
|
||||||
a_rid, a_tag)) {
|
a_rid, a_tag)) {
|
||||||
lfs_swap16(&p[0].alt, &alt);
|
LFS_SWAP(lfsr_tag_t, &p[0].alt, &alt);
|
||||||
lfs_swap32(&p[0].weight, &weight);
|
LFS_SWAP(lfsr_rid_t, &p[0].weight, &weight);
|
||||||
lfs_swap32(&p[0].jump, &jump);
|
LFS_SWAP(lfs_size_t, &p[0].jump, &jump);
|
||||||
alt = (alt & ~LFSR_TAG_R) | (p[0].alt & LFSR_TAG_R);
|
alt = (alt & ~LFSR_TAG_R) | (p[0].alt & LFSR_TAG_R);
|
||||||
p[0].alt |= LFSR_TAG_R;
|
p[0].alt |= LFSR_TAG_R;
|
||||||
|
|
||||||
@@ -2945,7 +2945,7 @@ trunk:;
|
|||||||
&alt, &weight,
|
&alt, &weight,
|
||||||
p[0].alt, p[0].weight,
|
p[0].alt, p[0].weight,
|
||||||
lower_rid, upper_rid);
|
lower_rid, upper_rid);
|
||||||
lfs_swap32(&jump, &branch_);
|
LFS_SWAP(lfs_size_t, &jump, &branch_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// do bounds want to take different paths? begin diverging
|
// do bounds want to take different paths? begin diverging
|
||||||
@@ -3125,9 +3125,9 @@ trunk:;
|
|||||||
// 1 2 3 4 1 2 3 4 1
|
// 1 2 3 4 1 2 3 4 1
|
||||||
if (branch_ < branch) {
|
if (branch_ < branch) {
|
||||||
if (jump > branch) {
|
if (jump > branch) {
|
||||||
lfs_swap16(&p[0].alt, &alt);
|
LFS_SWAP(lfsr_tag_t, &p[0].alt, &alt);
|
||||||
lfs_swap32(&p[0].weight, &weight);
|
LFS_SWAP(lfsr_rid_t, &p[0].weight, &weight);
|
||||||
lfs_swap32(&p[0].jump, &jump);
|
LFS_SWAP(lfs_size_t, &p[0].jump, &jump);
|
||||||
}
|
}
|
||||||
alt &= ~LFSR_TAG_R;
|
alt &= ~LFSR_TAG_R;
|
||||||
|
|
||||||
@@ -3173,7 +3173,7 @@ trunk:;
|
|||||||
&alt, &weight,
|
&alt, &weight,
|
||||||
p[0].alt, p[0].weight,
|
p[0].alt, p[0].weight,
|
||||||
lower_rid, upper_rid);
|
lower_rid, upper_rid);
|
||||||
lfs_swap32(&jump, &branch_);
|
LFS_SWAP(lfs_size_t, &jump, &branch_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// black alt? terminate 2-3-4 nodes
|
// black alt? terminate 2-3-4 nodes
|
||||||
@@ -3232,8 +3232,8 @@ trunk:;
|
|||||||
// swap tag/rid and move on to upper trunk
|
// swap tag/rid and move on to upper trunk
|
||||||
diverged = false;
|
diverged = false;
|
||||||
branch = trunk_;
|
branch = trunk_;
|
||||||
lfs_swap16(&a_tag, &b_tag);
|
LFS_SWAP(lfsr_tag_t, &a_tag, &b_tag);
|
||||||
lfs_sswap32(&a_rid, &b_rid);
|
LFS_SWAP(lfsr_srid_t, &a_rid, &b_rid);
|
||||||
goto trunk;
|
goto trunk;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -3580,8 +3580,8 @@ static lfs_ssize_t lfsr_rbyd_estimate(lfs_t *lfs, const lfsr_rbyd_t *rbyd,
|
|||||||
if (a_dsize > b_dsize
|
if (a_dsize > b_dsize
|
||||||
// bias so lower dsize >= upper dsize
|
// bias so lower dsize >= upper dsize
|
||||||
|| (a_dsize == b_dsize && a_rid > b_rid)) {
|
|| (a_dsize == b_dsize && a_rid > b_rid)) {
|
||||||
lfs_sswap32(&a_rid, &b_rid);
|
LFS_SWAP(lfsr_srid_t, &a_rid, &b_rid);
|
||||||
lfs_swap32(&a_dsize, &b_dsize);
|
LFS_SWAP(lfs_size_t, &a_dsize, &b_dsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a_rid > b_rid) {
|
if (a_rid > b_rid) {
|
||||||
@@ -5754,8 +5754,8 @@ static int lfsr_mdir_fetch(lfs_t *lfs, lfsr_mdir_t *mdir,
|
|||||||
if (i == 0
|
if (i == 0
|
||||||
|| err == LFS_ERR_CORRUPT
|
|| err == LFS_ERR_CORRUPT
|
||||||
|| lfs_scmp(revs[1], revs[0]) > 0) {
|
|| lfs_scmp(revs[1], revs[0]) > 0) {
|
||||||
lfs_swap32(&blocks_[0], &blocks_[1]);
|
LFS_SWAP(lfs_block_t, &blocks_[0], &blocks_[1]);
|
||||||
lfs_swap32(&revs[0], &revs[1]);
|
LFS_SWAP(uint32_t, &revs[0], &revs[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5773,8 +5773,8 @@ static int lfsr_mdir_fetch(lfs_t *lfs, lfsr_mdir_t *mdir,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
lfs_swap32(&blocks_[0], &blocks_[1]);
|
LFS_SWAP(lfs_block_t, &blocks_[0], &blocks_[1]);
|
||||||
lfs_swap32(&revs[0], &revs[1]);
|
LFS_SWAP(uint32_t, &revs[0], &revs[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// could not find a non-corrupt rbyd
|
// could not find a non-corrupt rbyd
|
||||||
@@ -6386,8 +6386,8 @@ static lfs_ssize_t lfsr_mdir_estimate__(lfs_t *lfs, const lfsr_mdir_t *mdir,
|
|||||||
if (a_dsize > b_dsize
|
if (a_dsize > b_dsize
|
||||||
// bias so lower dsize >= upper dsize
|
// bias so lower dsize >= upper dsize
|
||||||
|| (a_dsize == b_dsize && a_rid > b_rid)) {
|
|| (a_dsize == b_dsize && a_rid > b_rid)) {
|
||||||
lfs_sswap32(&a_rid, &b_rid);
|
LFS_SWAP(lfsr_srid_t, &a_rid, &b_rid);
|
||||||
lfs_swap32(&a_dsize, &b_dsize);
|
LFS_SWAP(lfs_size_t, &a_dsize, &b_dsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a_rid > b_rid) {
|
if (a_rid > b_rid) {
|
||||||
|
|||||||
+9
-26
@@ -193,32 +193,15 @@ static inline int32_t lfs_abs32(int32_t a) {
|
|||||||
return (a < 0) ? -a : a;
|
return (a < 0) ? -a : a;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO how many of these do we actually need
|
// Swap two variables
|
||||||
// Swap two 16-bit numbers
|
#define LFS_SWAP(_t, _a, _b) \
|
||||||
static inline void lfs_swap16(uint16_t *a, uint16_t *b) {
|
do { \
|
||||||
uint16_t t = *a;
|
_t *a = _a; \
|
||||||
*a = *b;
|
_t *b = _b; \
|
||||||
*b = t;
|
_t t = *a; \
|
||||||
}
|
*a = *b; \
|
||||||
|
*b = t; \
|
||||||
static inline void lfs_sswap16(int16_t *a, int16_t *b) {
|
} while (0)
|
||||||
int16_t t = *a;
|
|
||||||
*a = *b;
|
|
||||||
*b = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Swap two 32-bit numbers
|
|
||||||
static inline void lfs_swap32(uint32_t *a, uint32_t *b) {
|
|
||||||
uint32_t t = *a;
|
|
||||||
*a = *b;
|
|
||||||
*b = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void lfs_sswap32(int32_t *a, int32_t *b) {
|
|
||||||
int32_t t = *a;
|
|
||||||
*a = *b;
|
|
||||||
*b = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Align to nearest multiple of a size
|
// Align to nearest multiple of a size
|
||||||
static inline uint32_t lfs_aligndown(uint32_t a, uint32_t alignment) {
|
static inline uint32_t lfs_aligndown(uint32_t a, uint32_t alignment) {
|
||||||
|
|||||||
Reference in New Issue
Block a user