Tool/software:
I first compiled a library file (xxx. lib), then compiled other C files to obj files, and finally linked the obj files and lib file to generate the final executable product. It is found that the calculation results of calling sqrt and sqrtf in the lib is correct, but the calculation result of sqrt and sqrtf in other C file is abnormal.
(1) The code in the lib library:
The results of querying f_dbg11 and f_dbg12 are as follows, are correct
(2)Upon reviewing the assembly file's corresponding calls and definitions for sqrt and sqrtf in the lib, it was found that there is a prefix of $Tramp$s$$
8a421264 $C$L2:
8a421264 07fd70a9 MVK.S1 0xfffffae1,A15
8a421268 0600a359 || MVK.L1 0,A12
8a42126c 05000041 || MVK.D1 0,A10
8a421270 0580a35b || MVK.L2 0,B11
8a421274 0500002a || MVK.S2 0x0000,B10
8a421278 02ffae28 MVK.S1 0xffffff5c,A5
8a42127c 07a163e9 MVKH.S1 0x42c70000,A15
8a421280 0001b612 || B.S2 $Tramp$S$$sqrt (PC+3504 = 0x8a422030)
8a421284 02a02c68 MVKH.S1 0x40580000,A5
8a421288 0701a0a8 MVK.S1 0x0341,A14
8a42128c 06803128 MVK.S1 0x0062,A13
8a421290 026147a8 MVK.S1 0xffffc28f,A4
8a421294 $C$L3:
8a421294 02147ae9 MVKH.S1 0x28f50000,A4
8a421298 01870162 || ADDKPC.S2 $C$RL12 (PC+28 = 0x8a42129c),B3,0
8a42129c $C$RL12:
8a42129c 01948138 DPSP.L1 A5:A4,A3
8a4212a0 8786 MV.L1 A15,A4
8a4212a2 2c6e NOP 2
8a4212a4 1001b413 CALLP.S2 $Tramp$S$$sqrtf (PC+3488 = 0x8a422040),B3
8a4212a8 0182a27c || STW.D2T1 A3,*+B14[674]
8a4212ac 1001b613 CALLP.S2 $Tramp$S$$delayUsBySimu (PC+3504 = 0x8a422050),B3
8a4212b0 0202a37d || STW.D2T1 A4,*+B14[675]
8a4212b4 02340fd8 || MV.L1 A13,A4
8a4212b8 018baca8 MVK.S1 0x1759,A3
8a4212bc e0200000 .fphead n, l, W, BU, nobr, nosat, 0000001b
8a4212c0 01e8dbe8 MVKH.S1 0xd1b70000,A3
8a4212c4 05286578 ADDU.L1 A3,A10,A11:A10
8a4212c8 062d8078 ADD.L1 A12,A11,A12
8a4212cc 01b189a0 SHRU.S1 A12,0xc,A3
8a4212d0 0209c42a MVK.S2 0x1388,B4
8a4212d4 020c9802 MPY32.M2X B4,A3,B4
8a4212d8 05ac205a ADD.L2 1,B11,B11
8a4212dc 00002000 NOP 2
8a4212e0 00116a7a CMPEQ.L2 B11,B4,B0
8a4212e4 30000811 [!B0] B.S1 $C$L4 (PC+64 = 0x8a421320)
8a4212e8 32029a6e || [!B0] LDW.D2T2 *+B14[666],B4
8a4212ec 3289401e [!B0] LDBU.D2T2 *+B14[2368],B5
8a4212f0 20014810 [ B0] B.S1 $Tramp$S$$lightLed (PC+2624 = 0x8a421d20)
8a4212f4 00002000 NOP 2
8a4212f8 3310205a [!B0] ADD.L2 1,B4,B6
8a4212fc 018a0162 ADDKPC.S2 $C$RL15 (PC+40 = 0x8a421308),B3,0
8a421300 022b180b EXTU.S2 B10,24,24,B4
8a421304 0204a358 || MVK.L1 1,A4
8a422030 $Tramp$S$$sqrt:
8a422030 0fa5e02a MVK.S2 0x4bc0,B31
8a422034 0f8042ea MVKH.S2 0x850000,B31
8a422038 007c0362 B.S2 B31
8a42203c 00008000 NOP 5
8a422040 $Tramp$S$$sqrtf:
8a422040 0fb4d02a MVK.S2 0x69a0,B31
8a422044 0f8042ea MVKH.S2 0x850000,B31
8a422048 007c0362 B.S2 B31
8a42204c 00008000 NOP 5
(3) Code in other C files:
As shown in the figure, the 10 calculated results are as follows, all of which are incorrect
(4)The call and definition of assembly files sqrt and sqrtf in the C file are as follows, without prefix $Tramp $s$$
0084b300 $C$L5:
0084b300 00004000 NOP 3
0084b304 appNewComponent:
0084b304 25f7 STW.D2T1 A11,*B15--[2]
0084b306 75c6 MV.L1X B3,A11
0084b308 1016d413 || CALLP.S2 sqrtf (PC+46752 = 0x008569a0),B3
0084b30c 053c22f5 || STW.D2T1 A10,*+B15[1]
0084b310 020031a8 || MVK.S1 0x0063,A4
0084b314 01900958 INTSP.L1 A4,A3
0084b318 6272 MVK.S1 99,A4
0084b31a 2c6e NOP 2
0084b31c e8400008 .fphead n, l, W, BU, nobr, nosat, 1000010b
0084b320 10131413 CALLP.S2 sqrt (PC+39072 = 0x00854bc0),B3
0084b324 0182707c || STW.D2T1 A3,*+B14[624]
0084b328 01900958 INTSP.L1 A4,A3
0084b32c 02ffae28 MVK.S1 0xffffff5c,A5
0084b330 026147a8 MVK.S1 0xffffc28f,A4
0084b334 02a02c68 MVKH.S1 0x40580000,A5
0084b338 1016d013 CALLP.S2 sqrtf (PC+46720 = 0x008569a0),B3
0084b33c 0182717d || STW.D2T1 A3,*+B14[625]
0084b340 02147ae8 || MVKH.S1 0x28f50000,A4
0084b344 01900958 INTSP.L1 A4,A3
0084b348 02ffae28 MVK.S1 0xffffff5c,A5
0084b34c 026147a8 MVK.S1 0xffffc28f,A4
0084b350 02a02c68 MVKH.S1 0x40580000,A5
0084b354 10131013 CALLP.S2 sqrt (PC+39040 = 0x00854bc0),B3
0084b358 0182727d || STW.D2T1 A3,*+B14[626]
0084b35c 02147ae8 || MVKH.S1 0x28f50000,A4
0084b360 01900958 INTSP.L1 A4,A3
0084b364 8272 MVK.S1 100,A4
0084b366 2c6e NOP 2
0084b368 10130c13 CALLP.S2 sqrt (PC+39008 = 0x00854bc0),B3
0084b36c 0182737c || STW.D2T1 A3,*+B14[627]
0084b370 01900958 INTSP.L1 A4,A3
0084b374 0280a358 MVK.L1 0,A5
0084b378 02a02ce8 MVKH.S1 0x40590000,A5
0084b37c e0400000 .fphead n, l, W, BU, nobr, nosat, 0000010b
0084b380 02000028 MVK.S1 0x0000,A4
0084b384 10130813 CALLP.S2 sqrt (PC+38976 = 0x00854bc0),B3
0084b388 0182747c || STW.D2T1 A3,*+B14[628]
0084b38c 01900958 INTSP.L1 A4,A3
0084b390 8272 MVK.S1 100,A4
0084b392 2c6e NOP 2
0084b394 1016c413 CALLP.S2 sqrtf (PC+46624 = 0x008569a0),B3
0084b398 0182757c || STW.D2T1 A3,*+B14[629]
0084b39c e2000000 .fphead n, l, W, BU, nobr, nosat, 0010000b
0084b3a0 0210195a INTSP.L2X A4,B4
0084b3a4 0280a358 MVK.L1 0,A5
0084b3a8 02a02ce8 MVKH.S1 0x40590000,A5
0084b3ac 0200a358 MVK.L1 0,A4
0084b3b0 1016c013 CALLP.S2 sqrtf (PC+46592 = 0x008569a0),B3
0084b3b4 0202767e || STW.D2T2 B4,*+B14[630]
0084b3b8 02026d6e LDW.D2T2 *+B14[621],B4
0084b3bc 01900958 INTSP.L1 A4,A3
0084b3c0 00004000 NOP 3
0084b3c4 021000a2 SPDP.S2 B4,B5:B4
0084b3c8 0182777c STW.D2T1 A3,*+B14[631]
0084b3cc 00000000 NOP
0084b3d0 1016bc13 CALLP.S2 sqrtf (PC+46560 = 0x008569a0),B3
0084b3d4 02101458 || DADD.L1X 0,B5:B4,A5:A4
0084b3d8 01900958 INTSP.L1 A4,A3
0084b3dc 02826f6c LDW.D2T1 *+B14[623],A5
0084b3e0 02026e6c LDW.D2T1 *+B14[622],A4
0084b3e4 00000000 NOP
0084b3e8 1012fc13 CALLP.S2 sqrt (PC+38880 = 0x00854bc0),B3
0084b3ec 0182787c || STW.D2T1 A3,*+B14[632]
0084b3f0 01900959 INTSP.L1 A4,A3
0084b3f4 0fffc410 || B.S1 runTestdmaDDR (PC-480 = 0x0084b200)
0084b3f8 4e27 MVK.L2 10,B4
0084b3fa 2c6e NOP 2
0084b3fc e8000000 .fphead n, l, W, BU, nobr, nosat, 1000000b
0084b400 05101fd9 MV.L1X B4,A10
0084b404 0182797c || STW.D2T1 A3,*+B14[633]
00854bc0 sqrt:
00854bc0 .text:sqrt:
00854bc0 0726 MVK.L1 0,A6
00854bc2 62d6 || MV.D1 A5,A3
00854bc4 04100861 || DADD.S1 0,A5:A4,A9:A8
00854bc8 07a7 || MVK.L2 0,B7
00854bca 35f7 || STW.D2T2 B11,*B15--[2]
00854bcc 65cf || MV.S2 B3,B11
00854bce 8e82 SHL.S1 A5,0xc,A5
00854bd0 02188ff9 || OR.L1 A4,A6,A4
00854bd4 053c22f6 || STW.D2T2 B10,*+B15[1]
00854bd8 018c3508 EXTU.S1 A3,1,21,A3
00854bdc e1a000b3 .fphead n, l, W, BU, nobr, nosat, 0001101b
00854be0 021299a3 SHRU.S2X A4,0x14,B4
00854be4 01fe00d0 || ADDK.S1 -1023,A3
00854be8 031496e3 OR.S2X B4,A5,B6
00854bec 03020029 || MVK.S1 0x0400,A6
00854bf0 020004fa || ZERO.L2 B5:B4
00854bf4 c7e9 CMPEQ.L2 B6,B7,B0
00854bf6 1bf7 || MVK.D2 0,B7
00854bf8 03119ca3 || SHL.S2X A4,0xc,B6
00854bfc e4000c00 .fphead n, l, W, BU, nobr, nosat, 0100000b
00854c00 01986a79 || CMPEQ.L1 A3,A6,A3
00854c04 02200860 || DADD.S1 0,A9:A8,A5:A4
00854c08 201cca7b [ B0] CMPEQ.L2 B6,B7,B0
00854c0c 00911a60 || CMPGTDP.S1X A9:A8,B5:B4,A1
00854c10 1589 AND.L2X B0,A3,B0
00854c12 2047 MV.L2 B0,B1
00854c14 20001f13 || [ B0] B.S2 $C$L3 (PC+248 = 0x00854cf8)
00854c18 33250ba1 || [!B0] RSQRDP.S1 A9:A8,A7:A6
00854c1c e2000200 .fphead n, l, W, BU, nobr, nosat, 0010000b
00854c20 320004f8 || [!B0] ZERO.L1 A5:A4
00854c24 4080a359 [ B1] MVK.L1 0,A1
00854c28 30110a21 || [!B0] CMPEQDP.S1 A9:A8,A5:A4,A0
00854c2c 300ca35a || [!B0] MVK.L2 3,B0
00854c30 801b6122 [ A1] BNOP.S2 $C$L2 (PC+108 = 0x00854c8c),3
00854c34 8880a359 [ A1] MVK.L1 0,A17
00854c38 821903f1 || [ A1] FMPYDP.M1 A9:A8,A7:A6,A5:A4
00854c3c 88000028 || [ A1] MVK.S1 0x0000,A16
00854c40 88c6bd88 [ A1] SET.S1 A17,21,29,A17
00854c44 c0001911 [ A0] B.S1 $C$L4 (PC+200 = 0x00854d08)
00854c48 050010ab || MVK.S2 0x0021,B10
00854c4c c53c22e7 || [ A0] LDW.D2T2 *+B15[1],B10
00854c50 020004f8 || ZERO.L1 A5:A4
00854c54 d009e011 [!A0] B.S1 __c6xabi_errno_addr (PC+20224 = 0x00859b40)
00854c58 c5bc52e6 || [ A0] LDW.D2T2 *++B15[2],B11
00854c5c c08c6362 [ A0] BNOP.S2 B3,3
00854c60 01810162 ADDKPC.S2 $C$RL0 (PC+4 = 0x00854c64),B3,0
008569a0 sqrtf:
008569a0 .text:sqrtf:
008569a0 6246 MV.L1 A4,A3
008569a2 0712 || MVK.S1 128,A6
008569a4 3577 || STW.D2T2 B10,*B15--[2]
008569a6 4646 MV.L1 A4,A10
008569a8 028c3809 || EXTU.S1 A3,1,24,A5
008569ac 053c35c4 || STDW.D2T1 A11:A10,*B15--[1]
008569b0 02ffc0d1 ADDK.S1 -127,A5
008569b4 020d3ca2 || SHL.S2X A3,0x9,B4
008569b8 02100a5b CMPEQ.L2 0,B4,B4
008569bc e060000b .fphead n, l, W, BU, nobr, nosat, 0000011b
008569c0 0198aa78 || CMPEQ.L1 A5,A6,A3
008569c4 02900fa0 RSQRSP.S1 A4,A5
008569c8 9599 AND.L2X B4,A3,B1
008569ca 0213 || MVK.S2 0,B4
008569cc 01948e00 || MPYSP.M1 A4,A5,A3
008569d0 406a4121 [ B1] BNOP.S1 $C$L1 (PC+212 = 0x00856a94),2
008569d4 5280a35b || [!B1] MVK.L2 0,B5
008569d8 00109ea2 || CMPLTSP.S2X B4,A4,B0
008569dc e0800030 .fphead n, l, W, BU, nobr, nosat, 0000100b
008569e0 52971d8a [!B1] SET.S2 B5,24,29,B5
008569e4 020cbe02 MPYSP.M2X B5,A3,B4
008569e8 75c6 MV.L1X B3,A11
008569ea 2c6e NOP 2
008569ec 0190be00 MPYSP.M1X A5,B4,A3
008569f0 00006000 NOP 4
008569f4 020cb7ba FSUBSP.L2X B5,A3,B4
008569f8 00004000 NOP 3
008569fc e0800000 .fphead n, l, W, BU, nobr, nosat, 0000100b
00856a00 0190be00 MPYSP.M1X A5,B4,A3
00856a04 00004000 NOP 3
00856a08 02946798 FADDSP.L1 A3,A5,A5
00856a0c 00002000 NOP 2
00856a10 01948e00 MPYSP.M1 A4,A5,A3
00856a14 00006000 NOP 4
00856a18 020cbe02 MPYSP.M2X B5,A3,B4
00856a1c 00004000 NOP 3
00856a20 02149e02 MPYSP.M2X B4,A5,B4
00856a24 00004000 NOP 3
00856a28 0210a7ba FSUBSP.L2 B5,B4,B4
00856a2c 00004000 NOP 3
00856a30 0190be00 MPYSP.M1X A5,B4,A3
00856a34 00004000 NOP 3
00856a38 01946798 FADDSP.L1 A3,A5,A3
00856a3c 0280a358 MVK.L1 0,A5
00856a40 00148e20 CMPEQSP.S1 A4,A5,A0
00856a44 030c8e00 MPYSP.M1 A4,A3,A6
00856a48 8866 [ B0] MVK.L1 0,A0
00856a4a 4c6e NOP 3
00856a4c 0218be02 MPYSP.M2X B5,A6,B4
00856a50 00004000 NOP 3
00856a54 020c9e02 MPYSP.M2X B4,A3,B4
00856a58 00004000 NOP 3
00856a5c e0800000 .fphead n, l, W, BU, nobr, nosat, 0000100b
00856a60 0210a7ba FSUBSP.L2 B5,B4,B4
00856a64 00002000 NOP 2
00856a68 20000690 [ B0] B.S1 $C$L1 (PC+52 = 0x00856a94)
00856a6c 0190de00 MPYSP.M1X A6,B4,A3
00856a70 0c6e NOP 1
00856a72 282a [ A0] BNOP.S1 $C$L2 (PC+64 = 0x00856aa0),1
00856a74 05186798 FADDSP.L1 A3,A6,A10
00856a78 050010ab MVK.S2 0x0021,B10
00856a7c e2008000 .fphead n, l, W, BU, br, nosat, 0010000b
00856a80 d0061810 || [!A0] B.S1 __c6xabi_errno_addr (PC+12480 = 0x00859b40)
00856a84 c1ac1fda [ A0] MV.L2X A11,B3
00856a88 05140fd8 MV.L1 A5,A10
00856a8c 01844162 ADDKPC.S2 $C$RL0 (PC+16 = 0x00856a90),B3,2
(5)Search for the entire map file. The content related to sqrt and sqrtf are as follows:
00854bc0 00000160 rts6600_elf.lib : sqrt.obj (.text:sqrt)
00854d20 00000140 : sscanf.obj (.text:_chkmbc)
00854e60 00000140 : _printfi.obj (.text:_pproc_fflags)
00854fa0 00000140 : atoll.obj (.text:atoll)
008550e0 00000140 : lowlev.obj (.text:getdevice)
00855220 00000140 : logf.obj (.text:logf)
008569a0 00000120 rts6600_elf.lib : sqrtf.obj (.text:sqrtf)
00856ac0 00000100 : trgdrv.obj (.text:HOSTlseek)
8a422030 00000010 : sqrt.obj ($Tramp$S$$sqrt)
8a422040 00000010 : sqrtf.obj ($Tramp$S$$sqrtf)
$.text:sqrt:rts6600_elf.lib<sqrt.obj>$0x0 $Tramp$S$$sqrt
00854bc0 8a422030 8a421280 NR1193.lib : main.obj (.init_code)
8a4213c4 : main.obj (.init_code)
$.text:sqrtf:rts6600_elf.lib<sqrtf.obj>$0x0 $Tramp$S$$sqrtf
008569a0 8a422040 8a4212a4 NR1193.lib : main.obj (.init_code)
00854bc0 sqrt
008569a0 sqrtf
Why is the results of calling sqrt and sqrtf in the lib library correct? The result of calling sqrt and sqrtf from therC files are incorrect?