NetBSD-Bugs archive

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

lib/49083: redundant codes in m68k s_ceil/s_floor



>Number:         49083
>Category:       lib
>Synopsis:       redundant codes in m68k s_ceil/s_floor
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 07 07:30:00 +0000 2014
>Originator:     Tetsuya Isaki
>Release:        NetBSD-current
>Organization:
>Environment:
NetBSD x68k.XXXXX 6.99.40 NetBSD 6.99.40 (GENERIC) #0: Thu Apr 17 13:40:12 JST 
2014  isaki@XXXXXX:/var/obj/first/x68k/obj/sys/arch/x68k/compile/GENERIC x68k
>Description:
src/lib/libm/arch/m68k/{s_ceil,s_floor}.S seems to have some
redundant codes.

1)
  For s_ceil, I think FPCR should be "Round to +Inf"(0x30) always
  regardless of the sign of the input value, and the condition
  branch is not needed.  For s_floor, FPCR should be
  "Round to -Inf"(0x20) always as in the case of s_ceil.

  If they needs really such a special treatment (for example, some
  old chips have an errata), should write a note in comment.


2)
  I think that "fintd %sp@(4),%fp0" can be replaced by "fintx %fp0"
  in both of s_ceil and s_floor.  %fp0 already contains %sp@(4) here,
  so "fintx %fp0" is faster because it does not access memory.

Please review.

The attached patches pass tests/lib/libm/t_ceil on XM6i (which supports
68881 emulation).  Of course I know that it is not enough test,
but unfortunately I have no runnable real m68k machines now :(
>How-To-Repeat:
see lib/libm/arch/m68k/{s_ceil.S,s_floor.S}
>Fix:
1) redundant condition branch
Index: lib/libm/arch/m68k/s_ceil.S
===================================================================
RCS file: /cvsroot/src/lib/libm/arch/m68k/s_ceil.S,v
retrieving revision 1.7
diff -u -r1.7 s_ceil.S
--- lib/libm/arch/m68k/s_ceil.S 7 Aug 2003 16:44:40 -0000       1.7
+++ lib/libm/arch/m68k/s_ceil.S 7 Aug 2014 06:34:07 -0000
@@ -41,18 +41,12 @@
 RCSID("$NetBSD: s_ceil.S,v 1.7 2003/08/07 16:44:40 agc Exp $")
 
 | ceil(x)
-| -floor(-x), for all real x
 ENTRY(ceil)
        fmovel  %fpcr,%d0       | save old FPCR
        fmoved  %sp@(4),%fp0    | get argument
        fbun    Lret            | if NaN, return NaN
-       fbolt   Lrtz            | <0, round to zero
-       fmovel  #0x30,%fpcr     | >=0, round to inf
-       jra     Ldoit
-Lrtz:
-       fmovel  #0x10,%fpcr
-Ldoit:
-       fintd   %sp@(4),%fp0    | truncate
+       fmovel  #0x30,%fpcr     | round to +inf
+       fintd   %sp@(4),%fp0            | truncate
        fmovel  %d0,%fpcr       | restore old FPCR
 Lret:
 #ifndef __SVR4_ABI__
Index: lib/libm/arch/m68k/s_floor.S
===================================================================
RCS file: /cvsroot/src/lib/libm/arch/m68k/s_floor.S,v
retrieving revision 1.7
diff -u -r1.7 s_floor.S
--- lib/libm/arch/m68k/s_floor.S        7 Aug 2003 16:44:41 -0000       1.7
+++ lib/libm/arch/m68k/s_floor.S        7 Aug 2014 06:34:07 -0000
@@ -46,12 +46,7 @@
        fmovel  %fpcr,%d0       | save old FPCR
        fmoved  %sp@(4),%fp0    | get argument
        fbun    Lret            | if NaN, return NaN
-       fboge   Lrtz            | >=0, round to zero
-       fmovel  #0x20,%fpcr     | <0, round to -inf
-       jra     Ldoit
-Lrtz:
-       fmovel  #0x10,%fpcr
-Ldoit:
+       fmovel  #0x20,%fpcr     | round to -inf
        fintd   %sp@(4),%fp0    | truncate
        fmovel  %d0,%fpcr       | restore old FPCR
 Lret:


2) redundant memory access
--- lib/libm/arch/m68k/s_ceil.S.1       2014-08-07 15:51:06.000000000 +0900
+++ lib/libm/arch/m68k/s_ceil.S 2014-08-07 15:51:37.000000000 +0900
@@ -46,7 +46,7 @@
        fmoved  %sp@(4),%fp0    | get argument
        fbun    Lret            | if NaN, return NaN
        fmovel  #0x30,%fpcr     | round to +inf
-       fintd   %sp@(4),%fp0    | truncate
+       fintx   %fp0            | truncate
        fmovel  %d0,%fpcr       | restore old FPCR
 Lret:
 #ifndef __SVR4_ABI__
--- lib/libm/arch/m68k/s_floor.S.1      2014-08-04 14:50:54.000000000 +0900
+++ lib/libm/arch/m68k/s_floor.S        2014-08-07 15:51:48.000000000 +0900
@@ -47,7 +47,7 @@
        fmoved  %sp@(4),%fp0    | get argument
        fbun    Lret            | if NaN, return NaN
        fmovel  #0x20,%fpcr     | round to -inf
-       fintd   %sp@(4),%fp0    | truncate
+       fintx   %fp0            | truncate
        fmovel  %d0,%fpcr       | restore old FPCR
 Lret:
 #ifndef __SVR4_ABI__



Home | Main Index | Thread Index | Old Index