Skip to content
mikerabat edited this page Mar 22, 2018 · 1 revision

Installation

Installing the packages

To install the packages perform the following steps:

  • Add the mrMath, mrMath\win, mrMath\mac directories to the library path.
  • Open the file: mrMath.dpk in the Delphi IDE.
  • Compile
  • If you want to have the IDE Plugin installed open the file: mrMath\DelphiIDEPlugin\mrMathIDE.dpk
  • Compile and install the package.

Please note that there is only one package file for all Delphi versions since the difference is very subtle. I also suggest to check the project options and disable all range and overflow checking as well as assertions to get maximum speed out of the library. Some minor gain - but especially with all the native pascal functions - can be achieved if Andreas Hausladens great IDE Fixpack package and his fastcompiler is installed and the package is compiled with the fast FPU params. Check out his page here

I added the complete range of his new optional compiler switches: -x-orc -x-fvs -x-ff -x-fpr

-> Done.

Checking the Test Project

To check if the installation was successfully and the library is working one can execute the unit test project found in mrMath\test\MathUtilsTest.dpr.

This project is also a neat source on how to's ;)

FreePascal CodeTyphoon

I had some difficulties on different CodeTyphoon versions. Here is what works for me:

  • One installation with CodeTyphoon 5.6 works with the MathUtilsTestFPC.lpr and for the 32 bit versions the MathUtilsTestFPC32.lpr project. Open the project compile and run it. Note that I'm not that "fluent" with CodeTyphoon but I hope the provided project files are sufficient.
  • There exists also a CodeTyphoon library mrMath.ctpr that allows to install a package. (Like the Delphi package). Open and install that file.
  • For Linux and also later Windows CodeTyphoon installations there also exists the MathUtilsTestLinux.ppr project. Open and compile that one to check if the project works for you.

I'm still not sure if there is something better or more "common" I can do so if there is someone with better knowledge of Linux and CodeTyphoon let me know how I can do better.

Extending the project with AVX/FMA instructions

Since Delphi does not know these opcodes per default I needed to take a different route: Prepare the assembler codes in CodeTyphoon (32 and 64 bits) extract the opcodes and asm commands using the tool from the great ASM source tool from Agner and then automatically convert the opcodes to db statements for Delphi.

Instructions

-> Use Codetyphoon for this purpose and the MathUtilsTest32/64 (or MathUtilsTestLinux) projects for this purpos.

Compile all the projects without debug information and optimization o3 on.

-> Make sure the compiled object files are in the .\Test\lib\i386-win32 and the .\Test\lib\x86_64-win64 folders or adjust the paths in the processPasFiles.bat file.

-> download the tool object file converter tool from here and place the exe file in this directory.

-> compile the AVXPortToDelphi.dpr project. -> run processPasFiles.bat

-> DONE

The batch file invokes the objeconv.exe tool and strips out the assembler op codes These opcodes are then placed in the pas files via IFDEFS. Note that if you change some assembler instructions in FPC all you need is to run the tool again and the IFDEFS get updated.

Things to keep in mind

  • Delphi and FPC use different stack alignments and local variables mostly get hinted out.
  • Same is for global variables. Always use the lea (load effective address) instruction to first load the true destination into a register before you use the value with AVX instructions.
  • Local variables layout is somehow different (caused nasty AV's here in the first place). Try to either use lea first or manipulate the stack manually aka refer to fixed stack positions like in AVXMatrixVectorMultOperations.AVXMatrixVectMultT .
Clone this wiki locally