how to enable and use  VFPU and SPE2-SIMD for MPC57xx in S32DS project

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to enable and use  VFPU and SPE2-SIMD for MPC57xx in S32DS project

Jump to solution
4,628 Views
enwei
NXP Employee
NXP Employee

Hi,

 

As we know, in most of our MPC57xx parts, such as MPC5775K as below, there are VFPU and SPE2-SIMD, which are very useful when doing DSP and complex math calculation.but how can we enable and use it in a S32DS project?

MPC5xxx 32-bit MCU for ADAS Applications

There is no options for this when create the project, and there are some related options in project properties-->C/C++ Bulid-->Stettings-->Target Processor, I checked Use hardware floating point, and configured Signal Processing: generate SPE v2 SIMD instructions and use ewl_c9x library:

159634_159634.jpgS32DS_SPE_settings.jpg

 

However, after configurations as above, I find the disassemle code has nothing differerent,  no performance improve, no SPE instructions generated for my codes, it seems still call the ewl_c9x library to complete my math operations:

 

void calc_magnitude_doppler( fft_value_t* inAddr, magnitude_t* outAddr, bool_t bRCSComp, eDistRange distRange){

  fft_value_t real, img;

  uint64_t quad;

  double sqroot;

  uint16_t x, y;

 

  for(y=0; y<FFT_NUM_SAMPLES; y++){

   // Do it for one chirp

   for(x=0;x<FFT_NUM_CHIRPS;x++){

 

  // Pointer to values

  real = *(inAddr + (x * FFT_NUM_SAMPLES * 2));

  img = *(inAddr + (x * FFT_NUM_SAMPLES * 2) + 1);

 

  // Calculate magnitude

  quad = (uint64_t)((int64_t)real*real + (int64_t)img*img);

 

 

  sqroot = sqrt((double)quad);

// sqroot = __ev_fssqrt(quad);

 

  // Calculate RCS compensation

  /*if( par->bRCSComp == bTrue ){

   if( y < (FFT_NUM_SAMPLES/2) ){

  sqroot = sqroot * rcs_comp(y, par->distRange);

   }

   else{

  sqroot = sqroot * rcs_comp((y-(y-128)*2-1), par->distRange);

   }

  }*/

  // Save Value

  *(outAddr) = (magnitude_t)sqroot;

 

  // Adjust pointer

  outAddr++;

   }

   // Adjust Pointer

   inAddr+=2;

  }

}

 

So, how can we enable and use the powerful VFPU and SPE2-SIMD in S32DS project?  Is there any addtional header files should be included or any SPE/FPU initialization needed besides the above project settings/configurations?

 

Thanks~!

 

Best regard,

Enwei Hu.

Labels (1)
0 Kudos
Reply
1 Solution
3,147 Views
enwei
NXP Employee
NXP Employee

It's OK now, it seems can only work with newlib.

Besides, it's necessary to add the below codes in startup.s to enable SPE before use it:

I also attached my test project in S32DS version for your reference(the spe intrinsics instructions is tested in z7_1 CPU core project):

;#*************************** Enable SPE Bit in MSR ****************************

       mfmsr r6

       se_bseti r6,6

       mtmsr r6

Thanks very much for Stan's great support on this case~!:smileyhappy:

Enwei Hu.

View solution in original post

0 Kudos
Reply
5 Replies
3,147 Views
stanish
NXP Employee
NXP Employee

Hello Enwei,

Thanks for this report.

This is a know compiler defect - ENGR00382137 - mspe2 options doesn't enable SPE codegen and doesn't switch to SPE libs

Could you possibly add the switch "-mspe" into both compiler and linker flags.

pastedImage_2.png

 

pastedImage_3.png

Stan

0 Kudos
Reply
3,147 Views
enwei
NXP Employee
NXP Employee

Hi Stan,

I tried your suggestion and added the switch "-mspe" into both compiler and linker flags, it reported new error:

"Description Resource Path Location Type
C:/Freescale/S32_Power_v1.1/S32DS/e200_ewl2/EWL_C/include/pa/spe.h expected '=', ',', ';', 'asm' or '__attribute__' before 'static' MPC5775K_SPE_demo_prj_Z7_0 line 329, external location: C:\Freescale\S32_Power_v1.1\S32DS\e200_ewl2\EWL_C\include\pa\spe.h C/C++ Problem
"

what's wrong? how can I solve it?

thanks~!

Enwei Hu

0 Kudos
Reply
3,148 Views
enwei
NXP Employee
NXP Employee

It's OK now, it seems can only work with newlib.

Besides, it's necessary to add the below codes in startup.s to enable SPE before use it:

I also attached my test project in S32DS version for your reference(the spe intrinsics instructions is tested in z7_1 CPU core project):

;#*************************** Enable SPE Bit in MSR ****************************

       mfmsr r6

       se_bseti r6,6

       mtmsr r6

Thanks very much for Stan's great support on this case~!:smileyhappy:

Enwei Hu.

0 Kudos
Reply
3,147 Views
stanish
NXP Employee
NXP Employee

Hello Enwei,

gcc C compiler cannot use these specific SPE2 vector instructions for C code.

The only way is to use these instructions in inline/standalone assembly, or use SPE intrinsics.

Simply include "<S32_Power_v1.x>\S32DS\e200_ewl2\EWL_C\include\pa\spe.h" to your .C module and use the intrinsic functions available in the header file.

Other option is to use a library that implements algorithms using SPE SIMD.

There is a AMMCLIB for MPC577xK available : Automotive Math and Motor Control Library Set|NXP

Two versions are offered -  free and pro. Pro version includes highly optimized asm code (SPE/LSP) routines.

Hope it helps.

Stan

0 Kudos
Reply
3,147 Views
enwei
NXP Employee
NXP Employee

Hi Stan,

Thanks for your reply.

I include "spe.h"(it located in <S32_Power_v1.x>\S32DS\e200_ewl2\EWL_C\include\pa\), and tried to call the intrinsic functions, but got serveral errors, compiler reports :

"C:/Freescale/S32_Power_v1.1/S32DS/e200_ewl2/EWL_C/include/pa/spe.h unknown type name '__ev64_opaque__'"

I searched all the project and found no '__ev64_opaque__' type definition, it's a type  that can accept any data type according to discriptions in "SPE2 Programming Interface Manual, Rev. 1.0-2" .

Could you help to made a simple project to demonstrate how to call and use the  intrinsic functions in spe.h?  the demo code to implement "sqroot = sqrt((double)quad)" is a prefer if possible.

I also tried the free version AMMCLIB for MPC5775K, and it seems has none performance improved, no SPE optimizied. I'd like to try the Pro version.

Thanks again~!

Enwei Hu.

0 Kudos
Reply