fpu usefulness?

Programming, for all ages and all languages.
Post Reply
a5498828
Member
Member
Posts: 99
Joined: Thu Aug 12, 2010 7:25 am

fpu usefulness?

Post by a5498828 »

Is there anything fpu (x87) is usefull? Or its jsut included for backward compatibility?
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: fpu usefulness?

Post by NickJohnson »

It does all floating point operations. If you want to use float, double, long double and their associated operations (which are part of the C standard), you need it (or need to emulate it if the machine doesn't have it, which is rare).
User avatar
Coty
Member
Member
Posts: 286
Joined: Thu Feb 12, 2009 5:12 pm

Re: fpu usefulness?

Post by Coty »

MMX instructions also rely upon it, witch since the 64bit CPU became mainstream is almost useless. And SSE is much better. But good for compatibility...

@NickJohnson: I'm not to familiar with C (novice quite actually), but wouldn't it make scene for newer compilers to use SSE for floating point operations depending on the target processor? :?
My hero, is Mel.
a5498828
Member
Member
Posts: 99
Joined: Thu Aug 12, 2010 7:25 am

Re: fpu usefulness?

Post by a5498828 »

im talking about thinks like fadd/fmul/fdiv. Yes double extended precision is 80 bits, but will it make a huge diffrence in long mode?
All arithmetics can be done on 64bit integer registers, why use fpu? The only thing fpu can be usefull is when you have a data larger than 64 bits, but smaller than 80.

Why use fpu at all?
you want to use float, double, long double and their associated operations (which are part of the C standard), you need it (or need to emulate it if the machine doesn't have it, which is rare).
Whats the diffrence between float and int? Its just representation of data. Why would i need exponent part? All that matters is mantisa.

Ok 20 years ago when nly 16bit cpus existed fpu might have been a good idea (16bit vs 80bit diffrent chip). But today? Give me a good example of calculation wich can REALLY benefit from using fpu instead of 64bit GPR.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: fpu usefulness?

Post by Solar »

a5498828 wrote:All arithmetics can be done on 64bit integer registers, why use fpu?
Because the FPU can do such arithmetics orders of magnitude faster. That is what it was designed for, and that is why it is still included in modern architectures.

There are whole families of CPUs that are optimized for FPU performance, with integer performance that you would probably sneer at. They sell very well. There is a reason that performance of supercomputers is often calculated in GFLOPS (giga float operations / second) instead of MIPS (million -integer- instructions / second).

A special treat is the RIKEN MDGRAPE-3. That baby has been custom-built to do proteine structure prediction, reaching the PetaFLOP level. Integer performance just isn't important here.
Whats the diffrence between float and int? Its just representation of data. Why would i need exponent part? All that matters is mantisa.
No it doesn't. One of the advantages of floats is that they can store a much larger range of values.

A 64bit int stores values from -2^63 to 2^63-1.

A 64bit float can store values from 2^1023 to -2^1023, or values as small as 2^-1022. With a limited precision, of course, but for those things the FPU is used for, you don't need unlimited precision.
Give me a good example of calculation wich can REALLY benefit from using fpu instead of 64bit GPR.
Any 3D game engine, scientific simulation (meteorology for example), any kind of signal processing (audio, for example).

You do know that any modern graphics chip is essentially a highly parallel FPU unit?

Read up on double precision FP format, floating point and floating point units.
Every good solution is obvious once you've found it.
a5498828
Member
Member
Posts: 99
Joined: Thu Aug 12, 2010 7:25 am

Re: fpu usefulness?

Post by a5498828 »

80bit float is 64bit mantisa, sign and 15 bit exponent.

64bit mantisa can hold 2^64 (not counting Nan/inf/zero) values, ranging from 1.00000...1 to 1.11111.1.
exponent can hold 2^15 values (max is 32k not counting NaN/inf). Mantisa is shifted by exponent value, so mantisa can be as large as m^32k.

Ok this is larger than integer representation, but so what? Its like taking 2 integer registers, loading first with mantisa and second with exponent. Calculations are done only on mantisa, exponent is just a shift factor.

And if i want to add 2 numbers, first with small second with large exponent i dont see how would it work.

I understand that fpu is unreliable, but is it really so superior to integer calculations?

I can emulate it with integer registers, 1 mantisa second exponent, an number with smaller exponent simply shift right. If i lose bits oh well that happens. fpu work this way.

Tell me why bother with FPU, what benefits will i get by using it instead of register instructions.

First what came to my mind is crypto, calculation modular exponentation without modulo after each multiplication.

Lets take exponent 128 bits and base 128 bits. Result would be 16k bits wide. Okay, that fits into range. But hey, only 64bits are variable, rest are zeros. So its a bad idea.

Anything done with fpu can be done on integer registers with i belive better efficiency.
Why? Im not sure, but lets take addition.
First i determine wich exponent is larger. I shift mantisa of lower exponent right by bit diffrence and then add.
its a few instructions. Ok, fadd use only one. Is that it? Is it the reason x87 didnt died out?


So idea of FPU is to calculate data i dont need to keep track of every bit but rather allow it bo be wide in range?
if i dont care that 100 + 1 is still 100 fpu is for me.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: fpu usefulness?

Post by qw »

a5498828 wrote:I can emulate it with integer registers, 1 mantisa second exponent, an number with smaller exponent simply shift right.
Which is exactly what the x87 floating point representation is. What is your point? That you may do all calculations on the exponent and mantissa by hand? Be my guest...
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: fpu usefulness?

Post by Solar »

OK, now I start being annoyed. Do you really think you are smarter than all the CPU designers in the world together?
a5498828 wrote:I understand that fpu is unreliable, but is it really so superior to integer calculations?
It is faster! Damn, what is so difficult to understand about it? Of course you can do all those calculations in integer registers, but a FPU will run circles around you!
Anything done with fpu can be done on integer registers with i belive better efficiency.
That is where you are plain, repeatedly, stupidly, ignorantly wrong. (Did you bother to read any of the links I gave you?)
Why? Im not sure, but lets take addition.
First i determine wich exponent is larger. I shift mantisa of lower exponent right by bit diffrence and then add.
its a few instructions. Ok, fadd use only one. Is that it?
If you take into account that an MMX / SSE CPU can do that addition on several registers at once in less operations...
So idea of FPU is to calculate data i dont need to keep track of every bit but rather allow it bo be wide in range?
if i dont care that 100 + 1 is still 100 fpu is for me.
You have passed from the realm of being unaware into the realm of being ignorant on purpose.

It's not any FPU designer's fault that you are not educated enough in computer science (or, even, simple reading of, say, my previous post) to grasp the concept that, in many fields of science and calculation, 15 digits of mantissa precision are plenty enough and the speed of calculations does matter.

Go play a round of your ego shooter of choice. Enjoy the high frame rate and remain blisfully ignorant of the technology driving it.
Every good solution is obvious once you've found it.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: fpu usefulness?

Post by qw »

Solar wrote:Of course you can do all those calculations in integer registers, but a FPU will run circles around you!
To the OP: this is what emulators do, and why emulators are slow.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: fpu usefulness?

Post by qw »

Speaking of which, are there still x87 emulators operating out there? The FPU has been built-in since the 486.
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: fpu usefulness?

Post by NickJohnson »

I'm sure that I've seen an "emulate x87" option in the Linux kernel config.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: fpu usefulness?

Post by Combuster »

Not all 386 and 486 machines have an fpu. And you might find some excuse to fix certain (old) FPU bugs.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: fpu usefulness?

Post by qw »

I meant: are there still x86 machines out there without an FPU that do use floating point arithmetic and therefore need an emulator? Not that many, I guess...

Combuster,
Using an emulator to fix some FPU bugs may be reasonable, but it does seem like overkill to me.

Anyway, I'm just being curious. I am sure some people have good reasons to use an emulator.
Dario
Member
Member
Posts: 117
Joined: Sun Aug 31, 2008 12:39 pm

Re: fpu usefulness?

Post by Dario »

a5498828 wrote:Is there anything fpu (x87) is usefull?
No. It's there to consume power just to keep electric power companies happy. Rendering farms would do so much better without it.
____
Dario
Post Reply