Skip to content

Commit 452b325

Browse files
authored
Merge pull request #118 from qwe661234/wip/add_ARC
Add adaptive replacement cache
2 parents 7fffa03 + 32cfd32 commit 452b325

20 files changed

+3695
-3
lines changed

.clang-format

+4
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ UseTab: Never
1313
IndentWidth: 4
1414
BreakBeforeBraces: Linux
1515
AccessModifierOffset: -4
16+
ForEachMacros:
17+
- list_for_each_entry
18+
- list_for_each_entry_safe
19+
- hlist_for_each_entry

.github/workflows/main.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ jobs:
1313
sudo apt-get install libsdl2-dev
1414
- name: default build
1515
run: make
16-
- name: check
17-
run: make check
16+
- name: check + tests
17+
run: |
18+
make check
19+
make tests
1820
- name: diverse configurations
1921
run: |
2022
make distclean ENABLE_EXT_C=0

Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ OBJS := \
9393
emulate.o \
9494
riscv.o \
9595
elf.o \
96+
cache.o \
9697
$(OBJS_EXT) \
9798
main.o
9899

@@ -109,6 +110,7 @@ $(BIN): $(OBJS)
109110

110111
# RISC-V Architecture Tests
111112
include mk/riscv-arch-test.mk
113+
include mk/tests.mk
112114

113115
CHECK_ELF_FILES := \
114116
hello \
@@ -143,7 +145,7 @@ endif
143145
endif
144146

145147
clean:
146-
$(RM) $(BIN) $(OBJS) $(deps)
148+
$(RM) $(BIN) $(OBJS) $(deps) $(CACHE_OUT)
147149
distclean: clean
148150
-$(RM) $(DOOM_DATA) $(QUAKE_DATA)
149151
$(RM) -r $(OUT)/id1

mk/tests.mk

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
CACHE_TEST_DIR := tests/cache
2+
CACHE_BUILD_DIR := build/cache
3+
TARGET := test-cache
4+
5+
CACHE_OBJS := \
6+
test-cache.o
7+
8+
CACHE_OBJS := $(addprefix $(CACHE_BUILD_DIR)/, $(CACHE_OBJS))
9+
OBJS += $(CACHE_OBJS)
10+
deps += $(CACHE_OBJS:%.o=%.o.d)
11+
12+
13+
CACHE_CHECK_ELF_FILES := \
14+
cache-new \
15+
cache-put \
16+
cache-get \
17+
cache-lru-replace \
18+
cache-lfu-replace \
19+
cache-lfu-ghost-replace
20+
21+
CACHE_OUT = $(addprefix $(CACHE_BUILD_DIR)/, $(CACHE_CHECK_ELF_FILES:%=%.out))
22+
23+
tests : $(CACHE_OUT)
24+
$(Q)$(foreach e,$(CACHE_CHECK_ELF_FILES),\
25+
$(PRINTF) "Running $(e) ... "; \
26+
if cmp $(CACHE_TEST_DIR)/$(e).expect $(CACHE_BUILD_DIR)/$(e).out; then \
27+
$(call notice, [OK]); \
28+
else \
29+
$(PRINTF) "Failed.\n"; \
30+
exit 1; \
31+
fi; \
32+
)
33+
34+
$(CACHE_OUT): $(TARGET)
35+
$(Q)$(foreach e,$(CACHE_CHECK_ELF_FILES),\
36+
$(CACHE_BUILD_DIR)/$(TARGET) $(CACHE_TEST_DIR)/$(e).in > $(CACHE_BUILD_DIR)/$(e).out; \
37+
)
38+
39+
$(TARGET): $(CACHE_OBJS)
40+
$(VECHO) " CC\t$@\n"
41+
$(Q)$(CC) $^ build/cache.o -o $(CACHE_BUILD_DIR)/$(TARGET)
42+
43+
$(CACHE_BUILD_DIR)/%.o: $(CACHE_TEST_DIR)/%.c
44+
$(VECHO) " CC\t$@\n"
45+
$(Q)mkdir -p $(dir $@)
46+
$(Q)$(CC) -o $@ $(CFLAGS) -I./src -c -MMD -MF $@.d $<

0 commit comments

Comments
 (0)