1
1
// ---------- RUNTIME HEADER ----------
2
2
#define _GNU_SOURCE
3
+
4
+ #ifndef __TINYC__
3
5
#define _FORTIFY_SOURCE 2
6
+ #endif
4
7
5
8
#include <stddef.h>
6
9
#include <wchar.h>
@@ -49,7 +52,7 @@ typedef double NUMBER;
49
52
typedef const char * restrict STRING ;
50
53
typedef const struct cognate_list * restrict LIST ;
51
54
typedef const char * restrict SYMBOL ;
52
- typedef struct cognate_file * IO ;
55
+ typedef struct cognate_file * restrict IO ;
53
56
typedef const struct cognate_table * restrict TABLE ;
54
57
55
58
typedef struct cognate_block
@@ -384,6 +387,7 @@ int main(int argc, char** argv)
384
387
fn0 ();
385
388
cleanup ();
386
389
}
390
+
387
391
static void cleanup (void )
388
392
{
389
393
if unlikely (stack .top != stack .start )
@@ -1086,15 +1090,7 @@ static void gc_init(void)
1086
1090
bitmap [1 ][0 ] = ALLOC ;
1087
1091
}
1088
1092
1089
- __attribute__((hot ))
1090
- static _Bool is_heap_ptr (void * ptr )
1091
- {
1092
- const uint64_t index = (uintptr_t * )ptr - space [!z ];
1093
- if (index >= alloc [!z ]) return 0 ;
1094
- return 1 ;
1095
- }
1096
-
1097
- __attribute__((malloc , hot , assume_aligned (sizeof (uint64_t )), alloc_size (1 ), returns_nonnull ))
1093
+ __attribute__((noinline , hot , assume_aligned (sizeof (uint64_t )), returns_nonnull ))
1098
1094
static void * gc_malloc (size_t sz )
1099
1095
{
1100
1096
static ptrdiff_t interval = 1024l * 1024l * 10 ;
@@ -1115,7 +1111,7 @@ static void* gc_malloc(size_t sz)
1115
1111
return buf ;
1116
1112
}
1117
1113
1118
- __attribute__((malloc , hot , assume_aligned (sizeof (uint64_t )), alloc_size (1 ), returns_nonnull ))
1114
+ __attribute__((noinline , hot , assume_aligned (sizeof (uint64_t )), alloc_size (1 ), returns_nonnull ))
1119
1115
static void * gc_flatmalloc (size_t sz )
1120
1116
{
1121
1117
static ptrdiff_t interval = 1024l * 1024l * 10 ;
@@ -1190,6 +1186,24 @@ static void gc_collect_root(uintptr_t* restrict addr)
1190
1186
1191
1187
static __attribute__((noinline ,hot )) void gc_collect (void )
1192
1188
{
1189
+
1190
+ /*
1191
+ printf("BEFORE:\n");
1192
+ for (int Z = 0 ; Z < 2 ; ++Z)
1193
+ {
1194
+ for (int i = 0 ; i <= alloc[Z] ; ++i) switch(bitmap[Z][i])
1195
+ {
1196
+ case EMPTY: fputc('-', stdout); break;
1197
+ case ALLOC: fputc('A', stdout); break;
1198
+ case FLATALLOC: fputc('a', stdout); break;
1199
+ case FORWARD: printf("%zu", (uintptr_t*)space[Z][i] - space[!Z]); break;
1200
+ }
1201
+ if (Z == z) printf(" (active)");
1202
+ fputc('\n', stdout);
1203
+ }
1204
+ */
1205
+
1206
+
1193
1207
/*
1194
1208
clock_t start, end;
1195
1209
double cpu_time_used;
@@ -1216,6 +1230,21 @@ static __attribute__((noinline,hot)) void gc_collect(void)
1216
1230
printf("%lf seconds for %ziMB -> %ziMB\n", (double)(end - start) / CLOCKS_PER_SEC, heapsz * 8 /1024/1024, alloc[z] * 8 / 1024/1024);
1217
1231
*/
1218
1232
1233
+ /*
1234
+ printf("AFTER:\n");
1235
+ for (int Z = 0 ; Z < 2 ; ++Z)
1236
+ {
1237
+ for (int i = 0 ; i <= alloc[Z] ; ++i) switch(bitmap[Z][i])
1238
+ {
1239
+ case EMPTY: fputc('-', stdout); break;
1240
+ case ALLOC: fputc('A', stdout); break;
1241
+ case FLATALLOC: fputc('a', stdout); break;
1242
+ case FORWARD: printf("%zu", (uintptr_t*)space[Z][i] - space[!Z]); break;
1243
+ }
1244
+ if (Z == z) printf(" (active)");
1245
+ fputc('\n', stdout);
1246
+ }
1247
+ */
1219
1248
longjmp (a , 1 );
1220
1249
}
1221
1250
0 commit comments