64 points · by panic · 10y ago · 54 comments
In the first hardware implementation, integer divide had been botched, and gave wrong answers for odd-numbered divisors. There was an argument in the data sheet that most divisors are even, and a subroutine for correct divides when needed.
[1] http://www.cpushack.com/2013/02/21/charles-moore-forth-stack...
http://opencores.org/project,hive
I need to update the paper and code, the core is at v9.03 and the simulator can now parse assembly code as input.
IMO canonical stack processors aren't a good substitute for register-based processors. Hive is a stack / register hybrid that makes the 2 operand architecture more efficient. And I don't know why barrel processors aren't taking over the world - they make too much sense I suppose.
https://news.ycombinator.com/item?id=9920760
It's a thesis describing a C compiler for stack machines. (The link in the article is dead now. See https://www-users.cs.york.ac.uk/chrisb/main-pages/publicatio...)
It achieves comparable code density with gcc's x86 (albeit for a fictional architecture).
The really interesting bit is Appendix E, which proposes an architecture for a fast stack machine. It uses a fairly traditional 16-bit instruction encoding, except instead of registers each 4-bit operand slot contains an encoded stack manipulation --- a rot or a pick. This should give even better code density while still being easy to implement.
Unfortunately I've never tracked down a copy of his compiler...
Appendix E describes I believe what Hive does: a separate bit associated with the operand selector is used to control pop behavior. I'll have to credit this paper in mine (nothing ever really new under the sun).
For the rest of the paper, if you look at his "optimized" code there are still a ton of stack ops going on, which are time wasters IMO. This is why three operand machines "won" the techno shootout, a very useful move is included with every instruction. In contrast, well written Hive assembly contains very few time wasting copy / move / pop instructions (for a two operand machine).
Perhaps you, or someone here, would know: has anyone asked and tried to analytically answer what primitive operations an ALU ought to have? I mean, everything could be coded as a look-up-table, but given code "on average", what should be available in hardware.
It's a strange question that requires you pose it properly to even begin to answer it. For example, in the kind of stuff I do, popcnt and other "set-like" bit operations, i.e. most-significant set bit, are important enough that I just wish they were built in.
Mine you, I'm doing high-performance data processing, so perhaps it's not part of the scope of "average" code, but I disagree.
Very good question. I think this is where the "art" of computer design starts, and it generally gets short shrift. For instance, the ARM lacks a leading zero count instruction, which is a pretty wild omission because it has tons of uses (particularly for floating point) and is fairly expensive to implement in software using other primitives.
I know it's not scientific, but I learned what to put in the Hive ALU by programming various algorithms I figured I would need at some point. I just developed a bunch of floating point subroutines for Hive (cos, sin, sqrt, 2^x, log2, 1/x, etc., not in the paper yet) and, short of adding a floating point pipeline, could only really justify adding an opcode that returns +1 / -1 based on the sign bit (for use in storing sign and doing absolute value). My seat of the pants rule is that if it has broad applicability, saves time and code space, and isn't too costly in terms of hardware / speed, then I put it in. Otherwise I leave it out.
IMO, more of computer engineering should focus on what to leave out.
Do you want to go fast, or do you want to get the gate count down?
Intel does code measurement to decide which instructions have to go fast, and which don't. Typically they run Windows workloads for this. It's not an analysis from first principles.
The RISC crowd put a lot of effort into trying to reduce the instruction set. They tended to end up with simple instructions that could be hard-wired, and lots of registers. Many early microprocessors were microprogrammed to get the gate count down, and slow because of it. RISC was a reaction to that.
Early RISC thinking focused on not only making all instructions the same length, but making them all take the same time - one instruction per clock. Then superscalar came to microprocessors, with the Pentium Pro, and ordinary CPUs started getting more than one instruction per clock. (Before the Pentium Pro, only supercomputers had that kind of hardware.) This killed the basic advantage of RISC.
Most of the little Forth CPUs are one instruction per clock. Most Forth CPUs can hit the data stack, the call stack, and the main memory, which are all separate, on each cycle.
Their Java processor outperforms most of the others with small amount of space. It's open. Doesn't necessarily have to run Java as Oberon or something could probably be ported. The papers section is full of good stuff.
Why not?
Forth is the way it is mainly because Chuck Moore wants it that way. It's his preference. Tiny cores, typeless, hand-optimized to near metal, primitive VLSI tooling, 18-bit CPU's... nothing justified by scientific or engineering argument. All surpassed by other work in cost-benefit analysis. Nice write-up here by one person that delved deep into it to see good and bad of it:
http://yosefk.com/blog/my-history-with-forth-stack-machines....
As the blog author points out, local variables are a huge issue on a stack machine because they lead to stack thrash. ANY stack manipulation must be seen as fundamentally inefficient, and they make Forth a naturally obfuscated write-only language IMO.
I understand complexity push-back, particularly in the processor / SW worlds where so much of it seems actually harmful, but the cult they've formed around Chuck Moore is kinda weird and it makes it hard for noobs to get a balanced picture of computing.
It doesn't mean Forth is most convenient to write for any kind of problems, or that translator can easier optimize for Forth target... yet this at least is an opportunity to have a nicer language on the bare-bones level. Do you think it's a good enough thing?
One wonders why a company like GreenArray is trying to sell his designs. Must be a band of lunatics. A PhD paper from 2007 is certainly more serious than a company spending millions to get Moore's ideas on wafers.
The J1 was an interesting processor to work with. The speed was very impressive. They produced a pretty nice dev environment to process the code with the Arduino.
I think we know now that tailoring a processor to a particular language isn't particularly efficient (though the opposite i.e. assembly is).
And yet, given the way C exploits have plagued the industry, Intel, ARM, CHERI are actually adding tagged instructions that allow C compilers to generate code that validates array and pointer accesses at hardware level.
Just like the language specific processors that you state as not being efficient.
Early on there were efforts to build custom Lisp machines, etc. which were abandoned when CPUs became good enough and general purpose enough. Using a stack processor as a stack language target seems natural until you see all the inefficient stack gymnastics that go on at the lowest level.