From: Keith Marshall Date: Thu, 25 Feb 2021 16:21:59 +0000 (+0000) Subject: Consolidate fmod() and remainder() source code. X-Git-Tag: wsl-5.4.2-release~1 X-Git-Url: http://git.osdn.net/view?p=mingw%2Fmingw-org-wsl.git;a=commitdiff_plain;h=b3f510ab65f64fca31e823bbc7fd69eeca7cf1d9 Consolidate fmod() and remainder() source code. --- diff --git a/mingwrt/ChangeLog b/mingwrt/ChangeLog index 5d6cc9d..839028f 100644 --- a/mingwrt/ChangeLog +++ b/mingwrt/ChangeLog @@ -1,3 +1,19 @@ +2021-02-25 Keith Marshall + + Consolidate fmod() and remainder() source code. + + * mingwex/math/fmod_generic.sx.in: New file; it replaces... + * mingwex/math/remainder.s mingwex/math/remainderf.s: ...these... + * mingwex/math/remainderl.s mingwex/math/fmodf.c: ...and these... + * mingwex/math/fmodl.c: ...and also this; delete them. + + * Makefile.in (fmod_generic.sx, remainder_generic.sx): Add rule to + generate them. + +2021-02-24 Keith Marshall + + Correct remquo() quotient computation; cf. MinGW-Bug #41597 + 2021-02-24 Keith Marshall Correct remquo() quotient computation; cf. MinGW-Bug #41597 diff --git a/mingwrt/Makefile.in b/mingwrt/Makefile.in index e02ba23..6c562e8 100644 --- a/mingwrt/Makefile.in +++ b/mingwrt/Makefile.in @@ -514,8 +514,21 @@ $(addsuffix .$(OBJEXT), % %f %l): %_generic.sx $(COMPILE.sx) -D_$*f_source -o $*f.$(OBJEXT) $< $(COMPILE.sx) -D_$*l_source -o $*l.$(OBJEXT) $< +# Assembly language sources for all fmod() and remainder() object +# code variants originate from one fmod_generic.sx.in template. +# +vpath fmod_generic.sx.in ${srcdir}/mingwex/math +fmod_generic.sx remainder_generic.sx: %_generic.sx: fmod_generic.sx.in + sed '$($*_generic_subst)' $< > $@ + +# fmod() variants, and remainder() variants, require differing +# template substitutions. +# +fmod_generic_subst = s:%name%:$*:;s:%fprem%:fprem: +remainder_generic_subst = s:%name%:$*:;s:%fprem%:fprem1: + # Several generically implemented functions also require separate -# assembly of their generic back-end support routines. +# assembly of associated generic back-end support routines. # x87%.$(OBJEXT): %_generic.sx $(COMPILE.sx) -o $@ $< diff --git a/mingwrt/mingwex/math/fmod_generic.sx.in b/mingwrt/mingwex/math/fmod_generic.sx.in new file mode 100644 index 0000000..891b720 --- /dev/null +++ b/mingwrt/mingwex/math/fmod_generic.sx.in @@ -0,0 +1,119 @@ +/* + * %name%_generic.sx + * + * Generic implementation for each of the ISO-C99 fmod(), fmodl(), + * fmodf(), remainder(), remainderl(), and remainderf() functions. + * + * $Id$ + * + * Written by Keith Marshall + * Copyright (C) 2021, MinGW.org Project + * + * Adapted from original code written by J. T. Conklin . + * + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ +.intel_syntax noprefix + +.text +.align 4 + +#if defined _%name%_source +/* Preamble to load the FPU registers from the arguments passed in + * any call to either of the functions: + * + * double fmod (double, double); + * double remainder (double, double); + */ +.globl _%name% +.def _%name%; .scl 2; .type 32; .endef +.def ___x87cvt; .scl 2; .type 32; .endef + +_%name%: + fld QWORD ptr 12[esp] /* FPU TOS = y */ + fld QWORD ptr 4[esp] /* FPU TOS = x, y */ + +#elif defined _%name%f_source +/* Preamble to load the FPU registers from the arguments passed in + * any call to either of the functions: + * + * float fmodf (float, float); + * float remainderf (float, float); + */ +.globl _%name%f +.def _%name%f; .scl 2; .type 32; .endef +.def ___x87cvtf; .scl 2; .type 32; .endef + +_%name%f: + fld DWORD ptr 8[esp] /* FPU TOS = y */ + fld DWORD ptr 4[esp] /* FPU TOS = x, y */ + +#else /* _%name%l_source assumed */ +#ifndef _%name%l_source +#define _%name%l_source +#endif +/* Preamble to load the FPU registers from the arguments passed in + * any call to either of the functions: + * + * long double fmodl (long double, long double); + * long double remainderl (long double, long double); + */ +.globl _%name%l +.def _%name%l; .scl 2; .type 32; .endef + +_%name%l: + fld TBYTE ptr 16[esp] /* FPU TOS = y */ + fld TBYTE ptr 4[esp] /* FPU TOS = x, y */ + +#endif +/* Fall through to compute the remainder; this is an iterative procedure... + */ +10: %fprem% /* compute interim result */ + fstsw ax /* copy resultant FPU status... */ + sahf /* ...into CPU flags, for testing... */ + jp 10b /* ...until completion */ + +/* We now have the computed remainder (r), and the original value of y, + * in FPU registers st(0), and st(1) respectively; we no longer have any + * use for y, so discard it... + */ + fstp st(1) /* ...saving just 'r' for return */ + +#if defined _%name%l_source +/* For the %name%l() function, there is no more to do... + */ + ret /* ...but return the REAL10 result... */ + +#elif defined _%name%f_source +/* ...whereas for %name%f(), we must... + */ + jmp ___x87cvtf /* ...convert to REAL4... */ + +#else /* _%name%_source */ +/* ...while for %name%(), we must... + */ + jmp ___x87cvt /* ...convert to REAL8 */ + +#endif + +/* vim: set autoindent filetype=asm formatoptions=croqlj: */ +/* $RCSfile$: end of file */ diff --git a/mingwrt/mingwex/math/fmodf.c b/mingwrt/mingwex/math/fmodf.c deleted file mode 100644 index 6405d72..0000000 --- a/mingwrt/mingwex/math/fmodf.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * Adapted for float type by Danny Smith - * . - */ - -#include - -float -fmodf (float x, float y) -{ - float res; - - asm ("1:\tfprem\n\t" - "fstsw %%ax\n\t" - "sahf\n\t" - "jp 1b\n\t" - "fstp %%st(1)" - : "=t" (res) : "0" (x), "u" (y) : "ax", "st(1)"); - return res; -} diff --git a/mingwrt/mingwex/math/fmodl.c b/mingwrt/mingwex/math/fmodl.c deleted file mode 100644 index f1c97f1..0000000 --- a/mingwrt/mingwex/math/fmodl.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * Adapted for `long double' by Ulrich Drepper . - */ - -#include - -long double -fmodl (long double x, long double y) -{ - long double res; - - asm ("1:\tfprem\n\t" - "fstsw %%ax\n\t" - "sahf\n\t" - "jp 1b\n\t" - "fstp %%st(1)" - : "=t" (res) : "0" (x), "u" (y) : "ax", "st(1)"); - return res; -} diff --git a/mingwrt/mingwex/math/remainder.s b/mingwrt/mingwex/math/remainder.s deleted file mode 100644 index d9ab5ec..0000000 --- a/mingwrt/mingwex/math/remainder.s +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - */ - - .file "remainder.s" - .text - .align 4 -.globl _remainder - .def _remainder; .scl 2; .type 32; .endef -_remainder: - fldl 12(%esp) - fldl 4(%esp) -1: fprem1 - fstsw %ax - sahf - jp 1b - fstp %st(1) - ret diff --git a/mingwrt/mingwex/math/remainderf.s b/mingwrt/mingwex/math/remainderf.s deleted file mode 100644 index af1583a..0000000 --- a/mingwrt/mingwex/math/remainderf.s +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - */ - - .file "remainderf.s" - .text - .align 4 -.globl _remainder - .def _remainderf; .scl 2; .type 32; .endef -_remainderf: - flds 8(%esp) - flds 4(%esp) -1: fprem1 - fstsw %ax - sahf - jp 1b - fstp %st(1) - ret diff --git a/mingwrt/mingwex/math/remainderl.s b/mingwrt/mingwex/math/remainderl.s deleted file mode 100644 index 585f3af..0000000 --- a/mingwrt/mingwex/math/remainderl.s +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * Adapted for `long double' by Ulrich Drepper . - * Removed header file dependency for use in libmingwex.a by - * Danny Smith - */ - - .file "remainderl.s" - .text - .align 4 -.globl _remainderl - .def _remainderl; .scl 2; .type 32; .endef -_remainderl: - fldt 16(%esp) - fldt 4(%esp) -1: fprem1 - fstsw %ax - sahf - jp 1b - fstp %st(1) - ret