2022-04-07 10:15:16 I can't follow the forth way to implement it when using a high level language 2022-04-07 10:15:41 Yeah - it's a little unusual for an HLL to allow getting it "really right." 2022-04-07 10:15:52 GNU C is an exception; it has extensions that allow you to get there. 2022-04-07 10:16:25 then I'll worry not and just do it in my way 2022-04-07 10:16:34 With it you can malloc a block of memory and get a real Forth running in there. 2022-04-07 10:16:38 forthwrights won't be pleased but meh 2022-04-07 10:16:47 Hey, it's your project. 2022-04-07 10:16:53 but I'll be as long as it works 2022-04-07 10:17:08 Right - that's what matters. 2022-04-07 10:17:13 :D 2022-04-07 10:17:30 btw thanks KipIngram you really helped me a lot to understand a lot of things 2022-04-07 10:17:42 When you're ready to do a "real" one, I recommend biting the assembly bullet. I've done one in C, but it got hard to maintain eventually. 2022-04-07 10:17:56 The C I mean - the Forth itself was as good as any. 2022-04-07 10:18:13 Sure thing - anytime. 2022-04-07 10:18:48 assembly is a language I always wanted to learn, so it's probable I'll end trying to do a forth with it 2022-04-07 10:19:13 but for now I'll make a concatenative language with a stack and rpn 2022-04-07 10:19:15 It's a very educational thing to do. 2022-04-07 10:19:39 that's the only thing that will be similar to forth, and the fact it executes words and the compile mode 2022-04-07 10:20:27 but I'll 2022-04-07 10:21:11 I'll have a hash instead of a linked list for a dictionary, I don't mind having older words being updated with a previous definition 2022-04-07 10:29:09 You know, I should qualify "real" so far as a C Forth goes. You get a system that operates in every respect like Forth should. But several of the key quantities, like the stack pointers and so on, wind up in *variables*, not registers. 2022-04-07 10:29:23 So that's definitely a performance impact. Assembly is the only way to resolve that. 2022-04-07 10:29:59 I know there's the "register" keyword in C, but I don't think it has to be honored, and in any case there are a lot of useful things to do with registers, and it's doubtful you'd ever get them all covered by the compiler. 2022-04-07 10:30:43 At this point I'm using 12 of the 16 registers for stuff in my system. A couple of those are just used for scratch, but the other 10 are "purposeful." 2022-04-07 10:30:44 Most compilers ignore it now. 2022-04-07 10:30:54 Doesn't surprise me. 2022-04-07 10:31:26 So, a C Forth can be "real" in the sense that you can explore any Forth "concept" with it. 2022-04-07 10:31:29 If you _really_ want to do something like that, write assembly (inline or otherwise) 2022-04-07 10:31:38 Indeed. 2022-04-07 10:32:53 I intend to take one more register too. Right now one is doing "double duty" for me - it holds the base address of the system, which I needed for that MacOS relocatability requirement and still have in place, and it is also the address of NEXT, so that I can run NEXT at the end of primitives via 'jmp '. 2022-04-07 10:33:35 But I want to split those two purposes, because I want to be able to specify alternate versions of NEXT for various reasons by reloading that register. But it can't change given that it's designated the system origin. 2022-04-07 10:35:24 But I've got a really nice notion about how to do profiling that involves a "profiling NEXT." It's pretty lean, too - won't slow things down very much. But of course it will have some small cost. 2022-04-07 10:38:23 I've had a couple of other possible applications for NEXT tweaking occur to me, but they're not coming to mind at the moment. 2022-04-07 10:45:55 you could do a primitive form of multitasking 2022-04-07 10:46:42 https://termbin.com/203f this is the most minimal "base" I can get by not following the forth way 2022-04-07 10:46:48 it's 60 lines 2022-04-07 10:47:08 but now the dirty stuff will start 2022-04-07 10:47:41 did you put the number detection first on purpose? forths usually put that second 2022-04-07 10:47:57 which can create some funny bugs :) 2022-04-07 10:48:42 MrMobius: what goes first? 2022-04-07 10:49:09 I don't like to have to traverse the dictionary just to notice it's a number 2022-04-07 10:49:17 dictionary search then number detection 2022-04-07 10:49:54 if i had to guess i would say it's like that to support other bases without needed a prefix 2022-04-07 10:50:28 I'll make hex oct words which will just convert the number to that base 2022-04-07 10:51:23 MrMobius: what funny bugs can create to look the dictionary first? 2022-04-07 10:51:42 like if you have a word which has a number as its name? 2022-04-07 10:52:14 like a hex number 2022-04-07 10:52:41 ya like i was parsing forth source with python doing replacements and had defined a word twice or something on accident so " : foo" became " : 13" 2022-04-07 10:52:57 ahahahah 2022-04-07 10:54:04 also, it probably wont help you on your system but the later HP stack based calculators had numbers 1-42 defined as words instead of numbers to speed things up 2022-04-07 10:55:02 which you couldnt do if you looked for numbers before looking at the dicitonary 2022-04-07 10:55:49 I don't really know what the looks_like_number really checks for 2022-04-07 10:56:03 MrMobius: Yes, that's true. 2022-04-07 10:56:13 but I trust if it says true it will be a valid number for perl 2022-04-07 10:56:20 Now that I have signal catching working that's a way of moving toward multi-tasking as well. 2022-04-07 10:56:30 and I suppose it covers hex numbers and alike 2022-04-07 10:57:05 vms14: Forth usually defines a few "common numbers" (like 1 and 0, for instance) as primitives for a slight efficiency boost. If you check for number first you can never reach those. 2022-04-07 10:57:39 I don't like the idea of having a word named as a number 2022-04-07 10:58:03 I mean, like MrMobius says the hp calculators had 1-42 as a word 2022-04-07 10:58:11 Definitely not something to get carried away with, and in fact it's not a very large performance boost. It's just sort of traditional, but strictly optional. 2022-04-07 10:58:29 and I suppose my language will be slow no matter what I do 2022-04-07 10:58:49 ya depends on what youre going for. youd want to squeeze out the last 1% of performance on a calculator with a tiny cpu. probably doesnt matter if youre on a PC 2022-04-07 11:01:33 have to take the dogs for a walk 2022-04-07 11:01:49 see you guys and thanks for all hints and explainations :D 2022-04-07 11:22:46 MrMobius: Was it you that I was discussing header layouts with a week / week and a half ago or so? The notion of putting the name field last? 2022-04-07 11:29:25 KipIngram, i dont think so. we talked about linked lists and binary searches for dictionaries but not where to put the name field 2022-04-07 11:38:23 Ok; wasn't sure. One of the other guys, I guess. 2022-04-07 11:38:52 Re: linked lists, I convinced myself last night that GForth is using a hash algorithm to find words to interpret or compile. 2022-04-07 11:39:01 I think it's just too fast to be doing any kind of list search. 2022-04-07 11:39:08 It's borderline ridiculous how fast it is. 2022-04-07 11:39:59 I sped my own search up quite a lot yesterday by switching from a Forth string compare to a primitive that uses repe cmpsb. 2022-04-07 12:11:20 You know, I'm just feeling particularly struck this morning by what an abysmal failure the software industry is. 2022-04-07 12:11:47 Imagine a world in which, say, the auto industry, or the airline industry, had a quality record matching that of the software industry. 2022-04-07 12:12:19 Say every week you get a list of dozens or hundreds of changes that need to be made to your car, in order for you to feel "fully safe." 2022-04-07 12:12:32 Obviously that can't happen. 2022-04-07 12:13:03 The software industry uses the fact that it CAN modify its fleet of products after they're already in customer hands as a CRUTCH to excuse gross incompetence. 2022-04-07 12:13:29 KipIngram, how do you mean about searching in gforth? i think a modern PC could search an enormous number of words and it would still feel instant 2022-04-07 12:13:32 And we all just accept this without thinking about it, because... it's the way things are. 2022-04-07 12:14:07 search without hashing i mean 2022-04-07 12:14:08 I wrote a word that conditionally resets >in to get it to re-interpret a bit of code a huge number of times, and timed it. 2022-04-07 12:15:03 What I got was it taking a couple hundred nanoseconds to find and execute that one word on the command line. And even after I buried that word under a significant number of other words, the time didn't change at all. 2022-04-07 12:15:24 So it gave no indication that it was comparing against the later-defined words on its way to finding the word. 2022-04-07 12:15:38 It behaved like it was going straight to it, as you would with a hashing-based system. 2022-04-07 12:16:13 It was really that latter fact - the fact that burying the word with other words didn't change the timing - that said "hashing" to me. 2022-04-07 12:16:40 Plus a couple hundred nanoseconds seems believable to me if it's hashing, but not if it's searching through a dozen other words first. 2022-04-07 12:17:01 I made these names very long - like 45 characters, and all the later words were the same length and differed in just one byte. 2022-04-07 12:17:19 thats pretty slick 2022-04-07 12:17:27 Yeah, I had fun with it. 2022-04-07 12:17:42 : tib-loop 1- dup 0= if r> drop then >in off ; 2022-04-07 12:18:03 Put a number on the stack, then execute tib-loop by itself on a new line. 2022-04-07 12:18:26 You can put other code before it too, as long as it makes sure to balance things up and expose the counter before the 1- 2022-04-07 12:18:37 MrMobius: re: search time; my forth takes 41s to do 50,000 lookups in a non-hashed dictionary. My new one with hashed dictionary takes 3.5s to do the same test. 2022-04-07 12:18:52 Yeah - hashing clearly wins. 2022-04-07 12:19:20 I took 53 seconds to do 5 million, but that was when tib-loop was the last word defined, and so sitting right at the top of the list. 2022-04-07 12:19:40 That was after I added the string compare primitive. 2022-04-07 12:20:14 And that would have included 1) parsing the word out of the stream and 2) finding it in the dictionary. 2022-04-07 12:20:20 And executing it, but... negligible. 2022-04-07 12:21:04 The WORD stuff is still all in high level Forth, and the s= string compare word is the only real "assembly support" in FIND - the rest of it is in Forth too. 2022-04-07 12:21:38 You can test number conversion time with this: 2022-04-07 12:21:55 : tib-loop drop 1- ... (rest the same) 2022-04-07 12:21:59 100000 2022-04-07 12:22:03 17495 tib-loop 2022-04-07 12:22:17 so in my system that would search the WHOLE dictionary and then fall back to number. 2022-04-07 12:22:50 MrMobius: I think it's a lot of fun being able to "instrument" the system like that. 2022-04-07 12:25:13 It'll make tuning in the future a snap - measure something, flip a switch, measure it again. Take your pick. 2022-04-07 12:25:55 I'm bummed I didn't think to do some measurements before I deleted the high level Forth string compare stuff. :-( 2022-04-07 12:26:04 I may go to the trouble of putting it back in just to do that. 2022-04-07 12:27:05 Anyay, I've always had the impression that the GForth developers have put a fair bit of effort into performance optimization. 2022-04-07 12:27:34 They at least used to publish white papers discussiong it; I remember one about a study they did comparing performance vs. how many stack items were register cached. 2022-04-07 12:27:56 "One" gave a big payoff - "two" gave slightly better performance, but not very much. 2022-04-07 12:28:02 That first one was the big win, clearly. 2022-04-07 12:28:59 Also, I saw a page of GForth documentation last night that, while stopping short of saying outright they used hashing for dictionary searches, did say that "these days, most systems do." 2022-04-07 12:29:19 Seems reasonable, given operation to operand ratios. 2022-04-07 12:29:27 That and the measurements I made last night convinced me. 2022-04-07 12:30:28 I mean, this is also the case for sundry C calling conventions regarding register usage on parameter passing up to using redzones. 2022-04-07 12:30:28 But my feeling is that any sort of hash table big enough to give you really good results are going to blow out the idea of an "8kB system" or anything like that. 2022-04-07 12:30:47 Hash tables are either sparse or have collisions - you sort of kind of can't have both. 2022-04-07 12:31:05 maybe with a fixed string set you can search for a lucky hash algorithm that works for those. 2022-04-07 12:31:15 But in the general case it's just probability theory. 2022-04-07 12:32:05 If your hash table has N slots, then there's a 1/N chance of getting a collision on the second string, 2/N for the third, then 3/N, etc. 2022-04-07 12:32:09 Perfect hash algorithms exist. Get with the times. 2022-04-07 12:32:31 Well, what I just said is the best you can do, unless you know your strings in advance. 2022-04-07 12:32:55 The best you can do is get a uniform probability distribution over your slots. 2022-04-07 12:33:16 As an aside, whilst not constant time, Tries would make for a good second best structure, though managing that with fixed wired memory can be tricky. 2022-04-07 12:33:34 Yes. 2022-04-07 12:33:51 Pamela trees are interesting to - they're O(N) where N is the maximum name length. 2022-04-07 12:34:01 Regardless of how many items are in the structure. 2022-04-07 12:34:14 But - also not very RAM efficient. 2022-04-07 12:34:39 Yeah, trees and tries tend to be not very cache happy either. 2022-04-07 12:34:45 If you've got RAM to spare you can do some really slick things. 2022-04-07 12:38:33 That's the thing - caches have really changed a lot of the thinking on this stuff. Sometimes the "poorer" algorithm wins because it's cache happy. 2022-04-07 12:38:41 Yep, indeed. 2022-04-07 12:38:58 But the costs also need to be amortised, since caches need to warm up etc. 2022-04-07 12:39:36 Right. 2022-04-07 13:04:08 i wonder how much of a boost you get from just xoring or adding all the characters together and storing that in the header 2022-04-07 13:04:29 on tiny systems like 6502 so no hash table or anything 2022-04-07 14:14:23 Wouldn't you have collisions? 2022-04-07 14:14:37 But yeah - a small hash table designed to handle the most commonly used words. 2022-04-07 14:15:11 If you have a fixed set of strings and you know them in advance you can "do work" to search for a hash algorithm that avoids collisions on tohem and yet gets good density. 2022-04-07 14:16:03 That 1/N, 2/N, 3/N stuff is just best case when the strings are arbitrary. 2022-04-07 14:17:33 If I were going to try to "spend RAM" on a hash add-on for my system, without really changing the system, I'd allocate a great big empty buffer at the outset. Use a "relatively good uniformity" but cheap hash algorithm, and calculate it it on the fly as WORD pulled each character out of the input buffer. 2022-04-07 14:17:56 Then before searching the dictionary, I'd take that hash and index into that big buffer with it - if I get a hit that gives me the CFA immediately. 2022-04-07 14:18:24 If I don't get a hit, then do the search and populate that entry of the hash table. So starting the second time you see each word, you get to avoid the search on that word. 2022-04-07 14:18:32 I guess that's kind of a memoization method. 2022-04-07 14:18:41 Pay once, eat forever. 2022-04-07 14:19:01 In general most of the buffer would go unused, but the presumption here is that RAM is plentiful. 2022-04-07 14:19:14 Bigger it is, less chance of collision. 2022-04-07 14:19:33 Big ENOUGH and maybe you don't even bother to confirm - just hit and run. 2022-04-07 14:32:37 After all, you could know ahead of time for all the built-in words whether any of them collided. 2022-04-07 14:35:17 Oh, shoot. I forget to include the EXIT in my definition of tib-loop. 2022-04-07 14:35:41 : tib-loop 1- dup 0= if r> drop exit then >in off ; 2022-04-07 14:36:00 I have a conditional return I use in my system that gets rid of the if ... then and the dup: 2022-04-07 14:36:11 : tib-loop 1- .0=; >in off ; 2022-04-07 14:37:29 The . used as a prefix like that generally mens "do what the rest of this word does, but retain one argument you'd otherwise drop." 2022-04-07 14:37:53 Well, it generally means that *to me* - just a convention I've adopted. 2022-04-07 14:38:52 I can't recommend those conditional returns enough - they're powerful as hell. 2022-04-07 14:43:20 I mean, just look at how much that one shortened that definition. 2022-04-07 14:48:13 I'll implement if by using lists of code like the last time 2022-04-07 14:48:29 at least now I have a "better" kind of a string type 2022-04-07 14:49:04 not much better :D but now I'm not splitting words by spaces, I have a little parser 2022-04-07 14:49:38 ': oh [ 4 3 2 ] 3 2 1 s" haha" ; oh oh' atm this works 2022-04-07 14:50:02 and strings can interpolate items from the stack by using ~a and newlines with ~% 2022-04-07 14:51:10 but will never be a real forth :/ 2022-04-07 14:57:49 should I go to a #notsoforth channel instead xD 2022-04-07 16:22:04 what 2dup does? makes 2 copies of the tos or does it like over over? 2022-04-07 16:22:39 I made it work like over over but I think I saw differences in some forths 2022-04-07 17:17:54 vms14: it should be the same as ‘over over’ 2022-04-07 17:22:21 ty, I saw on some place they made it duplicate two times the tos 2022-04-07 17:22:28 but I've done it like you say anyways 2022-04-07 17:22:40 new_word('2dup', sub { push @stack, @stack[-2,-1]; }); 2022-04-07 17:23:04 now I have if and if-else, but I have to make loops 2022-04-07 17:23:28 I have dotimes and a word named 'i' which gives the current iteration value 2022-04-07 17:23:45 but I need to be able to nest loops and get the j as forth does 2022-04-07 18:08:50 1 dup { 7 less-than } { incf dup dup . } loop drop 2022-04-07 18:09:02 ahahaha it's super broken but kind of works 2022-04-07 18:09:08 I have to fix it btw 2022-04-07 18:09:27 it prints 234567 2022-04-07 18:10:24 maw 2022-04-07 18:10:31 hi dave0 2022-04-07 18:10:43 I'm making an abomination again 2022-04-07 18:11:06 but this time I will continue and make it even more horrible and bigger than before 2022-04-07 18:57:03 need nested lists to get nested loops :/ 2022-04-07 19:28:40 KipIngram: our garage door opener has a $1 a month fee it we want to use it with Amazon Alexa, don’t worry my wife hacked it! 2022-04-07 19:30:48 Also Toyota were charging $8 a month to use the remote starter on the key fob until 3G stopped working and they couldn’t enable/check it. 2022-04-07 20:00:35 :-) :-) :-) 2022-04-07 20:00:41 GOLD STAR for your wife, man. 2022-04-07 20:00:44 That's great. 2022-04-07 20:01:02 That's just crazy. 2022-04-07 20:01:18 I'd like to say "that's un-American," but unfortunately that would be very inaccurate. 2022-04-07 20:01:28 These companies basically ARE America these days. 2022-04-07 20:31:43 say, I wrote an morse encoder the other day but I am musing on how to do the decoder 2022-04-07 20:33:11 thinking about using leaky integrators for the length detection of marks and spaces 2022-04-07 20:34:11 what is a leaky integrator? it is basically a bucket with a hole in the bottom and float switches at various heights 2022-04-07 20:35:00 damn handy for implementing stuff like in the ai of pocket pets 2022-04-07 20:36:08 one bucket for say how annoyed the pet is 2022-04-07 20:37:26 when some event that causes it annoyance happens a set amount of water is put in that bucket 2022-04-07 20:38:09 and the amount can be in relation of how agrivating the pet finds it 2022-04-07 20:39:16 then the float switches generate events when their state changes 2022-04-07 20:40:42 which could for instance change priority ordering of certain task steps it has in it goal queue 2022-04-07 20:49:56 another leaky integrator in the pocket pet can be satation 2022-04-07 20:50:57 but there there is a variable flow valve at the egress hole 2022-04-07 20:51:32 controled by how much activity it is doing 2022-04-07 21:03:45 that bucket then might have some float switches that generate agrovation events 2022-04-07 21:05:00 for funsies regarding breeding, some genes could control the parameters of these things 2022-04-07 21:36:35 That's interesting. 2022-04-07 21:36:53 I wrote a Morse decoder on my first ever IBM PC. 2022-04-07 21:37:09 I hooked the keyboard interrupt and put recognized characters in the keyboard buffer. 2022-04-07 21:37:25 That's how I got my old Novice license back when 5 wpm code was still required. 2022-04-07 21:37:38 I'd peck my dos commands in on the alt key. 2022-04-07 21:38:26 What I did was keep a running average of "down lengths," and presumed that that average should be greater than dot times and less than dash times. 2022-04-07 21:38:36 I don't know if that's "optimum," but it worked. 2022-04-07 21:39:08 I guess better might be to use that as a first approximtaion and then start keeping separate dot and dash averages. 2022-04-07 21:39:56 But yeah, there are probably AI algorithms that will "clluster" your durations for you, right? 2022-04-07 21:40:12 I am supposed to know the name of one of those, but it's not coming forth at the moment. 2022-04-07 21:40:31 It recognized "longer" pauses as word breaks, too. 2022-04-07 21:40:48 6809 is a Forth'ers dream 2022-04-07 21:40:53 God... that was getting on toward 40 years ago. 2022-04-07 21:41:04 6809 is a FANTASTIC little processor. 2022-04-07 21:41:13 KipIngram: we're all getting old lol 2022-04-07 21:41:26 https://techheap.packetizer.com/processors/6809/6809Instructions.html 2022-04-07 21:41:35 That's a nice page. 2022-04-07 21:41:50 Lots of information, no fluff. 2022-04-07 21:42:08 http://colorcomputerarchive.com/repo/Documents/Manuals/Programming/MC6809%20Preliminary%20Programming%20Manual%20(Motorola).pdf 2022-04-07 21:42:19 :-) 2022-04-07 21:42:22 I had one of those. 2022-04-07 21:42:29 That's what I wrote my first Forth on. 2022-04-07 21:42:35 nice 2022-04-07 21:42:38 With that little EDTasm module. 2022-04-07 21:42:41 it was my first computer 2022-04-07 21:42:43 yes! 2022-04-07 21:42:46 Me too. 2022-04-07 21:42:59 I upgraded mine from 16k to 64k. 2022-04-07 21:43:06 And felt like I was SWIMMING in memory. 2022-04-07 21:43:16 i didn't know how to pronounce EDTASM i said ED-TASM 2022-04-07 21:43:28 That was the first real "personal" hardware project I ever did. 2022-04-07 21:43:41 I said eee-dee-tasm 2022-04-07 21:43:51 ehehe 2022-04-07 21:44:00 But yours is really more sensible. 2022-04-07 21:44:18 things would be different if i had known about OS-9 at the time, but i was a kid 2022-04-07 21:44:30 I made the top 32k of that 64k my "disk." At startup I'd read a cassette into it, and then those were my blocks. 2022-04-07 21:44:46 nice 2022-04-07 21:45:00 I didn't really know how Forth was supposed to work then. 2022-04-07 21:45:00 you had to bank-switch the ROM to RAM 2022-04-07 21:45:17 So my Forth did all the right things, but it was way, way too complicated. 2022-04-07 21:45:32 Maybe, but I don't actually remember that. 2022-04-07 21:45:53 ah ok 2022-04-07 21:46:04 Gosh, I pounded the hell out of those little chicklet keys. 2022-04-07 21:46:47 it's an 8 bit cpu but there's a load of 16 bit instructions 2022-04-07 21:46:54 heaps* 2022-04-07 21:47:12 The 6809 was the processor that UT Austin EE department used to teach us assembly. I think that was lucky for us. 2022-04-07 21:48:42 I remember that the JMP instruction took an absolute address, but all the branch instructions (and there were a PILE of them - every condition you could imagine) were relative. 2022-04-07 21:48:43 cool 2022-04-07 21:48:59 yes it even had a BRN -- branch never :-) 2022-04-07 21:49:03 brb gotta get food 2022-04-07 21:49:28 I was still young enough then to get a juvenile rush out of the BRA instruction. :-) 2022-04-07 21:50:35 Any of you guys watch that TV show a few years ago - Halt And Catch Fire"? 2022-04-07 21:52:09 First season, part of the second - that was right up my alley. Felt very very familiar. Then the plot wandered off into gaming and web and stuff I was never a part of; I kind of fell out of the habit. 2022-04-07 21:56:24 I have a 6309 here im gonna hook up someday 2022-04-07 21:57:13 63? 2022-04-07 21:57:31 MrMobius: https://github.com/bnobel/nitros9 2022-04-07 21:58:08 Ah, OS-9. 2022-04-07 21:59:16 Oh - 6309 sounds like it's a step above. 2022-04-07 21:59:33 32 bit math, division... 2022-04-07 22:01:28 Those were some days, man. You could hardly blink without something new and better appearing. 2022-04-07 22:01:58 I really enjoyed the '80s. 2022-04-07 22:02:37 I still perk up when a TV show or movie has women in 80's attire and hairstyles. 2022-04-07 22:05:47 A good one is when the guys go downstairs at the ski resort that "next morning" after their first trip in the Hot Tub Time Machine. 2022-04-07 22:18:46 KipIngram, ya 6809 compatible with a software switch to access the added stuff 2022-04-07 22:19:15 Looks neat. 2022-04-07 22:19:27 What are you going to do with it? 2022-04-07 22:20:12 probably nothing since ill die of old age before i get around to doing anything with all the junk i have 2022-04-07 22:20:33 but building a calculator would be the goal for that and 25+ other doodads i have lying around here 2022-04-07 22:21:02 I was looking at that 6809 instruction set page and thinking it likely wouldn't be too hard to write an emulator for that. 2022-04-07 22:21:59 like the RCA 1804 or 1806 i have, super fast single cycle 8051s, 16 bit 8051 derivatives, i960, and 6502 modem processors with hardware threading built in 2022-04-07 22:22:12 KipIngram, that would be cool! 2022-04-07 22:23:58 Do you think a byte-code interpreter? That would hook the first bytes, and the emulation code would move the pointer along however much further it needed to go. 2022-04-07 22:24:25 Keep all the '09 registers in native registers, and just diddle as appropriate. 2022-04-07 22:24:35 Probably could be pretty fast. 2022-04-07 22:25:55 KipIngram: i'm pretty sure there's a color computer emulator in the browser 2022-04-07 22:26:16 not 100% sure but i have a vague memory 2022-04-07 22:26:57 javascript is a scripting language and it runs an emulator faster than the original machine! 2022-04-07 22:27:14 a scripting language that compiles to machine code 2022-04-07 22:27:24 my 6502 runs at the equivalent of 60mhz or so in the browser 2022-04-07 22:27:30 *6502 emulator 2022-04-07 22:28:32 crazy 2022-04-07 22:28:47 KipIngram, ive really gotten into emulation and done several projects. would this be x86? keeping registers and flags matching the target system can work but it can be faster to just save the arguments generating the flags for later and not set anything until the flags are needed 2022-04-07 22:31:32 Oh cool - ok. I haven't actually done it; it just seemed like a reasonable way to try. And if I do it it would likely be for the x86, since that's what I've got. 2022-04-07 22:34:22 i havent shown anyone but i built a converter that would take a 6502 assembly listing and produce x86 assembly to eliminate the overhead of interpreting the instructions like byte codes 2022-04-07 22:34:34 runs at the equivalent of a 440mhz or so 6502 2022-04-07 22:35:32 still working on optimizing combinations of 6502 instructions down into less and faster x86 ones where possible. that's the only place forth snuck in since the optimization descriptions are in a forth like script 2022-04-07 22:36:46 That sounds fantastic. And fascinating. 2022-04-07 22:39:57 ya i couldnt figure out a way to specify a whole bunch of equivalent patterns at once so went with this. dunno how real optimizers like gcc keep track of it 2022-04-07 22:40:14 Motorola processors were big-endian, weren't they? 2022-04-07 22:41:17 like a 16 bit add is CLC / LDA foo / ADC bar / STA foo / LDA foo+1 / ADC bar+1 / STA foo+1 which can be replaced with two x86 instructions 2022-04-07 22:41:23 KipIngram, I think so 2022-04-07 22:42:46 but there are a huge number of equivalent permutations there since the CLC and LDA can be swapped. also LDA foo / ADC bar is equivalent to LDA bar / ADC foo. the same for the second ADC 2022-04-07 22:43:37 That sounds fancy - seems interesting, but I'm sure I'm not following it quite right. 2022-04-07 22:44:16 Do you just study the instruction sets until you notice these things? 2022-04-07 22:46:10 well think about it this way 2022-04-07 22:46:43 if you have a bunch of 8 bit 6502 operations that youre converting to x86 you can just spit out the equivalent 8 bit x86 operations 2022-04-07 22:47:45 but because x86 can also do 16 bit operations, your translation to x86 will be smaller and faster if you spot when the 6502 is doing a 16 bit operation using 8 bit operations and use 16 bit x86 operations instead of the 1 to 1 translation to equivalent 8 bit x86 2022-04-07 22:48:20 so the question is, what does a 16 bit add even look like for 6502? it will always be those same 7 instructions i showed above 2022-04-07 22:49:28 but they can appear in different orders and still do the same thing. it should be the same on 6809 or x86 if you think about it. clear carry, load a, add b, store a on any architecture is equivalent to load a, clear carry, add b, store a 2022-04-07 22:49:50 Ah. Ok, that's straightforward enough. 2022-04-07 22:51:35 so there are at least dozens of combos on the 6502 of that 7 instruction sequence to look out for. the question is whether you are patient enough to write them all out for the optimizer to spot. i am not so i made a type of scripting where i only specify two patterns then use a bunch of forth looking formulas the optimizer uses to test whether a particular 7 instruction stretch fits the pattern 2022-04-07 22:52:39 Yes - nice. 2022-04-07 22:55:20 So, it seems like there should be some way to write out the effect of each instruction in some "mathematical way" - the effect on some sort of "generic resources." Then you could start mapping out sequences and maybe find some of this stuff automatically. 2022-04-07 23:02:10 ya that might be a more effective way 2022-04-07 23:02:35 what im doing is basically peephole optimizing 2022-04-07 23:02:56 apparently if you track the flow of bits and flags and everything you can do more effective optimization 2022-04-07 23:03:24 I see what you mean about waiting until status is actually needed - we do a whole lot of instructions in our programs that produce status we never use. 2022-04-07 23:03:49 In fact, I'd almost say that the times we do use the status would be quite a minority. 2022-04-07 23:03:50 the other thing i though of mainly in relation to optimizing forth is to keep track of the effects of some code then ignore the original and have your optimizer create code to do make the same effect and keep it if it's shorter/faster than original. dunno if that's a way real optimizers work either 2022-04-07 23:04:08 that means that's power wasted, too. 2022-04-07 23:04:45 yep. thats why optimizing out flag setting for the 6502 to x86 stuff is probably the most effective optimization 2022-04-07 23:04:48 Oh, I think that sounds like a very possible thing to do. 2022-04-07 23:04:52 as long as you can live without self modifying code 2022-04-07 23:05:30 And it should certainly get the "obvious" cases. Like, swap swap, or dup drop. 2022-04-07 23:10:21 I'm thinking along the lines of representing the effect of each instruction as a vector in some sort of weird vector space. 2022-04-07 23:10:36 A sequence of instructions is a sum of vectors, and it gets you to a certain point. 2022-04-07 23:10:48 Any set that adds up to that same vector is equivalent. 2022-04-07 23:11:38 And since we have a lot of freedom, in an emulation, as to how we map target resources onto actor resources, that could vary too, and that could maybe in some cases be like rotations. 2022-04-07 23:12:06 But I think that somewhere in there would the actual permutations of the axes. 2022-04-07 23:12:17 It doesn't really feel like a perfect fit to me. 2022-04-07 23:13:25 Another analogy is getting a chess piece between two different points on the board. The different pieces move in different ways, so the sequence of moves would be differ. 2022-04-07 23:14:30 I think I'll have some fun thinking about this. 2022-04-07 23:17:52 its one of those things i like thinking about too and have made some progress implementing useful things but havent read the books or papers that would explain the most efficient way 2022-04-07 23:18:14 But that can sometimes be the most effective kind of learning. 2022-04-07 23:18:45 "Seeing for yourself," even if it's not quite optimum, beats memorizing something from a book any day. 2022-04-07 23:19:06 So let's take a step back. 2022-04-07 23:19:13 The processor state is a pile of bits. 2022-04-07 23:19:18 All the bits of all the registers. 2022-04-07 23:19:23 ya thankfully im not a student and dont need to cram for anything. i like failing before reading how youre supposed to do it 2022-04-07 23:19:30 The instruction stream is an input stream. 2022-04-07 23:19:47 So it's just a Mealy state machine. That's like the "launchpad." 2022-04-07 23:19:59 Then we go from there. 2022-04-07 23:20:40 Wel, that was that first Color Computer Forth for me. 2022-04-07 23:21:16 It worked - I was proud of it. Then I found that "Forth fundamentals" book, and when I read that... it was just so beautiful. Simple, clean. 2022-04-07 23:24:08 That state machine view is probably "too general." Consider all the add instructions. 2022-04-07 23:25:02 The ground zero state machine sees the new state as one in which the bits have changed, but it has no insight into why it's those particular bits. Having it somehow "figure out" that all the add instructions, with different operands, had something in common would probably be hard. 2022-04-07 23:25:59 I think our analyzer has to have some concept of what "canonical operations" are being performed. 2022-04-07 23:28:15 ya i can see how to simulate stack juggling operations and then create assembly to do the same but havent figured out yet how to model addition 2022-04-07 23:31:20 Well, some of the "next state bits" would be the sum of a pair of bitfields from the prior step. It would be "in there." 2022-04-07 23:31:33 But seems very hard to detect automatically. 2022-04-07 23:32:39 Anyway, the *simplest* emulator, I think, would be to just grab the next byte in the stream (with lodsb or someting), and turn that into a table index. 2022-04-07 23:33:01 Jump through the table to a short snip of code that emulates that opcode. 2022-04-07 23:33:15 right. no need to optimize further in most cases 2022-04-07 23:39:08 and one trick if you have a cache is to put a copy of the jump code at the end of every short snip 2022-04-07 23:45:32 Hang on - getting a drink. 2022-04-07 23:49:19 Yes - caches have gotten big. 2022-04-07 23:51:01 Even just my L1 cache is 256k. 2022-04-07 23:51:17 That's big enough to hold my entire system as it stands today. 2022-04-07 23:51:49 Like 15 times. 2022-04-07 23:56:46 So I was thinking earlier about allocate another register, so that my "NEXT pointer" and system origin pointer can be separate. Opens the door to alternative NEXTs. But, I'm also thinking that perhaps I need a register that points to a "thread block." That block would contain at least one slot to hold a stack pointer for the thread while it sleeps (everything else would be ON the stack), and and perhaps 2022-04-07 23:56:49 some variables that offset from that register. "Task local variables." 2022-04-07 23:57:07 Then that slot, whaever variables the thread used, and hte two stacks would be all that was required to define a thread. 2022-04-07 23:57:27 That might be just a few hundred bytes. All the code would be a system-wide shared resource. 2022-04-07 23:57:42 Few hundred bytes - that's getting down to Erlang / "green" thread territory. 2022-04-07 23:57:53 Might need a message queue in that block as well. 2022-04-07 23:58:15 In Erlang the idea is that tasks have private states and communicate with each other only via messages.