summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2023-01-20 23:48:21 +0300
committerIvan Maidanski <ivmai@mail.ru>2023-01-24 11:38:44 +0300
commit564274514901f43f9b2e308c96ac8b835026a35d (patch)
treebb9b67c45316ce83acfcb7c2006bb293f3d34e8d
parent9d00bac77558d340d2af1dfbe37829cc16667a06 (diff)
downloadbdwgc-564274514901f43f9b2e308c96ac8b835026a35d.tar.gz
Check highest bit of word using SIGNB instead of cast to signed_word
(refactoring) * allchblk.c (GC_merge_unmapped): Replace overflow check (signed_word)(sz1+sz2)>0 to !((sz1+sz2)&SIGNB). * allchblk.c (GC_freehblk): Likewise. * mark.c (GC_mark_from): Replace (signed_word)descr>=0 expression to !(descr&SIGNB). * ptr_chck.c (GC_is_visible): Likewise.
-rw-r--r--allchblk.c11
-rw-r--r--mark.c2
-rw-r--r--ptr_chck.c2
3 files changed, 7 insertions, 8 deletions
diff --git a/allchblk.c b/allchblk.c
index 85bb9d4e..0b9df79e 100644
--- a/allchblk.c
+++ b/allchblk.c
@@ -537,9 +537,9 @@ GC_INNER void GC_merge_unmapped(void)
next = (struct hblk *)((word)h + size);
GET_HDR(next, nexthdr);
/* Coalesce with successor, if possible */
- if (0 != nexthdr && HBLK_IS_FREE(nexthdr)
- && (signed_word) (size + (nextsize = nexthdr->hb_sz)) > 0
- /* no pot. overflow */) {
+ if (nexthdr != NULL && HBLK_IS_FREE(nexthdr)
+ && !((size + (nextsize = nexthdr -> hb_sz)) & SIGNB)
+ /* no overflow */) {
/* Note that we usually try to avoid adjacent free blocks */
/* that are either both mapped or both unmapped. But that */
/* isn't guaranteed to hold since we remap blocks when we */
@@ -990,8 +990,7 @@ GC_INNER void GC_freehblk(struct hblk *hbp)
prev = GC_free_block_ending_at(hbp);
/* Coalesce with successor, if possible */
if (nexthdr != NULL && HBLK_IS_FREE(nexthdr) && IS_MAPPED(nexthdr)
- && (signed_word)(hhdr -> hb_sz + nexthdr -> hb_sz) > 0
- /* no overflow */) {
+ && !((hhdr -> hb_sz + nexthdr -> hb_sz) & SIGNB) /* no overflow */) {
GC_remove_from_fl(nexthdr);
hhdr -> hb_sz += nexthdr -> hb_sz;
GC_remove_header(next);
@@ -1000,7 +999,7 @@ GC_INNER void GC_freehblk(struct hblk *hbp)
if (prev /* != NULL */) { /* CPPCHECK */
prevhdr = HDR(prev);
if (IS_MAPPED(prevhdr)
- && (signed_word)(hhdr -> hb_sz + prevhdr -> hb_sz) > 0) {
+ && !((hhdr -> hb_sz + prevhdr -> hb_sz) & SIGNB)) {
GC_remove_from_fl(prevhdr);
prevhdr -> hb_sz += hhdr -> hb_sz;
# ifdef USE_MUNMAP
diff --git a/mark.c b/mark.c
index ae8f314f..9f9027d0 100644
--- a/mark.c
+++ b/mark.c
@@ -678,7 +678,7 @@ GC_INNER mse * GC_mark_from(mse *mark_stack_top, mse *mark_stack,
mark_stack_limit, ENV(descr));
continue;
case GC_DS_PER_OBJECT:
- if ((signed_word)descr >= 0) {
+ if (!(descr & SIGNB)) {
/* Descriptor is in the object. */
descr = *(word *)(current_p + descr - GC_DS_PER_OBJECT);
} else {
diff --git a/ptr_chck.c b/ptr_chck.c
index 0cc8a726..a363563a 100644
--- a/ptr_chck.c
+++ b/ptr_chck.c
@@ -240,7 +240,7 @@ GC_API void * GC_CALL GC_is_visible(void *p)
/* For now we just punt. */
break;
case GC_DS_PER_OBJECT:
- if ((signed_word)descr >= 0) {
+ if (!(descr & SIGNB)) {
descr = *(word *)((ptr_t)base + (descr & ~GC_DS_TAGS));
} else {
ptr_t type_descr = *(ptr_t *)base;