Why is there no exponentiation operation in hardware, even though many languages have builtin operators for it?
Is it because even hardware implementations would need to use the same algorithm as software (i.e. no hardware implementation could be significantly more efficient), or because it is rarely used, or another reason?
2
For integers, the only exponentiation operations that are normally present in hardware are the shifts, <<
and >>
(in C parlance), which multiply by exponential powers of two. For anything else with integers, you run out of bits to represent things far too quickly for it to be useful; by the time you’ve sorted that problem out, you might as well not have special hardware support as you’ve also had to deal with memory management and other such expensive things.
I don’t know floating-point hardware so well, but hardware exponentiation makes more sense there as you’ve got the numeric range to make it reasonable. (My google-fu indicates that someone seems to be selling the hardware layout to make this possible…)
Some machines (especially microcontrollers) include hardware to accelerate extended-precision (512+ bits) multiplies, and such hardware will inherently help with exponentiation as well (useful for things like RSA ciphers). Hardware to expedite precise exponentiation (other than by expediting multiplication) is rare because performance with or without such hardware is going to be dominated by the time required to do the constituent multiplications.
If one doesn’t need precise results, one may raise floating-point numbers to any desired power by computing the log of the base, multiplying it by the exponent, and raising e to that power; many floating-point units include hardware to expedite all three of those steps.
1