Superfluous instructions in crufty old releng/12.0/lib/msun/i387/s_remquo.S, releng/12.0/lib/msun/amd64/s_remquo.S, ...

Stefan Kanthak stefan.kanthak at nexgo.de
Fri Sep 6 10:54:45 UTC 2019


Hi,

although I doubt that this FPU code might still be used,
here's a patch to shave 2 superfluous instructions from
http://sources.freebsd.org/releng/12.0/lib/msun/i387/s_remquo.S
http://sources.freebsd.org/releng/12.0/lib/msun/i387/s_remquof.S
http://sources.freebsd.org/releng/12.0/lib/msun/i387/s_remquol.S
http://sources.freebsd.org/releng/12.0/lib/msun/amd64/s_remquo.S
http://sources.freebsd.org/releng/12.0/lib/msun/amd64/s_remquof.S
http://sources.freebsd.org/releng/12.0/lib/msun/amd64/s_remquol.S

regards
Stefan Kanthak

--- -/releng/12.0/lib/msun/i387/s_remquo.S
+++ +/releng/12.0/lib/msun/i387/s_remquo.S
@@ -51,8 +51,6 @@
 /* Negate the quotient bits if x*y<0.  Avoid using an unpredictable branch. */
         movl    16(%esp),%ecx
         xorl    8(%esp),%ecx
-        sarl    $16,%ecx
-        sarl    $16,%ecx
+        sarl    $31,%ecx
         xorl    %ecx,%eax
-        andl    $1,%ecx
-        addl    %ecx,%eax
+        subl    %ecx,%eax

--- -/releng/12.0/lib/msun/i387/s_remquof.S
+++ +/releng/12.0/lib/msun/i387/s_remquof.S
@@ -51,8 +51,6 @@
 /* Negate the quotient bits if x*y<0.  Avoid using an unpredictable branch. */
         movl    8(%esp),%ecx
         xorl    4(%esp),%ecx
-        sarl    $16,%ecx
-        sarl    $16,%ecx
+        sarl    $31,%ecx
         xorl    %ecx,%eax
-        andl    $1,%ecx
-        addl    %ecx,%eax
+        subl    %ecx,%eax

--- -/releng/12.0/lib/msun/i387/s_remquol.S
+++ +/releng/12.0/lib/msun/i387/s_remquol.S
@@ -51,9 +51,7 @@
 /* Negate the quotient bits if x*y<0.  Avoid using an unpredictable branch. */
         movl    24(%esp),%ecx
         xorl    12(%esp),%ecx
         movsx   %cx,%ecx
         sarl    $16,%ecx
-        sarl    $16,%ecx
         xorl    %ecx,%eax
-        andl    $1,%ecx
-        addl    %ecx,%eax
+        subl    %ecx,%eax

--- -/releng/12.0/lib/msun/amd64/s_remquo.S
--- +/releng/12.0/lib/msun/amd64/s_remquo.S
@@ -53,8 +53,6 @@
 /* Negate the quotient bits if x*y<0.  Avoid using an unpredictable branch. */
         movl    -12(%rsp),%ecx
         xorl    -4(%rsp),%ecx
-        sarl    $16,%ecx
-        sarl    $16,%ecx
+        sarl    $31,%ecx
         xorl    %ecx,%eax
-        andl    $1,%ecx
-        addl    %ecx,%eax
+        subl    %ecx,%eax

--- -/releng/12.0/lib/msun/amd64/s_remquof.S
--- +/releng/12.0/lib/msun/amd64/s_remquof.S
@@ -53,8 +53,6 @@
 /* Negate the quotient bits if x*y<0.  Avoid using an unpredictable branch. */
         movl    -8(%rsp),%ecx
         xorl    -4(%rsp),%ecx
-        sarl    $16,%ecx
-        sarl    $16,%ecx
+        sarl    $31,%ecx
         xorl    %ecx,%eax
-        andl    $1,%ecx
-        addl    %ecx,%eax
+        subl    %ecx,%eax

--- -/releng/12.0/lib/msun/amd64/s_remquol.S
--- +/releng/12.0/lib/msun/amd64/s_remquol.S
@@ -51,9 +51,6 @@
 /* Negate the quotient bits if x*y<0.  Avoid using an unpredictable branch. */
         movl    32(%rsp),%ecx
         xorl    16(%rsp),%ecx
         movsx   %cx,%ecx
         sarl    $16,%ecx
-        sarl    $16,%ecx
         xorl    %ecx,%eax
-        andl    $1,%ecx
-        addl    %ecx,%eax
+        subl    %ecx,%eax


More information about the freebsd-numerics mailing list