fix blackhole (partially), kill apply1
This commit is contained in:
parent
1909e97d46
commit
d7fcbcdbf0
|
@ -1,71 +1,12 @@
|
||||||
|
|
||||||
.include "include/data.s"
|
.include "include/data.s"
|
||||||
|
|
||||||
#TODO apply1 seems obsolete by generic apply
|
|
||||||
|
|
||||||
# | fun | arg | -> cont
|
|
||||||
.thunkcode apply1
|
|
||||||
needs_alloc $050
|
|
||||||
thunkto %rsi, $apply1_fini, $3, 030(%rbp), %rbp, %rsi
|
|
||||||
enter 020(%rbp) # evaluate fun
|
|
||||||
|
|
||||||
# fun -> | arg | ret | cont |
|
|
||||||
.thunkcode apply1_fini
|
|
||||||
# we now know that fun points to a FUN with at least one arg missing.
|
|
||||||
# we're certainly going to copy a lot of args.
|
|
||||||
mov 020(%rsi), %r11 # amount of args applied now
|
|
||||||
|
|
||||||
# prepare enough memory for the worst case alloc (make FUN from arg count + 3)
|
|
||||||
lea 030(,%r11,010), %r12
|
|
||||||
needs_alloc %r12
|
|
||||||
|
|
||||||
# the copying code is shared so let's do that first:
|
|
||||||
pushq 020(%rbp) #push the new arg
|
|
||||||
lea 030(%rsi), %rdx # the end (first arg)
|
|
||||||
lea (%rdx, %r11, 010), %rbx # address behind the last arg
|
|
||||||
|
|
||||||
cmp %rdx, %rbx
|
|
||||||
jbe apply1_fini_cont
|
|
||||||
apply1_fini_copy:
|
|
||||||
sub $010, %rbx # iterate down
|
|
||||||
pushq (%rbx) # push what we have
|
|
||||||
cmp %rdx, %rbx # check if we are at the end
|
|
||||||
ja apply1_fini_copy # if not, continue
|
|
||||||
apply1_fini_cont:
|
|
||||||
add $1, %r11
|
|
||||||
pushq %r11 # new number of args of fun/thunk
|
|
||||||
pushq 010(%rsi) # thunk code pointer
|
|
||||||
|
|
||||||
# copying of all args and their thunky header is now done, let's find
|
|
||||||
# out how we need to finish it.
|
|
||||||
|
|
||||||
mov (%rsi), %rdi # infotable for the original fun
|
|
||||||
mov -010(%rdi), %r12 # amount of args required to make the thunk
|
|
||||||
cmp %r11, %r12
|
|
||||||
ja apply1_fini_feed # not enough args, just make a bigger FUN
|
|
||||||
|
|
||||||
# if there was enough args, we simply have a thunk that we want to
|
|
||||||
# continue evaluating, so let's jump to it.
|
|
||||||
mov 030(%rbp), %rdi # load the original thunk
|
|
||||||
mov %rsp, 010(%rdi) # set indirect to the new thunk
|
|
||||||
movq $IND_code, 0(%rdi)
|
|
||||||
mov 040(%rbp), %rsi # set continuation to the original continuation
|
|
||||||
enter %rsp # evaluate the new thunk
|
|
||||||
|
|
||||||
apply1_fini_feed:
|
|
||||||
# if there were not enough args, we push the function info and return
|
|
||||||
pushq (%rsi) # copy the function infoptr
|
|
||||||
|
|
||||||
mov 030(%rbp), %rdi # load the original thunk
|
|
||||||
mov %rsp, 010(%rdi) # set the indirect to the new FUN
|
|
||||||
movq $IND_code, 0(%rdi)
|
|
||||||
mov %rsp, %rsi # return the new FUN
|
|
||||||
enter 040(%rbp) # jump to the continuation
|
|
||||||
|
|
||||||
# | fun | arg[1] | arg[2] | ... | arg[args-1] | -> cont
|
# | fun | arg[1] | arg[2] | ... | arg[args-1] | -> cont
|
||||||
.thunkcode apply
|
.thunkcode apply
|
||||||
needs_alloc $040
|
needs_alloc $040
|
||||||
thunkto %rsi, $apply_fini, $2, %rbp, %rsi
|
thunkto %rsi, $apply_fini, $2, %rbp, %rsi
|
||||||
|
# TODO: this needs to be blackholed here, but we need to copy out all
|
||||||
|
# the args because the blackhole can't hold them
|
||||||
enter 020(%rbp)
|
enter 020(%rbp)
|
||||||
|
|
||||||
# fun -> | ret (with args) | cont |
|
# fun -> | ret (with args) | cont |
|
||||||
|
|
|
@ -67,8 +67,12 @@ IND_code:
|
||||||
# Blackhole (contains the original thunkptr for debugging purposes)
|
# Blackhole (contains the original thunkptr for debugging purposes)
|
||||||
# | ptr | orig_thunkptr |
|
# | ptr | orig_thunkptr |
|
||||||
BLE_evacuate:
|
BLE_evacuate:
|
||||||
|
pushq 010(%rbp)
|
||||||
|
pushq $BLE_code
|
||||||
|
mov %rsp,%rbp
|
||||||
jmp _gc_evacuate_ret
|
jmp _gc_evacuate_ret
|
||||||
BLE_scavenge:
|
BLE_scavenge:
|
||||||
|
add $020, %rbp
|
||||||
jmp _gc_scavenge_ret
|
jmp _gc_scavenge_ret
|
||||||
|
|
||||||
BLE_info_table:
|
BLE_info_table:
|
||||||
|
|
|
@ -51,4 +51,10 @@ _macros_s_file:
|
||||||
mov %rsp, \reg
|
mov %rsp, \reg
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
|
.macro blackhole
|
||||||
|
mov (%rbp), %rax
|
||||||
|
mov %rax, 010(%rbp)
|
||||||
|
movq $BLE_code, (%rbp)
|
||||||
|
.endm
|
||||||
|
|
||||||
.endif # _macros_s_file
|
.endif # _macros_s_file
|
||||||
|
|
|
@ -12,6 +12,7 @@ _primops_s_file:
|
||||||
needs_alloc $040
|
needs_alloc $040
|
||||||
# push a thunk for collecting the first arg and set it as continuation
|
# push a thunk for collecting the first arg and set it as continuation
|
||||||
thunkto %rsi, $\name\()_fini, $2, %rbp, %rsi
|
thunkto %rsi, $\name\()_fini, $2, %rbp, %rsi
|
||||||
|
blackhole
|
||||||
enter 020(%rbp) # evaluate arg1
|
enter 020(%rbp) # evaluate arg1
|
||||||
|
|
||||||
# arg1 -> | ret | cont |
|
# arg1 -> | ret | cont |
|
||||||
|
@ -43,6 +44,7 @@ _primops_s_file:
|
||||||
needs_alloc $050
|
needs_alloc $050
|
||||||
# push a thunk for collecting the first arg and set it as continuation
|
# push a thunk for collecting the first arg and set it as continuation
|
||||||
thunkto %rsi, $\name\()_step1, $3, 030(%rbp), %rbp, %rsi
|
thunkto %rsi, $\name\()_step1, $3, 030(%rbp), %rbp, %rsi
|
||||||
|
blackhole
|
||||||
enter 020(%rbp) # evaluate arg1
|
enter 020(%rbp) # evaluate arg1
|
||||||
|
|
||||||
# arg1 -> | arg2 | ret | cont |
|
# arg1 -> | arg2 | ret | cont |
|
||||||
|
|
5
zipfib.s
5
zipfib.s
|
@ -7,11 +7,10 @@
|
||||||
.include "include/main_exit.s"
|
.include "include/main_exit.s"
|
||||||
.include "include/apply.s"
|
.include "include/apply.s"
|
||||||
|
|
||||||
# TODO this seems to fill the memory with plus_fini thunks; find out why.
|
|
||||||
|
|
||||||
.thunkcode zipWith
|
.thunkcode zipWith
|
||||||
needs_alloc $070
|
needs_alloc $070
|
||||||
thunkto %rsi, $zipWith_arg1, $5, 020(%rbp), 030(%rbp), 040(%rbp), %rbp, %rsi
|
thunkto %rsi, $zipWith_arg1, $5, 020(%rbp), 030(%rbp), 040(%rbp), %rbp, %rsi
|
||||||
|
blackhole
|
||||||
enter 030(%rbp)
|
enter 030(%rbp)
|
||||||
|
|
||||||
.thunkcode zipWith_arg1
|
.thunkcode zipWith_arg1
|
||||||
|
@ -60,7 +59,7 @@
|
||||||
mov %r10, 030(%r8)
|
mov %r10, 030(%r8)
|
||||||
mov %r9, 040(%r8)
|
mov %r9, 040(%r8)
|
||||||
|
|
||||||
thunkto %r8, $INT_code, $20
|
thunkto %r8, $INT_code, $25
|
||||||
thunkto %r8, $list_int_index, $2, %r8, %r10
|
thunkto %r8, $list_int_index, $2, %r8, %r10
|
||||||
thunkto %r8, $print, $1, %r8
|
thunkto %r8, $print, $1, %r8
|
||||||
thunkto %rsi, $main_exit, $0
|
thunkto %rsi, $main_exit, $0
|
||||||
|
|
Loading…
Reference in a new issue