* * *

Author Topic: AVX and SSE support question  (Read 2968 times)

dzjorrit

  • Newbie
  • Posts: 2
AVX and SSE support question
« on: May 25, 2016, 10:22:03 am »
Hi,
I have the following code:

const
  vectorsize = 4;
type
  tVector=array[0..vectorsize-1] of single;

function vectoradd(a,b:tVector):tVector;
begin
  result:=a+b;
end;
   
This compiles fine when SSE and vector processing are enabled.

But when I increase vectorsize to 8 and enable the AVX compiler options I get this error:
Compile Project, Target: project1.exe: Exit code 1, Errors: 1
unit1.pas(60,12) Error: Internal error 200610072

Is AVX not properly supported yet by fpc or is this a bug?

I'm using lazarus 64bit version 1.6 with fpc 3.0.0 on Windows 10 x64 with AMD A10 AVX enabled processor.

Thanks!
Jorrit





Thaddy

  • Hero Member
  • *****
  • Posts: 4429
Re: AVX and SSE support question
« Reply #1 on: May 25, 2016, 10:51:56 am »
Which FPC version are you using? That's really important, because AVX is only properly supported from 3.0 and higher.

Ah, I see, 3.0. In that case: how did you compile? An internal error should never happen and should be reported on bugs.freepascal.org. If you ever see an internal error it is a bug by definition.

When you file your bug report give as much information as possible and preferably a complete code example that reproduces the bug.
« Last Edit: May 25, 2016, 10:59:27 am by Thaddy »
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

dzjorrit

  • Newbie
  • Posts: 2
Re: AVX and SSE support question
« Reply #2 on: May 25, 2016, 11:49:38 am »
Ok, thanks, I will file a bug report soon. I use a new lazarus project only adding the code I produced in my post and having these compiler options specified:
-O4
-CfAVX
-CpCOREAVX
-OpCOREAVX
-Sv
-XX
-CX

Pascal Fan

  • Newbie
  • Posts: 2
Re: AVX and SSE support question
« Reply #3 on: June 11, 2016, 05:46:05 am »
I noticed something else related to the vector processing.  I was playing around with this code this evening, trying a few things, and I noticed that when I used the code posted in this thread with a vector size of 4, and enabled SSE and vector processing with FPC 3.0, I got the same internal error as the poster got when using AVX with a size of 8, if I did an "a xor b" operation instead of an "a + b" operation.  If I did the "a + b" operation as shown in this thread, it works with SSE, but an xor operation will trigger the internal error.  I suspect this isn't correct, because it seems like an xor operation should be possible, and in any event the internal error seems like it's not the correct response.  Anyhow, I thought I should mention it because it looks like there might be some issues with the SSE vector processing as well.
« Last Edit: June 11, 2016, 05:51:36 am by Pascal Fan »

shobits1

  • Sr. Member
  • ****
  • Posts: 278
  • .
Re: AVX and SSE support question
« Reply #4 on: June 11, 2016, 06:13:26 am »
maybe you should refrain from using -O4 since the compiler help screens contains the following:
Code: [Select]
  -O<x>  Optimizations:
      -O-        Disable optimizations
      -O1        Level 1 optimizations (quick and debugger friendly)
      -O2        Level 2 optimizations (-O1 + quick optimizations)
      -O3        Level 3 optimizations (-O2 + slow optimizations)
      -O4        Level 4 optimizations (-O3 + optimizations which might have unexpected side effects)

maybe I'm wrong.

Pascal Fan

  • Newbie
  • Posts: 2
Re: AVX and SSE support question
« Reply #5 on: June 11, 2016, 06:54:07 am »
That's a totally valid point, and you're absolutely correct,  but what I forgot to mention in my post is that my compiles were done with -O3, not the -O4 the original poster used.  So I do think there might be a legitimate bug here.  But you are absolutely correct that -O4 is probably not a good idea!

schuler

  • New member
  • *
  • Posts: 23
Re: AVX and SSE support question
« Reply #6 on: September 19, 2017, 05:02:14 pm »
 :) Hello :)

I have exactly the same problem on FPC 3.0.2 32 bits/windows. Tried with -Cp and -Op COREAVX/COREAVX2 and PENTIUMM.

  :( I can't figure my own login info at bugs.freepascal  :(


marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5641
Re: AVX and SSE support question
« Reply #7 on: September 19, 2017, 05:07:29 pm »
Did you check if something already existed ? :-)

https://bugs.freepascal.org/view.php?id=31612

Thaddy

  • Hero Member
  • *****
  • Posts: 4429
Re: AVX and SSE support question
« Reply #8 on: September 19, 2017, 05:08:23 pm »
:) Hello :)

I have exactly the same problem on FPC 3.0.2 32 bits/windows. Tried with -Cp and -Op COREAVX/COREAVX2 and PENTIUMM.

  :( I can't figure my own login info at bugs.freepascal  :(

You have to specify  -Sv  otherwise the compiler does not do anything interesting,  Your vector also needs to be a two dimensional vector atm. And you have to specify the alignment.
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

schuler

  • New member
  • *
  • Posts: 23
Re: AVX and SSE support question
« Reply #9 on: September 19, 2017, 08:58:52 pm »
 :) Hello Thaddy,  :)
Thank you for paying attention. Yes. I do have -Sv .

This is a known bug:
https://bugs.freepascal.org/view.php?id=31612

https://bugs.freepascal.org/view.php?id=30186

In the case that someone is interested, I've just tried this with success:

Code: Pascal  [Select]
  1. {$ASMMODE intel}
  2.  
  3. type
  4.   Single8 = record a,b,c,d,x,y,z,w:Single end;
  5.  
  6. procedure testAsm2();
  7. var
  8.   A: Single8;
  9.   AA: array[0..2] of Single8;
  10.   const ElSize = SizeOf(Single8);
  11. begin
  12.   A.x := 1;
  13.   A.y := 10;
  14.   A.z := 100;
  15.   A.w := 1000;
  16.   A.a := 1000;
  17.   A.b := 1000;
  18.   A.c := 1000;
  19.   A.d := 1000;
  20.  
  21.   asm
  22.     vmovups ymm0,A
  23.     vmovups ymm1,A
  24.     vaddps ymm0, ymm0, ymm1
  25.     vmovups A,ymm0
  26.     vmovups AA[1*ElSize],ymm0
  27.     vmovups AA[2*ElSize],ymm0
  28.   end;
  29.   WriteLn(A.x:6:4,' ',A.y:6:4,' ', A.z:6:4,' ', A.w:6:4);
  30.  
  31.   AA[1].y := 12;
  32.   AA[2].z := 14;
  33.  
  34.   WriteLn(AA[1].x:6:4,' ',AA[1].y:6:4,' ', AA[1].z:6:4,' ', AA[1].w:6:4);
  35.   WriteLn(AA[2].x:6:4,' ',AA[2].y:6:4,' ', AA[2].z:6:4,' ', AA[2].w:6:4);
  36.  
  37.   asm
  38.     vmovups ymm0,AA[1*ElSize]
  39.     vmovups ymm1,AA[2*ElSize]
  40.     vaddps ymm0, ymm0, ymm1
  41.     vmovups AA[0*ElSize],ymm0
  42.   end;
  43. WriteLn(AA[0].x:6:4,' ',AA[0].y:6:4,' ', AA[0].z:6:4,' ', AA[0].w:6:4);
  44.  
  45. end;
  46.  

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus