]> gitweb.factorcode.org Git - factor.git/commitdiff
vm: minor cleanup
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 8 Nov 2009 12:08:17 +0000 (06:08 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 8 Nov 2009 12:08:17 +0000 (06:08 -0600)
vm/bitwise_hacks.hpp
vm/full_collector.cpp

index 03a6ea5ad0c623ddb667224f4708be7755cad3e8..6cd2a5b6945b56f754a39c382c66a4472969b938 100644 (file)
@@ -1,7 +1,29 @@
 namespace factor
 {
 
-/* These algorithms were snarfed from various places. I did not come up with them myself */
+inline cell log2(cell x)
+{
+       cell n;
+#if defined(FACTOR_X86) || defined(FACTOR_AMD64)
+       asm ("bsr %1, %0;":"=r"(n):"r"(x));
+#elif defined(FACTOR_PPC)
+       asm ("cntlzw %1, %0;":"=r"(n):"r"(x));
+       n = (31 - n);
+#else
+       #error Unsupported CPU
+#endif
+       return n;
+}
+
+inline cell rightmost_clear_bit(cell x)
+{
+       return log2(~x & (x + 1));
+}
+
+inline cell rightmost_set_bit(cell x)
+{
+       return log2(x & -x);
+}
 
 inline cell popcount(cell x)
 {
@@ -24,39 +46,7 @@ inline cell popcount(cell x)
        x = (x       +  (x >> 4)) & k4 ; // put count of each 8 bits into those 8 bits
        x = (x * kf) >> ks; // returns 8 most significant bits of x + (x<<8) + (x<<16) + (x<<24) + ...
 
-       return (cell)x;
-}
-
-inline cell log2(cell x)
-{
-#if defined(FACTOR_X86)
-       cell n;
-       asm ("bsr %1, %0;":"=r"(n):"r"(x));
-#elif defined(FACTOR_AMD64)
-       cell n;
-       asm ("bsr %1, %0;":"=r"(n):"r"(x));
-#else
-       cell n = 0;
-#ifdef FACTOR_64
-       if (x >= (cell)1 << 32) { x >>= 32; n += 32; }
-#endif
-       if (x >= (cell)1 << 16) { x >>= 16; n += 16; }
-       if (x >= (cell)1 <<  8) { x >>=  8; n +=  8; }
-       if (x >= (cell)1 <<  4) { x >>=  4; n +=  4; }
-       if (x >= (cell)1 <<  2) { x >>=  2; n +=  2; }
-       if (x >= (cell)1 <<  1) {           n +=  1; }
-#endif
-       return n;
-}
-
-inline cell rightmost_clear_bit(cell x)
-{
-       return log2(~x & (x + 1));
-}
-
-inline cell rightmost_set_bit(cell x)
-{
-       return log2(x & -x);
+       return x;
 }
 
 }
index 07c410218c2a69682a1691a6c1dbf7e9f0cf0f7c..4edb23cf7301eb505580b0ab87d32cf4a8f85652 100644 (file)
@@ -126,7 +126,7 @@ void factor_vm::collect_full(bool trace_contexts_p)
 {
        collect_mark_impl(trace_contexts_p);
        collect_sweep_impl();
-       if(data->tenured->largest_free_block() <= data->nursery->size + data->aging->size)
+       if(data->low_memory_p())
                collect_compact_impl(trace_contexts_p);
        else
                update_code_heap_words_and_literals();