NEON/SIMD

Want a new feature? Discuss what you would like to see in Ultibo.
pik33
Posts: 852
Joined: Fri Sep 30, 2016 6:30 pm
Location: Poland
Contact:

Re: NEON/SIMD

Postby pik33 » Sat Nov 26, 2016 6:30 am

Lazarus generates executables which not depends on all this 1000 libraries bull*. I wrote some programs with it ,for windows, for linux - all of these were "unpack and run" type. Eventually: "do apt-get libsdl, if you haven't any yet in your linux" - in windows, sdl.dll can be in the in the same directory, where the main program is.
Gavinmc42
Posts: 1552
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

Re: NEON/SIMD

Postby Gavinmc42 » Sun Nov 27, 2016 12:20 am

The appimage method of packaging would allow the Ultibo IDE to be used on any Linux box.
Hmm would that include Pi's..

Pretty much off track, should have it's own post.

pik33,
Yep those 1000's dependences and ALM (Application Lifetime Management) of them is a big headache and it eventually led me to Ultibo.
One small file exe, one or a few source files, much easier to maintain.
I still have 8GB backups of some earlier Pi projects from 4-5 years ago.
We had to get a server to put them on.

FPC/Delphi have always made small exe that just work ;)
Garry has now provided us with a toolset that help makes it much easier to do ALM.
Billions of IoT devices are predicted to be made, I refuse to backup 8GB for each one :roll:
Rambling again
Gavinmc42
Posts: 1552
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

Re: NEON/SIMD

Postby Gavinmc42 » Sun Nov 27, 2016 2:30 am

mbrot source from here
http://rosettacode.org/wiki/Mandelbrot_set#Pascal
Used a single color to get it working.

Trying to figure out how to get RGB values into the color variable.
GraphicsWindowDrawPixel(Handle, ix, iy, color);

color is a LongWord in the source but how do you get the RGBA values into it.
Simple FPC stuff I have not learned or can find a google answer for yet.

Native framebuffer is ARGB or RGBA or???
User avatar
Ultibo
Site Admin
Posts: 2183
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: NEON/SIMD

Postby Ultibo » Sun Nov 27, 2016 4:03 am

Gavinmc42 wrote:color is a LongWord in the source but how do you get the RGBA values into it.

Because this is a common thing that you might want to do we (of course) provide an easy way to handle it, in the GlobalTypes unit you will find declarations of various TColorFormat structures including generic ones like TColorFormat32 and TColorFormat24 as well as more specific ones.

The one you want is TColorFormatARGB32 and you can typecast this around a LongWord to allow easy setting of the individual components in a color. Like this:

Code: Select all

uses
 GlobalTypes;
 
var
 Color:LongWord;

begin

 TColorFormatARGB32(Color).Alpha:=50;
 TColorFormatARGB32(Color).Red:=100;
 TColorFormatARGB32(Color).Green:=150;
 TColorFormatARGB32(Color).Blue:=200;


Of course if you need to do this thousands of times there are some optimizations you can use, like creating some presets beforehand or there are ways to do the exact same thing using AND/OR and SHL/SHR (Shift Left or Right) which may be quicker if doing many iterations.

Gavinmc42 wrote:Native framebuffer is ARGB or RGBA or???

On the Pi the default framebuffer is ARGB (Little Endian) so Ultibo uses that as the default format as well (for want of a better default choice), see COLOR_FORMAT_DEFAULT in GlobalConst. Of course the Pi GPU can support creating the framebuffer in many different formats (8, 16, 24 or 32 bit) so there really is no actual native format.
Ultibo.org | Make something amazing
https://ultibo.org
Gavinmc42
Posts: 1552
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

Re: NEON/SIMD

Postby Gavinmc42 » Sun Nov 27, 2016 9:12 am

Thanks Garry.

Simple enough now that you pointed it out ;)
Going to add some timers to see if different colour formats make much difference.
Takes long enough to calculate, timers should give enough info to test accelerated maths.

Code: Select all

 begin
            TColorFormatARGB32(Color).Red   := 0;
            TColorFormatARGB32(Color).Green := 0;
            TColorFormatARGB32(Color).Blue  := 0;
          end
         else
         begin
            TColorFormatARGB32(Color).Red   := 30 * iteration;
            TColorFormatARGB32(Color).Green := 10 * iteration;
            TColorFormatARGB32(Color).Blue  := 255 - 10 * iteration;
         end;
         GraphicsWindowDrawPixel(Handle, ix, iy, color); 
Attachments
mbrot2.png
mbrot2.png (84.42 KiB) Viewed 1829 times
pik33
Posts: 852
Joined: Fri Sep 30, 2016 6:30 pm
Location: Poland
Contact:

Re: NEON/SIMD

Postby pik33 » Mon Jul 03, 2017 5:58 am

Up!

I needed an equalizer for my player. I wrote a simple 10-filter bank using standard asm. NEON can be useful here. My version of Ultibo fpc can compile subset of it, but then if I use this, noone else can compile the source.

Now some explanation:

To compile the code using a subset of NEON nstructions, the compiler have to call the assembler with -mfpu=neon parameter
This can be done using the parameter in fpc.cfg - the example with assembly code is lying somewhere in this forum

But then after using the switch, the fpc cannot compile floating point expressions; it simply doesn't know what to do with fpu=neon. So as it is now, we can have only one of these: subset of NEON or floating point.

The hack is simple: tell the assembler to use NEON while the compiler will use standard VFP

In the file ultibo/core/fpc/source/compiler/arm/agarmgas.pas, about line 110

comment this:

Code: Select all

       if (current_settings.fputype = fpu_vfpv3) then
        result:='-mfpu=vfpv3 '+result;


and add this:

Code: Select all

        if (current_settings.fputype = fpu_vfpv3) then
          result:='-mfpu=neon '+result;


Then rebuild fpc - the cheat is done. It works; nothing was spoiled by this as I use the hacked compiler to compile the player: 50k lines of code compile and work.

There are 2 problems then

(1) This is a dirty hack. The legal way is to tell the compiler how to compile floating point when fpu is set to vfp3_neon. I tried this, but there are too many places to change while my understanding what is going there is way too low

(2) Using compiler switch or the hack described above enables only a subset of NEON. Only instructions which are common to NEON and VFP are enabled. The other instructions are rejected by fpc syntax check as invalid. I tried to add these instructions (more precise: one of them) to the instruction list in fpc but without succes: I gave up after several hours of fighting.

The NEON stuff was not on the list of feature request survey, so I am moving the topic up.

If someone know how to add the asm instructions to the fpc syntax checker... I will add them. The NEON can speed up both graphics and sound processing.
User avatar
Ultibo
Site Admin
Posts: 2183
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: NEON/SIMD

Postby Ultibo » Mon Jul 03, 2017 10:33 am

pik33 wrote:The NEON stuff was not on the list of feature request survey, so I am moving the topic up.

The NEON support isn't on the feature survey because it is technically already done, only problem is it is currently broken.

The changes to fix it were left out of the last release but will be in the next build of the installer, not sure exactly when that will be yet.

EDIT: The updated compiler is included in the Ultibo core 2.0.029 release and the GitHub FPC source also includes this fix.
Ultibo.org | Make something amazing
https://ultibo.org
Gavinmc42
Posts: 1552
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

Re: NEON/SIMD

Postby Gavinmc42 » Mon Jul 03, 2017 10:51 am

I thought it needed a change/fix in the FPC compiler.
Or was that just for the Aarch64/NEON?
Been so long since I looked at it and with accelerated graphics of some sort now looking possible, things are getting interesting.
pik33
Posts: 852
Joined: Fri Sep 30, 2016 6:30 pm
Location: Poland
Contact:

Re: NEON/SIMD

Postby pik33 » Mon Jul 03, 2017 11:19 am

I thought it needed a change/fix in the FPC compiler.


You were right, it needs changes in fpc compiler :) which as I understand will be pushed with the next installer.

Return to “Feature requests”

Who is online

Users browsing this forum: No registered users and 1 guest