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 2016/03/20 22:35:04 UTC

lucy-clownfish git commit: Rework rounding in Memory_oversize

Repository: lucy-clownfish
Updated Branches:
  refs/heads/master c1ed8ee70 -> 39b0cb0c4


Rework rounding in Memory_oversize

Fixes -Wconversion warning on 32-bit.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/39b0cb0c
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/39b0cb0c
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/39b0cb0c

Branch: refs/heads/master
Commit: 39b0cb0c48bc122a3854dd2ccb7332c41d7e9db6
Parents: c1ed8ee
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sun Mar 20 22:20:54 2016 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sun Mar 20 22:26:44 2016 +0100

----------------------------------------------------------------------
 runtime/core/Clownfish/Test/Util/TestMemory.c |  2 +-
 runtime/core/Clownfish/Util/Memory.c          | 51 +++++++++++-----------
 2 files changed, 27 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/39b0cb0c/runtime/core/Clownfish/Test/Util/TestMemory.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/Util/TestMemory.c b/runtime/core/Clownfish/Test/Util/TestMemory.c
index 2800708..8151c72 100644
--- a/runtime/core/Clownfish/Test/Util/TestMemory.c
+++ b/runtime/core/Clownfish/Test/Util/TestMemory.c
@@ -98,7 +98,7 @@ test_oversize__rounding(TestBatchRunner *runner) {
         for (unsigned i = 0; i < 25; i++) {
             size_t size = Memory_oversize(i, width);
             size_t bytes = size * width;
-            if (bytes % sizeof(void*) != 0) {
+            if (bytes % sizeof(size_t) != 0) {
                 FAIL(runner, "Rounding failure for %u, width %u",
                      i, width);
                 return;

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/39b0cb0c/runtime/core/Clownfish/Util/Memory.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Util/Memory.c b/runtime/core/Clownfish/Util/Memory.c
index 66f7291..2ab4486 100644
--- a/runtime/core/Clownfish/Util/Memory.c
+++ b/runtime/core/Clownfish/Util/Memory.c
@@ -77,33 +77,34 @@ Memory_oversize(size_t minimum, size_t width) {
 
     // Round up for small widths so that the number of bytes requested will be
     // a multiple of the machine's word size.
-    if (sizeof(size_t) == 8) { // 64-bit
-        switch (width) {
-            case 1:
-                amount = (amount + 7) & INT64_C(0xFFFFFFFFFFFFFFF8);
-                break;
-            case 2:
-                amount = (amount + 3) & INT64_C(0xFFFFFFFFFFFFFFFC);
-                break;
-            case 4:
-                amount = (amount + 1) & INT64_C(0xFFFFFFFFFFFFFFFE);
-                break;
-            default:
-                break;
-        }
+#if CHY_SIZEOF_SIZE_T == 8
+    // 64-bit
+    switch (width) {
+        case 1:
+            amount = (amount + 7) & ~(size_t)7;
+            break;
+        case 2:
+            amount = (amount + 3) & ~(size_t)3;
+            break;
+        case 4:
+            amount = (amount + 1) & ~(size_t)1;
+            break;
+        default:
+            break;
     }
-    else { // 32-bit
-        switch (width) {
-            case 1:
-                amount = (amount + 3) & ((size_t)0xFFFFFFFC);
-                break;
-            case 2:
-                amount = (amount + 1) & ((size_t)0xFFFFFFFE);
-                break;
-            default:
-                break;
-        }
+#else /* CHY_SIZEOF_SIZE_T == 8 */
+    // 32-bit
+    switch (width) {
+        case 1:
+            amount = (amount + 3) & ~(size_t)3;
+            break;
+        case 2:
+            amount = (amount + 1) & ~(size_t)1;
+            break;
+        default:
+            break;
     }
+#endif /* CHY_SIZEOF_SIZE_T == 8 */
 
     return amount;
 }