diff --git a/m4/octave_blas_f77_func.m4 b/m4/octave_blas_f77_func.m4
--- a/m4/octave_blas_f77_func.m4
+++ b/m4/octave_blas_f77_func.m4
@@ -154,26 +154,50 @@ elif test x"$ax_blas_ok" = xyes; then
# FIXME: this may fail with things like -ftrapping-math.
AC_MSG_CHECKING([BLAS library integer size])
AC_RUN_IFELSE(AC_LANG_PROGRAM(,[[
- integer*8 n
- integer*4 n4
- real s,a(1),b(1),sdot
+ integer*8 two, n
+ integer*4 n2(2)
+ double precision d, a(1), b(1), ddot
+ equivalence (n, n2)
+
a(1) = 1.0
b(1) = 1.0
-c Generate -2**33 + 1. With BLAS compiled to use 64-bit integers, SDOT
-c will return early, setting the result to 0. With BLAS compiled to use
-c 32-bit integers, this value should be interpreted as 1 and SDOT will
-c return 1.
- n = 2
- n = -4 * (n ** 30)
- n = n + 1
-c Check that our expectation about the type conversion is correct.
- n4 = n
- if (n4 .ne. 1) then
+
+c Generate 2**32 + 1 in an 8-byte integer. Whether we have a big
+c endian or little endian system, both 4-byte words of this value
+c should be 1.
+
+ two = 2
+ n = (two ** 32) + 1
+
+c Check that our expectation about the type conversions are correct.
+
+ if (n2(1) .ne. 1 .or. n2(2) .ne. 1) then
print *, 'invalid assumption about integer type conversion'
stop 2
endif
- s = sdot(n,a,1,b,1)
- if (s .ne. 0.0) stop 1
+
+* print *, n, n2(1), n2(2)
+* print *, a(1), b(1)
+
+c SDOT will either see 1 or a large value for N. Since INCX and INCY
+c are both 0, we will never increment the index, so A and B only need to
+c have a single element. If N is interpreted as 1 (BLAS compiled with 4
+c byte integers) then the result will c be 1. If N is interpreted as a
+c large value (BLAS compiled with 8 byte integers) then the result will
+c be the summation a(1)*b(1) 2^32+1 times. This will also take some
+c time some time to compute, but at least for now it is the unusual case
+c so we are much more likely to exit quickly after detecting that the
+c BLAS library was compiled with 4-byte integers.
+
+ d = ddot (n, a, 0, b, 0)
+
+* print *, a(1), b(1), d
+
+c Success (0 exit status) means we detected BLAS compiled with
+c 8-byte integers.
+
+ if (d .eq. 1.0) stop 1
+
]]),[ax_blas_integer_size=8],
[ax_blas_integer_size=4])
AC_MSG_RESULT([$ax_blas_integer_size])