Skip to content

Commit

Permalink
store the symbol hash to make global lookups slightly faster
Browse files Browse the repository at this point in the history
  • Loading branch information
devyn committed Aug 15, 2023
1 parent c4e2e84 commit 4fa4cd7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions stage1/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct lisp_cons {
struct lisp_symbol {
char *buf;
unsigned long len; // cap = len for symbols (they must be allocated with exact size)
char hash; // for hashtables
};

struct lisp_string {
Expand Down
1 change: 1 addition & 0 deletions stage1/object.h.s
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

.set LISP_SYMBOL_BUF, 8
.set LISP_SYMBOL_LEN, 16
.set LISP_SYMBOL_HASH, 24

.set LISP_CONS_HEAD, 8
.set LISP_CONS_TAIL, 16
Expand Down
6 changes: 5 additions & 1 deletion stage1/symbol.s
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,12 @@ symbol_intern:
mv a1, s1
mv a2, s4
call mem_copy
# get symbol hash
mv a0, s4
mv a1, s2
call symbol_hash
# create a new object for the symbol
mv a3, zero
andi a3, a0, 0xff # LISP_SYMBOL_HASH
mv a2, s2 # LISP_SYMBOL_LEN
mv a1, s4 # LISP_SYMBOL_BUF
li a0, LISP_OBJECT_TYPE_SYMBOL
Expand Down
4 changes: 1 addition & 3 deletions stage1/words.s
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,7 @@ get_words_ptr:
lwu t2, LISP_OBJECT_TYPE(t1)
li t3, LISP_OBJECT_TYPE_SYMBOL
bne t2, t3, .Lget_words_ptr_error # not symbol => error
ld a0, LISP_SYMBOL_BUF(t1)
ld a1, LISP_SYMBOL_LEN(t1)
call symbol_hash
lb a0, LISP_SYMBOL_HASH(t1)
# mask the hash to number of bits
andi a0, a0, (1 << WORDS_HASH_BITS) - 1
# times 8 (double word)
Expand Down

0 comments on commit 4fa4cd7

Please sign in to comment.