duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit e534e82d9f5a62cf6cd763c71c335b7fb1e8d8d3
parent a829c53254a214e0b6d346d45b59a5bf93c62382
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Sat, 24 Jun 2023 12:18:23 -0400

Move "move" and "[]=" back into the kernel

These words are so central to Dusk's general speed that it's better to have the
logic duplicated in each kernel.

I'm also planning on moving "[c]?" and "fill" into the kernel, which will
lighten the load on Low HAL and possibly allow us to shrink it a bit.

Diffstat:
Mfs/xcomp/arm/rpi/kernel.fs | 21+++++++++++++++++++++
Mfs/xcomp/bootlo.fs | 12------------
Mfs/xcomp/i386/kernel.fs | 22++++++++++++++++++++++
Mposix/vm.c | 30++++++++++++++++++++++++++++--
4 files changed, 71 insertions(+), 14 deletions(-)

diff --git a/fs/xcomp/arm/rpi/kernel.fs b/fs/xcomp/arm/rpi/kernel.fs @@ -843,6 +843,27 @@ pc mov) rTOP rd) r1 rm) ,) \ quotient exit, +xcode move ( src dst u -- ) + r2 ppop, r0 ppop, \ r0=src r2=dst + mov) r1 rd) rTOP rm) ,) xdrop, \ r1=u + cmp) r2 rn) 0 i) ,) + lblmoverange abs>rel b) nz) ,) + exit, + +xcode []= ( src dst u -- f ) + r2 ppop, r0 ppop, \ r0=src r2=dst + mov) r1 rd) rTOP rm) ,) \ r1=u + mov) rTOP rd) 0 i) ,) +pc + ldr) r3 rd) r0 rn) 8b) 1 +i) post) ,) + ldr) r4 rd) r2 rn) 8b) 1 +i) post) ,) + cmp) r3 rn) r4 rm) ,) + return) nz) ,) + sub) r1 rdn) 1 i) f) ,) + ( pc ) abs>rel b) ne) ,) + mov) rTOP rd) 1 i) ,) + exit, + \ Interpret loop xcode ; ximm pushret, wcall, popret, diff --git a/fs/xcomp/bootlo.fs b/fs/xcomp/bootlo.fs @@ -274,22 +274,10 @@ create _repl 3 nc, LF CR 0 : word" [compile] S" NEXTWORD litn compile ! ; immediate : '" [compile] word" compile ' ; immediate -code []= ( a1 a2 u -- f ) - W=0>Z, 0 Z) branchC, PSP) @!, W>A, begin \ P+4=a1 P+0=u A=a2 - PSP) 4 +) 8b) [@+], A) 8b) compare, 0 Z) branchC, - 8 ps+, 0 LIT>W, exit, then - 1 A+n, -1 PSP) +n, NZ) branchC, drop then - 8 ps+, 1 LIT>W, exit, : s= ( s1 s2 -- f ) over c@ 1+ []= ; : [if] not if S" [then]" begin word over s= until drop then ; alias noop [then] -code move ( src dst u -- ) - W=0>Z, 0 Z) branchC, W>A, begin \ A=u - PSP) 4 +) 8b) [@+], PSP) 8b) [!+], - -1 A+n, NZ) branchC, drop then - 8 ps+, drop, exit, - : move, ( src u -- ) here swap dup allot move ; : -move, ( src u -- ) here over - swap move ; diff --git a/fs/xcomp/i386/kernel.fs b/fs/xcomp/i386/kernel.fs @@ -399,6 +399,28 @@ xcode p! ( n32 port -- ) ax dx out, xdrop, ret, +xcode move ( src dst u -- ) + si push, + cx ax mov, + di si 0 d) mov, + si si 4 d) mov, + rep, movsb, + si pop, + xnip, xnip, xdrop, + ret, + +xcode []= ( a1 a2 u -- f ) + si push, + di si 0 d) mov, + si si 4 d) mov, + cx ax mov, + ax ax xor, + repz, cmpsb, + si pop, + al setz, + xnip, xnip, + ret, + \ Interpret loop 0 align4 pc to lblbootptr 0 , diff --git a/posix/vm.c b/posix/vm.c @@ -337,6 +337,20 @@ static void WIFETCHINC8() { M8B; _wifetchinc(); } static void WISTOREINC8() { M8B; _wistoreinc(); } // 0x28 +static void MOVE() { + dword u = ppop(); + dword dst = ppop(); + dword src = ppop(); + if (u && memchk(dst+u) && memchk(src+u)) { + if (u && (dst >= src) && (dst < src+u)) { + fprintf(stderr, "overlapping MOVE! %x %x %d\n", src, dst, u); + vmabort(); + return; + } + memmove(&vm.mem[dst], &vm.mem[src], u); + } +} + static void BOOTRD() { ppush(fgetc(fp)); } static void STDOUT() { dword c = ppop(); write(STDOUT_FILENO, &c, 1); } // ( -- c? f ) @@ -346,6 +360,18 @@ static void MAYBEKEY() { ppush(c); ppush(1); } else { ppush(0); } } +// ( a1 a2 u -- f ) +static void RANGEEQ() { + dword u = ppop(); + dword a2 = ppop(); + dword a1 = ppop(); + if (u && memchk(a1+u) && memchk(a2+u)) { + ppush(memcmp(&vm.mem[a1], &vm.mem[a2], u) == 0); + } else { + ppush(1); + } +} + // n -- operand static void MAKEMEM() { vm.W = hbankset(OPHASDISP|OPMEM, vm.W); } // operand n -- operand @@ -874,7 +900,7 @@ static void (*ops[OPCNT])() = { WFETCH, NULL, WSWAP, ADDN, WCMP, WIFETCHINC, WISTOREINC, WLEA, WFETCH16, NULL, WSWAP16, ADDN16, WCMP16, WIFETCHINC16, WISTOREINC16, WLEA, WFETCH8, NULL, WSWAP8, ADDN8, WCMP8, WIFETCHINC8, WISTOREINC8, WLEA, - NULL, BOOTRD, STDOUT, MAYBEKEY, NULL, MAKEMEM, ADDDISP, NULL, + MOVE, BOOTRD, STDOUT, MAYBEKEY, RANGEEQ, MAKEMEM, ADDDISP, NULL, MAYBEWORD, WORD, PARSE, FIND, WNF, FINDMOD, NULL, NULL, STACKCHK, COMPWORD, RUNWORD, COMPILING, STARTCOMP, STOPCOMP, RSADDWR, COMPOP, ALIGN4, ENTRY, CODE, CODE16, CODE8, COMPBINOP, NULL, NULL, @@ -917,7 +943,7 @@ static void compileop(byte op) { litwr(op); cwritewr(); } // Names for simple word-to-code mappings static char *opnames[OPCNT-0x28] = { - NULL, "boot<", "(emit)", "(key?)", NULL, "m)", "+)", NULL, + "move", "boot<", "(emit)", "(key?)", "[]=", "m)", "+)", NULL, "maybeword", "word", "parse", "find", "(wnf)", "findmod", NULL, NULL, "stack?", "compword", "runword", "compiling", "]", NULL, "rs+,", NULL, "align4", "entry", "code", "code16b", "code8b", NULL, NULL, NULL,