sqrt function with hard FPU instrustion

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

sqrt function with hard FPU instrustion

1,457 Views
MK60FX512
Contributor I

Dear Sir

K60 microcontroller has inbuit FPU, So it support floating point instuction by hard ware itself rather than softcode

I am using KDS for K60  and i using sqrtf() function in .list file it shows software root function. as below

****b_out = sqrtf(a);
  82              .loc 1 82 0 discriminator 1
  83 0036 40F20003movwr3, #:lower16:a
  84 003a C0F20003movtr3, #:upper16:a
  85 003e D3ED007Afldss15, [r3]
  86 0042 B0EE670Afcpyss0, s15
  87 0046 FFF7FEFFblsqrtf
  88 004a F0EE407Afcpyss15, s0
  89 004e 40F20003movwr3, #:lower16:b_out
  90 0052 C0F20003movtr3, #:upper16:b_out
  91 0056 C3ED007Afstss15, [r3]
  83:../Sources/main.c ****timecount = timecount+1.2;

1.can somebody say how to invoke floting instuction ?

2. is possible to do square root by excecuting sqrt hardware instruction? if yes then how.

Labels (1)
0 Kudos
4 Replies

658 Views
BlackNight
NXP Employee
NXP Employee

In the compiler settings, make sure you have these options set:

pastedImage_0.png

Erich

0 Kudos

658 Views
MK60FX512
Contributor I

Hi

As i was using KDS but because all this problem again i started to use CW10.6 with GCC compiler instead of freescale compiler

In this case float multiplication is generting Instruction like only with "f" only  with GCC compiler.

.loc 1 134 0

flds s15, [r5, #0]

fmuls s14, s15, s17

fcpys s0, s16

fmacs s0, s15, s14

movw r2, #:lower16:.LANCHOR1

movt r2, #:upper16:.LANCHOR1

fsts s0, [r2, #0]

but in freescale compiler , it was generating with starting of "V" like  vmov.F32

so the above instruction instruction with starting of "f" like fcpys is correct ????

but still it is generating instruction both fsqrt and also branch of sqrt like follow

138:../Sources/main.c ****dummy_float = sqrtf(dummy_float);
181              .loc 1 138 0
182 0078 F1EEC00Afsqrtss1, s0
183 007c F4EE600Afcmpss1, s1
184 0080 F1EE10FAfmstat
185 0084 03D0    beq.L4
186 0086 FFF7FEFFblsqrtf
187              .LVL14:
188 008a F0EE400Afcpyss1, s0
189              .L4:
190 008e 40F20003movwr3, #:lower16:.LANCHOR1
191 0092 C0F20003movtr3, #:upper16:.LANCHOR1
192 0096 C3ED000Afstss1, [r3, #0]

so in above instruction sqrt is executing with FPU or it is software execution.

Please Help

0 Kudos

658 Views
MK60FX512
Contributor I

There are option of setting FPU type whether hard or soft in KDS but if i set "Toolchaing default" then it is taking as software and generating branch  and software code without any FPU instrucation and not giving any error

but I set as

mfloat-abi=hard

mfpu=fpv4-sp-d16

from  project setting then while running it is giving Hard fault and haging at

PE_ISR(Cpu_Interrupt)

{

  /* This code can be changed using the CPU component property "Build Options / Unhandled int code" */

  PE_DEBUGHALT();

}

but same thing i tried in CW10/6 it is working and it generate FSQRTS instruction.

Please help to sort out issue of KDS.

Thanks and regards

Bipin

0 Kudos

658 Views
BlackNight
NXP Employee
NXP Employee

It looks like you have not enabled the floating point unit?

Add this code to your application

void vPortEnableVFP(void) {

  /* The FPU enable bits are in the CPACR. */

  __asm volatile (

    "  ldr.w r0, =0xE000ED88  \n" /* CAPCR, 0xE000ED88 */

    "  ldr r1, [r0]           \n" /* read CAPR */

    "  orr r1, r1, #(0xf<<20) \n" /* enable CP10 and CP11 coprocessors */

    "  str r1, [r0]           \n" /* store to new value back */

    : /* no output */

    : /* no input */

    : "r0","r1" /* clobber */

  );

}

and call it in main() as the first thing.

Erich

0 Kudos