4 ms·
Reflection: - Machine code is very dense. Really, this is not an accident, although maybe it’s not entirely on purpose either, more just common sense at the ti
by jchw 7y ago
Reflection:
- Machine code is very dense. Really, this is not an accident, although maybe it’s not entirely on purpose either, more just common sense at the time. In the end, there were probably many platforms using this or predecessor CPUs with very little RAM/ROM and bytes still counted even on IBM PC.
- Assembly code is still very readable. The trouble is not that machine code isn’t readable, and it probably never really was. It just doesn’t offer ways to build abstraction beyond what the machine supported (like routines, sw interrupts, etc.) Only gets worse as hardware gets more complicated. Imagine avoiding VGA and instead attempting to support initializing a modern graphics card all the way through! It would probably be quite ridiculous even with documentation. This is part of what bugs me about a lot of non-x86 platforms, since that’s kind of the environment you’re dropped into in many of them.
- Speaking of compatibility, one must wonder how many new layers have been introduced on top of things like VGA since the original VGA.
- derefr 7y ago> Machine code is very dense. It's intriguingly dense. If you're writing an emulator or a bytecode VM, and you can't just slap a JIT in (because you need to ensure that e.g. data races resolve the same way they did on the original machine), it's very hard to come up with a data structure to represent "decoded" code, that is more performant than just keeping the original code around in memory in its packed-stream-of-opcodes form. One would think, for example, that it would make sense to do the "instruction decode" pass ahead of time, to end up with an array of pointers-to-instructions plus literal-values... but the resulting representation of the code is usually much larger in memory, and so less of it will fit in cache (and it'll also fight the VM interpreter itself for cache-lines.) You might gain from your instruction impls not having to trampoline back to the interpreter (https://en.wikipedia.org/wiki/Threaded_code https://en.wikipedia.org/wiki/Threaded_code, basically), but you'll lose in cache coherence. Really, the best you can do in such a situation is to translate the stream of opcodes to another stream of opcodes, just ones that you can execute more efficiently (i.e. create your own "microcode" ISA for your VM.) Either way, "a loop that walks/jumps through an in-memory buffer of variable-length CISC opcodes using a byte-granular program-counter pointer register" seems to be an optimum somehow in design space.
- earlz 7y ago> One would think, for example, that it would make sense to do the "instruction decode" pass ahead of time, to end up with an array of pointers-to-instructions plus literal-values... but the resulting representation of the code is usually much larger in memory, and so less of it will fit in cache (and it'll also fight the VM interpreter itself for cache-lines.) You might gain from your instruction impls not having to trampoline back to the interpreter (https://en.wikipedia.org/wiki/Threaded_code https://en.wikipedia.org/wiki/Threaded_code, basically), but you'll lose in cache coherence. As someone currently writing a (subset of an) x86 VM, I feel this pain entirely too much. My subset greatly simplifies things by not using segment registers and getting to (mostly) not have to implement the 16bit version of ModR/M. The biggest problem with x86 is the sheer number of ways to do addressing within a single opcode using a Mod R/M operand. For instance, all of these lines of assembly can use the same primary opcode: push eax push [eax] push [1000] push [1000 + eax] push [0x11 + (eax * 2 + ecx)] push [0x11223344 + (eax * 8 + ecx)] push [(eax * 8 + ecx) - 10] If not for the Mod R/M and SIB operands, x86 would be a static-width instruction set I'm building an interpreter that goes the way of decoding to build a pipeline (really a "basic block") and then to execute the entire pipeline with minimal branching across execution. I'm less afraid of excessive cache use than the unpredictable indirect branch problem. The hope is that building a pipeline and executing it with a branchless unrolled loop will allow me to avoid that problem, while also greatly simplifying the implementation of each opcode where the actual logic just receives a set of operands it can get or set.
- Narishma 7y ago> but you'll lose in cache coherence. Did you mean cache locality?
- userbinator 7y agox86 is very dense. Traditional RISCs like MIPS and SPARC are not. ARM is somewhere between the two. Imagine avoiding VGA and instead attempting to support initializing a modern graphics card all the way through! If you just need a framebuffer, and not any kind of acceleration (which is sufficient for something like this), then VBE is a good "better than VGA" (i.e. "SuperVGA") standard you could use. I believe most OSs can fall back to VBE in the absence of GPU-specific drivers. https://en.wikipedia.org/wiki/VESA_BIOS_Extensions#Other_commonly_available_graphics_modes https://en.wikipedia.org/wiki/VESA_BIOS_Extensions#Other_com... - Speaking of compatibility, one must wonder how many new layers have been introduced on top of things like VGA since the original VGA. AFAIK a VGA is basically a framebuffer with a timing controller and some very basic fixed-function hardware to assist the CPU with changing pixel values. A modern GPU, as its name implies, is a complete processor (or more precisely, a massively parallel array of them) that has its own instruction set and runs its own firmware. I believe the basic VGA hardware (i.e. the timing controller, sequencer, DACs, etc.) still exists in somewhat extended form on a modern GPU.
- jchw 7y agoThe true spirit of my thought experiment was, initializing a graphics card, like an NVIDIA card for example, from scratch; sure, VBE works, but no graphics driver actually implements the framebuffer this way. Not saying bothering to do acceleration, just avoiding compatibility layers.
- mjg59 7y agoVBE basically went away with UEFI[1], but on the plus side UEFI basically gives you a function pointer to do mode setup. You just need to jump through multiple other function pointers to find it, which makes everything more annoying... (of course, if you're using UEFI you're also not writing a 512 byte boot sector, so the comparison isn't entirely fair) One meaningful distinction between VBE and the UEFI GOP standard is that you can do VBE calls at OS runtime but can't call GOP after the OS has transitioned away from the boot environment, so modern OSs pretty much require native graphics modesetting for anything other than the case where you only ever need one mode and don't support suspend/resume. [1] OK not strictly true - older UEFI systems would leave a VGA BIOS in the legacy location and let you call it anyway, and UEFI Windows<8 actually relied on this - Windows 8 was the first that would boot on legacy-free UEFI
- vectorEQ 7y agoVGA was only dropped really recently. not sure if nvidia already did, amd did only 1 or 2 generations back.. so it's surprisingly compatible ;)...
- einr 7y agoI don't think anything has dropped support for VGA. Every modern graphics card will still happily show not only all VGA modes, but CGA and EGA as well. There are some edge cases that do not work right that can become apparent if for some ungodly reason you want to run 80's DOS games on bare metal on a new system. Are you thinking of the analog VGA monitor output? Because I think that's been dropped from some recent cards, but that is different from the VGA graphics standard. You can output VGA graphics over HDMI or DVI or DisplayPort.