cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Observer
Observer
2,662 Views
Registered: ‎06-23-2013

Compiler wrongly generates fsqrt FPU instruction for double precision sqrt in MB

Jump to solution

We have Microblaze with extended-fpu in our design. Compiling code with –mxl-float-sqrt and –O1/O2 optimization generates incorrect code with double-precision SQRT function and results are corrupted.

Disassembly shows compiler generates wrong (maybe) fsqrt FPU instruction for double values.

 

SDK: 2016.4 GCC:5.2.0

 

Example Code:

double x;
....
double res = sqrt(x);

 

1a0:  5b180380   fsqrt     r24, r24
1a4:  10f80000   addk    r7, r24, r0
1a8:  11190000   addk    r8, r25, r0
1ac:  10b80000   addk    r5, r24, r0
1b0:  b000fffe   imm     -2
1b4:  b9f4deb0   brlid     r15, -8528   // 3064 <__eqdf2>  (WHAT IS THIS??????)
1b8:  10d90000   addk    r6, r25, r0
1bc:  be230244   bneid   r3, 580        // 400
1c0:  10ba0000   addk    r5, r26, r0

 

 

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Observer
Observer
847 Views
Registered: ‎06-23-2013

By the way, in new version of sdk 2018.2, the problem solved and code have been compiled correctly.

View solution in original post

5 Replies
Highlighted
Scholar
Scholar
2,629 Views
Registered: ‎03-22-2016
Can you share the microblaze configuration? Need to be careful with compatibility between the generated core and the compiler flags.
vitorian.com --- We do this for fun. Always give kudos. Accept as solution if your question was answered.
I will not answer to personal messages - use the forums instead.
0 Kudos
Highlighted
Observer
Observer
2,577 Views
Registered: ‎06-23-2013

 

MicroBlaze configurations are

Version 10.0/ Enable barrel shift/ FPU extended/Mul 64bit/Integer divider/ Pattern comparator/ Optimize for performance and no cache.

 

Compiler flags are

mb-g++ -Wall -O2 -g -c -fmessage-length=0  -mlittle-endian -mxl-barrel-shift -mxl-pattern-compare -mno-xl-soft-div -mcpu=v10.0 -mno-xl-soft-mul -mxl-multiply-high -mhard-float -mxl-float-convert -mxl-float-sqrt 

 

0 Kudos
Highlighted
Observer
Observer
2,525 Views
Registered: ‎06-23-2013

For generating the issue, example file and compile procedure is attached.

 

main.cc

#include <math.h>
int main()
{
	volatile double d;
	volatile double dr;

	d = 1.44e-4;
	dr = sqrt(d);
	return 0;
}

 

Compiler commands:

mb-g++ -o main.o main.cc -O2 -c -mlittle-endian -mno-xl-soft-div -mcpu=v10.0 -mno-xl-soft-mul -mxl-multiply-high -mhard-float -mxl-float-convert -mxl-float-sqrt

mb-objdump -dr main.o > main.asm

Disassembly of object file showing the issue:

00000000 <main>:
   0:	b00094cc 	imm	-27444
   4:	3080ab3f 	addik	r4, r0, -21697
   8:	b0003f22 	imm	16162
   c:	30a0dfd6 	addik	r5, r0, -8234
  10:	3021ffc4 	addik	r1, r1, -60
  14:	fb010034 	swi	r24, r1, 52
  18:	f8810024 	swi	r4, r1, 36
  1c:	f8a10028 	swi	r5, r1, 40
  20:	fb210038 	swi	r25, r1, 56
  24:	eb010024 	lwi	r24, r1, 36
  28:	eb210028 	lwi	r25, r1, 40
  2c:	fac1002c 	swi	r22, r1, 44
  30:	fae10030 	swi	r23, r1, 48
  34:	5ad80380 	fsqrt	r22, r24       // Why calling FSQRT instruction for double ????
  38:	12f90000 	addk	r23, r25, r0
  3c:	f9e10000 	swi	r15, r1, 0
  40:	10f60000 	addk	r7, r22, r0
  44:	11170000 	addk	r8, r23, r0
  48:	10b60000 	addk	r5, r22, r0
  4c:	b0000000 	imm	0
			4c: R_MICROBLAZE_64_PCREL	__eqdf2
  50:	b9f40000 	brlid	r15, 0
.......
Tags (1)
0 Kudos
Highlighted
Observer
Observer
848 Views
Registered: ‎06-23-2013

By the way, in new version of sdk 2018.2, the problem solved and code have been compiled correctly.

View solution in original post

Highlighted
Visitor
Visitor
164 Views
Registered: ‎10-07-2018

zhangjinhua_0-1601016672265.png

select basic FPU  can correct it

0 Kudos