diff --git a/ChangeLog b/ChangeLog
index 9b416ecc24e469dddca7dc1932fea8aca1c1f3cc..058691eb71fa49e2a1a812b2fdd3b302d44c5c57 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,17 @@
 2015-03-31  Niels Möller  <nisse@diamant.hack.org>
 
+	* x86_64/ecc-224-modp.asm: Require that GMP_NUMB_BITS == 64.
+	* x86_64/ecc-521-modp.asm: Likewise. Note that the other
+	ecc-*-modp.asm files happen to work fine on x86_64, with either 32
+	or 64 bits.
+
+	* asm.m4 (GMP_NUMB_BITS): New macro, expanding to nothing.
+
 	* configure.ac: Move tests for compiler characteristics,
 	libraries, and GMP_NUMB_BITS, before assembler-related tests.
+	For files in $asm_hogweed_optional_list, check if they declare
+	a GMP_NUMB_BITS requirement, and skip files which are incompatible
+	with the configuration. Needed for --enable-mini-gmp om w64.
 
 	* Makefile.in (clean-here): Unconditionally delete *.a (including
 	stub libraries like *.dll.a).
diff --git a/asm.m4 b/asm.m4
index bbc90bd4e2d07050d3b6d19b034e8a580c49bf54..4018c2356a1dcfe57c5978d8ef1bfe04b24f0d07 100644
--- a/asm.m4
+++ b/asm.m4
@@ -27,6 +27,8 @@ COFF_STYLE, yes,
 .endef>,
 <>)>)
 
+define(<GMP_NUMB_BITS>,<>)dnl
+
 define(<PROLOGUE>,
 <.globl C_NAME($1)
 DECLARE_FUNC(C_NAME($1))
diff --git a/configure.ac b/configure.ac
index 30071f9f031048f796c0e0fbdae094b95ce9f44e..5a16151d5fff3a8f596768530d14b383b816cc42 100644
--- a/configure.ac
+++ b/configure.ac
@@ -464,6 +464,13 @@ EOF
       tmp_b=`echo "$tmp_h" | sed 's/\.[[^.]]*$//'`
       for asm_dir in $asm_path ; do
 	if test -f "$srcdir/$asm_dir/$tmp_h"; then
+	  dnl Note double square brackets, for extra m4 quoting.
+	  tmp_bits=`grep GMP_NUMB_BITS "$srcdir/$asm_dir/$tmp_h" \
+            | sed 's/^.*GMP_NUMB_BITS(\([[0-9]]*\)).*$/\1/'`
+	  if test "$tmp_bits" && test "$tmp_bits" != '${GMP_NUMB_BITS}' ; then
+	     AC_MSG_WARN([skipping $tmp_h, because GMP_NUMB_BITS != $tmp_bits])
+	     continue
+	  fi
 	  asm_file_list="$asm_file_list $tmp_h"
 	  AC_CONFIG_LINKS($tmp_h:$asm_dir/$tmp_h)
 	  while read tmp_func ; do
diff --git a/x86_64/ecc-224-modp.asm b/x86_64/ecc-224-modp.asm
index 282859c6b7b11c80bcdca53e82c996406a7733a2..07bd4003670515487726c96adc74289fe9970f50 100644
--- a/x86_64/ecc-224-modp.asm
+++ b/x86_64/ecc-224-modp.asm
@@ -32,6 +32,8 @@ ifelse(<
 
 	.file "ecc-224-modp.asm"
 
+GMP_NUMB_BITS(64)
+
 define(<RP>, <%rsi>)
 define(<T0>, <%rdi>) C Overlaps unused modulo input
 define(<T1>, <%rcx>)
diff --git a/x86_64/ecc-521-modp.asm b/x86_64/ecc-521-modp.asm
index 69dc1f06f7c1eab86db429e843c8a83423f1b6cd..6e818ad81d415807eb76daa4ca550be6b983ff62 100644
--- a/x86_64/ecc-521-modp.asm
+++ b/x86_64/ecc-521-modp.asm
@@ -32,6 +32,8 @@ ifelse(<
 
 	.file "ecc-521-modp.asm"
 
+GMP_NUMB_BITS(64)
+
 define(<RP>, <%rsi>)
 define(<U0>, <%rax>)
 define(<U1>, <%rbx>)