From 431ac2a912708546cd7271332e9331399e66bc62 Mon Sep 17 00:00:00 2001 From: Liu Hao Date: Wed, 3 May 2017 15:52:32 +0800 Subject: [PATCH] winpthreads/src/dll_math.c: Implement `__divmoddi4()' for GCC 7. GCC targeting i686 _may_ generate an external call to the function in question when divding a 64-bit (DIMode) integer with another one. Since we are linking against a fake libgcc, we have to implement it too. Signed-off-by: Liu Hao --- .../winpthreads/src/libgcc/dll_math.c | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/mingw-w64-libraries/winpthreads/src/libgcc/dll_math.c b/mingw-w64-libraries/winpthreads/src/libgcc/dll_math.c index e09b481b..aeec0680 100644 --- a/mingw-w64-libraries/winpthreads/src/libgcc/dll_math.c +++ b/mingw-w64-libraries/winpthreads/src/libgcc/dll_math.c @@ -120,6 +120,7 @@ u_quad_t __qdivrem(u_quad_t u, u_quad_t v, u_quad_t *rem); u_quad_t __udivdi3(u_quad_t a, u_quad_t b); u_quad_t __umoddi3(u_quad_t a, u_quad_t b); int __ucmpdi2(u_quad_t a, u_quad_t b); +quad_t __divmoddi4(quad_t a, quad_t b, quad_t *rem); #endif /* !_LIBKERN_QUAD_H_ */ @@ -546,6 +547,32 @@ __umoddi3(a, b) (void)__qdivrem(a, b, &r); return (r); } + +/* + * Divide two signed quads. + * This function is new in GCC 7. + */ +quad_t +__divmoddi4(a, b, rem) + quad_t a, b, *rem; +{ + u_quad_t ua, ub, uq, ur; + int negq, negr; + + if (a < 0) + ua = -(u_quad_t)a, negq = 1, negr = 1; + else + ua = a, negq = 0, negr = 0; + if (b < 0) + ub = -(u_quad_t)b, negq ^= 1; + else + ub = b; + uq = __qdivrem(ua, ub, &ur); + if (rem) + *rem = (negr ? -ur : ur); + return (negq ? -uq : uq); +} + #else static int __attribute__((unused)) dummy; #endif /*deined (_X86_) && !defined (__x86_64__)*/ -- 2.13.0