Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2008-11

SSE in FPC

17 messages · 9 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mattias Gaertner
to darekm
Show quoted text 10 lines
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

Reply by email

Felipe Monteiro de Carvalho
to Mattias Gaertner

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

Reply by email

Jonas Maebe
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote
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

That only applies to (scalar) FPU operations at this time. It won't do any (auto or other) vectorisation.

Jonas

Reply by email

Florian Klaempfl
to Jonas Maebe
Show quoted text 10 lines
On 29 Nov 2008, at 11:11, Felipe Monteiro de Carvalho wrote: > 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 That only applies to (scalar) FPU operations at this time. It won't do any (auto or other) vectorisation.

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.

Reply by email

Dariusz Mazur
to Florian Klaempfl

Florian Klaempfl pisze:

Show quoted text 16 lines
Jonas Maebe schrieb: > On 29 Nov 2008, at 11:11, Felipe Monteiro de Carvalho wrote: > > >> 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 >> > That only applies to (scalar) FPU operations at this time. It won't do > any (auto or other) vectorisation. > With -Sv -Cfsse2 you can compile things like

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.

Show quoted text 9 lines
function f : double; var d1,d2,d3 : array[0..1] of double; begin d1:=d2*d3; end;
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

Reply by email

Jonas Maebe
to Dariusz Mazur
Dariusz Mazur wrote 32 lines
Florian Klaempfl pisze: > function f : double; > var > d1,d2,d3 : array[0..1] of double; > > begin > d1:=d2*d3; > end; > 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

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

Reply by email

Dariusz Mazur
to Mattias Gaertner: On Fri, 28 Nov 2008 21:25:16 +0100 Use the mmx unit to discover what mmx/sse instruction…

Mattias Gaertner pisze:

Show quoted text 23 lines
On Fri, 28 Nov 2008 21:25:16 +0100 darekm wrote: > 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.

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

Reply by email

Dariusz Mazur
to Jonas Maebe: Why can't you now? It's not like multiplication has any other meaning for arrays. And…

Jonas Maebe pisze:

Show quoted text 9 lines
> > > Of course tSSEVector should be declared in System unit. > Then any one can use SSE intentionally 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).

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.

Darek

Reply by email

Florian Klaempfl
to Dariusz Mazur
Show quoted text 13 lines
Jonas Maebe pisze: >> >> >> Of course tSSEVector should be declared in System unit. >> Then any one can use SSE intentionally > > 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). 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.

Of course one knows. For array operations as shown SSE/SSE2 is used if enabled.

Reply by email

Dariusz Mazur
to Florian Klaempfl

Florian Klaempfl pisze:

Show quoted text 21 lines
Dariusz Mazur schrieb: > Jonas Maebe pisze: > >>> Of course tSSEVector should be declared in System unit. >>> Then any one can use SSE intentionally >>> >> 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). >> > 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. > Of course one knows. For array operations as shown SSE/SSE2 is used if enabled. _______________________________________________

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;
Darek

Reply by email

Florian Klaempfl
to Dariusz Mazur
Show quoted text 34 lines
Florian Klaempfl pisze: > Dariusz Mazur schrieb: > >> Jonas Maebe pisze: >> >>>> Of course tSSEVector should be declared in System unit. >>>> Then any one can use SSE intentionally >>>> >>> 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). >>> >> 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. > > Of course one knows. For array operations as shown SSE/SSE2 is used if > enabled. > _______________________________________________ > 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?

Yes.

Show quoted text 13 lines
Or something like this: function f ; var d1,d2,d3 : array[0..4] of integer; begin d1:=d2*d3; end;

No. Not yet implemented iirc.

Reply by email

Dariusz Mazur
to Florian Klaempfl

Florian Klaempfl pisze:

Show quoted text 47 lines
Dariusz Mazur schrieb: > Florian Klaempfl pisze: > >> Dariusz Mazur schrieb: >> >> >>> Jonas Maebe pisze: >>> >>> >>>>> Of course tSSEVector should be declared in System unit. >>>>> Then any one can use SSE intentionally >>>>> >>>>> >>>> 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). >>>> >>>> >>> 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. >>> >> Of course one knows. For array operations as shown SSE/SSE2 is used if >> enabled. >> _______________________________________________ >> >> > 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? > Yes.

Thanks. Now I understand.

Show quoted text 16 lines
> Or something like this: > > function f ; > > var > > d1,d2,d3 : array[0..4] of integer; > begin > > d1:=d2*d3; > > end; > No. Not yet implemented iirc.

But will be in the same manner?

Darek

Reply by email

Alain Michaud
to Dariusz Mazur: 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

Dariusz Mazur wrote 38 lines
Mattias Gaertner pisze: > On Fri, 28 Nov 2008 21:25:16 +0100 > darekm wrote: > > >> 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. > 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 _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Vinzent Höfler
to Alain Michaud
Alain Michaud wrote 16 lines
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!

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.

Reply by email

Alain Michaud
to Vinzent Höfler
Vinzent Höfler wrote 31 lines
Alain Michaud wrote: > 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! 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. _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

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

Reply by email

Thaddy
to Alain Michaud
Alain Michaud wrote 59 lines
Vinzent Höfler wrote: > Alain Michaud wrote: >> 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! > > 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. > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-devel 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)

Reply by email