-
Notifications
You must be signed in to change notification settings - Fork 6
memset optimizer(?) still thinks DCPU is 8-bit addressible #14
Copy link
Copy link
Open
Labels
Description
The optimizer seems to think a 16-bit set is enough to clear two adjacent words in some cases. The code is correct without -O.
$ cat memset3.c
void* mymemclr4(int *buf, int len) {
int *end = buf+len;
while(buf != end) {
*buf++ = 0;
*buf++ = 0;
*buf++ = 0;
*buf++ = 0;
}
}
extern int buf[128];
int main() {
mymemclr4(buf, sizeof(buf));
}
$ bin/clang -target dcpu16 -S memset3.c -O -o -
memset3.c:9:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
; .file "memset3.c"
.text
.globl mymemclr4
; .align 1
:mymemclr4
IFE B, 0x0
SET PC, .LBB0_2
:.LBB0_1
SET [0x2+A], 0x0 ; <--- it somehow thinks set [a+2],0 and set [a], 0
SET [A], 0x0 ; <--- is sufficient to clear 4 words.
ADD A, 0x4
ADD B, 0xfffc ; <-- it's also somewhat perplexing that it doesn't generate sub B, 4 here
IFN B, 0x0
SET PC, .LBB0_1
:.LBB0_2
SET PC, POP
.globl main
; .align 1
:main
SET PUSH, J
SET J, SP
SET A, SP
SET [A], 0x80
SET A, buf
SET B, 0x0
SET C, 0x0
JSR memset
SET A, 0x0
SET J, POP
SET PC, POP
Reactions are currently unavailable