You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2017/02/04 17:53:26 UTC
[3/7] lucy git commit: Optimize NumUtil_encode_bigend_* functions
Optimize NumUtil_encode_bigend_* functions
Make GCC generate bswap instructions. For details see:
http://stackoverflow.com/q/36497605
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/2c43cf0d
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/2c43cf0d
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/2c43cf0d
Branch: refs/heads/master
Commit: 2c43cf0d0922812d5178cc085502a4f09d221905
Parents: a923dd3
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Fri Feb 3 14:34:07 2017 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Fri Feb 3 14:53:03 2017 +0100
----------------------------------------------------------------------
core/Lucy/Util/NumberUtils.cfh | 50 ++++++++++++++++---------------------
1 file changed, 21 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/2c43cf0d/core/Lucy/Util/NumberUtils.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/NumberUtils.cfh b/core/Lucy/Util/NumberUtils.cfh
index b2bd04a..5ecf7fa 100644
--- a/core/Lucy/Util/NumberUtils.cfh
+++ b/core/Lucy/Util/NumberUtils.cfh
@@ -217,48 +217,40 @@ lucy_NumUtil_is_bigend() {
static CFISH_INLINE void
lucy_NumUtil_encode_bigend_u16(uint16_t value, void *dest_ptr) {
uint8_t *dest = *(uint8_t**)dest_ptr;
- if (lucy_NumUtil_is_bigend()) {
- memcpy(dest, &value, sizeof(uint16_t));
- }
- else {
- uint8_t *source = (uint8_t*)&value;
- dest[0] = source[1];
- dest[1] = source[0];
+ if (!lucy_NumUtil_is_bigend()) {
+ value = ((value & 0xFF00) >> 8) | ((value & 0x00FF) << 8);
}
+ memcpy(dest, &value, sizeof(uint16_t));
}
static CFISH_INLINE void
lucy_NumUtil_encode_bigend_u32(uint32_t value, void *dest_ptr) {
uint8_t *dest = *(uint8_t**)dest_ptr;
- if (lucy_NumUtil_is_bigend()) {
- memcpy(dest, &value, sizeof(uint32_t));
- }
- else {
- uint8_t *source = (uint8_t*)&value;
- dest[0] = source[3];
- dest[1] = source[2];
- dest[2] = source[1];
- dest[3] = source[0];
+ if (!lucy_NumUtil_is_bigend()) {
+ value =
+ ((value & 0xFF000000) >> 24) |
+ ((value & 0x00FF0000) >> 8) |
+ ((value & 0x0000FF00) << 8) |
+ ((value & 0x000000FF) << 24);
}
+ memcpy(dest, &value, sizeof(uint32_t));
}
static CFISH_INLINE void
lucy_NumUtil_encode_bigend_u64(uint64_t value, void *dest_ptr) {
uint8_t *dest = *(uint8_t**)dest_ptr;
- if (lucy_NumUtil_is_bigend()) {
- memcpy(dest, &value, sizeof(uint64_t));
- }
- else {
- uint8_t *source = (uint8_t*)&value;
- dest[0] = source[7];
- dest[1] = source[6];
- dest[2] = source[5];
- dest[3] = source[4];
- dest[4] = source[3];
- dest[5] = source[2];
- dest[6] = source[1];
- dest[7] = source[0];
+ if (!lucy_NumUtil_is_bigend()) {
+ value =
+ ((value & 0xFF00000000000000) >> 56) |
+ ((value & 0x00FF000000000000) >> 40) |
+ ((value & 0x0000FF0000000000) >> 24) |
+ ((value & 0x000000FF00000000) >> 8) |
+ ((value & 0x00000000FF000000) << 8) |
+ ((value & 0x0000000000FF0000) << 24) |
+ ((value & 0x000000000000FF00) << 40) |
+ ((value & 0x00000000000000FF) << 56);
}
+ memcpy(dest, &value, sizeof(uint64_t));
}
static CFISH_INLINE uint16_t