NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: port-mips/57680: printf("%.1f") shows wrong resultsonR3000mipseb
The following reply was made to PR port-mips/57680; it has been noted by GNATS.
From: Izumi Tsutsui <tsutsui%ceres.dti.ne.jp@localhost>
To: riastradh%NetBSD.org@localhost
Cc: gnats-bugs%netbsd.org@localhost, tsutsui%ceres.dti.ne.jp@localhost
Subject: Re: port-mips/57680: printf("%.1f") shows wrong resultsonR3000mipseb
Date: Tue, 7 Nov 2023 02:47:16 +0900
> > As I wrote an other mail, <mips/fenv.h> always has fegetround()
> > (and other fe*() functions) as static inline functions:
> > https://github.com/NetBSD/src/blob/trunk/sys/arch/mips/include/fenv.h
> > so I'm afraid __weak_reference(fegetround) will never referred on mips.
> > (I'm not sure how __weak_reference() works in such static inline cases)
>
> I was assuming the weak reference wouldn't pick up the static inline,
> but I guess I was wrong.
It looks it does.
With DBG="-save-temps -O2 -fno-inline" dtoa.pico emits the following asm:
---
.file 1 "dtoa.c"
.section .mdebug.abi32
.previous
.nan legacy
.module fp=32
.module nooddspreg
.abicalls
.text
.align 2
$LFB14 = .
.cfi_startproc
.set nomips16
.set nomicromips
.ent __rfs
.type __rfs, @function
__rfs:
.frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, gp= 0
.mask 0x00000000,0
.fmask 0x00000000,0
#APP
# 78 "/s/netbsd-9/src/obj.newsmips/destdir.newsmips/usr/include/mips/fenv.h" 1
cfc1 $2,$31
# 0 "" 2
#NO_APP
jr $31
.end __rfs
.cfi_endproc
$LFE14:
.size __rfs, .-__rfs
.align 2
$LFB21 = .
.cfi_startproc
.set nomips16
.set nomicromips
.ent fegetround
.type fegetround, @function
fegetround:
.frame $sp,32,$31 # vars= 0, regs= 1/0, args= 16, gp= 8
.mask 0x80000000,-4
.fmask 0x00000000,0
.set noreorder
.cpload $25
.set nomacro
lw $25,%got(__rfs)($28)
addiu $sp,$sp,-32
.cfi_def_cfa_offset 32
addiu $25,$25,%lo(__rfs)
sw $31,28($sp)
.cprestore 16
.cfi_offset 31, -4
.reloc 1f,R_MIPS_JALR,__rfs
1: jalr $25
nop
lw $31,28($sp)
andi $2,$2,0x3
jr $31
addiu $sp,$sp,32
.cfi_def_cfa_offset 0
.cfi_restore 31
.set macro
.set reorder
.end fegetround
.cfi_endproc
$LFE21:
.size fegetround, .-fegetround
__libc_fegetround_ref = fegetround
.section .rodata.str1.4,"aMS",@progbits,1
.align 2
$LC0:
.ascii "Infinity\000"
.align 2
$LC1:
.ascii "NaN\000"
.align 2
$LC2:
.ascii "0\000"
.text
.align 2
.globl __dtoa
$LFB45 = .
.cfi_startproc
.set nomips16
.set nomicromips
.ent __dtoa
.type __dtoa, @function
__dtoa:
.frame $sp,120,$31 # vars= 56, regs= 10/0, args= 16, gp= 8
.mask 0xc0ff0000,-4
.fmask 0x00000000,0
.set noreorder
.cpload $25
.set nomacro
lw $25,%got(__libc_fegetround_ref)($28)
addiu $sp,$sp,-120
.cfi_def_cfa_offset 120
addiu $25,$25,%lo(__libc_fegetround_ref)
.cprestore 16
sw $18,88($sp)
sw $31,116($sp)
sw $fp,112($sp)
sw $23,108($sp)
sw $22,104($sp)
sw $21,100($sp)
sw $20,96($sp)
sw $19,92($sp)
sw $17,84($sp)
sw $16,80($sp)
swc1 $f12,124($sp)
swc1 $f13,120($sp)
sw $7,132($sp)
.cfi_offset 18, -32
.cfi_offset 31, -4
.cfi_offset 30, -8
.cfi_offset 23, -12
.cfi_offset 22, -16
.cfi_offset 21, -20
.cfi_offset 20, -24
.cfi_offset 19, -28
.cfi_offset 17, -36
.cfi_offset 16, -40
lw $3,140($sp)
.reloc 1f,R_MIPS_JALR,__libc_fegetround_ref
1: jalr $25
move $18,$6
addiu $2,$2,-1
sltu $4,$2,3
lw $28,16($sp)
beq $4,$0,$L153
li $20,1 # 0x1
---
i.e. fegetround() (via weak_reference) and __rfs() are linked as functions.
With DBG="-save-temps -O2" (i.e. default) dtoa.pico emits:
---
.file 1 "dtoa.c"
.section .mdebug.abi32
.previous
.nan legacy
.module fp=32
.module nooddspreg
.abicalls
.text
.section .rodata.str1.4,"aMS",@progbits,1
.align 2
$LC0:
.ascii "Infinity\000"
.align 2
$LC1:
.ascii "NaN\000"
.align 2
$LC2:
.ascii "0\000"
.text
.align 2
.globl __dtoa
$LFB45 = .
.cfi_startproc
.set nomips16
.set nomicromips
.ent __dtoa
.type __dtoa, @function
__dtoa:
.frame $sp,120,$31 # vars= 56, regs= 10/0, args= 16, gp= 8
.mask 0xc0ff0000,-4
.fmask 0x00000000,0
.set noreorder
.cpload $25
.set reorder
addiu $sp,$sp,-120
.cfi_def_cfa_offset 120
.cprestore 16
sw $18,88($sp)
sw $31,116($sp)
sw $fp,112($sp)
sw $23,108($sp)
sw $22,104($sp)
sw $21,100($sp)
sw $20,96($sp)
sw $19,92($sp)
sw $17,84($sp)
sw $16,80($sp)
.cfi_offset 18, -32
.cfi_offset 31, -4
.cfi_offset 30, -8
.cfi_offset 23, -12
.cfi_offset 22, -16
.cfi_offset 21, -20
.cfi_offset 20, -24
.cfi_offset 19, -28
.cfi_offset 17, -36
.cfi_offset 16, -40
swc1 $f12,124($sp)
swc1 $f13,120($sp)
move $18,$6
sw $7,132($sp)
lw $3,140($sp)
#APP
# 78 "/s/netbsd-9/src/obj.newsmips/destdir.newsmips/usr/include/mips/fenv.h" 1
cfc1 $2,$31
# 0 "" 2
#NO_APP
andi $2,$2,0x3
^^^^^^^^^^^^^^^^^ this may be "__fpsr & _ROUND_MASK" in fegetround()?
addiu $2,$2,-1
sltu $4,$2,3
.set noreorder
.set nomacro
beq $4,$0,$L149
li $20,1 # 0x1
.set macro
.set reorder
---
BTW, weird enough, gcc with DBG="-save-temps -O2" complains about
-Wimplicit-fallthrough:
---
/s/netbsd-9/src/lib/libc/gdtoa/dtoa.c: In function '__dtoa':
/s/netbsd-9/src/lib/libc/gdtoa/dtoa.c:316:14: warning: this statement may fall through [-Wimplicit-fallthrough=]
leftright = 0;
~~~~~~~~~~^~~
/s/netbsd-9/src/lib/libc/gdtoa/dtoa.c:318:3: note: here
case 4:
^~~~
/s/netbsd-9/src/lib/libc/gdtoa/dtoa.c:324:14: warning: this statement may fall through [-Wimplicit-fallthrough=]
leftright = 0;
~~~~~~~~~~^~~
/s/netbsd-9/src/lib/libc/gdtoa/dtoa.c:326:3: note: here
case 5:
^~~~
---
while not if -save-temps is not specified..
> Try the attached test2 instead, with and without -lm as with test1?
> test2 doesn't include fenv.h, so it shouldn't get the static inline
> fegetround from there -- it should only get the library symbols.
Here it is:
---
news3470-% rm -f test2 && make test2 && ./test2
cc -O2 -o test2 test2.c
FLT_ROUNDS=1
FE_TONEAREST=0
news3470-% rm -f test2 && make test2 LDLIBS=-lm && ./test2
cc -O2 -o test2 test2.c -lm
FLT_ROUNDS=1
fegetround()=0
news3470-%
---
(seems expected)
> Can you also share the output of these commands?
> nm -gD /lib/libc.so | grep f.getround
(On NWS-5000, which certainly has 9.3 release libraries)
---
news5000-% nm -gD /lib/libc.so | grep f.getround
0005e970 T _fpgetround
0005e970 W fpgetround
---
> nm -gD /lib/libm.so | grep f.getround
---
news5000-% nm -gD /lib/libm.so | grep f.getround
0001d644 T _fegetround
0001d644 W fegetround
---
> objdump -dr /lib/libc.so | grep -A15 'f.getround>:'
---
news5000-% objdump -dr /lib/libc.so | grep -A15 'f.getround>:'
0005e970 <_fpgetround>:
5e970: 4442f800 cfc1 v0,$31
5e974: 03e00008 jr ra
5e978: 30420003 andi v0,v0,0x3
5e97c: 00000000 nop
0005e980 <_fpgetmask>:
5e980: 4442f800 cfc1 v0,$31
5e984: 00000000 nop
5e988: 000211c2 srl v0,v0,0x7
5e98c: 03e00008 jr ra
5e990: 3042001f andi v0,v0,0x1f
...
0005e9a0 <__signbitd>:
5e9a0: e7ad0000 swc1 $f13,0(sp)
---
> objdump -dr /lib/libm.so | grep -A15 'f.getround>:'
---
news5000-% objdump -dr /lib/libm.so | grep -A15 'f.getround>:'
0001d644 <_fegetround>:
1d644: 4442f800 cfc1 v0,$31
1d648: 03e00008 jr ra
1d64c: 30420003 andi v0,v0,0x3
0001d650 <_fesetround>:
1d650: 2403fffc li v1,-4
1d654: 00831024 and v0,a0,v1
1d658: 14400008 bnez v0,1d67c <_fesetround+0x2c>
1d65c: 00000000 nop
1d660: 4445f800 cfc1 a1,$31
1d664: 00000000 nop
1d668: 00a31824 and v1,a1,v1
1d66c: 00832025 or a0,a0,v1
1d670: 44c4f800 ctc1 a0,$31
1d674: 03e00008 jr ra
---
> objdump -dr $OBJDIR/lib/libc/dtoa.o | grep -A40 'dtoa>:'
(on cross-build i386 host)
---
mirage-% /s/netbsd-9/src/obj.newsmips/tooldir.NetBSD-10.0_BETA-i386/bin/mipseb--netbsd-objdump -d obj.newsmips/dtoa.o | grep -A40 'dtoa>:'
00000000 <__dtoa>:
0: 3c1c0000 lui gp,0x0
0: R_MIPS_HI16 _gp_disp
4: 279c0000 addiu gp,gp,0
4: R_MIPS_LO16 _gp_disp
8: 0399e021 addu gp,gp,t9
c: 27bdff88 addiu sp,sp,-120
10: afbc0010 sw gp,16(sp)
14: afb20058 sw s2,88(sp)
18: afbf0074 sw ra,116(sp)
1c: afbe0070 sw s8,112(sp)
20: afb7006c sw s7,108(sp)
24: afb60068 sw s6,104(sp)
28: afb50064 sw s5,100(sp)
2c: afb40060 sw s4,96(sp)
30: afb3005c sw s3,92(sp)
34: afb10054 sw s1,84(sp)
38: afb00050 sw s0,80(sp)
3c: e7ac007c swc1 $f12,124(sp)
40: e7ad0078 swc1 $f13,120(sp)
44: 00c09025 move s2,a2
48: afa70084 sw a3,132(sp)
4c: 8fa3008c lw v1,140(sp)
50: 4442f800 cfc1 v0,$31
54: 00000000 nop
58: 30420003 andi v0,v0,0x3
5c: 2442ffff addiu v0,v0,-1
60: 2c440003 sltiu a0,v0,3
64: 108000cb beqz a0,394 <__dtoa+0x394>
68: 24140001 li s4,1
6c: 8f840000 lw a0,0(gp)
6c: R_MIPS_GOT16 .rodata
70: 00021080 sll v0,v0,0x2
74: 24840000 addiu a0,a0,0
74: R_MIPS_LO16 .rodata
78: 00441021 addu v0,v0,a0
7c: 8fa5007c lw a1,124(sp)
80: 8fa40078 lw a0,120(sp)
84: 8fb00078 lw s0,120(sp)
88: 8c540000 lw s4,0(v0)
8c: afa50024 sw a1,36(sp)
---
Izumi Tsutsui
Home |
Main Index |
Thread Index |
Old Index