Recent

Author Topic: Compilation error with CPU vector extensions  (Read 954 times)

explainedd

  • New Member
  • *
  • Posts: 10
Compilation error with CPU vector extensions
« on: March 28, 2023, 06:10:18 pm »
Hi,

I am trying to compile the following code:

Code: Pascal  [Select][+][-]
  1. unit Point3DType;
  2.  
  3. interface
  4.  
  5.     uses SysUtils, Classes;
  6.  
  7.     type Point3DTrMat = Array [0..8] of double; // 3x3 Transformation matrix (row-major)
  8.  
  9.     type Point3D = record
  10.         x, y, z: double;
  11.         class operator Multiply(const left:Point3DTrMat; const right:Point3D):Point3D; overload; // Matrix multiplication (result is a column-matrix)
  12.     end;
  13.  
  14. implementation
  15.  
  16.     class operator Point3D.Multiply(const left:Point3DTrMat; const right:Point3D):Point3D;
  17.     var retval: Point3D;
  18.     begin
  19.         Result := retval;
  20.     end;
  21.  
  22. end.

I get the following error message with -Sv compiler option:

Point3DType.pas(11,86) Error: Impossible operator overload
Point3DType.pas(14,1) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: C:\FPC3.2.3\bin\x86_64-win64\ppcx64.exe returned an error exitcode

The problem is with the Point3DTrMat variable in the multiply operator. Theoretically, can its type be a static array?

FPC version: fixes_3_2
language mode: delphi
target OS: Win64
instructionset: COREAVX2
fpu: AVX2

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Compilation error with CPU vector extensions
« Reply #1 on: March 29, 2023, 12:49:36 am »
Did you try "Constref" ?
The only true wisdom is knowing you know nothing

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Compilation error with CPU vector extensions
« Reply #2 on: March 29, 2023, 02:48:53 am »
There is no operator Multiply in Pascal. You can do:
Code: Pascal  [Select][+][-]
  1. {$modeswitch advancedrecords}
  2. // ...
  3.   type Point3D = record
  4.         x, y, z: double;
  5.         class operator *(const left:Point3DTrMat; const right:Point3D):Point3D; overload; // Matrix multiplication (result is a column-matrix)
  6.     end;
or you can implement function Multiply().

More on topic: https://wiki.freepascal.org/Operator_overloading
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

explainedd

  • New Member
  • *
  • Posts: 10
Re: Compilation error with CPU vector extensions
« Reply #3 on: March 29, 2023, 01:27:19 pm »
Did you try "Constref" ?

Thanks, but it gives the same result.

There is no operator Multiply in Pascal.

This is Delphi, a dialect of the Object Pascal programming language.
https://www.freepascal.org/docs-html/prog/progse74.html
https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Operator_Overloading_(Delphi)

The code quoted above works fine without vector processing support.

I see two possible reasons for the error phenomenon:
  • Syntax problem.
  • The "expression" is not supported by the compiler under these circumstances.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Compilation error with CPU vector extensions
« Reply #4 on: March 29, 2023, 01:41:42 pm »
Are you sure you have enabled delphi mode on the commandline, as you don't seem to have a {$mode delphi} in the code?

It compiles fine here:

Quote
c:\testing>fpc -Sd point3dtype.pp
Free Pascal Compiler version 3.3.1 [2023/03/28] for i386
Copyright (c) 1993-2023 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling point3dtype.pp
point3dtype.pp(19,23) Warning: Local variable "retval" does not seem to be initialized
21 lines compiled, 0.1 sec
1 warning(s) issued

explainedd

  • New Member
  • *
  • Posts: 10
Re: Compilation error with CPU vector extensions
« Reply #5 on: March 29, 2023, 01:58:35 pm »
Are you sure you have enabled delphi mode on the commandline, as you don't seem to have a {$mode delphi} in the code?

I'm sure. Please apply the -Sv compiler option.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Compilation error with CPU vector extensions
« Reply #6 on: March 29, 2023, 02:08:13 pm »
Indeed. Please file a bug.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Compilation error with CPU vector extensions
« Reply #7 on: March 29, 2023, 05:16:58 pm »
Quote
This is Delphi, a dialect of the Object Pascal programming language.

Sorry for confusion. Even worse, it is listed in the table I myself linked for you. That's because I practically never use {$mode Delphi} so I always overload operators with +-*/= signs.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Thaddy

  • Hero Member
  • *****
  • Posts: 14213
  • Probably until I exterminate Putin.
Re: Compilation error with CPU vector extensions
« Reply #8 on: March 29, 2023, 05:20:42 pm »
so I always overload operators with +-*/= signs.
Which happens to be the first candidate to be removed.
Specialize a type, not a var.

 

TinyPortal © 2005-2018