]> granicus.if.org Git - gc/commitdiff
Fix comment about inv_sz computation in setup_header
authorIvan Maidanski <ivmai@mail.ru>
Thu, 14 Jun 2018 08:50:03 +0000 (11:50 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 17 Jul 2018 06:03:56 +0000 (09:03 +0300)
(a cherry-pick of commit e55f4632 from 'master')

* allchblk.c [MARK_BIT_PER_OBJ] (setup_header): Fix comment
(sz*inv_sz>=2**32).
* allchblk.c [MARK_BIT_PER_OBJ && INV_SZ_COMPUTATION_CHECK]
(setup_header): Add assertion to check the computation of inv_sz.

allchblk.c

index b86aadcc59ee01cf9251f365dbce46d7b39b0e94..5e348c2289e1454fa55bbf373b589c7929a5b069 100644 (file)
@@ -248,7 +248,7 @@ static GC_bool setup_header(hdr * hhdr, struct hblk *block, size_t byte_sz,
 
 #   ifdef MARK_BIT_PER_OBJ
      /* Set hb_inv_sz as portably as possible.                          */
-     /* We set it to the smallest value such that sz * inv_sz > 2**32    */
+     /* We set it to the smallest value such that sz * inv_sz >= 2**32  */
      /* This may be more precision than necessary.                      */
       if (byte_sz > MAXOBJBYTES) {
          hhdr -> hb_inv_sz = LARGE_INV_SZ;
@@ -263,6 +263,9 @@ static GC_bool setup_header(hdr * hhdr, struct hblk *block, size_t byte_sz,
           inv_sz = ((unsigned)1 << 31)/byte_sz;
           inv_sz *= 2;
           while (inv_sz*byte_sz > byte_sz) ++inv_sz;
+#       endif
+#       ifdef INV_SZ_COMPUTATION_CHECK
+          GC_ASSERT(((1ULL << 32) + byte_sz - 1) / byte_sz == inv_sz);
 #       endif
         hhdr -> hb_inv_sz = inv_sz;
       }