News for hackers. Stuff that matters.
Re:BOOM Open Source RISC-V Core Runs on Amazon EC2 F1 Instances by Cyph0n on Thursday December 13, 2018 @10:22AM (#18672876)
Most (all?) modern processors utilize out-of-order execution. The main advantage is that it increases IPC (instructions per cycle) in the long run.

The high-level idea is that you queue up your instructions in a table of sorts and execute them as they're ready (i.e., based on dependencies). You then re-order the instructions at the end of the pipeline.

The main challenges with this technique are: (1) handling exceptions and (2) speculative execution. For (1), you can use a re-order buffer. For (2), you would typically flush the instruction table noted above.

Re:BOOM Open Source RISC-V Core Runs on Amazon EC2 F1 Instances by dbcurtis on Thursday December 13, 2018 @12:17PM (#18673988)
Let me add a couple thoughts:

1. You typically won't get very far without also implementing register renaming, such that the reorder buffer is actually much larger than the register file.

2. You need to distinguish between instructions that are "complete" (result is available for internal bypass to another instruction that is being speculatively executed) versus "retired" (all instructions before it have retired, the instruction can no longer raise an exception, you know for certain that it was not executed because of incorrect speculation). Canonical, architecturally visible state is only written on retirement.

3. Without good branch prediction, it is kind of pointless. A reasonable rule-of-thumb-Kentucky-windage estimate is that 20-25% of the instructions that you encounter in execution order (not static code analysis) are branches. So if you have 30 or more instructions active in the pipe, your branch prediction needs to be pretty good or you waste too much work. (Note that some branches are just "flakey" (hard to predict) but the compiler can usually do a decent job of identifying those ahead of time. Thus, modern processors include a conditional-move instruction which allows the compiler to manage speculation and replace the flakey branch with an instruction that does not pollute the branch target buffer.

4. Watching what happens in the simulator at the end of a pointer chasing loop is good humor. A strongly predicted branch gets mispredicted on: while(p!=NULL) {}, and all sorts of page-fault, memory-exception, arithmetic-exception logic lights up all over the place until something asserts "OOPS_NEVER_MIND", at which point all that fun stuff collapses in a smoldering heap. Watching that never gets old.

Re:BOOM Open Source RISC-V Core Runs on Amazon EC2 F1 Instances by cesarb on Thursday December 13, 2018 @11:23AM (#18673496)
> The main challenges with this technique are: (1) handling exceptions

RISC-V has an advantage here: other than load/store and instruction fetch/decode, the instruction set is designed to not cause exceptions. For instance, integer division by zero is defined to return a specific value, instead of being an error.

Re:BOOM Open Source RISC-V Core Runs on Amazon EC2 F1 Instances by jabl on Thursday December 13, 2018 @11:39AM (#18673650)
Also, RISC-V doesn't have a flags register. Instead fused cmp+jmp branching instructions.
Re:BOOM Open Source RISC-V Core Runs on Amazon EC2 F1 Instances by kannanvijayan on Thursday December 13, 2018 @01:36PM (#18674775)
This is interesting to hear, and surprising. What are the provisions for efficient handling of integer overflows & underflows? I took a quick look at the ISA spec and am trying to track down how this is handled, as a curiosity.
Re:BOOM Open Source RISC-V Core Runs on Amazon EC2 F1 Instances by jabl on Thursday December 13, 2018 @01:53PM (#18674946)
AFAIU, none. It's designed for C, essentially, where signed integer overflows are undefined. In practice, the easiest and fastest design is to have it wrap around, just like unsigned.

I'm not sure I agree with that particular design decision, considering newer languages such as Rust that want to detect overflows. Then again, if/when such languages become more important, I guess RISC-V could add an extension featuring some kind of trapping overflow (or whatever mechanism is deemed best).

Re:BOOM Open Source RISC-V Core Runs on Amazon EC2 F1 Instances by zozbot123 on Thursday December 13, 2018 @02:38PM (#18675288)
The RISC-V spec does claim that "many overflow checks can be cheaply implemented using branches" and then provides recommended instruction sequences. One could definitely imagine a RV implementation where e.g. macro-op fusion is used to systematically turn some of these recommended sequences into hardware-assisted branches.

(Ref: search for the "Integer Computational Instructions" section in the RISC-V "user mode" reference. It should be section 2.4)

Re:BOOM Open Source RISC-V Core Runs on Amazon EC2 F1 Instances by brucehoult on Thursday December 13, 2018 @09:46PM (#18678040)
Not mentioned there: you can if you want replace the BLTU (for carry) with a SLTU to set a register to 0 if no carry and 1 if there is a carry, effectively getting you a condition code register in a normal register, at the cost of one instruction (or three for signed overflow).

If you're going to be doing a lot of signed overflow checking (e.g. JavaScript) it may be better to store your numbers as N+0x8000000 (for 32 bit). Then each addition needs to subtract the offset afterwards, and each subtraction needs to add it (which works out to the same thing). The overflow check is then a single branch after the add and the adjust, for a total of three instructions instead of a total of four.

This seems bad, but if you're loading the values from memory and putting them back afterwards then it's pretty minor.

A later extension (such as J) could add instructions such as BADC/BADV/BSUC/BSUV a,b,label -- "Branch if ADd generates Carry" etc. These would fit into the existing instruction encoding and execution pipelines no problem.

Or, if this is a rare thing (as it should be in JavaScript) then making them "Trap if ADd generates oVerflow" would take a tiny amount of opcode space and allow the trap handler (which can be delegated to User space) to perhaps transparently fix up the result.

Re:BOOM Open Source RISC-V Core Runs on Amazon EC2 F1 Instances by nickik on Thursday December 13, 2018 @04:09PM (#18676146)
This. Also the J extention should add some more stuff in that direction.
Re:BOOM Open Source RISC-V Core Runs on Amazon EC2 F1 Instances by kannanvijayan on Thursday December 13, 2018 @05:25PM (#18676700)
I can appreciate the implementation benefits in not having a single mutating global state register.

One option I just thought of is simply to have multi-output variants of the instruction which would take an extra flags register as an output operand.

Anyway that's really interesting to find out. It would complicate the optimized implementation of JS engines, which need it to promote int32 arithmetic to doubles where needed, which is what I was thinking of when I asked the question.

Re:BOOM Open Source RISC-V Core Runs on Amazon EC2 F1 Instances by muizelaar on Thursday December 13, 2018 @11:08AM (#18673351)
The ARM Cortex-A55 is modern and in-order. Out-of-order CPUs tend to be large so if you want a small CPU you'll still go with in-order.
Re:BOOM Open Source RISC-V Core Runs on Amazon EC2 F1 Instances by zozbot123 on Thursday December 13, 2018 @12:10PM (#18673942)
Energy/power efficiency might be a more relevant concern than mere size - OOO execution is fast but energy intensive, for a given workload. (Granted, the latest process nodes might be a tad different, with "size" also impacting power consumption directly due to leakage currents. This stuff can get a bit complicated.)
Re:BOOM Open Source RISC-V Core Runs on Amazon EC2 F1 Instances by bogomipz on Thursday December 13, 2018 @12:35PM (#18674199)
Interesting. Is lower power OOE an area of active research?
Re:BOOM Open Source RISC-V Core Runs on Amazon EC2 F1 Instances by Symmetry on Thursday December 13, 2018 @01:08PM (#18674528)
Well, to the extent that improved process brings lower power it's an area of stupendous research investment. If you just mean architecturally there are people looking at ways to use less power by being less flexible but still get most of the benefit but it's not a huge topic.
Re:BOOM Open Source RISC-V Core Runs on Amazon EC2 F1 Instances by zozbot123 on Thursday December 13, 2018 @02:53PM (#18675421)
The Mill processor architecture deserves mention here, as it basically aims to bridge VLIW-like low power usage with OOO-like performance. The way it attempts to do this is too complex to explain in a short comment, you can find detailed info on their website - but broadly-speaking it involves all sorts of 'tweaks' to ordinary VLIW, that ultimately result in something a bit different. (It should also be noted though that the initial, instruction decoding stages of a Mill-like 'belt' architecture are a lot closer to OOO than an ordinary VLIW. So the projected power savings would seemingly have to come from elsewhere - but they can be quite significant nonetheless, so the effort is projected to be worthwhile.)
Re:BOOM Open Source RISC-V Core Runs on Amazon EC2 F1 Instances by marcosdumay on Thursday December 13, 2018 @09:00PM (#18677815)
I imagine (because there are not that many details on the Mill out there) that the power savings come mainly from:

- A post-compiler compilation step that adapts a binary for a specific chip, replacing a complex hardware control module by a one-time software run, so the only thing actually on the chip is the routing;

- A very nice set of primitives that push the non-determinism into data, instead of flow control.

- Cheap interruptions, cheap memory access, and every other detail rethought to be cheap.

Re:BOOM Open Source RISC-V Core Runs on Amazon EC2 F1 Instances by bogomipz on Thursday December 13, 2018 @05:04PM (#18676550)
Interesting I remember hearing about this processor architecture. Is is still being actively developed? I didn't see much in the way of news on the Mill site.
Re:BOOM Open Source RISC-V Core Runs on Amazon EC2 F1 Instances by opencl on Thursday December 13, 2018 @07:54PM (#18677542)
There are a few recent forum posts indicating that they're still working on it at least, but it seems to be going extremely slowly.

5 years ago it had already been in development for 10 years and there was supposed to be silicon shipping in 2-3 years. 2 years ago they were talking about an FPGA prototype that has yet to show up.