• R/O
  • HTTP
  • SSH
  • HTTPS

mingw-org-wsl: 提交

The MinGW.OSDN Windows System Libraries. Formerly designated as "MinGW.org Windows System Libraries", this encapsulates the "mingwrt" C runtime library extensions, and the "w32api" 32-bit MS-Windows API libraries.

Please note that this project no longer owns the "MinGW.org" domain name; any software which may be distributed from that domain is NOT supported by this project.


Commit MetaInfo

修訂b3f510ab65f64fca31e823bbc7fd69eeca7cf1d9 (tree)
時間2021-02-26 01:21:59
作者Keith Marshall <keith@user...>
CommiterKeith Marshall

Log Message

Consolidate fmod() and remainder() source code.

Change Summary

差異

--- a/mingwrt/ChangeLog
+++ b/mingwrt/ChangeLog
@@ -1,3 +1,19 @@
1+2021-02-25 Keith Marshall <keith@users.osdn.me>
2+
3+ Consolidate fmod() and remainder() source code.
4+
5+ * mingwex/math/fmod_generic.sx.in: New file; it replaces...
6+ * mingwex/math/remainder.s mingwex/math/remainderf.s: ...these...
7+ * mingwex/math/remainderl.s mingwex/math/fmodf.c: ...and these...
8+ * mingwex/math/fmodl.c: ...and also this; delete them.
9+
10+ * Makefile.in (fmod_generic.sx, remainder_generic.sx): Add rule to
11+ generate them.
12+
13+2021-02-24 Keith Marshall <keith@users.osdn.me>
14+
15+ Correct remquo() quotient computation; cf. MinGW-Bug #41597
16+
117 2021-02-24 Keith Marshall <keith@users.osdn.me>
218
319 Correct remquo() quotient computation; cf. MinGW-Bug #41597
--- a/mingwrt/Makefile.in
+++ b/mingwrt/Makefile.in
@@ -514,8 +514,21 @@ $(addsuffix .$(OBJEXT), % %f %l): %_generic.sx
514514 $(COMPILE.sx) -D_$*f_source -o $*f.$(OBJEXT) $<
515515 $(COMPILE.sx) -D_$*l_source -o $*l.$(OBJEXT) $<
516516
517+# Assembly language sources for all fmod() and remainder() object
518+# code variants originate from one fmod_generic.sx.in template.
519+#
520+vpath fmod_generic.sx.in ${srcdir}/mingwex/math
521+fmod_generic.sx remainder_generic.sx: %_generic.sx: fmod_generic.sx.in
522+ sed '$($*_generic_subst)' $< > $@
523+
524+# fmod() variants, and remainder() variants, require differing
525+# template substitutions.
526+#
527+fmod_generic_subst = s:%name%:$*:;s:%fprem%:fprem:
528+remainder_generic_subst = s:%name%:$*:;s:%fprem%:fprem1:
529+
517530 # Several generically implemented functions also require separate
518-# assembly of their generic back-end support routines.
531+# assembly of associated generic back-end support routines.
519532 #
520533 x87%.$(OBJEXT): %_generic.sx
521534 $(COMPILE.sx) -o $@ $<
--- /dev/null
+++ b/mingwrt/mingwex/math/fmod_generic.sx.in
@@ -0,0 +1,119 @@
1+/*
2+ * %name%_generic.sx
3+ *
4+ * Generic implementation for each of the ISO-C99 fmod(), fmodl(),
5+ * fmodf(), remainder(), remainderl(), and remainderf() functions.
6+ *
7+ * $Id$
8+ *
9+ * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
10+ * Copyright (C) 2021, MinGW.org Project
11+ *
12+ * Adapted from original code written by J. T. Conklin <jtc@netbsd.org>.
13+ *
14+ *
15+ * Permission is hereby granted, free of charge, to any person obtaining a
16+ * copy of this software and associated documentation files (the "Software"),
17+ * to deal in the Software without restriction, including without limitation
18+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
19+ * and/or sell copies of the Software, and to permit persons to whom the
20+ * Software is furnished to do so, subject to the following conditions:
21+ *
22+ * The above copyright notice and this permission notice (including the next
23+ * paragraph) shall be included in all copies or substantial portions of the
24+ * Software.
25+ *
26+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
31+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32+ * DEALINGS IN THE SOFTWARE.
33+ *
34+ */
35+.intel_syntax noprefix
36+
37+.text
38+.align 4
39+
40+#if defined _%name%_source
41+/* Preamble to load the FPU registers from the arguments passed in
42+ * any call to either of the functions:
43+ *
44+ * double fmod (double, double);
45+ * double remainder (double, double);
46+ */
47+.globl _%name%
48+.def _%name%; .scl 2; .type 32; .endef
49+.def ___x87cvt; .scl 2; .type 32; .endef
50+
51+_%name%:
52+ fld QWORD ptr 12[esp] /* FPU TOS = y */
53+ fld QWORD ptr 4[esp] /* FPU TOS = x, y */
54+
55+#elif defined _%name%f_source
56+/* Preamble to load the FPU registers from the arguments passed in
57+ * any call to either of the functions:
58+ *
59+ * float fmodf (float, float);
60+ * float remainderf (float, float);
61+ */
62+.globl _%name%f
63+.def _%name%f; .scl 2; .type 32; .endef
64+.def ___x87cvtf; .scl 2; .type 32; .endef
65+
66+_%name%f:
67+ fld DWORD ptr 8[esp] /* FPU TOS = y */
68+ fld DWORD ptr 4[esp] /* FPU TOS = x, y */
69+
70+#else /* _%name%l_source assumed */
71+#ifndef _%name%l_source
72+#define _%name%l_source
73+#endif
74+/* Preamble to load the FPU registers from the arguments passed in
75+ * any call to either of the functions:
76+ *
77+ * long double fmodl (long double, long double);
78+ * long double remainderl (long double, long double);
79+ */
80+.globl _%name%l
81+.def _%name%l; .scl 2; .type 32; .endef
82+
83+_%name%l:
84+ fld TBYTE ptr 16[esp] /* FPU TOS = y */
85+ fld TBYTE ptr 4[esp] /* FPU TOS = x, y */
86+
87+#endif
88+/* Fall through to compute the remainder; this is an iterative procedure...
89+ */
90+10: %fprem% /* compute interim result */
91+ fstsw ax /* copy resultant FPU status... */
92+ sahf /* ...into CPU flags, for testing... */
93+ jp 10b /* ...until completion */
94+
95+/* We now have the computed remainder (r), and the original value of y,
96+ * in FPU registers st(0), and st(1) respectively; we no longer have any
97+ * use for y, so discard it...
98+ */
99+ fstp st(1) /* ...saving just 'r' for return */
100+
101+#if defined _%name%l_source
102+/* For the %name%l() function, there is no more to do...
103+ */
104+ ret /* ...but return the REAL10 result... */
105+
106+#elif defined _%name%f_source
107+/* ...whereas for %name%f(), we must...
108+ */
109+ jmp ___x87cvtf /* ...convert to REAL4... */
110+
111+#else /* _%name%_source */
112+/* ...while for %name%(), we must...
113+ */
114+ jmp ___x87cvt /* ...convert to REAL8 */
115+
116+#endif
117+
118+/* vim: set autoindent filetype=asm formatoptions=croqlj: */
119+/* $RCSfile$: end of file */
--- a/mingwrt/mingwex/math/fmodf.c
+++ /dev/null
@@ -1,23 +0,0 @@
1-/*
2- * Written by J.T. Conklin <jtc@netbsd.org>.
3- * Public domain.
4- *
5- * Adapted for float type by Danny Smith
6- * <dannysmith@users.sourceforge.net>.
7- */
8-
9-#include <math.h>
10-
11-float
12-fmodf (float x, float y)
13-{
14- float res;
15-
16- asm ("1:\tfprem\n\t"
17- "fstsw %%ax\n\t"
18- "sahf\n\t"
19- "jp 1b\n\t"
20- "fstp %%st(1)"
21- : "=t" (res) : "0" (x), "u" (y) : "ax", "st(1)");
22- return res;
23-}
--- a/mingwrt/mingwex/math/fmodl.c
+++ /dev/null
@@ -1,22 +0,0 @@
1-/*
2- * Written by J.T. Conklin <jtc@netbsd.org>.
3- * Public domain.
4- *
5- * Adapted for `long double' by Ulrich Drepper <drepper@cygnus.com>.
6- */
7-
8-#include <math.h>
9-
10-long double
11-fmodl (long double x, long double y)
12-{
13- long double res;
14-
15- asm ("1:\tfprem\n\t"
16- "fstsw %%ax\n\t"
17- "sahf\n\t"
18- "jp 1b\n\t"
19- "fstp %%st(1)"
20- : "=t" (res) : "0" (x), "u" (y) : "ax", "st(1)");
21- return res;
22-}
--- a/mingwrt/mingwex/math/remainder.s
+++ /dev/null
@@ -1,19 +0,0 @@
1-/*
2- * Written by J.T. Conklin <jtc@netbsd.org>.
3- * Public domain.
4- */
5-
6- .file "remainder.s"
7- .text
8- .align 4
9-.globl _remainder
10- .def _remainder; .scl 2; .type 32; .endef
11-_remainder:
12- fldl 12(%esp)
13- fldl 4(%esp)
14-1: fprem1
15- fstsw %ax
16- sahf
17- jp 1b
18- fstp %st(1)
19- ret
--- a/mingwrt/mingwex/math/remainderf.s
+++ /dev/null
@@ -1,19 +0,0 @@
1-/*
2- * Written by J.T. Conklin <jtc@netbsd.org>.
3- * Public domain.
4- */
5-
6- .file "remainderf.s"
7- .text
8- .align 4
9-.globl _remainder
10- .def _remainderf; .scl 2; .type 32; .endef
11-_remainderf:
12- flds 8(%esp)
13- flds 4(%esp)
14-1: fprem1
15- fstsw %ax
16- sahf
17- jp 1b
18- fstp %st(1)
19- ret
--- a/mingwrt/mingwex/math/remainderl.s
+++ /dev/null
@@ -1,22 +0,0 @@
1-/*
2- * Written by J.T. Conklin <jtc@netbsd.org>.
3- * Public domain.
4- * Adapted for `long double' by Ulrich Drepper <drepper@cygnus.com>.
5- * Removed header file dependency for use in libmingwex.a by
6- * Danny Smith <dannysmith@users.sourceforge.net>
7- */
8-
9- .file "remainderl.s"
10- .text
11- .align 4
12-.globl _remainderl
13- .def _remainderl; .scl 2; .type 32; .endef
14-_remainderl:
15- fldt 16(%esp)
16- fldt 4(%esp)
17-1: fprem1
18- fstsw %ax
19- sahf
20- jp 1b
21- fstp %st(1)
22- ret
Show on old repository browser