Altivec vector comparison - GCC AmigaOS4 SDK

4 posts / 0 new
Last post
flash
flash's picture
Offline
Last seen: 3 months 2 weeks ago
Joined: 2018-02-24 17:25
Altivec vector comparison - GCC AmigaOS4 SDK

Hello friends,
I'd like to ask you if the following code is ok.
It uses altivec extensions under GCC AmigaOS4 compiler/SDK.

I'm using AmigaOS under Winuae and can't test Altivec code :-(

I'd like to focus you in the following line: "if (vec_all_gt (vec_add (zi2, zr2), maxdist)) break;"

I know vectors comparisions are bit strange and in some others examples in internet I find other more complex ways to make same job using masking tecniques.

Here there's the whole function:

#include "exec/types.h"
#include "FlashMandel.h"

#ifdef __ALTIVEC__
#include "altivec.h"

__inline WORD MandelnAltivec (LONG Iterazioni, LONG Power, LDouble Cre, LDouble Cim)
{
REGISTER WORD Exp;
const vector float zero = (vector float) {0};
const vector float maxdist = (vector float) {4.0};

vector float vCre = (vector float) {(float) Cre};
vector float vCim = (vector float) {(float) Cim};
vector float zr = vCre;
vector float zi = vCim;
vector float zi2, zr2;

do
{
for (Exp = Power; Exp != -1; Exp--)
{
zi2 = vec_madd (zi, zi, zero);
zi = vec_madd (zi, zr, zero);
zr2 = vec_madd (zr, zr, zero);
zr = vec_sub (zr2, zi2);
zi = vec_add (zi, zi);
}

if (vec_all_gt (vec_add (zi2, zr2), maxdist)) break;

zi = vec_add (zi, vCim);
zr = vec_add (zr, vCre);

if (--Iterazioni == 0) break;

for (Exp = Power; Exp != -1; Exp--)
{
zi2 = vec_madd (zi, zi, zero);
zi = vec_madd (zi, zr, zero);
zr2 = vec_madd (zr, zr, zero);
zr = vec_sub (zr2, zi2);
zi = vec_add (zi, zi);
}

if (vec_all_gt (vec_add (zi2, zr2), maxdist)) break;

zi = vec_add (zi, vCim);
zr = vec_add (zr, vCre);

} while (--Iterazioni);

return 0;
}
#endif /* __ALTIVEC__ */

flash
flash's picture
Offline
Last seen: 3 months 2 weeks ago
Joined: 2018-02-24 17:25
Re: Altivec vector comparison - GCC AmigaOS4 SDK

Ok friends, i want to update the thread and reply myself because I got the answer.
Due I haven't any real Amiga and Winuae platform doesn't support Altivec extensions I had to try it on my PowerMac G5 Quad under XCode development tool.

..Maybe this is the only existing one mandelbrot program to use altivec ad output a ascii text as result :-)

#include "stdio.h"
#include "altivec.h"

int main()
{
int a, b;
vector float cre, cim, zi, zr, zi2, zr2;
const int maxiter = 32;
int iter;

vector bool int exitMask, loopMask = {1}, zeroInt = {0};

const vector float zero = (vector float) {0};
const vector float maxdist = (vector float) {4.0};

for (b = 0; b <= 32; b++)
{
cim = (vector float) {((b - 16) / 10.0)};

for (a = 0; a <= 85; a++)
{
iter = 1;

cre = (vector float) {((a - 50) / 20.0)};

zr = cre;
zi = cim;

do {

zi2 = vec_madd (zi, zi, zero);
zi = vec_madd (zi, zr, zero);
zr2 = vec_madd (zr, zr, zero);
zr = vec_sub (zr2, zi2);
zi = vec_add (zi, zi);

// if (vec_all_gt (vec_add (zi2, zr2), maxdist)) break;

exitMask = vec_and (vec_cmpgt (vec_add (zi2, zr2), maxdist),loopMask);
if (vec_any_ne (exitMask,zeroInt)) break;

zi = vec_add (zi, cim);
zr = vec_add (zr, cre);

iter++;
} while (iter < maxiter);

if (iter == maxiter)
putchar(' ');
else
putchar (" .:-;!/>)|&IH%*#"[iter & 15]);
}
putchar ('\n');
}
return 0;
}

As you can see there's no simple way to compare vectors and I needed to use masking.
If someone knows a faster way is welcome to share.

I'm looking for fortunate amigans with G4 cpu and/or altivec ebabled extensions for testing purposes..

TSK
TSK's picture
Offline
Last seen: 4 months 3 weeks ago
Joined: 2011-06-28 02:06
Re: Altivec vector comparison - GCC AmigaOS4 SDK

The code compiles and runs (from the post #2) and returns this on X1000 (with Altivec):

  1. ..........................:::::::::::::::::::::::::::::::::::::::::::::::::...........
  2. ........................:::::::::::::::::::::::::::::::::::::::::::::::::::::.........
  3. ......................:::::::::::::::::::::::::::::::::::::::::::::::::::::::::.......
  4. ....................:::::::::::::::-----------:::::::::::::::::::::::::::::::::::.....
  5. ..................::::::::::-------------------------::::::::::::::::::::::::::::::...
  6. .................:::::::----------------;;;;;!-)!!;;;----:::::::::::::::::::::::::::..
  7. ................:::::----------------;;;;;;!!/>I|I !;;;;----:::::::::::::::::::::::::.
  8. ...............:::----------------;;;;;;;!!!/)| )I)/!!;;;;-----:::::::::::::::::::::::
  9. ..............::----------------;;;;;;;!!//>)* :)/!!!!;;------:::::::::::::::::::::
  10. .............::--------------;;;;;;!!/>))))|&* %&|)///:!;;-----::::::::::::::::::::
  11. ............::-------------;;;;!!!!//>H & ;H*# #!;------:::::::::::::::::::
  12. ............:-----------;;!!!!!!!///)*H ;>/!;------::::::::::::::::::
  13. ...........:-------;;;!!>H>>>>>>>>>)I; .|-!;;------:::::::::::::::::
  14. ...........---;;;;;;!!!/>& ;H% %I||I) #)/;;-------::::::::::::::::
  15. ...........-;;;;;;!!!!/>)I: # #>!;;;------::::::::::::::::
  16. ...........;;;;;////>)H%*/ )/!;;;------::::::::::::::::
  17. .......... H)>/!;;;-------:::::::::::::::
  18. ...........;;;;;////>)H%*/ )/!;;;------::::::::::::::::
  19. ...........-;;;;;;!!!!/>)I: # #>!;;;------::::::::::::::::
  20. ...........---;;;;;;!!!/>& ;H% %I||I) #)/;;-------::::::::::::::::
  21. ...........:-------;;;!!>H>>>>>>>>>)I; .|-!;;------:::::::::::::::::
  22. ............:-----------;;!!!!!!!///)*H ;>/!;------::::::::::::::::::
  23. ............::-------------;;;;!!!!//>H & ;H*# #!;------:::::::::::::::::::
  24. .............::--------------;;;;;;!!/>))))|&* %&|)///:!;;-----::::::::::::::::::::
  25. ..............::----------------;;;;;;;!!//>)* :)/!!!!;;------:::::::::::::::::::::
  26. ...............:::----------------;;;;;;;!!!/)| )I)/!!;;;;-----:::::::::::::::::::::::
  27. ................:::::----------------;;;;;;!!/>I|I !;;;;----:::::::::::::::::::::::::.
  28. .................:::::::----------------;;;;;!-)!!;;;----:::::::::::::::::::::::::::..
  29. ..................::::::::::-------------------------::::::::::::::::::::::::::::::...
  30. ....................:::::::::::::::-----------:::::::::::::::::::::::::::::::::::.....
  31. ......................:::::::::::::::::::::::::::::::::::::::::::::::::::::::::.......
  32. ........................:::::::::::::::::::::::::::::::::::::::::::::::::::::.........
  33. ..........................:::::::::::::::::::::::::::::::::::::::::::::::::...........
flash
flash's picture
Offline
Last seen: 3 months 2 weeks ago
Joined: 2018-02-24 17:25
Re: Altivec vector comparison - GCC AmigaOS4 SDK

It was tested on PowerMac g5 quad, I'm very glad to know it runs ok on Amiga X1000 too :-)
I uploaded a version for both, altivec and scalar fpu versions, on os4depot and aminet.
As always C source code is included.

@TSK
I send you a PM

Log in or register to post comments