logoalt Hacker News

Joker_vDtoday at 6:53 PM1 replyview on HN

> The subtraction instruction has a set with reversed operands, so we have SUB, SUBU, SUBS, SUBC, SUBCU, SUBCS, but also SUBR, SUBRU, SUBRS, SUBRC, SUBRCU, SUBRCS.

Pretty much the only use of "reversed subtraction" instruction on a 3-operand machine is to implement NEG (subtract from immediate zero) and NOT (subtract from immediate -1, which Am29000 can't actually do since it zero-extends the immediates)... but NOT is usually not a very useful operation on its own anyway, especially when you have an actual ANDN instruction (most of the uses of ~ in C are of "var &= ~mask" or "expr & ~mask" variety) and a whole slew of NAND/NOR/XNOR instructions as well. Oh, and also, if you know for sure that your value is either 1 or 0, you can logically negate it by subtracting it from immediate 1.

On the other hand, on a 2-operand machine "SUBR reg, reg" is a surprisingly useful instruction.

> I made a phantom ROM that reads the disk using a special instruction coded in the emulator, and returns on unhandled services.

Really puts into perspective just how useful BIOS/UEFI utilities are, doesn't it? Just give me the device tree info (or the equivalent) and load the bloody OS image, thank you, that's all I need.

> I find fun how they implement the multiplication instruction using a trap and 32 continuous MUL instructions (bit-shifting all the way).

They did division the same way; I believe it was a done as a clever to have an interruptible MULTIPLY/DIVIDE instructions: otherwise, those 32-35 cycle beasts would need some special handling in the pipeline.


Replies

ronsortoday at 7:05 PM

The BIOS originates from an era where most or all of the OS software was burned to a ROM on the computer. Then disks arrived and we wanted more, but we didn't want the OS to implement drivers for every hardware configuration. There wasn't enough room. Then there was enough room and it turned out BIOS functions mostly sucked.