From 726d41838408ab4bd057bc2ae888c757e21f96e1 Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Mon, 11 May 2009 18:21:03 -0400 Subject: [PATCH] Changed divisions to shifts, there were only divisions by 2 or 4. [pflanze@gmx.ch: split original patch into two separate patches, this being the first one] Signed-off-by: Christian Jaeger --- gc.c | 12 ++++++------ picobit-vm.c | 8 ++++---- primitives.c | 18 +++++++++--------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/gc.c b/gc.c index 5c1a95d..daf57b2 100644 --- a/gc.c +++ b/gc.c @@ -12,7 +12,7 @@ void init_ram_heap (void) { free_list = 0; - while (o > (MIN_RAM_ENCODING + (glovars + 1) / 2)) { + while (o > (MIN_RAM_ENCODING + (glovars + 1) >> 1)) { // we don't want to add globals to the free list, and globals occupy the // beginning of memory at the rate of 2 globals per word (car and cdr) ram_set_gc_tags (o, GC_TAG_UNMARKED); @@ -26,7 +26,7 @@ void init_ram_heap (void) { // each node of the free list must know the free length that follows it // this free length is stored in words, not in bytes // if we did count in bytes, the number might need more than 13 bits - ram_set_cdr (free_list_vec, VEC_BYTES / 4); + ram_set_cdr (free_list_vec, VEC_BYTES >> 2); for (i=0; i= (MIN_RAM_ENCODING + ((glovars + 1) / 2))) { + while (visit >= (MIN_RAM_ENCODING + ((glovars + 1) >> 1))) { // we don't want to sweep the global variables area if ((RAM_COMPOSITE(visit) && (ram_get_gc_tags (visit) == GC_TAG_UNMARKED)) // 2 mark bit @@ -179,7 +179,7 @@ void sweep (void) { obj o = ram_get_cdr (visit); uint16 i = ram_get_car (visit); // number of elements ram_set_car (o, free_list_vec); - ram_set_cdr (o, (i + 3) / 4); // free length, in words + ram_set_cdr (o, (i + 3) >> 2); // free length, in words free_list_vec = o; // TODO merge free spaces } @@ -304,13 +304,13 @@ obj alloc_vec_cell (uint16 n) { // case 2 : there is still some space left in the free section, create a new // node to represent this space else { - obj new_free = o + (n + 3)/4; + obj new_free = o + (n + 3) >> 2; if (prec) ram_set_car (prec, new_free); else free_list_vec = new_free; ram_set_car (new_free, ram_get_car (o)); - ram_set_cdr (new_free, ram_get_cdr (o) - (n + 3)/4); + ram_set_cdr (new_free, ram_get_cdr (o) - (n + 3) >> 2); } return o; diff --git a/picobit-vm.c b/picobit-vm.c index b9d1767..fa1e4b4 100644 --- a/picobit-vm.c +++ b/picobit-vm.c @@ -130,15 +130,15 @@ obj rom_get_entry (obj o){ obj get_global (uint8 i) { // globals occupy the beginning of ram, with 2 globals per word if (i & 1) - return ram_get_cdr (MIN_RAM_ENCODING + (i / 2)); + return ram_get_cdr (MIN_RAM_ENCODING + (i >> 1)); else - return ram_get_car (MIN_RAM_ENCODING + (i / 2)); + return ram_get_car (MIN_RAM_ENCODING + (i >> 1)); } void set_global (uint8 i, obj o) { if (i & 1) - ram_set_cdr (MIN_RAM_ENCODING + (i / 2), o); + ram_set_cdr (MIN_RAM_ENCODING + (i >> 1), o); else - ram_set_car (MIN_RAM_ENCODING + (i / 2), o); + ram_set_car (MIN_RAM_ENCODING + (i >> 1), o); } // TODO generic functions (get_field0, get_car, etc) that work for both rom and ram were not used, are in garbage diff --git a/primitives.c b/primitives.c index f0a853c..59999c3 100644 --- a/primitives.c +++ b/primitives.c @@ -366,7 +366,7 @@ void prim_make_u8vector (void) { VECTOR_FIELD2 | (arg3 >> 8), arg3 & 0xff); - a1 = (a1 + 3) / 4; // actual length, in words + a1 = (a1 + 3) >> 2; // actual length, in words while (a1--) { ram_set_field0 (arg3, a2); ram_set_field1 (arg3, a2); @@ -397,7 +397,7 @@ void prim_u8vector_ref (void) { TYPE_ERROR("u8vector-ref.2", "vector"); if (IN_VEC(arg1)) { - arg1 += (a2 / 4); + arg1 += (a2 >> 2); a2 %= 4; arg1 = encode_int (ram_get_fieldn (arg1, a2)); @@ -432,7 +432,7 @@ void prim_u8vector_set (void) { // TODO a lot in common with ref, abstract that else TYPE_ERROR("u8vector-set!.1", "vector"); - arg1 += (a2 / 4); + arg1 += (a2 >> 2); a2 %= 4; ram_set_fieldn (arg1, a2, a3); @@ -475,10 +475,10 @@ void prim_u8vector_copy (void) { // position to the start arg1 = ram_get_cdr (arg1); - arg1 += (a1 / 4); + arg1 += (a1 >> 2); a1 %= 4; arg3 = ram_get_cdr (arg3); - arg3 += (a2 / 4); + arg3 += (a2 >> 2); a2 %= 4; // copy @@ -486,10 +486,10 @@ void prim_u8vector_copy (void) { ram_set_fieldn (arg3, a2, ram_get_fieldn (arg1, a1)); a1++; - arg1 += (a1 / 4); + arg1 += (a1 >> 2); a1 %= 4; // TODO merge with the previous similar block ? a2++; - arg3 += (a2 / 4); + arg3 += (a2 >> 2); a2 %= 4; } } @@ -506,7 +506,7 @@ void prim_u8vector_copy (void) { arg1 = rom_get_cdr (arg1); arg3 = ram_get_cdr (arg3); - arg3 += (a2 / 4); + arg3 += (a2 >> 2); a2 %= 4; while (a3--) { @@ -514,7 +514,7 @@ void prim_u8vector_copy (void) { arg1 = rom_get_cdr (arg1); a2++; - arg3 += (a2 / 4); + arg3 += (a2 >> 2); a2 %= 4; // TODO very similar to the other case } } -- 2.11.4.GIT