2021-11-18 13:11:15 Are there any write-ups on optimizing machine code forths, like for mecrisp or similar? 2021-11-18 13:45:13 veltas, i asked the guy who made mecrisp about that and he gave me this link: https://home.hccnet.nl/a.w.m.van.der.horst/forthlecture5.html 2021-11-18 13:46:09 Thanks MrMobius, exactly the kind of content I'm after 2021-11-18 13:47:04 veltas, also, the german forth club called Vierte Dimension puts out a newsletter that has mentioned mecrisp several times 2021-11-18 13:47:05 https://forth-ev.de/wiki/res/lib/exe/fetch.php/vd-archiv:4d2019-01.pdf 2021-11-18 13:47:32 i think this one is a follow up. there is at least one other about how it works 2021-11-18 13:48:03 and Matthias himself is in #mecrisp if you want to ask. he's very friendly 2021-11-18 13:48:23 nvm i see youre already there :P 2021-11-18 13:49:01 Yeah sorry I always spam my questions to all relevant channels :P 2021-11-18 13:49:43 aaand if youve seen the forth2020 videos on youtube/facebook someone was talking about z80 optimizing a month or two ago 2021-11-18 13:54:03 iirc that's your interest veltas 2021-11-18 14:00:34 Yes I did write a Z80 forth but I'm not that interested in optimisation there 2021-11-18 14:00:50 You don't have room in 48K to optimise, need to leave space for the program really 2021-11-18 14:01:05 Well you can optimise, but not write an optimising compiler 2021-11-18 14:01:29 I'm interested to know how their optimised forth compares to my one 2021-11-18 14:01:42 ive been thinking about optimizing 6502 and Matthias' advice was to focus on a few powerful optimizations which i think is a good approach 2021-11-18 14:01:49 I'm writing an x86-64 forth right now, for desktop computers 2021-11-18 14:02:05 neat. you can always look at the source of mecrisp 2021-11-18 14:02:12 Yeah I don't disagree but really you can just not bother 2021-11-18 14:02:38 The old philosophy of FORTH is if your CODE words are properly optimised then the FORTH will be fast enough 2021-11-18 14:02:39 i think he said it's only 2-3 times slower than C which is amazing. you could compare yours to gcc and also to win32forth which is i think the one for x86 that optimizes a lot 2021-11-18 14:03:04 My FORTH will only be 2-3 times slower than C probably, I know what SDCC's output looks like 2021-11-18 14:03:17 SDCC is a pretty good 8-bit compiler, 8-bit is especially hard to optimise for 2021-11-18 14:03:24 thats is quite naive but i dont want to be resopnsible for starting a flame war (again) :) 2021-11-18 14:03:31 :P 2021-11-18 14:03:42 naive and yet backed up by experience 2021-11-18 14:04:00 not backed up by my experience. ymmv as they say 2021-11-18 14:04:07 I've written C, assembly, and forth extensively for Z80. Well actually FORTH is the thing I've written least for it 2021-11-18 14:04:27 It certainly has good parts and bad parts 2021-11-18 14:04:50 hmm, ive only used SDCC briefly and for 8051. ive heard it's not too well optimized. how does it looked compared to hand written assembly? 2021-11-18 14:05:50 It's much worse but in my opinion it's quite a good C compiler 2021-11-18 14:06:11 People have forked it and made it a little better at Z80, but it's already not too bad 2021-11-18 14:06:18 But it's way worse than writing assembly 2021-11-18 14:06:41 eh that's pretty bad imo for a c compiler when you consider that some are just about as good as a human 2021-11-18 14:07:08 and i get what you mean about it being hard to make a good c compiler for 8 bit chips but a lot of those problems can be overcome if you write your c code differently 2021-11-18 14:07:20 I am convinced 8-bit is necessarily much harder than normal archs for C compilers. Z80 is highly non-ortho and C deals with 16-bit words, stacks etc that Z80 is weaker/limited on 2021-11-18 14:07:22 ie declaring your array index as an 8 bit type and avoiding pointers when possible 2021-11-18 14:08:01 You can certainly avoid as many 16-bit calcs but frankly you need 16-bit calcs for most stuff anyway. Z80 programmers are used to juggling the limited 16-bit support 2021-11-18 14:08:42 you do need them but when you do the C compiler isnt any slower than asm. the thing is to prevent the C compiler from using 16 bit stuff when you would use an 8 bit operation in assembly 2021-11-18 14:09:09 The reason later archs have compilers that are as good as or better than humans is because e.g. x86 translation from C is quite trivial (and of course it's a more popular arch) 2021-11-18 14:09:37 There is some finesse stuff in GCC these days that's really cool but even DOS compilers were not that bad for x86, it is much easier 2021-11-18 14:10:19 its also the huge amount of work that was put into the compiler for x86. no one seems to have cared enough to do it for 8 bitters like 6502 and Z80 to a high degree 2021-11-18 14:12:14 do you know if anyone has tried to get llvm working for Z80? there have been a couple attempts for 6502 and one is ongoing but im not holding my breath 2021-11-18 14:24:24 Yeah people have tried 2021-11-18 14:24:40 The best attempts are transalting x86-16 to 6502 and Z80 2021-11-18 15:09:06 MrMobius: I looked around for a while but not much came up 2021-11-18 15:09:11 there's this though 2021-11-18 15:09:23 https://github.com/earl1k/llvm-z80 2021-11-18 15:53:51 I don't know too much about LLVM but I would guess the problem is not really about what LLVM does, but is instead about code generation, so whether it comes from x86-16 or LLVM you're going to have trouble 2021-11-18 15:54:50 Because Z80 is so awkward you are going to need code that probably does some clever approximations and techniques to optimise without much deterministic help 2021-11-18 15:56:41 Maybe LLVM has stuff that makes code generation easier, but it's also designed for machines that are 16-bit or larger 2021-11-18 15:56:54 And nowhere near as janky 2021-11-18 15:58:21 You could probably start with the sdcc backends and cludge them into LLVM somehow (if sdcc hasn't been mentioned already) 2021-11-18 15:58:29 I didn't really read the scrollback. 2021-11-18 15:59:48 Oh, it was. Nevermind. 2021-11-18 16:00:41 SDCC has the kind of code you need 2021-11-18 16:03:49 I believe it does something like generates the code with many alternative code selections for each IR step, and then peep-hole optimises each, and uses heuristics to decide which are worth continuing with 2021-11-18 16:04:13 But then it has kind of a rigid and inefficient method for handling stacks / structs 2021-11-18 16:04:27 It's IR is GIMPLE, right? 2021-11-18 16:04:31 Its, even. 2021-11-18 16:04:36 But go ahead and try doing a better job. No really, I hope you manage to do something better because that would be really useful 2021-11-18 21:58:59 any new chuck moore videos? I think the government should grant him some money to teach forth his way and should use greenarraychips.com to do government websites instead of oracle and microsoft