Hi
Are in FPC some instruction set contains streaming SIMD (SSE) like in GCC:
http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/X86-Built_002din-Functions.html
or in Microsoft Visual
http://msdn.microsoft.com/en-us/library/kcwz153a(VS.80).aspx

Mailing lists / fpc-devel / 2008-11
17 messages · 9 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi
Are in FPC some instruction set contains streaming SIMD (SSE) like in GCC:
http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/X86-Built_002din-Functions.html
or in Microsoft Visual
http://msdn.microsoft.com/en-us/library/kcwz153a(VS.80).aspx
Use the mmx unit to discover what mmx/sse instruction set is supported by your cpu. You can use mmx/sse commands directly in the asm blocks and FPC automatically uses MMX/SSE instructions for your pascal code if you allow it (specify CPU type). In my experiments FPC often created faster code itself. So don't expect much speed gain when using SSE instructions directly.
Mattias
You can tell FPC to do the SSE code for you:
-Cf<x> Select fpu instruction set to use, see fpc -i for possible values
And in fpc - i I see:
Supported CPU instruction sets:
386
PENTIUM
PENTIUM2
PENTIUM3
PENTIUM4
PENTIUMM
Supported FPU instruction sets:
X87
SSE
SSE2
SSE3
So I would use something like:
-CfSSE3
maybe also -CfPENTIUM4
Felipe Monteiro de Carvalho wroteYou can tell FPC to do the SSE code for you: -Cf<x> Select fpu instruction set to use, see fpc -i for possible values
That only applies to (scalar) FPU operations at this time. It won't do any (auto or other) vectorisation.
Jonas
With -Sv -Cfsse2 you can compile things like
function f : double;
var
d1,d2,d3 : array[0..1] of double;
begin
d1:=d2*d3;
end;However, it's not well tested.
Florian Klaempfl pisze:
I know this, but its hard to discover where and when is is used. Often is good, when compiler make optimization itself, but some times is better tell them about possible vectorization.
I would expect some thing like this
type
tSSEvector= packed record of
a,b : double;
end;
{ or }
tSSEvector= array[0..1] of double;
function f : double;
var
d1,d2,d3 : tSSEVector;
begin
d1:=d2*d3;
end;Of course tSSEVector should be declared in System unit. Then any one can use SSE intentionally.
However, it's not well tested.
Is there a list of SSE function, which can FPC use?
Darek
Why can't you now? It's not like multiplication has any other meaning for arrays. And declaring "magic compiler types" in the system unit is something that should be avoided as much as possible (it makes both the compiler and rtl harder to adapt and understand).
Jonas
On Fri, 28 Nov 2008 21:25:16 +0100 Use the mmx unit to discover what mmx/sse instruction…
Mattias Gaertner pisze:
MMX can operate on 2 longint simultaneous and SSE on 4, FPC often sometime make optimization to SSE, thus is faster.
I don't want write SSE instruction by hand, but would by nice to to tell to compiler, where those optimization should be made (if its possible)
Darek
Why can't you now? It's not like multiplication has any other meaning for arrays. And…
Jonas Maebe pisze:
Of course, but SIMD is thing, which has more and more impact to performance. And compiler should respect it (and do this, as Florian said). But till now nobody know, where compiler use SSE instruction. In my mind, to achieve this is declare some primitives represents SSE types. On one side there are "magic compiler types" but on second there exists in real world (most of used CPU has them). And it will be harmless, because its not change in language (we can use record, array) and is easy implement needed primitives in pure pascal. Its very similar to IEEE-754: on platform where FPU not exists all function are implemented by hand.
Of course one knows. For array operations as shown SSE/SSE2 is used if enabled.
Florian Klaempfl pisze:
Ok. I only want to discover how to use it.
if I write
type
tSSEVector = array[0..1] of double
var
d1 : tSSeVector;
d2 : array[0..1]of tSSEVector;
begin
d1:=d2[0]*d2[1];
end;will be work too?
Or something like this:
function f ;
var
d1,d2,d3 : array[0..4] of integer;
begin
d1:=d2*d3;
end;Yes.
No. Not yet implemented iirc.
Florian Klaempfl pisze:
Thanks. Now I understand.
But will be in the same manner?
Mattias Gaertner pisze: MMX can operate on 2 longint simultaneous and SSE on 4, FPC often…
Hi,
Not exactly related to this thread, but worth mentioning:
Some time ago I was interested in (numerical) computing some Bessel function to the highest precision!
I looked at MMX, SSE, SSE2, SSE3, SSE4, FP87, 3D-something etc... And all that jazz...
It turns out that only the "old" FP87 (FPU) has the 80 bit (extended) floating format! Anything else, and you are limited to the 64 bit (double) floating numbers.
I fell sorry to see that even 25 years after the original 8087, modern CPUs are not even capable to have the same precision!
Alain
If you need precision you have to do integer math anyway. Floating point numbers are always crude approximations, no matter how many bits they have. Considering that the numerical range of an 80-bit floating point number is larger than the relation between the diameter of an atom and the diameter of the known universe, this so-called "precision" is hardly ever needed. Or to express this a bit (pun intended) differently: How much of the universe do you expect to fit into 80 bits?
Vinzent.
I think that high precision numerical computing is very useful in many fields of science and technology:
The Rydberg constant is defined using 13 digits.
The second is measured using 15 digits
Some laser spectroscopist make measurements using 18 digits.
The Lamb shift in hydrogen has been measured using 13 digits. Right now this measurement is more accurate than the theoretical evaluation:
In order to evaluate this number (to 12 digits), the researchers had to make a long calculation involving the sum of about 2000 numerical integrals.
You are right, they have used symbolic computation. However, in order to make sure that the did not miss someting, they have also checked every integral by performing a numerical integration a test!
Therefore, I think that 64 bits is a limit !
Alain
You are right, but scientific math libraries are for that reason alwas based on large integer calculations. SSE, MMX etc are designed for multimedia applications, not science.
However, there are dedicated units available that implement large scaled integers in hardware (really fpga's I believe, but not sure) to speed up scientific processing (at a - very high - price, but at least up to 1024 bit that I know of)