commit 8322bb1136d57b8b656ea2457335082e0075e828
parent c2be425ebda1badb3999ccfa7863c35e18bc7bca
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Thu, 22 Sep 2022 20:53:20 -0400
Make all words aligned to 4b
Aligned words are theoretically faster than unaligned one, although word "on the
streets" say that its benefits are dubious. I haven't measured them.
The reason why I do this is something else: having this alignment will allow me
to simplify struct management in CC. You'll see.
Diffstat:
6 files changed, 31 insertions(+), 15 deletions(-)
diff --git a/fs/doc/dict.txt b/fs/doc/dict.txt
@@ -155,7 +155,7 @@ move src dst u -- Copy u bytes from address src to address dst, moving
upwards.
move, src u -- Copy u bytes to "here" and increase "here" by u.
fill a u c -- Fill range [a, a+u] with byte c.
-align4 -- Allot 0, 1, 2 or 3 bytes so that "here" is divisible
+align4 n -- Allot 0, 1, 2 or 3 bytes so that "here+n" is divisible
by 4.
nc, n -- Parse n numbers from input stream and write them as
8-bit values.
diff --git a/fs/fs/fatlo.fs b/fs/fs/fatlo.fs
@@ -231,7 +231,7 @@ extends File struct[ FATFile
0 ( entryoff ) ,
: :createcursor ( fat -- hdl )
- align4 dup to' FAT lastcursor llinsert ( fat newll )
+ 0 align4 dup to' FAT lastcursor llinsert ( fat newll )
swap :cursorsize allot ( newll ) CELLSZ + ( hdl )
0 over to flags ( mark as "free" ) ;
@@ -273,7 +273,7 @@ struct+[ FAT
r@ to FATFile entryoff DirEntry filesize r@ to FATFile size ( ) r> ;
: :mountvolume ( drv -- fs )
- align4 here >r dup , ( drv R:fs ) 0 ( flags ) ,
+ 0 align4 here >r dup , ( drv R:fs ) 0 ( flags ) ,
['] :child , ['] abort , ['] :fatopen , ['] :iter , ['] abort , ['] abort ,
['] abort ,
0 , 0 , 0 , 0 , ( drv )
diff --git a/fs/tests/sys/file.fs b/fs/tests/sys/file.fs
@@ -30,7 +30,7 @@ myinfo FSInfo dir? #
\ For the writeable part of the tests, we use a RAMDrive with a FAT12 mounted
\ in it so that write tests can be made without affecting the host.
100 const TOTSEC
-align4 512 TOTSEC RAMDrive :new value mydrv
+512 TOTSEC RAMDrive :new value mydrv
mydrv 16 1 1 TOTSEC 17 - FAT newFAT12
mydrv FAT :mountvolume value myfat
myfat 0 Path :new structbind Path myroot
diff --git a/fs/xcomp/bootlo.fs b/fs/xcomp/bootlo.fs
@@ -3,7 +3,9 @@
," ;" 0 , sysdict @ , $81 8b , HERE @ w>e sysdict !
' [ execute, ' exit, execute, exit,
," entry" 0 , sysdict @ , 5 8b , HERE @ w>e sysdict ! ]
- dup 1+ swap 8b @ tuck move, nextmeta @ , over @ , 8b ,
+ dup 1+ swap 8b @
+ dup 1+ align4
+ tuck move, nextmeta @ , over @ , 8b ,
HERE @ w>e swap ! 0 nextmeta ! 0 [rcnt] ! ;
," code" 0 , sysdict @ , 4 8b , HERE @ w>e sysdict ! ]
sysdict word entry ;
@@ -83,7 +85,6 @@ create toptr 0 ,
: c!+ 8b !+ ;
: fill ( a u c -- ) >r >r begin V1 swap c!+ next drop rdrop ;
: allot0 ( n -- ) HERE @ over 0 fill allot ;
-: align4 ( -- ) HERE @ 4 mod ?dup if 4 -^ allot0 then ;
: nc, ( n -- ) >r begin word runword c, next ;
\ Compiling words
diff --git a/fs/xcomp/i386.fs b/fs/xcomp/i386.fs
@@ -37,7 +37,7 @@ $80000 const PSTOP
PSTOP STACKSZ - const HEREMAX
\ Let's go!
-align4 here to org
+0 align4 here to org
forward16 jmp, to L1
pc to lblintnoop iret,
\ Interrupt Descriptor Table
@@ -560,6 +560,15 @@ xcode []= ( a1 a2 u -- f )
[ebp] ax mov,
ret,
+xcode align4 ( n -- )
+ AX pspop,
+ ax lblhere m) add,
+ ax 3 i) and,
+ lblret abs>rel jz,
+ lblhere m) ax sub,
+ lblhere m) 4 i) add,
+ ret,
+
pc to lbl[rcnt] 0 ,
xcode [rcnt]
lbl[rcnt] pspushN,
@@ -664,7 +673,7 @@ xcode ABORT
lblabort pspushN,
ret,
-align4 pc to lblbootptr 0 ,
+0 align4 pc to lblbootptr 0 ,
xcode boot<
si lblbootptr m) mov,
al [esi] movclr,
@@ -783,11 +792,11 @@ xcode ' ( "name" -- w )
xwordlbl (wnf) abs>rel jz,
ret,
-align4 pc to L1 \ parse unsuccessful
+0 align4 pc to L1 \ parse unsuccessful
[ebp] 0 i) mov,
ret,
-align4 pc to lblparsec ( str -- n? f ) \ esi=sa ecx=sl
+0 align4 pc to lblparsec ( str -- n? f ) \ esi=sa ecx=sl
cx 3 i) cmp,
L1 abs>rel jnz, \ fail
8b! si 2 d) ''' i) cmp,
@@ -797,7 +806,7 @@ align4 pc to lblparsec ( str -- n? f ) \ esi=sa ecx=sl
1 pspushN,
ret,
-align4 pc to lblparseh ( str -- n? f ) \ esi=sa ecx=sl
+0 align4 pc to lblparseh ( str -- n? f ) \ esi=sa ecx=sl
cx 2 i) cmp,
L1 abs>rel jc, \ fail
si inc, \ skip $
@@ -826,7 +835,7 @@ L2 forward! \ parse ok
1 pspushN,
ret,
-align4 pc to lblparseud ( str -- n? f ) \ esi=sa ecx=sl
+0 align4 pc to lblparseud ( str -- n? f ) \ esi=sa ecx=sl
cx cx test,
L1 abs>rel jz, \ fail
ax ax xor, \ res
diff --git a/posix/vm.c b/posix/vm.c
@@ -497,11 +497,17 @@ static void DIVMOD() { // op: 3d
ppush(a/b);
}
-static void AND() { // op: 3f
+static void AND() { // op: 3e
dword n = ppop();
ppush(ppop()&n);
}
+static void ALIGN4() { // op: 3f
+ dword n = ppop();
+ n = (here() + n) % 4;
+ if (n) { allot(4-n); }
+}
+
static void OR() { // op: 40
dword n = ppop();
ppush(ppop()|n);
@@ -982,7 +988,7 @@ static void (*ops[OPCNT])() = {
RSADD, RSADDWR, RSADDR, RSADDRWR, SCNT, RCNT, NULL, NULL,
FETCH, STORE, ADDSTORE, FETCHSTORE, FETCHADD, STOREADD, IFETCHADD, ISTOREADD,
WRITE, SRD, SWR, WOFF, SETBW, SET16B, SET8B, SETNB,
- INC, DEC, ADD, SUB, MUL, DIVMOD, AND, NULL,
+ INC, DEC, ADD, SUB, MUL, DIVMOD, AND, ALIGN4,
OR, XOR, BOOL, NOT, LT, SHLC, SHRC, LSHIFT,
RSHIFT, LITN, EXECUTEWR, EXITWR, MOVE, MOVEWR, RTYPE, WNF,
STACKCHK, MAYBEWORD, WORD, PARSE, REQ, FIND, APOS, COMPILING,
@@ -998,7 +1004,7 @@ static char *opnames[OPCNT] = {
NULL, "r+,", NULL, "r',", "scnt", "rcnt", NULL, NULL,
"@", "!", "+!", "@!", "@+", "!+", "@@+", "@!+",
",", "\"<", ",\"", "(woff)", NULL, "16b", "8b", "?b",
- "1+", "1-", "+", "-", "*", "/mod", "and", NULL,
+ "1+", "1-", "+", "-", "*", "/mod", "and", "align4",
"or", "xor", "bool", "not", "<", "<<c", ">>c", "lshift",
"rshift", "litn", "execute,", "exit,", "move", "move,", "rtype", "(wnf)",
"stack?", "maybeword", "word", "parse", "[]=", "find", "'", "compiling",