
Jul 15th, 2024, 05:27 AM
#1
Thread Starter
Frenzied Member
How is a power_of_two calculated in x87 assembly?
The x87 floating point instructions have the F2XM1 instruction, which would seem to be what you want. It's supposed to calculate (2^x)1 from which you should be able to easily calculate 2^x by simply then adding 1 to the result of the F2XM1 instruction. However when I look at this https://www.felixcloutier.com/x86/f2xm1 it makes it clear that the exponent has a VERY limited range from 1 to 1. If you want an exponent smaller than 1 or larger than 1, you are out of luck. Not entirely though because of the FSCALE instruction, but reading up about that instruction at https://www.felixcloutier.com/x86/fscale makes it very clear that the exponent must be an integer value. So now we have one instruction that allows floating point exponents but only between 1 and 1, and another instruction that allows any arbitrarily large or small exponent but it's limited to being an integer valued exponent. Why is there no instruction that allows arbitrarily large and small exponents while NOT imposing an integer restriction? I know that computers can do math that involves raising 2 to any arbitrary floatingpoint valued exponent (in fact computers can do math with any arbitrary base as well), but how the computer is doing such math I don't know. There don't seem to be any actual floating point instructions for arbitrary exponents, even when talking about limiting the base to only being 2.
Last edited by Ben321; Jul 15th, 2024 at 05:31 AM.

Jul 15th, 2024, 06:24 AM
#2
Re: How is a power_of_two calculated in x87 assembly?
Btw, powers of 2 are easiest calculated with bitshifting i.e. 2^n = 1 << n
cheers,
</wqw>
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
