9 ms·
Qnice – An Elegant 16 Bit Processor
- magicalhippo 7y agoAh neat! Very recently I picked up an FPGA dev board and started playing with implementing my first toy soft-CPU. For fun, and definitely not for profit, I decided to design my own ISA for it. I decided to see if I could make a RISC-y MISC (minimal instruction set computer) design. From what I could see a lot of MISC-based computers had quite complex instructions. While my resulting ISA is likely quite crap, being my very first ISA ever, it's been quite a fun exercise so far. I programmed quite a lot of asm back in the days, but thinking about which instructions are needed and why was something else.
- colatkinson 7y agoI've always wanted to do exactly what you just described! Can you recommend any resources to get started with FPGA design for a software dev?
- magicalhippo 7y agoI've so far been quite happy with the iCE40UP5k[1] based dev kit I got, though there are a lot of options out there[2]. The iCE40 FPGAs are a bit whimpy compared to Altera and Xilinx offerings from what I understand, but I really liked the idea of an open-source toolchain[3][4] being available. To get a taste without committing cash you could just use a simulator[5], which I imagine you'd be using a fair bit anyway as it allows you easier access to the internal state. As to actually programming, I've found the following resources useful. I started with Verilog mainly because code-gen tools like nMigen[6] generate Verilog, but for writing by hand it seems VHDL is preferred. Anyway, links, first off some exercises to get going[7]. Introduction to Verilog[8], also has a nice general overview of HDL. Details of how non-blocking vs blocking statements in Verilog works[9], quite specific but was very informative for me. There's also quite a lot of activity over at Reddit[10], and good experiences over at the EEVBlog forums[11]. As I said I just got started so no expert yet :) [1]: https://www.digikey.com/product-detail/en/lattice-semiconductor-corporation/ICE40UP5K-B-EVN/220-2134-ND/6596291 https://www.digikey.com/product-detail/en/lattice-semiconduc... [2]: https://joelw.id.au/FPGA/CheapFPGADevelopmentBoards https://joelw.id.au/FPGA/CheapFPGADevelopmentBoards [3]: https://symbiflow.github.io/ https://symbiflow.github.io/ [4]: https://github.com/cliffordwolf/icestorm https://github.com/cliffordwolf/icestorm [5]: http://iverilog.icarus.com/ http://iverilog.icarus.com/ [6]: https://nmigen.org https://nmigen.org [7]: https://www.fpga4fun.com/ https://www.fpga4fun.com/ [8]: https://www.chipverify.com/verilog/verilog-tutorial https://www.chipverify.com/verilog/verilog-tutorial [9]: http://sunburst-design.com/papers/CummingsSNUG2002Boston_NBAwithDelays.pdf http://sunburst-design.com/papers/CummingsSNUG2002Boston_NBA... [10]: https://www.reddit.com/r/FPGA/ https://www.reddit.com/r/FPGA/ [11]: https://www.eevblog.com/forum/fpga/ https://www.eevblog.com/forum/fpga/
- magicalhippo 7y agoForgot to mention http://www.asic-world.com/verilog/veritut.html http://www.asic-world.com/verilog/veritut.html which also has some nice explanation of HDL and hardware in general. Also it's very important to keep in mind that HDLs describe hardware, the HDL code is not executed on the hardware. Think of it as writing C++ templates.
- tails4e 7y agoVerilog for writing RTL is fine, especially if you use the syhthesizable subset of SystemVerilog. There used to be a bit of a religious war between VHDL and Verilog, as VHDL had some syntax that prevented certain errors, but with SV and some basic coding guidelines it's fine. While I'm sure some will still be hanging onto VHDL, I'd say most of the industry is going the SV way.
- magicalhippo 7y agoGuess it might just be the bias of the forums I've been in, but most seemed to use VHDL there. Good point about SystemVerilog though.
- aseipp 7y agoSystemVerilog improves things a lot actually, but the problem is that there is (currently) no freely available, robust synthesis frontend that supports the majority of the useful SV features (e.g. interfaces). In fact I don't think there's any robust, ~complete FOSS SystemVerilog simulators either -- though Icarus and Verilator support SV to varying degrees... So if you want to stick with FOSS tools, then you're stuck with synthesizable Verilog-2005 at best, for the moment. And standard Verilog very much sucks in a lot of ways, I would argue, synthesizable subset or not. It's an understandable choice though, in a field full of awful options. One day I'm hopeful Yosys will support most of the necessary SystemVerilog features people want for synthesis... (Then, it can also serve as an effective SystemVerilog -> Verilog translation tool, which would be very useful on its own.)
- ZirconiumX 7y agoCould you please point [6] at https://github.com/nmigen/nmigen https://github.com/nmigen/nmigen which is the new upstream after a hard fork? Additionally, I'd like to clarify that nMigen generates Verilog indirectly; it actually generates RTLIL, which is the intermediate representation of Yosys, and then Yosys turns it into Verilog after some cleanup passes. I'll happily admit to being biased, but nMigen is so much easier for me to work in than Verilog ever was.
- magicalhippo 7y agoOh yeah also forgot to add that once you have some hardware you'll most likely want a cheap logic analyzer that supports sigrok[1] like this[2] one. Some LEDs and a breadboard etc is useful too. [1]: https://sigrok.org/ https://sigrok.org/ [2]: https://www.aliexpress.com/item/32877931876.html https://www.aliexpress.com/item/32877931876.html (random seller link)
- saagarjha 7y agoHas anyone implemented this in hardware yet?
- ngcc_hk 7y agoAlso got some spare fpga, any test required?
- titzer 7y agoI really like conditional subroutine calls. I wish x86 had them. It makes it really easy to inline a fastpath of some safety check (e.g. nullcheck, bounds check, write barrier, etc), and have the slowpath be factored out to a common place. What PL implementations like the JVM, JavaScript engines, etc typically have to do without this is they insert a conditional branch to "deferred code" which is at the end of the function (statically predicted not-taken), but that deferred code can't be shared, because it needs to branch back to the mainline code. That costs code size. A conditional subroutine call is exactly the right mechanism to solve this!
- aparashk 7y agoCan’t agree more!
- projektfu 7y agoCurious why it leaves out PC-relative addressing. By 1990 it seems that was one of the obvious shortcomings of 8086.
- Taniwha 7y agoVery pdp11ish, even looks like it supports "mov -(pc), -(pc)" (if you ignore the register windows and the lack of byte instructions - word addressing harks back to a previous age)
- throwaway_pdp09 7y agoTangential question, something I've always wanted to ask. The ISA here is given by example, here's a couple MOVE src, dst: dst := src ADD src, dst: dst := dst + src I have always wondered why assembler is written the first way MOVE src, dst ADD src, dst rather than the far more intuitive (and slightly more compact) second, something like dst := src dst += src This also completely eliminates questions about which direction data goes, is 'mov a,b' a:=b or b:=a for example. I can't see any reason for not using the established C-type notation, so why is the original style always perpetuated? I'm aware that C approximately maps onto the original PDP ISA and has been called a high-level assembler, true or not that's irrelevant, but why the higher-level syntax has never made its way to lower level ASM has baffled me.
- gtirloni 7y agoAT&T vs Intel syntax
- Zardoz84 7y agoIt's Intel vs AT&T syntax : Intel: mov eax, 4 AT&T : movl $4, %eax One could interpret that doing ADD a, b, c would be "do a + b and put in c"
- titzer 7y agoIt's very useful to have the actual instruction mnemonics spelled out, instead of relying on an implicit (often overloaded) definition of "+". E.g. there might be a 8-bit, 16-bit, 32-bit integer add, a 32-bit, 64-bit floating point add, a 16x8 vector integer add, etc.
- throwaway_pdp09 7y agoHm, good point. How about a +=L b for a long type? Or have a non-annotated opcode for the native machine word size (just '+') and annotated for anything smaller (edit: anything other) - ('+B' for byte addition). An alternative and perhaps much better higher-level solution is to have typed ASM. I believe there is work done in this area (quick search gets http://www.cs.cornell.edu/talc/ http://www.cs.cornell.edu/talc/), which would allow the type to be implicit but checkably safe but for the occasional explicitly needed coercions.
- ape4 7y agoMisspelling "architectur" on the 3rd line doesn't exactly inspire confidence.
- arethuza 7y agoHas there ever been any attempts to systematically generate processor instruction set designs, evaluate them against 'real' code and measure the results? Edit: You'd need to generate compiler back ends for each design as well, which might be fun...
- carapace 7y agoI don't have a link handy to give you but, yes, people have done things like that. Look into Prolog research on compiling.
- chalst 7y ago> 16 registers divided into to areas: R0 to R7 are in fact a window to a register bank containing 256 times 8 registers while R8 to R15 are fixed. This architecture makes subroutine calls and saving registers very easy (just increment/decrement the register bank pointer which is part of the status register). All in all QNICE features 256 * 8 + 8 = 2056 registers. This is indeed nice and the kind of thing whose availability can affect the design of low-level languages, e.g. non-ISO local variables in a Forth dialect. Cf. http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Gforth-locals.html http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Gfor...
- zimpenfish 7y agoPretty neat but doesn't seem to be making it to the Real World(tm) despite several attempts. https://en.wikipedia.org/wiki/Register_window https://en.wikipedia.org/wiki/Register_window
- chalst 7y agoDecent link, thanks. It doesn't surprise me that having more visible registers and doing a good job of register allocation in the compiler is a better strategy (i.e., both more efficient and more flexible), but doing so means you are not so close to the metal. From the point of view of an efficiency feature that doesn't ask for complexity in the compiler, I see some appeal to register windows.
- JoshTriplett 7y agoIt's not just that. If you have a huge internal register file and register renaming, along with a few other tricks, then it's at least as efficient (and potentially more efficient) to just push and pop the registers that actually get used.
- throwaway_pdp09 7y agoIs 'efficient' what you want though? For embedded, yes. For maximum speed where you are willing to blow large power use, you can be much faster but it will cost you efficiency, badly (think Xeons). Without quantifying what you're trying to do, 'efficient' is only a metric not a target.
- FeepingCreature 7y agoABRA because it jumps away?