Please review, i'll commit it, just need an OK.





diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 7245956..9731aa9 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -233,7 +233,7 @@ src_libmingwex=\
   math/fabs.c           math/fabsf.c       math/fabsl.c          math/fdim.c          math/fdimf.c         math/fdiml.c         \
   math/fmal.c           math/fmax.c        math/fmaxf.c          math/fmaxl.c         math/fmin.c          math/fminf.c         \
   math/fminl.c          math/fp_consts.c   math/fp_constsf.c     \
-  math/fp_constsl.c     math/fpclassify.c  math/fpclassifyf.c    math/fpclassifyl.c   math/frexpf.c        math/fucom.c         \
+  math/fp_constsl.c     math/fpclassify.c  math/fpclassifyf.c    math/fpclassifyl.c   math/frexpf.c        \
   math/hypotf.c         math/hypotl.c      math/isnan.c          math/isnanf.c        math/isnanl.c        \
   math/ldexpf.c         math/lgamma.c      math/lgammaf.c        math/lgammal.c       math/llrint.c        \
   math/signgam.c \
@@ -299,13 +299,14 @@ src_libmingwex64=\
   math/atanhf.c             math/atanhl.c             math/cos.c                math/cosf.c               math/cosl.c               \
   math/cosl_internal.S      math/cossin.c             math/exp.c                math/expl.c               math/exp2.S               \
   math/exp2f.S              math/exp2l.S              math/expm1.c              math/expm1f.c             math/expm1l.c             \
-  math/fmod.c               math/fmodf.c              math/fmodl.c              math/ilogb.S              math/ilogbf.S             \
-  math/ilogbl.S             math/internal_logl.S      math/ldexp.c              math/ldexpl.c             math/log.c               \
-  math/log10l.S             math/log1p.S              math/log1pf.S             math/log1pl.S             math/log2.S               \
-  math/log2f.S              math/log2l.S              math/logb.c               math/logbf.c              math/logbl.c              \
-  math/logl.c               math/pow.c                math/powl.c               math/remainder.S          math/remainderf.S         \
-  math/remainderl.S         math/scalbn.S             math/scalbnf.S            math/scalbnl.S            math/sin.c                \
-  math/sinf.c               math/sinl.c               math/sinl_internal.S      math/tanf.c               math/tanl.S
+  math/fmod.c               math/fmodf.c              math/fmodl.c              math/fucom.c              math/ilogb.S              \
+  math/ilogbf.S             math/ilogbl.S             math/internal_logl.S      math/ldexp.c              math/ldexpl.c             \
+  math/log.c                math/log10l.S             math/log1p.S              math/log1pf.S             math/log1pl.S             \
+  math/log2.S               math/log2f.S              math/log2l.S              math/logb.c               math/logbf.c              \
+  math/logbl.c              math/logl.c               math/pow.c                math/powl.c               math/remainder.S          \
+  math/remainderf.S         math/remainderl.S         math/scalbn.S             math/scalbnf.S            math/scalbnl.S            \
+  math/sin.c                math/sinf.c               math/sinl.c               math/sinl_internal.S      math/tanf.c               \
+  math/tanl.S
 
 # these only go into the 32 bit version:
 src_libmingwex32=\
@@ -315,13 +316,14 @@ src_libmingwex32=\
   math/atanhf.c             math/atanhl.c             math/cos.c                math/cosf.c               math/cosl.c               \
   math/cosl_internal.S      math/cossin.c             math/exp.c                math/expl.c               math/exp2.S               \
   math/exp2f.S              math/exp2l.S              math/expm1.c              math/expm1f.c             math/expm1l.c             \
-  math/fmod.c               math/fmodf.c              math/fmodl.c              math/ilogb.S              math/ilogbf.S             \
-  math/ilogbl.S             math/internal_logl.S      math/ldexp.c              math/ldexpl.c             math/log.c               \
-  math/log10l.S             math/log1p.S              math/log1pf.S             math/log1pl.S             math/log2.S               \
-  math/log2f.S              math/log2l.S              math/logb.c               math/logbf.c              math/logbl.c              \
-  math/logl.c               math/pow.c                math/powl.c               math/remainder.S          math/remainderf.S         \
-  math/remainderl.S         math/scalbn.S             math/scalbnf.S            math/scalbnl.S            math/sin.c                \
-  math/sinf.c               math/sinl.c               math/sinl_internal.S      math/tanf.c               math/tanl.S
+  math/fmod.c               math/fmodf.c              math/fmodl.c              math/fucom.c              math/ilogb.S              \
+  math/ilogbf.S             math/ilogbl.S             math/internal_logl.S      math/ldexp.c              math/ldexpl.c             \
+  math/log.c                math/log10l.S             math/log1p.S              math/log1pf.S             math/log1pl.S             \
+  math/log2.S               math/log2f.S              math/log2l.S              math/logb.c               math/logbf.c              \
+  math/logbl.c              math/logl.c               math/pow.c                math/powl.c               math/remainder.S          \
+  math/remainderf.S         math/remainderl.S         math/scalbn.S             math/scalbnf.S            math/scalbnl.S            \
+  math/sin.c                math/sinf.c               math/sinl.c               math/sinl_internal.S      math/tanf.c               \
+  math/tanl.S
 
 # these only go into the ARM32 version:
 src_libmingwexarm32=\
diff --git a/mingw-w64-crt/math/lrint.c b/mingw-w64-crt/math/lrint.c
index 69cd0f6..0353b8f 100644
--- a/mingw-w64-crt/math/lrint.c
+++ b/mingw-w64-crt/math/lrint.c
@@ -5,10 +5,26 @@
  */
 #include <math.h>
 
+#if defined(__arm__) || defined(_ARM_)
+/* This works around a compiler bug */
+long __lrint_internal( double x ) __attribute__((visibility ("hidden")));
+asm(".def __lrint_internal; .scl 2; .type 32; .endef\n"
+    "\t.text\n"
+    "\t.align 4\n"
+    "\t.globl __lrint_internal\n"
+    "__lrint_internal:\n"
+    "\tvcvtr.s32.f64    s0, d0\n"
+    "\tfmrs             r0, s0\n"
+    "\tbx lr");
+#endif /* defined(__arm__) || defined(_ARM_) */
+
 long lrint (double x) 
 {
   long retval = 0L;
-  __asm__ __volatile__							      \
-    ("fistpl %0"  : "=m" (retval) : "t" (x) : "st");				      \
+#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
+  __asm__ __volatile__ ("fistpl %0"  : "=m" (retval) : "t" (x) : "st");
+#elif defined(__arm__) || defined(_ARM_)
+    retval = __lrint_internal(x);
+#endif
   return retval;
 }
diff --git a/mingw-w64-crt/math/lrintf.c b/mingw-w64-crt/math/lrintf.c
index cf17599..5535b12 100644
--- a/mingw-w64-crt/math/lrintf.c
+++ b/mingw-w64-crt/math/lrintf.c
@@ -5,10 +5,26 @@
  */
 #include <math.h>
 
+#if defined(__arm__) || defined(_ARM_)
+/* This works around a compiler bug */
+long __lrintf_internal( float x ) __attribute__((visibility ("hidden")));
+asm(".def __lrintf_internal; .scl 2; .type 32; .endef\n"
+    "\t.text\n"
+    "\t.align 4\n"
+    "\t.globl __lrintf_internal\n"
+    "__lrintf_internal:\n"
+    "\tvcvtr.s32.f32    s0, s0\n"
+    "\tfmrs             r0, s0\n"
+    "\tbx lr");
+#endif /* defined(__arm__) || defined(_ARM_) */
+
 long lrintf (float x) 
 {
   long retval = 0l;
-  __asm__ __volatile__							      \
-    ("fistpl %0"  : "=m" (retval) : "t" (x) : "st");				      \
+#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
+  __asm__ __volatile__ ("fistpl %0"  : "=m" (retval) : "t" (x) : "st");
+#elif defined(__arm__) || defined(_ARM_)
+    retval = __lrintf_internal(x);
+#endif
   return retval;
 }
diff --git a/mingw-w64-crt/math/lrintl.c b/mingw-w64-crt/math/lrintl.c
index 21f3009..94c4e49 100644
--- a/mingw-w64-crt/math/lrintl.c
+++ b/mingw-w64-crt/math/lrintl.c
@@ -8,8 +8,11 @@
 long lrintl (long double x) 
 {
   long retval = 0l;
-  __asm__ __volatile__							      \
-    ("fistpl %0"  : "=m" (retval) : "t" (x) : "st");				      \
+#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
+  __asm__ __volatile__ ("fistpl %0"  : "=m" (retval) : "t" (x) : "st");
+#elif defined(__arm__) || defined(_ARM_)
+    retval = lrint(x);
+#endif
   return retval;
 }
 
diff --git a/mingw-w64-crt/math/nearbyint.S b/mingw-w64-crt/math/nearbyint.S
index 7a4f3b0..9775737 100644
--- a/mingw-w64-crt/math/nearbyint.S
+++ b/mingw-w64-crt/math/nearbyint.S
@@ -34,8 +34,10 @@ __MINGW_USYMBOL(nearbyint):
 	movsd	-16(%rsp),%xmm0
 	ret
 #elif defined(_ARM_) || defined(__arm__)
+	vmrs	r1, fpscr
 	vcvtr.s32.f64	s0, d0
 	vcvt.f64.s32	d0, s0
+	vmsr	fpscr, r1
 	bx	lr
 #elif defined(_X86_) || defined(__i386__)
 	fldl	4(%esp)
diff --git a/mingw-w64-crt/math/nearbyintf.S b/mingw-w64-crt/math/nearbyintf.S
index 1f4a9d1..7e8889d 100644
--- a/mingw-w64-crt/math/nearbyintf.S
+++ b/mingw-w64-crt/math/nearbyintf.S
@@ -34,8 +34,10 @@ __MINGW_USYMBOL(nearbyintf):
 	movss	-12(%rsp),%xmm0
 	ret
 #elif defined(_ARM_) || defined(__arm__)
+	vmrs	r1, fpscr
 	vcvt.s32.f32	s0, s0
 	vcvt.f32.s32	s0, s0
+	vmsr	fpscr, r1
 	bx	lr
 #elif defined(_X86_) || defined(__i386__)
 	flds	4(%esp)
diff --git a/mingw-w64-crt/math/nearbyintl.S b/mingw-w64-crt/math/nearbyintl.S
index 8f3578c..6a1302e 100644
--- a/mingw-w64-crt/math/nearbyintl.S
+++ b/mingw-w64-crt/math/nearbyintl.S
@@ -35,8 +35,10 @@ __MINGW_USYMBOL(nearbyintl):
 	fstpt	(%r8)
 	ret
 #elif defined(_ARM_) || defined(__arm__)
+	vmrs	r1, fpscr
 	vcvtr.s32.f64	s0, d0
 	vcvt.f64.s32	d0, s0
+	vmsr	fpscr, r1
 	bx	lr
 #elif defined(_X86_) || defined(__i386__)
 	fldt	4(%esp)
diff --git a/mingw-w64-crt/math/rint.c b/mingw-w64-crt/math/rint.c
index ac9512f..93a70dd 100644
--- a/mingw-w64-crt/math/rint.c
+++ b/mingw-w64-crt/math/rint.c
@@ -4,8 +4,26 @@
  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
  */
 #include <math.h>
+
+#if defined(__arm__) || defined(_ARM_)
+/* This works around a compiler bug */
+double __rint_internal( double x ) __attribute__((visibility ("hidden")));
+asm(".def __rint_internal; .scl 2; .type 32; .endef\n"
+    "\t.text\n"
+    "\t.align 4\n"
+    "\t.globl __rint_internal\n"
+    "__rint_internal:\n"
+    "\tvcvtr.s32.f64    s0, d0\n"
+    "\tvcvt.f64.s32     d0, s0\n"
+    "\tbx lr");
+#endif /* defined(__arm__) || defined(_ARM_) */
+
 double rint (double x) {
   double retval = 0.0;
+#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
   __asm__ __volatile__ ("frndint;" : "=t" (retval) : "0" (x));
+#elif defined(__arm__) || defined(_ARM_)
+    retval = __rint_internal(x);
+#endif
   return retval;
 }
diff --git a/mingw-w64-crt/math/rintf.c b/mingw-w64-crt/math/rintf.c
index f5a6bf2..f81dd75 100644
--- a/mingw-w64-crt/math/rintf.c
+++ b/mingw-w64-crt/math/rintf.c
@@ -5,8 +5,25 @@
  */
 #include <math.h>
 
+#if defined(__arm__) || defined(_ARM_)
+/* This works around a compiler bug */
+float __rintf_internal( float x ) __attribute__((visibility ("hidden")));
+asm(".def __rintf_internal; .scl 2; .type 32; .endef\n"
+    "\t.text\n"
+    "\t.align 4\n"
+    "\t.globl __rintf_internal\n"
+    "__rintf_internal:\n"
+    "\tvcvtr.s32.f32    s0, s0\n"
+    "\tvcvt.f32.s32     s0, s0\n"
+    "\tbx lr");
+#endif /* defined(__arm__) || defined(_ARM_) */
+
 float rintf (float x) {
   float retval = 0.0F;
+#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
   __asm__ __volatile__ ("frndint;": "=t" (retval) : "0" (x));
+#elif defined(__arm__) || defined(_ARM_)
+    retval = __rintf_internal(x);
+#endif
   return retval;
 }
diff --git a/mingw-w64-crt/math/rintl.c b/mingw-w64-crt/math/rintl.c
index a870322..9ec159d 100644
--- a/mingw-w64-crt/math/rintl.c
+++ b/mingw-w64-crt/math/rintl.c
@@ -7,6 +7,10 @@
 
 long double rintl (long double x) {
   long double retval = 0.0L;
+#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
   __asm__ __volatile__ ("frndint;": "=t" (retval) : "0" (x));
+#elif defined(__arm__) || defined(_ARM_)
+    retval = rint(x);
+#endif
   return retval;
 }
diff --git a/mingw-w64-crt/math/truncl.c b/mingw-w64-crt/math/truncl.c
index 52cef3a..ddc6af6 100644
--- a/mingw-w64-crt/math/truncl.c
+++ b/mingw-w64-crt/math/truncl.c
@@ -9,6 +9,9 @@
 long double
 truncl (long double _x)
 {
+#if defined(_ARM_) || defined(__arm__)
+  return trunc(_x);
+#else
   long double retval = 0.0L;
   unsigned short saved_cw;
   unsigned short tmp_cw;
@@ -19,4 +22,5 @@ truncl (long double _x)
   __asm__ __volatile__ ("frndint;" : "=t" (retval)  : "0" (_x)); /* round towards zero */
   __asm__ __volatile__ ("fldcw %0;" : : "m" (saved_cw) ); /* restore saved control word */
   return retval;
+#endif /* defined(_ARM_) || defined(__arm__) */
 }
diff --git a/mingw-w64-crt/stdio/vfscanf.c b/mingw-w64-crt/stdio/vfscanf.c
index 0b2f18a..ece4701 100644
--- a/mingw-w64-crt/stdio/vfscanf.c
+++ b/mingw-w64-crt/stdio/vfscanf.c
@@ -18,7 +18,7 @@
 int __ms_vfscanf (FILE * __restrict__ stream, const char * __restrict__ format, va_list arg)
 {
   int ret;
-#ifdef _WIN64
+#if defined(_AMD64_) || defined(__x86_64__)
   __asm__ __volatile__ (
 
     /* allocate stack (esp += frame - arg3 - (8[arg1,2] + 12)) */
@@ -54,7 +54,7 @@ int __ms_vfscanf (FILE * __restrict__ stream, const char * __restrict__ format,
     : "1"(stream), "2"(format), "S"(arg),
       "a"(&ret)
     : "rbx", "rdi");
-#else
+#elif defined(_X86_) || defined(__i386__)
   __asm__ __volatile__ (
 
     /* allocate stack (esp += frame - arg3 - (8[arg1,2] + 12)) */
@@ -83,6 +83,36 @@ int __ms_vfscanf (FILE * __restrict__ stream, const char * __restrict__ format,
     : "1"(stream), "2"(format), "S"(arg),
       "a"(&ret)
     : "ebx", "edi");
+#elif defined(_ARM_) || defined(__arm__)
+  int tmp1, tmp2, tmp3, tmp4, tmp5;
+  __asm__ __volatile__ (
+    "mov %[t1], sp\n\t"
+    "sub %[t1], %[t1], #128\n\t"
+    "mov %[t2], %[arg]\n\t"
+
+    "ldr ip, [%[t2]], #4\n\t"
+    "mov %[t4], ip\n\t"
+    "ldr ip, [%[t2]], #4\n\t"
+    "mov %[t5], ip\n\t"
+
+    "mov %[t3], #120\n\t"
+    "1: ldr ip, [%[t2]], #4\n\t"
+    "str ip, [%[t1]], #4\n\t"
+    "subs %[t3], %[t3], #4\n\t"
+    "bge 1b\n\t"
+
+    "sub sp, sp, #128\n\t"
+    "mov r0, %[s]\n\t"
+    "mov r1, %[format]\n\t"
+    "mov r2, %[t4]\n\t"
+    "mov r3, %[t5]\n\t"
+    "bl " QUOTE(__MINGW_USYMBOL(fscanf)) "\n\t"
+    "add sp, sp, #128\n\t"
+    "mov %[ret], r0\n\t"
+    : [ret] "=r" (ret), [t1] "+r" (tmp1), [t2] "+r" (tmp2), [t3] "+r" (tmp3), [t4] "+r" (tmp4), [t5] "+r" (tmp5)
+    : [s] "r" (stream), [format] "r" (format), [arg] "r" (arg)
+    : "r0", "r1", "r2", "r3", "ip", "cc", "memory"
+    );
 #endif
 
   return ret;
diff --git a/mingw-w64-crt/stdio/vfwscanf.c b/mingw-w64-crt/stdio/vfwscanf.c
index 89cfc63..eb1c83e 100644
--- a/mingw-w64-crt/stdio/vfwscanf.c
+++ b/mingw-w64-crt/stdio/vfwscanf.c
@@ -17,7 +17,7 @@ int __ms_vfwscanf (FILE * __restrict__ stream, const wchar_t * __restrict__ form
 
   int ret;
 
-#ifdef _WIN64
+#if defined(_AMD64_) || defined(__x86_64__)
   __asm__ __volatile__ (
 
     // allocate stack (esp += frame - arg3 - (8[arg1,2] + 12))
@@ -28,7 +28,7 @@ int __ms_vfwscanf (FILE * __restrict__ stream, const wchar_t * __restrict__ form
     // set up stack
     "movq	%1, 0x18(%%rsp)\n\t"  // stream
     "movq	%2, 0x20(%%rsp)\n\t"  // format
-    "lea	0x28(%%rsp), %%edi\n\t"
+    "lea	0x28(%%rsp), %%rdi\n\t"
     "movq	%%rdi, (%%rsp)\n\t"  // memcpy dest
     "movq	%5, 0x8(%%rsp)\n\t"  // memcpy src
     "movq	%5, 0x10(%%rsp)\n\t"
@@ -53,7 +53,7 @@ int __ms_vfwscanf (FILE * __restrict__ stream, const wchar_t * __restrict__ form
     : "1"(stream), "2"(format), "S"(arg),
       "a"(&ret)
     : "rbx", "rdi");
-#else
+#elif defined(_X86_) || defined(__i386__)
   __asm__ __volatile__ (
 
     // allocate stack (esp += frame - arg3 - (8[arg1,2] + 12))
@@ -82,6 +82,36 @@ int __ms_vfwscanf (FILE * __restrict__ stream, const wchar_t * __restrict__ form
     : "1"(stream), "2"(format), "S"(arg),
       "a"(&ret)
     : "ebx", "edi");
+#elif defined(_ARM_) || defined(__arm__)
+  int tmp1, tmp2, tmp3, tmp4, tmp5;
+  __asm__ __volatile__ (
+    "mov %[t1], sp\n\t"
+    "sub %[t1], %[t1], #128\n\t"
+    "mov %[t2], %[arg]\n\t"
+
+    "ldr ip, [%[t2]], #4\n\t"
+    "mov %[t4], ip\n\t"
+    "ldr ip, [%[t2]], #4\n\t"
+    "mov %[t5], ip\n\t"
+
+    "mov %[t3], #120\n\t"
+    "1: ldr ip, [%[t2]], #4\n\t"
+    "str ip, [%[t1]], #4\n\t"
+    "subs %[t3], %[t3], #4\n\t"
+    "bge 1b\n\t"
+
+    "sub sp, sp, #128\n\t"
+    "mov r0, %[s]\n\t"
+    "mov r1, %[format]\n\t"
+    "mov r2, %[t4]\n\t"
+    "mov r3, %[t5]\n\t"
+    "bl " QUOTE(__MINGW_USYMBOL(fwscanf)) "\n\t"
+    "add sp, sp, #128\n\t"
+    "mov %[ret], r0\n\t"
+    : [ret] "=r" (ret), [t1] "+r" (tmp1), [t2] "+r" (tmp2), [t3] "+r" (tmp3), [t4] "+r" (tmp4), [t5] "+r" (tmp5)
+    : [s] "r" (stream), [format] "r" (format), [arg] "r" (arg)
+    : "r0", "r1", "r2", "r3", "ip", "cc", "memory"
+    );
 #endif
 
   return ret;
diff --git a/mingw-w64-crt/stdio/vsscanf.c b/mingw-w64-crt/stdio/vsscanf.c
index e2ad8f0..0c148c1 100644
--- a/mingw-w64-crt/stdio/vsscanf.c
+++ b/mingw-w64-crt/stdio/vsscanf.c
@@ -14,7 +14,7 @@
 
 int __ms_vsscanf (const char * __restrict__ s, const char * __restrict__ format, va_list arg) {
   int ret;
-#ifdef _WIN64
+#if defined(_AMD64_) || defined(__x86_64__)
   __asm__ __volatile__ (
 
     // allocate stack (esp += frame - arg3 - (8[arg1,2] + 12))
@@ -50,7 +50,7 @@ int __ms_vsscanf (const char * __restrict__ s, const char * __restrict__ format,
     : "1"(s), "2"(format), "S"(arg),
       "a"(&ret)
     : "rbx", "rdi");
-#else
+#elif defined(_X86_) || defined(__i386__)
   __asm__ __volatile__ (
 
     // allocate stack (esp += frame - arg3 - (8[arg1,2] + 12))
@@ -79,6 +79,36 @@ int __ms_vsscanf (const char * __restrict__ s, const char * __restrict__ format,
     : "1"(s), "2"(format), "S"(arg),
       "a"(&ret)
     : "ebx", "edi");
+#elif defined(_ARM_) || defined(__arm__)
+  int tmp1, tmp2, tmp3, tmp4, tmp5;
+  __asm__ __volatile__ (
+    "mov %[t1], sp\n\t"
+    "sub %[t1], %[t1], #128\n\t"
+    "mov %[t2], %[arg]\n\t"
+
+    "ldr ip, [%[t2]], #4\n\t"
+    "mov %[t4], ip\n\t"
+    "ldr ip, [%[t2]], #4\n\t"
+    "mov %[t5], ip\n\t"
+
+    "mov %[t3], #120\n\t"
+    "1: ldr ip, [%[t2]], #4\n\t"
+    "str ip, [%[t1]], #4\n\t"
+    "subs %[t3], %[t3], #4\n\t"
+    "bge 1b\n\t"
+
+    "sub sp, sp, #128\n\t"
+    "mov r0, %[s]\n\t"
+    "mov r1, %[format]\n\t"
+    "mov r2, %[t4]\n\t"
+    "mov r3, %[t5]\n\t"
+    "bl " QUOTE(__MINGW_USYMBOL(sscanf)) "\n\t"
+    "add sp, sp, #128\n\t"
+    "mov %[ret], r0\n\t"
+    : [ret] "=r" (ret), [t1] "+r" (tmp1), [t2] "+r" (tmp2), [t3] "+r" (tmp3), [t4] "+r" (tmp4), [t5] "+r" (tmp5)
+    : [s] "r" (s), [format] "r" (format), [arg] "r" (arg)
+    : "r0", "r1", "r2", "r3", "ip", "cc", "memory"
+    );
 #endif
 
   return ret;
diff --git a/mingw-w64-crt/stdio/vswscanf.c b/mingw-w64-crt/stdio/vswscanf.c
index 419fd18..d93ff28 100644
--- a/mingw-w64-crt/stdio/vswscanf.c
+++ b/mingw-w64-crt/stdio/vswscanf.c
@@ -17,7 +17,7 @@ int __ms_vswscanf(const wchar_t * __restrict__ s, const wchar_t * __restrict__ f
 {
   int ret;
 
-#ifdef _WIN64
+#if defined(_AMD64_) || defined(__x86_64__)
   __asm__ __volatile__ (
 
     // allocate stack (esp += frame - arg3 - (8[arg1,2] + 12))
@@ -53,7 +53,7 @@ int __ms_vswscanf(const wchar_t * __restrict__ s, const wchar_t * __restrict__ f
     : "1"(s), "2"(format), "S"(arg),
       "a"(&ret)
     : "rbx", "rdi");
-#else
+#elif defined(_X86_) || defined(__i386__)
   __asm__ __volatile__ (
 
     // allocate stack (esp += frame - arg3 - (8[arg1,2] + 12))
@@ -82,6 +82,36 @@ int __ms_vswscanf(const wchar_t * __restrict__ s, const wchar_t * __restrict__ f
     : "1"(s), "2"(format), "S"(arg),
       "a"(&ret)
     : "ebx", "edi");
+#elif defined(_ARM_) || defined(__arm__)
+  int tmp1, tmp2, tmp3, tmp4, tmp5;
+  __asm__ __volatile__ (
+    "mov %[t1], sp\n\t"
+    "sub %[t1], %[t1], #128\n\t"
+    "mov %[t2], %[arg]\n\t"
+
+    "ldr ip, [%[t2]], #4\n\t"
+    "mov %[t4], ip\n\t"
+    "ldr ip, [%[t2]], #4\n\t"
+    "mov %[t5], ip\n\t"
+
+    "mov %[t3], #120\n\t"
+    "1: ldr ip, [%[t2]], #4\n\t"
+    "str ip, [%[t1]], #4\n\t"
+    "subs %[t3], %[t3], #4\n\t"
+    "bge 1b\n\t"
+
+    "sub sp, sp, #128\n\t"
+    "mov r0, %[s]\n\t"
+    "mov r1, %[format]\n\t"
+    "mov r2, %[t4]\n\t"
+    "mov r3, %[t5]\n\t"
+    "bl " QUOTE(__MINGW_USYMBOL(swscanf)) "\n\t"
+    "add sp, sp, #128\n\t"
+    "mov %[ret], r0\n\t"
+    : [ret] "=r" (ret), [t1] "+r" (tmp1), [t2] "+r" (tmp2), [t3] "+r" (tmp3), [t4] "+r" (tmp4), [t5] "+r" (tmp5)
+    : [s] "r" (s), [format] "r" (format), [arg] "r" (arg)
+    : "r0", "r1", "r2", "r3", "ip", "cc", "memory"
+    );
 #endif
   return ret;
 }
------------------------------------------------------------------------------
Slashdot TV.  Video for Nerds.  Stuff that Matters.
http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to