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 2015/05/12 20:01:22 UTC
[6/6] lucy-clownfish git commit: Compute NumUtil shifts and masks
directly
Compute NumUtil shifts and masks directly
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/c3cf1b37
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/c3cf1b37
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/c3cf1b37
Branch: refs/heads/master
Commit: c3cf1b373fb7fa7d69b5937197de66ab8d84daa1
Parents: 1e30e5a
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat May 9 17:17:24 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue May 12 19:57:45 2015 +0200
----------------------------------------------------------------------
runtime/core/Clownfish/Util/NumberUtils.c | 34 ------------------------
runtime/core/Clownfish/Util/NumberUtils.cfh | 28 +++++++------------
2 files changed, 10 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c3cf1b37/runtime/core/Clownfish/Util/NumberUtils.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Util/NumberUtils.c b/runtime/core/Clownfish/Util/NumberUtils.c
deleted file mode 100644
index c76b4d9..0000000
--- a/runtime/core/Clownfish/Util/NumberUtils.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define C_CFISH_NUMBERUTILS
-#define CFISH_USE_SHORT_NAMES
-
-#include <string.h>
-
-#include "Clownfish/Util/NumberUtils.h"
-
-const uint8_t NumUtil_u1masks[8] = {
- 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
-};
-
-const uint8_t NumUtil_u2shifts[4] = { 0x0, 0x2, 0x4, 0x6 };
-const uint8_t NumUtil_u2masks[4] = { 0x3, 0xC, 0x30, 0xC0 };
-
-const uint8_t NumUtil_u4shifts[2] = { 0x00, 0x04 };
-const uint8_t NumUtil_u4masks[2] = { 0x0F, 0xF0 };
-
-
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c3cf1b37/runtime/core/Clownfish/Util/NumberUtils.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Util/NumberUtils.cfh b/runtime/core/Clownfish/Util/NumberUtils.cfh
index efab6cb..13b4a92 100644
--- a/runtime/core/Clownfish/Util/NumberUtils.cfh
+++ b/runtime/core/Clownfish/Util/NumberUtils.cfh
@@ -23,12 +23,6 @@ parcel Clownfish;
*/
inert class Clownfish::Util::NumberUtils nickname NumUtil {
- inert const uint8_t[8] u1masks;
- inert const uint8_t[4] u2masks;
- inert const uint8_t[4] u2shifts;
- inert const uint8_t[2] u4masks;
- inert const uint8_t[2] u4shifts;
-
/** Encode an unsigned 16-bit integer as 2 bytes in the buffer provided,
* using big-endian byte order.
*/
@@ -397,7 +391,7 @@ static CFISH_INLINE bool
cfish_NumUtil_u1get(const void *array, uint32_t tick) {
uint8_t *const u8bits = (uint8_t*)array;
const uint32_t byte_offset = tick >> 3;
- const uint8_t mask = cfish_NumUtil_u1masks[tick & 0x7];
+ const uint8_t mask = 1 << (tick & 0x7);
return !((u8bits[byte_offset] & mask) == 0);
}
@@ -405,7 +399,7 @@ static CFISH_INLINE void
cfish_NumUtil_u1set(void *array, uint32_t tick) {
uint8_t *const u8bits = (uint8_t*)array;
const uint32_t byte_offset = tick >> 3;
- const uint8_t mask = cfish_NumUtil_u1masks[tick & 0x7];
+ const uint8_t mask = 1 << (tick & 0x7);
u8bits[byte_offset] |= mask;
}
@@ -413,7 +407,7 @@ static CFISH_INLINE void
cfish_NumUtil_u1clear(void *array, uint32_t tick) {
uint8_t *const u8bits = (uint8_t*)array;
const uint32_t byte_offset = tick >> 3;
- const uint8_t mask = cfish_NumUtil_u1masks[tick & 0x7];
+ const uint8_t mask = 1 << (tick & 0x7);
u8bits[byte_offset] &= ~mask;
}
@@ -421,7 +415,7 @@ static CFISH_INLINE void
cfish_NumUtil_u1flip(void *array, uint32_t tick) {
uint8_t *const u8bits = (uint8_t*)array;
const uint32_t byte_offset = tick >> 3;
- const uint8_t mask = cfish_NumUtil_u1masks[tick & 0x7];
+ const uint8_t mask = 1 << (tick & 0x7);
u8bits[byte_offset] ^= mask;
}
@@ -429,16 +423,15 @@ static CFISH_INLINE uint8_t
cfish_NumUtil_u2get(const void *array, uint32_t tick) {
uint8_t *ints = (uint8_t*)array;
uint8_t byte = ints[(tick >> 2)];
- int shift = cfish_NumUtil_u2shifts[tick & 0x3];
+ int shift = 2 * (tick & 0x3);
return (byte >> shift) & 0x3;
}
static CFISH_INLINE void
cfish_NumUtil_u2set(void *array, uint32_t tick, uint8_t value) {
uint8_t *ints = (uint8_t*)array;
- unsigned sub_tick = tick & 0x3;
- int shift = cfish_NumUtil_u2shifts[sub_tick];
- uint8_t mask = cfish_NumUtil_u2masks[sub_tick];
+ int shift = 2 * (tick & 0x3);
+ uint8_t mask = 0x3 << shift;
uint8_t new_val = value & 0x3;
uint8_t new_bits = new_val << shift;
ints[(tick >> 2)] = (ints[(tick >> 2)] & ~mask) | new_bits;
@@ -449,16 +442,15 @@ static CFISH_INLINE uint8_t
cfish_NumUtil_u4get(const void *array, uint32_t tick) {
uint8_t *ints = (uint8_t*)array;
uint8_t byte = ints[(tick >> 1)];
- int shift = cfish_NumUtil_u4shifts[(tick & 1)];
+ int shift = 4 * (tick & 1);
return (byte >> shift) & 0xF;
}
static CFISH_INLINE void
cfish_NumUtil_u4set(void *array, uint32_t tick, uint8_t value) {
uint8_t *ints = (uint8_t*)array;
- unsigned sub_tick = tick & 0x1;
- int shift = cfish_NumUtil_u4shifts[sub_tick];
- uint8_t mask = cfish_NumUtil_u4masks[sub_tick];
+ int shift = 4 * (tick & 0x1);
+ uint8_t mask = 0xF << shift;
uint8_t new_val = value & 0xF;
uint8_t new_bits = new_val << shift;
ints[(tick >> 1)] = (ints[(tick >> 1)] & ~mask) | new_bits;