NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

toolchain/45310: some mixed int/float computations are wrong on mips64



>Number:         45310
>Category:       toolchain
>Synopsis:       mixed int/float computations are wrong on mips64
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Aug 29 21:55:00 +0000 2011
>Originator:     Manuel Bouyer
>Release:        NetBSD 5.99.55
>Organization:
>Environment:
System: NetBSD cuba.soc.lip6.fr 5.99.55 NetBSD 5.99.55 (LOONGSON) #52: Mon Aug 
29 21:38:41 CEST 2011 
bouyer@roll:/dsk/l1/misc/bouyer/tmp/evbmips64el/obj/dsk/l1/misc/bouyer/current/src/sys/arch/evbmips/compile/LOONGSON
 evbmips
Architecture: mipsel
Machine: evbmips-mips64el
>Description:
        I first noticed that ftp(1) and progress(1) reported speeds of 0b/s.
        I tracked it down to ptransfer() in ftp and finally ended up with this
        test program:

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>

main()
{
        float a;
        off_t b;

        a = 0.544355;
        b = 4866695;

        printf("a %f b %d\n",a, (int)b);
        b /= a;
        printf("now b %d\n", (int)b);
}
        On i386 this gives:
a 0.544355 b 4866695
now b 8940297
        on mips64el:
a 0.544355 b 4866695
now b 0

        note that b has to be off_t for this to fail; with a int
        everything works as expected.
        Below is the assembly produced by gcc -S

        .section .mdebug.abiN32
        .previous
        .gnu_attribute 4, 3
        .abicalls
        .section        .debug_abbrev,"",@progbits
$Ldebug_abbrev0:
        .section        .debug_info,"",@progbits
$Ldebug_info0:
        .section        .debug_line,"",@progbits
$Ldebug_line0:
        .text
$Ltext0:
        .rdata
        .align  3
$LC1:
        .ascii  "a %f b %d\012\000"
        .globl  __extendsfdf2
        .globl  __floatdisf
        .globl  __divsf3
        .globl  __fixsfdi
        .align  3
$LC2:
        .ascii  "now b %d\012\000"
        .text
        .align  2
        .globl  main
$LFB13 = .
        .file 1 "test.c"
        .loc 1 6 0
        .set    nomips16
        .ent    main
        .type   main, @function
main:
        .frame  $fp,48,$31              # vars= 16, regs= 4/0, args= 0, gp= 0
        .mask   0xd0010000,-8
        .fmask  0x00000000,0
        .set    noreorder
        .set    nomacro
        addiu   $sp,$sp,-48
$LCFI0:
        sd      $31,40($sp)
$LCFI1:
        sd      $fp,32($sp)
$LCFI2:
        sd      $28,24($sp)
$LCFI3:
        sd      $16,16($sp)
$LCFI4:
        move    $fp,$sp
$LCFI5:
        lui     $28,%hi(%neg(%gp_rel(main)))
        addu    $28,$28,$25
        addiu   $28,$28,%lo(%neg(%gp_rel(main)))
        .loc 1 10 0
        lw      $2,%got_page($LC0)($28)
        lw      $2,%got_ofst($LC0)($2)
        sw      $2,0($fp)
        .loc 1 11 0
        li      $2,4849664                      # 0x4a0000
        ori     $2,$2,0x4287
        sd      $2,8($fp)
        .loc 1 13 0
        lw      $2,%got_page($LC1)($28)
        addiu   $16,$2,%got_ofst($LC1)
        lw      $2,%call16(__extendsfdf2)($28)
        lw      $4,0($fp)
        move    $25,$2
        jalr    $25
        nop

        move    $3,$2
        ld      $2,8($fp)
        sll     $2,$2,0
        move    $4,$16
        move    $5,$3
        move    $6,$2
        lw      $2,%call16(printf)($28)
        move    $25,$2
        jalr    $25
        nop

        .loc 1 14 0
        lw      $2,%call16(__floatdisf)($28)
        ld      $4,8($fp)
        move    $25,$2
        jalr    $25
        nop

        move    $3,$2
        lw      $2,%call16(__divsf3)($28)
        move    $4,$3
        lw      $5,0($fp)
        move    $25,$2
        jalr    $25
        nop

        move    $3,$2
        lw      $2,%call16(__fixsfdi)($28)
        move    $4,$3
        move    $25,$2
        jalr    $25
        nop

        sd      $2,8($fp)
        .loc 1 15 0
        lw      $2,%got_page($LC2)($28)
        addiu   $3,$2,%got_ofst($LC2)
        ld      $2,8($fp)
        sll     $2,$2,0
        move    $4,$3
        move    $5,$2
        lw      $2,%call16(printf)($28)
        move    $25,$2
        jalr    $25
        nop

        .loc 1 16 0
        move    $sp,$fp
        ld      $31,40($sp)
        ld      $fp,32($sp)
        ld      $28,24($sp)
        ld      $16,16($sp)
        addiu   $sp,$sp,48
        j       $31
        nop

>How-To-Repeat:
        run progress(1) or ftp(1) on a mip64el, notice speed is not properly
        printed, debug
>Fix:
        I guess the issue is in one of __floatdisf, __divsf3 or __fixsfdi



Home | Main Index | Thread Index | Old Index