It's done in hardware so it's cheap (2012)
"It's done in hardware so it's cheap"

It isn't.
This is one of these things that look very obvious to me, to the point where it seems not worth discussing. However, I've
heard the idea that "hardware magically makes things cheap" from several PhDs over the years. So apparently, if you aren't into
hardware, it's not obvious at all.
So why doesn't "hardware support" automatically translate to "low cost"/"efficiency"? The short answer is, hardware is an
electric circuit and you can't do magic with that, there are rules. So what are the rules? We know that hardware support does
help at times. When does it, and when doesn't it?
To see the limitations of hardware support, let's first look at what hardware can do to speed things up. Roughly,
you can really only do two things:

Specialization - save dispatching costs in speed and energy.
Parallelization - save time, but not energy, by throwing more hardware at the job.

Let's briefly look at examples of these two speed-up methods – and then some examples where hardware support does nothing for
you, because none of the two methods helps. We'll only consider run time and energy per operation, ignoring silicon area
(considering a third variable just makes it too hairy).
I'll also discuss the difference between real costs of operations and the price you pay for these
operations, and argue that in the long run, costs are more stable and more important than prices.
Specialization: cheaper dispatching
If you want to extract bits 3 to 7 of a 32-bit word and then multiply them by 13 – let's say an encryption algorithm requires
this – you can have an instruction doing just that. That will be faster and use less energy than, say, using bitwise AND, shift
& multiplication instructions.
Why – what costs were cut out? The costs of dispatching individual operations – circuitry controlling which operation is
executed, where the inputs come from and where the outputs go.
Specialization can be taken to an extreme. For instance, if you want a piece of hardware doing nothing but JPEG decoding, you
can bring dispatching costs close to zero by having a single "instruction" – "decode a JPEG image". Then you have no flexibility
– and none of the "overhead" circuitry found in more flexible machines (memory for storing instructions, logic for decoding
these instructions, multiplexers choosing the registers that inputs come from based on these instructions, etc.)
Before moving on, let's look a little closer at why we won here:

We got a speed-up because the operations were fast to begin with – so dispatching costs dominated. With
specialization, we need 4 wires connected directly to bits 3 to 7 that have tiny physical delay – just the time it takes the
signal to travel to a nearby multiplier-by-13. Without specialization, we'd use a shifter shifting by a configurable amount of
bits – 3 in our case but not always – which is a bunch of gates introducing a much larger delay. On top of that, since we'd be
using several such circuits communicating through registers (let's say we're on a RISC CPU), we'd have delays due to reading and
writing registers, delays due to selecting registers from a large register file, etc. With all this taken out by having a
specialized instruction, no wonder we're seeing a big speed-up.
Likewise, we'll see lower energy consumption because the operations didn't require a lot of energy to begin with. Roughly,
most of the energy is consumed when a signal value changes from 1 to 0 or back. When we use general-purpose instructions, most
of the gate inputs & outputs and most flip-flops changing their values are those implementing the dispatching. When we use a
specialized instruction, most of the switching is gone.

This means that, unsurprisingly, there's a limit to efficiency – the fundamental cost of the operations we need to do, which
can't be cut.
When the operations themselves are costly enough – for instance, memory access or floating point operations – then their cost
dominates the cost of dispatching. So specialized instructions that cut dispatching costs will give us little or nothing.
Parallelization: throwing more hardware at the job
What to do when specialization doesn't help? We can simply have N processors instead of one. For the parts that can be
parallelized, we'll cut the run time by N – but spend the same amount of energy. So things got faster but not necessarily
cheaper. A fixed power budget limits parallelization – as does a fixed budget of, well, money (the price of a 1000-CPU rack is
still not trivial today).
[Why have multicore chips if it saves no energy? Because a multicore chip is cheaper than many single core ones, and because,
above a certain frequency, many low-frequency cores use less energy than few high-frequency ones.]
We can combine parallelization with specialization – in fact it's done very frequently. Actually a JPEG decoder mentioned
above would do that – a lot of its specialized circuits would execute in parallel.
Another example is how SIMD or SIMT
processors broadcast a single instruction to multiple execution units. This way, we get only a speed-up, but no energy savings
at the execution unit level: instead of one floating point ALU, we now have 4, or 32, etc. We do, however, get energy savings at
the dispatching level – we save on program memory and decoding logic. As always with specialization, we pay in flexibility – we
can't have our ALUs do different things at the same time, as some programs might want to.
Why do we see more single-precision floating point SIMD than double-precision SIMD? Because the higher the raw cost of
operations, the less we save by specialization, and SIMD is a sort of specialization. If we have to pay for double-precision
ALUs, why not put each in a full-blown CPU core? That way, at least we get the most flexibility, which means more opportunities
to actually use the hardware rather than keeping it idle.
(It's really more complicated than that because SIMD can actually be a more useful programming model than multiple threads or
processes in some cases, but we won't dwell on that.)
What can't be done
Now that we know what can be done – and there really isn't anything else – we basically already also know what can't be done.
Let's look at some examples.
Precision costs are forever
8-bit integers are fundamentally more efficient than 32-bit floating point, and no hardware support for any sort of floating
point operations can change this.
For one thing, multiplier circuit size (and energy consumption) is roughly quadratic in the size of inputs. IEEE 32b floating
point numbers have 23b mantissas, so multiplying them means a ~9x larger circuit than an 8×8-bit multiplier with the same
throughput. Another cost, linear in size, is that you need more memory, flip-flops and wires to store and transfer a float than
an int8.
(People are more often aware of this one because SIMD instruction sets usually have fixed-sized registers which can be used
to keep, say, 4 floats or 16 uint8s. However, this makes people underestimate the overhead of floating point as 4x – when it's
more like 9x if you look at multiplying mantissas, not to mention handling exponents. Even int16 is 4x more costly to multiply
than int8, not 2x as the storage space difference makes one guess.)
We design our own chips, and occasionally people say that it'd be nice to have a chip with, say, 256 floating point ALUs.
This sounds economically nonsensical – sure it's nice and it's also quite obvious, so if nobody makes such chips at a budget
similar to ours, it must be impossible, so why ask?
But actually it's a rather sensible suggestion, in that you can make a chip with 256 ALUs that is more efficient
than anything on the market for what you do, but not flexible enough to be marketed as a general-purpose computer. That's
precisely what specialization does.
However, specialization only helps with operations which are cheap enough to begin with compared to the cost of dispatching.
So this can work with low-precision ALUs, but not with high-precision ALUs. With high-precision ALUs, the raw cost of operations
would exceed our power budget, even if dispatching costs were zero.
Memory indirection costs are forever
I mentioned this in my old needlessly combative write-up about "high-level CPUs". There's this idea that we can have a
machine that makes "high-level languages" run fast, and that they're really only slow because we're running on "C machines" as
opposed to Lisp machines/Ruby machines/etc.
Leaving aside the question of what "high-level language" means (I really don't find it obvious at all, but never mind),
object-orientation and dynamic typing frequently result in indirection: pointers instead of values and pointers to pointers
instead of pointers. Sometimes it's done for no apparent reason – for instance, Erlang strings that are kept as linked lists of
ints. (Why do people even like linked lists as "the" data structure and head/tail recursion as "the" control structure? But I
digress.)
This kind of thing can never be sped up by specialization, because memory access fundamentally takes quite a lot of time and
energy, and when you do p->a, you need one such access, and when you do p->q->a, you need two, hence you'll spend twice
the time. Having a single "LOAD_LOAD" instruction instead of two – LOAD followed by a LOAD – does nothing for you.
All you can do is parallelization - throw more hardware at the problem, N processors instead of one. You can, alternatively,
combine parallelization with specialization, similarly to N-way floating point SIMD that's somewhat cheaper than having N
full-blown processors. For example, you could have several load-store units and several cache banks and a multiple-issue
processor. Than if you had to run p1->q1->a and somewhere near that, p2->q2->b, and the pointers point into
different banks, some of the 4 LOADs would end up running in parallel, without having several processors.
But, similarly to low-precision math being cheaper whatever the merits of floating point SIMD, one memory access is always
twice cheaper than two despite the merits of cache banking and multiple issue. Specifically, doubling the memory access
throughput roughly doubles the energy cost. This can sometimes be better than simply using two processors, but it's a
non-trivial cost and will always be.
A note about latency
We could discuss other examples but these two are among the most popular – floating point support is a favorite among math
geeks, and memory indirection support is a favorite among language geeks. So we'll move on to a general conclusion – but first,
we should mention the difference between latency costs and throughput costs.
In our two examples, we only discussed throughput costs. A floating point ALU with a given throughout uses more energy than
an int8 ALU. Two memory banks with a given throughput use about twice the energy of a single memory bank with half the
throughput. This, together with the relatively high costs of these operations compared to the costs of dispatching them, made us
conclude that we have nothing to do.
In reality, the high latency of such heavyweight operations can be the bigger problem than our inability to increase their
throughput without paying a high price in energy. For example, consider the instruction sequence:
c = FIRST(a,b)
e = SECOND(c,d)
If FIRST has a low latency, then we'll quickly proceed to SECOND. If FIRST has a high latency, then SECOND will have to wait
for that amount of time, even if FIRST has excellent throughput. Say, if FIRST is a LOAD, being able to issue a LOAD every cycle
doesn't help if SECOND depends on the result of that LOAD and the LOAD latency is 5 cycles.
A large part of computer architecture is various methods for dealing with these latencies – VLIW, out-of-order, barrel processors/SIMT, etc. These are all forms of parallelization –
finding something to do in parallel with the high-latency instruction. A barrel processor helps when you have many threads. An
out-of-order processor helps when you have nearby independent instructions in the same thread. And so on.
Just like having N processors, all these parallelization methods don't lower dispatching costs - in fact, they raise
them (more registers, higher issue bandwidth, tricky dispatching logic, etc.) The processor doesn't become more energy
efficient - you get more done per unit of time but not per unit of energy. A simple processor would be stuck at the FIRST
instruction, while a more clever one would find something to do – and spend the energy to do it.
So latency is a very important problem with fundamentally heavyweight operations, and machinery for hiding this latency is
extremely consequential for execution speed. But fighting latency using any of the available methods is just a special case of
parallelization, and in this sense not fundamentally different from simply having many cores in terms of energy consumed.
The upshot is that parallelization, whether it's having many cores or having single-core latency-hiding circuitry, can help
you with execution speed – throughput per cycle – but not with energy efficiency – throughput per watt.
The latency of heavyweight stuff is important and not hopeless; its throughput is important and hopeless.
Cost vs price
"But on my GPU, floating point operations are actually as fast as int8 operations! How about that?"
Well, a bus ticket can be cheaper than the price of getting to the same place in a taxi. The bus ticket will be cheaper even
if you're the only passenger, in which case the real cost of getting from A to B in a bus is surely higher than the cost of
getting from A to B in a taxi. Moreover, a bus might take you there more quickly if there are lanes reserved for buses that
taxis are not allowed to use.
It's basically a cost vs price thing – math and physics vs economics and marketing. The fundamentals only say that a hardware
vendor always can make int8 cheaper than float – but they can have good reasons not to. It's not that they made floats
as cheap as int8 – actually, they made int8 as expensive as floats in terms of real costs.
Just like you going alone in a bus designed to carry dozens of people is an inefficient use of a bus, using float ALUs to
process what could be int8 numbers is an inefficient use of float ALUs. Similarly, just like transport regulations can make
lanes available for buses but not cars, an instruction set can make fetching a float easy but make fetching a single byte hard
(no load byte/load byte with sign extension instructions). But cars could use those lanes – and loading bytes
could be made easy.
As a passenger, of course you will use the bus and not the taxi, because economics and/or marketing and/or regulations made
it the cheaper option in terms of price. Perhaps it's so because the bus is cheaper overall, with all the passengers it carries
during rush hours. Perhaps it's so because the bus is a part of the contract with your employer – it's a bus carrying employees
towards a nearby something. And perhaps it's so because the bus is subsidized by the government. Whatever the reason, you go
ahead and use the cheaper bus.
Likewise, as a programmer, if you're handed a platform where floating point is not more expensive or even cheaper than int8,
it is perhaps wise to use floating point everywhere. The only things to note are, the vendor could have given you
better int8 performance; and, at some point, a platform might emerge that you want to target and where int8 is much more
efficient than float.
The upshot is that it's possible to lower the price of floating point relative to int8, but not the
cost.
What's more "important" – prices or costs?
Prices have many nice properties that real costs don't have. For instance, all prices can be compared – just convert them all
to your currency of choice. Real costs are hard to compare without prices: is 2x less time for 3x more energy better or
worse?
In any discussion about "fundamental real costs", there tend to be hidden assumptions about prices. For example, I chose to
ignore area in this discussion under the assumption that area is usually less important than power. What makes this assumption
true – or false – is the prices fabs charge for silicon production, the sort of cooling solutions that are marketable today (a
desktop fan could be used to cool a cell phone but you couldn't sell that phone), etc. It's really hard to separate costs from
prices.
Here's
a computer architect's argument to the effect of "look at prices, not costs":

While technical metrics like performance, power, and programmer effort make up for nice fuzzy debates, it is pivotal for
every computer guy to understand that “Dollar” is the one metric that rules them all. The other metrics are just sub-metrics
derived from the dollar: Performance matters because that’s what customers pay for; power matters because it allows OEMs to put
cheaper, smaller batteries and reduce people’s electricity bills; and programmer effort matters because it reduces the cost of
making software.

I have two objections: that prices are the effect, not the cause, and that prices are too volatile to commit to memory as a
"fundamental".
Prices are the effect in the sense that, customers pay for performance because it matters, not "performance matters because
customers pay for it". Or, more precisely – customers pay for performance because it matters to them. As a result –
because customers pay for it – performance matters to vendors. Ultimately, the first cause is that performance matters,
not that it sells.
The other thing about prices is that they're rather jittery. Even a price index designed for stability such as S&P 500 is jumping up and down like crazy. In a
changing world, knowledge about costs has a longer shelf life than knowledge about prices.
For instance, power is considered cheap for desktops but expensive for servers and really expensive for mobile devices. In
reality, desktops likely consume more power than servers, there being more desktops than servers. So the real costs are not like
the prices – and prices change; the rise of mobile computing means rising prices for power-hungry architectures.
It seems to me that, taking the long view, the following makes sense:

It's best to reason in costs and project them to the relevant prices – not forget the underlying costs and "think in
prices", so as to not get into habits that will become outdated when prices change.
If you see a high real cost "hidden" by contemporary prices, it's a good bet to assume that at some point in the future,
prices will shift so that the real cost will rear its ugly head.

For example, any RISC architecture – ARM, MIPS, PowerPC, etc. – is fundamentally cheaper than, specifically, x86, in at least
two ways: hardware costs – area & power – and the costs of developing said hardware. [At least so I believe; let's say that
it's not as significant in my view than my other more basic examples, and I might be wrong and I'm only using this as an
illustration.]
In the long run, this spells doom for the x86, whatever momentum it otherwise has at any point in time – software
compatibility costs, Intel's manufacturing capabilities vs competitors capabilities, etc. Mathematically or physically
fundamental costs will, in the long run, trump everything else.
In the long run, there is no x86, no ARM, no Windows, no iPhone, etc. There are just ideas. We remember ideas originating in
ancient Greece and Rome, but no products. Every product is eventually outsold by another product. Old software is forgotten and
old fabs rot. But fundamentals are forever. An idea that is sufficiently more costly fundamentally than a competing idea can not
survive.
This is why I disagree with the following quote by Bob Colwell – the chief architect of the Pentium Pro (BTW, I love the interview and intend
to publish a summary of the entire 160-something page document):

...you might say that CISC only stayed viable because Intel was able to throw a lot of money and people at it, and die size,
bigger chips and so on.
In that sense, RISC still was better, which is what was claimed all along. And I said you know, there's point to be made
there. I agree with you that Intel had more to do to stay competitive. They were starting a race from far behind the start line.
But if you can throw money at a problem then, it's not really so fundamental technologically, is it? We look for more deep
things than that, so if all the RISC/CISC thing amounted to was, you had a slight advantage economically, well, that's not as
profound as it seemed back in the 80s was it?

Well, here's my counter-argument and it's not technical. The technical argument would be, CISC is worse, to the point where
Intel's 32nm Medfield performs about as well as ARM-based 40nm chips in a space where power matters. Which can be countered with
an economical argument – so what, Intel does have a better manufacturing ability so who cares, they still compete.
But my non-technical argument is, sure, you can be extremely savvy business-wise, and perhaps, if Intel realized early on how
big mobile is going to be, they'd make a good enough x86-based offering back then and then everyone would have been locked out
due to software compatibility issues and they'd reign like they reign in the desktop market.
But you can't do that forever. Every company is going to lose to some company at some point or other because you only need
one big mistake and you'll make it, you'll ignore a single emerging market and that will be the end. Or, someone will outperform
you technically – build a better fab, etc. If an idea is only ("only"?) being dragged into the future kicking and screaming by a
very business-savvy and technically excellent company, then the idea has no chance.
The idea that will win is the idea that every new product will use. New products always beat old products – always
have.
And nobody, nobody at all has made a new CISC architecture in ages. Intel will lose to a company or companies making RISC
CPUs because nobody makes anything else – and it has to lose to someone. Right now it seems like it's ARM but it
doesn't matter how it comes out in this round. It will happen at some point or other.
And if ARM beats x86, it won't be, straightforwardly, "because RISC is better" – x86 will have lost for business
reasons, and it could have gone the other way for business reasons. But the fact that it will have lost to a
RISC – that will be because RISC is technically better. That's why there's no CISC competitor to lose to.
Or, if you dismiss this with the sensible "in the long run, we're all dead" – then, well, if you're alive right now and
you're designing hardware, you are not making a CISC processor, are you? QED, not?
Getting back to our subject – based on the assumption that real costs matter, I believe that ugly, specialized hardware is
forever. It doesn't matter how much money is poured into general-purpose computing, by whom and why. You will always have
sufficiently important tasks that can be accomplished 10x or 100x more cheaply by using fundamentally cheap operations, and it
will pay off for someone to make the ugly hardware and write the ugly, low-level code doing low-precision arithmetic to make it
work.
And, on the other hand, the market for general-purpose hardware is always going to be huge, in particular, because there are
so many things that must be done where specialization fundamentally doesn't help at all.
Conclusion
Hardware can only deliver "efficiency miracles" for operations that are fundamentally cheap to begin with. This is done by
lowering dispatching costs and so increasing throughput per unit of energy. The price paid is reduced flexibility.
Some operations, such as high-precision arithmetic and memory access, are fundamentally expensive in terms of energy consumed
to reach a given throughput. With these, hardware can still give you more speed through parallelization, but at an energy cost
that may be prohibitive.
