Skip to content

Commit 6398e60

Browse files
committed
Finished. optimized current code. needs thread cache redesign and documentation
1 parent 4c751ae commit 6398e60

File tree

12 files changed

+1349
-1215
lines changed

12 files changed

+1349
-1215
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ docs/plan.md
55
build/
66
build_*/
77
libs/
8+
bin/
89

910
# Compiled Object files
1011
*.o

Makefile

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
CC ?= gcc
3+
CXX ?= g++
34
CFLAGS := -std=c17 -Wall -Wextra -Wpedantic -Werror
45
CFLAGS += -fno-strict-aliasing
56
CFLAGS += -D_GNU_SOURCE
@@ -20,6 +21,8 @@ endif
2021

2122
LDFLAGS += -lm -lpthread $(EXTRA_LDFLAGS)
2223

24+
CXXFLAGS := $(filter-out -std=c17,$(CFLAGS)) -std=c++20
25+
2326
TEST_SRCS := src/tests/test_correctness.c \
2427
src/tests/test_stress.c \
2528
src/tests/test_edge.c \
@@ -34,16 +37,27 @@ BENCH_SRCS := src/benchmarks/bench_synthetic.c \
3437
DEFAULT_ALLOC := allocators/glibc/glibc_allocator.c
3538

3639
ALLOCATOR ?= $(DEFAULT_ALLOC)
37-
3840
BUILD_DIR := build
3941
BIN_DIR := bin
4042

43+
ZIALLOC_MAIN := allocators/zialloc/alloc.cpp
44+
ifeq ($(ALLOCATOR),$(ZIALLOC_MAIN))
45+
ALLOC_CPP_SRCS := allocators/zialloc/alloc.cpp \
46+
allocators/zialloc/free.cpp \
47+
allocators/zialloc/os.cpp \
48+
allocators/zialloc/segments.cpp
49+
ALLOC_OBJ := $(patsubst %.cpp,$(BUILD_DIR)/%.o,$(ALLOC_CPP_SRCS))
50+
LINKER := $(CXX)
51+
else
52+
ALLOC_OBJ := $(BUILD_DIR)/allocator.o
53+
LINKER := $(CC)
54+
endif
55+
4156
TEST_BIN := $(BIN_DIR)/run_tests
4257
BENCH_BIN := $(BIN_DIR)/run_bench
4358

4459
TEST_OBJS := $(patsubst %.c,$(BUILD_DIR)/%.o,$(TEST_SRCS))
4560
BENCH_OBJS := $(patsubst %.c,$(BUILD_DIR)/%.o,$(BENCH_SRCS))
46-
ALLOC_OBJ := $(BUILD_DIR)/allocator.o
4761

4862
.PHONY: all tests bench clean help run-tests run-bench
4963

@@ -54,12 +68,12 @@ tests: $(TEST_BIN)
5468
bench: $(BENCH_BIN)
5569

5670
$(TEST_BIN): $(TEST_OBJS) $(ALLOC_OBJ) | $(BIN_DIR)
57-
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
71+
$(LINKER) -o $@ $^ $(LDFLAGS)
5872
@echo "Built test runner: $@"
5973
@echo "Allocator: $(ALLOCATOR)"
6074

6175
$(BENCH_BIN): $(BENCH_OBJS) $(ALLOC_OBJ) | $(BIN_DIR)
62-
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
76+
$(LINKER) -o $@ $^ $(LDFLAGS)
6377
@echo "Built benchmark runner: $@"
6478
@echo "Allocator: $(ALLOCATOR)"
6579

@@ -72,8 +86,14 @@ $(BUILD_DIR)/src/benchmarks/%.o: src/benchmarks/%.c | $(BUILD_DIR)/src/benchmark
7286
$(BUILD_DIR)/src/harness/%.o: src/harness/%.c | $(BUILD_DIR)/src/harness
7387
$(CC) $(CFLAGS) -c -o $@ $<
7488

89+
ifneq ($(ALLOCATOR),$(ZIALLOC_MAIN))
7590
$(ALLOC_OBJ): $(ALLOCATOR) | $(BUILD_DIR)
7691
$(CC) $(CFLAGS) -c -o $@ $<
92+
endif
93+
94+
$(BUILD_DIR)/allocators/zialloc/%.o: allocators/zialloc/%.cpp
95+
mkdir -p $(dir $@)
96+
$(CXX) $(CXXFLAGS) -c -o $@ $<
7797

7898
$(BUILD_DIR):
7999
mkdir -p $@

0 commit comments

Comments
 (0)