freenode/#sicl - IRC Chatlog
Search
10:07:24
heisig
Success! I can now execute arbitrary vectors of bytes as x86 assembler. It only took me two ours of reading manpages and tinkering with GDB.
10:08:49
heisig
I made one terrible mistake - I used C instead of Lisp, thinking it was more 'low level' and appropriate.
10:11:08
heisig
I will now switch back from C to Lisp. SBCL can't address bytes and call MMAP, too, and I won't have to deal with this humongous bullshit.
10:12:27
heisig
From the last two hours, I spend most of the time figuring out linker problems and casting pointers. What a mess.
10:13:34
heisig
I think it really doesn't matter that much how I generate the assembler instructions though. The snippets, callees and callers are all very short.
10:15:43
no-defun-allowed
From what I read, there is sb-alien:alien-funcall to call an alien function object, but I don't know how to make an alien function object. But NASM might be a better choice for writing assembler snippets.
10:16:54
heisig
After my recent encounter with C, NASM and x86 assembler might be downright soothing.
10:21:51
heisig
no-defun-allowed: sb-alien:alien-funcall might be just what I need. I will use NASM to generate the bytes, load them into a foreign array, and invoke the code with alien-funcall.
10:22:37
no-defun-allowed
Hm. Can you not generate an ELF file with NASM? Then you could use the usual CFFI machinery to load the foreign library and define the function.
10:24:04
heisig
I could. But I also want to print some things to stdout, measure the execution time, and occasionally change the snippet being jumped to.
10:25:15
no-defun-allowed
I guess it's likely CFFI will not let you overwrite the foreign code loaded, so using sb-alien might be the better choice.
10:26:00
heisig
The crucial part is that of atomically exchanging part of the code of the caller (the snippet address being jumped to). It will be interesting to see how modern CPUs cope with that.
10:56:10
heisig
shka_: That wouldn't be so bad. These addresses are only mutated when the callee is redefined.
11:12:47
heisig
shka_: I use mmap to allocate new pages that are both writable and executable, and I store my code there. So that should work.
11:13:20
no-defun-allowed
I think some operating systems don't allow WX pages, which makes modifying code a bit trickier.
11:14:07
no-defun-allowed
Not impossible, eg Java (I think) has some code to handle it on OpenBSD and macOS on AArch64 - it came up on #sbcl while porting some time ago.
11:39:58
no-defun-allowed
If you were a C programmer, I would say "that sounds like a _you_ problem..."
15:13:47
heisig
beach: I plan to measure the cost of various kinds of function calls, using different techniques.
15:14:20
heisig
One technique would be via a classical calling convention like that of SBCL, the other would be using the default snippet, the last one using the optimized snippet.
15:15:17
heisig
And then I want to measure these costs for a call with one mandatory argument, one optional argument, or one keyword argument.
15:23:13
heisig
Honestly, I just want to see all the machinery in action, and I'm not patient enough to wait for the full thing :)
15:48:27
beach
Now, if you do a good job, I'll include the results in the paper, and then you can't reject it for lack of benchmarks. :)
16:18:32
beach
I think I'll introduce an AST class and an instruction class NAMED-CALL. They would store the name of a global function to call, and there won't be an associated FDEFINITION.
16:19:35
beach
For the benefit of the HIR interpreter, I will CHANGE-CLASS that instruction so that it also contains a function cell. Then the HIR interpreter will take the CAR of that cell and call it with the arguments.
16:20:37
beach
Instead of hoisting FDEFINITIONs, the `tie' function will populate the function cells.
16:21:47
beach
Instead of hoisting FDEFINITIONs, AST-to-HIR will find the NAMED-CALL instructions and store them in the TOP-LEVEL-ENTER instruction.
16:22:52
beach
So instead of finding function cells and storing them in the static environment of the top-level function, the `tie' operation will populate the NAMED-CALL instructions with function cells.
16:24:15
beach
This change will likely speed up compilation and bootstrapping, because there will be a lot fewer shared variables, so processing shared variables at compile time will be faster, and creating static environments at run time will be faster as well.