Miscellaneous scripts
This repository contains miscellaneous scripts that does not fit in one repository, yet I will use them sometimes for my personal use. Note that some of the scripts might contain hardcoded paths and opinionated presets, and you are advised to inspect them before actually using.
Loading...
Searching...
No Matches
cache_memory Namespace Reference

Functions

tuple add_cache (list[dict] cache, int block, int history, int miss)
tuple direct_map_add_cache (list[dict] cache, int block, int history, int miss)

Variables

list cache = [{}, {}, {}, {}, {}, {}, {}, {}]
int counter = 1
int miss = 0

Function Documentation

◆ add_cache()

tuple cache_memory.add_cache ( list[dict] cache,
int block,
int history,
int miss )

Definition at line 1 of file cache_memory.py.

1def add_cache(cache: list[dict], block: int, history: int, miss: int) -> tuple:
2 address = block % 4
3 if cache[address].get(block):
4 cache[address][block] = history
5 return cache, miss
6 if len(cache[address]) < 2:
7 cache[address][block] = history
8 miss += 1
9 return cache, miss
10 assert len(cache[address]) < 3
11 for data in cache[address]:
12 # least recently used
13 if cache[address][data] == min(cache[address].values()):
14 del cache[address][data]
15 cache[address][block] = history
16 miss += 1
17 return cache, miss
18
19

◆ direct_map_add_cache()

tuple cache_memory.direct_map_add_cache ( list[dict] cache,
int block,
int history,
int miss )

Definition at line 20 of file cache_memory.py.

20def direct_map_add_cache(cache: list[dict], block: int, history: int, miss: int) -> tuple:
21 address = block % 8
22 if cache[address].get(block):
23 cache[address][block] = history
24 return cache, miss
25 else:
26 cache[address] = {block: history}
27 miss += 1
28 return cache, miss
29
30

Variable Documentation

◆ cache

list cache_memory.cache = [{}, {}, {}, {}, {}, {}, {}, {}]

Definition at line 33 of file cache_memory.py.

◆ counter

int cache_memory.counter = 1

Definition at line 31 of file cache_memory.py.

◆ miss

int cache_memory.miss = 0

Definition at line 32 of file cache_memory.py.