5 ms·
A Plan 9 C compiler for RISC-V [pdf]
- kragniz 8y agoI went to a local RISC-V meetup last night, and it seems like something interesting to play with. Does anyone know when actual chips might become affordable? The only board I could find available at the moment is the HiFive Unleashed, which is $999.
- snazz 8y agoYou can buy affordable FPGA boards that can be configured with open-source RISC-V chip designs, like the Arty A7-35T[0] for $119. There are a number of other FPGA development boards that would run RISC-V at a much lower cost than $999. [0]: https://store.digilentinc.com/arty-a7-artix-7-fpga-development-board-for-makers-and-hobbyists/ https://store.digilentinc.com/arty-a7-artix-7-fpga-developme...
- rjsw 8y agoA Parallella should be faster than that Arty as it has 32-bit wide DRAM, the Arty only has 16-bit.
- geokon 8y agoThere are a handful of micros. The lowfive and a few coming from China Here is an AI chip: https://hackaday.com/2018/10/08/new-part-day-the-risc-v-chip-with-built-in-neural-networks/ https://hackaday.com/2018/10/08/new-part-day-the-risc-v-chip... It's an interesting proposition b/c they using RISC for the core, but the APUs are custom - so they can create some lock-in there for themselves (without lock in it'll just be a race to the bottom with razor thin margins) And here is RISC-on-an-FPGA in a nice package. It's very Chinese hobbyist oriented https://www.cnx-software.com/2018/09/04/licheetang-anlogic-eg4s20-fpga-board-targets-risc-v-development/ https://www.cnx-software.com/2018/09/04/licheetang-anlogic-e... Both those projects are by Zepan. That guy is a machine But I'm not quite sure what's holding up general purpose CPUs (even just something crappy/good-enough).. The way I understand it CPUs aren't just beefy microcontrollers and they require some extra onchip hardware, but no one has done that yet for some reason.. Maybe someone knows better :)
- nickik 8y agolowRisc and SiFive, there is no lowfive
- als0 8y ago> CPUs aren't just beefy microcontrollers and they require some extra onchip hardware, but no one has done that yet for some reason For example, Graphics, Bluetooth, Wi-Fi, modem, are all heavily encumbered with patents. Very complex subsystems. Even components that have expired patents or no patents, such as an MMU, are non-trivial to create and take time. I suspect it'll take time before FOSS implementations appear.
- wbl 8y agoGraphics can sit on a PCI bus. Same with Wi-Fi. The MMU is probably a blocker.
- _chris_ 8y ago> But I'm not quite sure what's holding up general purpose CPUs (even just something crappy/good-enough).. The way I understand it CPUs aren't just beefy microcontrollers and they require some extra onchip hardware, but no one has done that yet for some reason.. Maybe someone knows better :) There's general-purpose RISC-V CPU RTL lying around, and it's not too difficult to license the necessary peripherals, but it costs money to put together a board and fabricate at volume if you want to hit a Raspberry Pi/hobbyist price point. Unfortunately, it takes time and you need a market to justify the effort. But eventually it'll happen.
- tyingq 8y agoThe closest seem to be Lowrisc.org and the Incore Shakti chip. LowRisc seems behind on their original timeline plan. Shakti booted Linux in August. Can't tell if they just want to make chips though...LowRisc is going to make full RPI type boards.
- yiyus 8y agoIt looks like Richard Miller, author of the article and living UNIX legend, is using a verilog implementation by Clifford Wolf [1] in this FPGA board [2]. [1] https://github.com/cliffordwolf/picorv32 https://github.com/cliffordwolf/picorv32 [2] https://www.tindie.com/products/Folknology/blackice-ii/ https://www.tindie.com/products/Folknology/blackice-ii/
- nickik 8y agoIf you want actual hardware you can get: - Kendryte KD233 - HiFive1 (https://www.sifive.com/boards https://www.sifive.com/boards) - GAPUINO GAP8 (https://greenwaves-technologies.com/product/gapduino/ https://greenwaves-technologies.com/product/gapduino/) - HiFive Unleashed (https://www.sifive.com/boards/hifive-unleashed https://www.sifive.com/boards/hifive-unleashed) Those are the only ones that exist commercially as far as I know.
- Sir_Cmpwn 8y agoNice! I hope they publish their work. plan9 is a great and very portable OS for experimenting with new architectures, for the reasons outlined in the slides. You can cross-compile the entire OS for a foreign architecture by simply setting objtype=arm and running mk (plan9's take on make) - less than 5 minutes later the whole OS is done compiling.
- yellowapple 8y agoThis is even the officially-documented way to turn your 32-bit 9front install into a 64-bit 9front install, IIRC from doing this exact thing when I installed 9front on an old laptop of mine.
- MisterTea 8y agoI'm pretty sure if someone sends aiju or cinap a high-five unleashed we'll have an official "unofficial" 9front port running in a few months.
- bakul 8y agoIt took a minute to compile plan9 kernel from scratch on the original raspberry pi (running plan9). You can even cross compile a x86 kernel in similar time. 10 seconds in 9vx emulator running on FreeBSD/amd64. I don’t recall the details now but a from-scratch Linux kernel compile was 10 or 11 hours (under Linux on the same raspberry pi). Thank goodness it wasn’t written in C++; the compile time would’ve been so much worse! C compiler optimizations seems like micro-optimizations when people should be looking at the bloat elsewhere. Missing the forest for the trees. C is basically a low level language. A portable assembly language. A predictable compiler shouldn’t second guess the programmer’s intent. To put things in perspective, if all the man-years spent on gcc were spent on GNU Hurd... :-)
- Sir_Cmpwn 8y agofwiw I can compile the Linux kernel, depending on the configuration, in 15-20 minutes. I usually give it 4 cores. EDIT: On x86. If you don't cross-compile your raspberry pi kernel, you're in for a bad time.
- jpfr 8y agoWhat are the advantages of using the Plan9 compiler versus TinyCC? https://bellard.org/tcc/ https://bellard.org/tcc/ https://repo.or.cz/w/tinycc.git https://repo.or.cz/w/tinycc.git
- ddevault 8y agotcc only supports x86, and is 4-5 times bigger (lines of code) than the plan9 compiler.
- beagle3 8y agoTcc has supported AMD64 and ARM for ages. It produces reasonably fast code, usable as a library, and has many other nice features. Worth looking at again if you last looked when it only supported x86.
- Sir_Cmpwn 8y agoOh, neat, I will. Still, the main advantage of plan9's compiler is its simplicity.
- arcticbull 8y agoJust double-checking the part of the presentation where they cite Plan 9's C compiler as "predictable" because it doesn't optimize away a useless loop... that's because the compiler is missing a bunch of useful optimizations isn't it? Specifically they say GCC requires this form for the busy loop to be emitted: for (int i = 0; i < 1000000; i++) asm volatile ("" ::: "memory"); Where 9c will output a bunch of useless code when you tell it this: for (int i = 0; i < 1000000; i++); And this is... a good thing?
- simias 8y agoI agree that it's a bit silly. They say: >Plan 9 C implements C by attempting to follow the programmer’s instructions, which is surprisingly useful in systems programming. It's like coding with -fno-strict-aliasing or -fwrapv in GCC, it's perfectly fine and justifiable but that doesn't mean that it makes sense for a compiler to default to it IMO because you're basically lulling your devs into writing into a specific dialect of C instead of the "real" language. It means that your code is effectively not portable anymore which is probably less of an issue for low level kernel code but could still easily cause issues as code is shared between projects. Again, there are situations where it makes sense to do so but I strongly believe that it should be an explicit choice by the programmer, not a compiler default. Now I would argue that the for loop example is even worse than aliasing or wrapping-related issues because I very rarely write busy timing loops but I do very often write for loops that I expect the compiler to optimize (drop useless code, unroll etc...) correctly. So yeah, that really seems like a way to spin a limitation of the compiler into a "feature" that makes really little sense. Also I just checked and gcc 8.2 does output the loop code when building with -O0 I guess they could alias that to --plan9-mode.
- colanderman 8y ago> Plan 9 C implements C by attempting to follow the programmer’s instructions Which, I might add, is a very silly thing to say. A programmer's intent and their written code are two very different things. How one maps to the other is defined only by the C standard, which says nothing about emitting specific assembly instructions, but only about the ultimate effect of code on memory. The Plan 9 compiler deciding to pessimize your code because it assumes you actually meant for the code to be interpreted as portable assembly rather than a high-level description of a computation is kind of presumptuous. At that point it's just a different language with different (albeit compatible) semantics.
- archi42 8y agoHm... A non-optimizing compiler? Nice hobby, but I don't see the point of this. Even folks doing safety critical stuff (like in failure = dead people) use -O0 and are craving for some optimizations. E.g. why no DCE? Constant propagation? With a proper representation (SSA?) some of this near-trivial.
- 9fans 8y agoThe Plan 9 C compiler does perform optimisations including constant folding and dead code elimination. (Actually it's the linker which eliminates dead code, so it can remove functions which are not called from any other source file.) The example loop on the slide however was not dead code or useless: it was a timing delay loop, an idiom commonly encountered in OS kernels and embedded applications.
- henesy 8y agoGreat to see RISC-V news make it public. Always glad to find more Plan 9 hobby projects to learn from :)
- jhallenworld 8y agoSo which is the easiest compiler to re-target to a new processor? That would certainly have some value even if it's not the most optimizing compiler.