wingo pushed a commit to branch wip-whippet
in repository guile.

commit 33aa5230dab63bd4b0255c725a11e2cc8d95ccdd
Author: Andy Wingo <wi...@igalia.com>
AuthorDate: Mon Aug 15 18:30:42 2022 +0200

    Add bdw-inline.h
---
 bdw-inline.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 bdw.h        | 57 +++++----------------------------------------------------
 gc-assert.h  |  2 ++
 semi.h       |  2 --
 4 files changed, 59 insertions(+), 54 deletions(-)

diff --git a/bdw-inline.h b/bdw-inline.h
new file mode 100644
index 000000000..511c86d5f
--- /dev/null
+++ b/bdw-inline.h
@@ -0,0 +1,52 @@
+#ifndef BDW_INLINE_H
+#define BDW_INLINE_H
+
+#include "gc-api.h"
+
+static inline enum gc_allocator_kind gc_allocator_kind(void) {
+  return GC_ALLOCATOR_INLINE_FREELIST;
+}
+static inline size_t gc_allocator_small_granule_size(void) {
+  return 2 * sizeof(void *);
+}
+static inline size_t gc_allocator_large_threshold(void) {
+  return 256;
+}
+
+static inline size_t gc_allocator_allocation_pointer_offset(void) {
+  abort();
+}
+static inline size_t gc_allocator_allocation_limit_offset(void) {
+  abort();
+}
+
+static inline size_t gc_allocator_freelist_offset(size_t size) {
+  GC_ASSERT(size);
+  return sizeof(void*) * ((size - 1) / gc_allocator_small_granule_size());
+}
+
+static inline size_t gc_allocator_alloc_table_alignment(void) {
+  return 0;
+}
+static inline uint8_t gc_allocator_alloc_table_begin_pattern(void) {
+  abort();
+}
+static inline uint8_t gc_allocator_alloc_table_end_pattern(void) {
+  abort();
+}
+
+static inline int gc_allocator_needs_clear(void) {
+  return 0;
+}
+
+static inline enum gc_write_barrier_kind gc_small_write_barrier_kind(void) {
+  return GC_WRITE_BARRIER_NONE;
+}
+static inline size_t gc_small_write_barrier_card_table_alignment(void) {
+  abort();
+}
+static inline size_t gc_small_write_barrier_card_size(void) {
+  abort();
+}
+
+#endif // BDW_INLINE_H
diff --git a/bdw.h b/bdw.h
index 07ba9d7c9..b01155d4e 100644
--- a/bdw.h
+++ b/bdw.h
@@ -1,6 +1,7 @@
 #include <stdint.h>
 #include <string.h>
 
+#include "bdw-inline.h"
 #include "conservative-roots.h"
 
 // When pthreads are used, let `libgc' know about it and redirect
@@ -45,34 +46,6 @@ static inline size_t gc_inline_freelist_object_size(size_t 
idx) {
   return (idx + 1U) * GC_INLINE_GRANULE_BYTES;
 }
 
-static inline enum gc_allocator_kind gc_allocator_kind(void) {
-  return GC_ALLOCATOR_INLINE_FREELIST;
-}
-static inline size_t gc_allocator_small_granule_size(void) {
-  return GC_INLINE_GRANULE_BYTES;
-}
-static inline size_t gc_allocator_large_threshold(void) {
-  return 256;
-}
-
-static inline size_t gc_allocator_allocation_pointer_offset(void) {
-  abort();
-}
-static inline size_t gc_allocator_allocation_limit_offset(void) {
-  abort();
-}
-
-static inline size_t gc_allocator_freelist_offset(size_t size) {
-  GC_ASSERT(size);
-  return sizeof(void*) * gc_inline_bytes_to_freelist_index(size);
-}
-
-static inline void gc_allocator_inline_success(struct mutator *mut,
-                                               struct gc_ref obj,
-                                               uintptr_t aligned_size) {}
-static inline void gc_allocator_inline_failure(struct mutator *mut,
-                                               uintptr_t aligned_size) {}
-
 // The values of these must match the internal POINTERLESS and NORMAL
 // definitions in libgc, for which unfortunately there are no external
 // definitions.  Alack.
@@ -131,30 +104,6 @@ static inline void collect(struct mutator *mut) {
   GC_gcollect();
 }
 
-static inline enum gc_write_barrier_kind gc_small_write_barrier_kind(void) {
-  return GC_WRITE_BARRIER_NONE;
-}
-static inline size_t gc_small_write_barrier_card_table_alignment(void) {
-  abort();
-}
-static inline size_t gc_small_write_barrier_card_size(void) {
-  abort();
-}
-
-static inline size_t gc_allocator_alloc_table_alignment(void) {
-  return 0;
-}
-static inline uint8_t gc_allocator_alloc_table_begin_pattern(void) {
-  abort();
-}
-static inline uint8_t gc_allocator_alloc_table_end_pattern(void) {
-  abort();
-}
-
-static inline int gc_allocator_needs_clear(void) {
-  return 0;
-}
-
 static inline struct mutator *add_mutator(struct heap *heap) {
   struct mutator *ret = GC_malloc(sizeof(struct mutator));
   ret->heap = heap;
@@ -230,6 +179,10 @@ static int parse_options(int argc, struct gc_option argv[],
 
 static int gc_init(int argc, struct gc_option argv[],
                    struct heap **heap, struct mutator **mutator) {
+  GC_ASSERT_EQ(gc_allocator_small_granule_size(), GC_INLINE_GRANULE_BYTES);
+  GC_ASSERT_EQ(gc_allocator_large_threshold(),
+               GC_INLINE_FREELIST_COUNT * GC_INLINE_GRANULE_BYTES);
+
   struct options options = { 0, };
   if (!parse_options(argc, argv, &options))
     return 0;
diff --git a/gc-assert.h b/gc-assert.h
index 472297a1e..dc39bee25 100644
--- a/gc-assert.h
+++ b/gc-assert.h
@@ -12,4 +12,6 @@
 #define GC_ASSERT(x) do { } while (0)
 #endif
 
+#define GC_ASSERT_EQ(a, b) GC_ASSERT((a) == (b))
+
 #endif // GC_ASSERT_H
diff --git a/semi.h b/semi.h
index 90a42d05d..224819f2c 100644
--- a/semi.h
+++ b/semi.h
@@ -302,8 +302,6 @@ static int parse_options(int argc, struct gc_option argv[],
   return 1;
 }
 
-#define GC_ASSERT_EQ(a, b) GC_ASSERT((a) == (b))
-
 static int gc_init(int argc, struct gc_option argv[],
                    struct heap **heap, struct mutator **mut) {
   GC_ASSERT_EQ(gc_allocator_allocation_pointer_offset(),

Reply via email to