Clean up cacheflush.

No cacheflush for LP64; use the GCC builtin instead. Clean up the
32-bit MIPS implementation now we no longer need to worry about
old versions of GCC.

Bug: 12924756
Change-Id: Ie23955b3ec194e226c4b2bce35b11d5e061f4753
diff --git a/libc/arch-mips/bionic/cacheflush.cpp b/libc/arch-mips/bionic/cacheflush.cpp
index 7955dd6..98c0bd4 100644
--- a/libc/arch-mips/bionic/cacheflush.cpp
+++ b/libc/arch-mips/bionic/cacheflush.cpp
@@ -25,75 +25,39 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #include <unistd.h>
 #include <sys/cachectl.h>
 
-#ifdef DEBUG
 #include "private/libc_logging.h"
-#define  XLOG(...) __libc_format_log(ANDROID_LOG_DEBUG,"libc-cacheflush",__VA_ARGS__)
-#endif
 
-/*
- * Linux historically defines a cacheflush(3) routine for MIPS
- * with this signature:
- * int cacheflush(char *addr, int nbytes, int cache);
- *
- * Android defines an alternate cacheflush routine which exposes the
- * ARM system call interface:
- * int cacheflush (long start, long end, long flags)
- *
- * This is an attempt to maintain compatibility between the historical MIPS
- * usage for software previously ported to MIPS and Android specific
- * uses of cacheflush()
- *
- * Use the gcc __clear_cache builtin if possible. This will generate inline synci
- * instructions if available or call _flush_cache(start, len, BCACHE) directly
- */
+// Linux historically defines a cacheflush(3) routine for MIPS
+// with this signature:
 
-#if defined (__GNUC__)
-#define GCC_VERSION ((__GNUC__*10000) + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
-#endif
+//   int cacheflush(char *addr, int nbytes, int cache);
 
-/* This is the Android signature */
-int cacheflush (long start, long end, long /*flags*/) {
-	if (end < start) {
-		/*
-		 * It looks like this is really MIPS style cacheflush call
-		 * start => addr
-		 * end => nbytes
-		 */
-#ifdef DEBUG
-		static int warned = 0;
-		if (!warned) {
-			XLOG("called with (start,len) instead of (start,end)");
-			warned = 1;
-		}
-#endif
-		end += start;
-	}
+// Android defines an alternate cacheflush routine which exposes the
+// ARM system call interface:
 
-#if !defined(ARCH_MIPS_USE_FLUSHCACHE_SYSCALL) && \
-	defined(GCC_VERSION) && (GCC_VERSION >= 40300)
+//   int cacheflush (long start, long end, long flags)
 
-#if (__mips_isa_rev >= 2) && (GCC_VERSION < 40403)
-	/*
-	 * Modify "start" and "end" to avoid GCC 4.3.0-4.4.2 bug in
-	 * mips_expand_synci_loop that may execute synci one more time.
-	 * "start" points to the first byte of the cache line.
-	 * "end" points to the last byte of the line before the last cache line.
-	 * Because size is always a multiple of 4, this is safe to set
-	 * "end" to the last byte.
-	 */
-	{
-		int lineSize;
-		asm("rdhwr %0, $1" : "=r" (lineSize));
-		start = start & (-lineSize);
-		end = (end & (-lineSize)) - 1;
-	}
-#endif
-	__builtin___clear_cache((char *)start, (char *)end);
-#else
-	_flush_cache((char *)start, end-start, BCACHE);
-#endif
-	return 0;
+// This is an attempt to maintain compatibility between the historical MIPS
+// usage for software previously ported to MIPS and Android specific
+// uses of cacheflush().
+
+int cacheflush(long start, long end, long /*flags*/) {
+  if (end < start) {
+    // It looks like this is really a MIPS-style cacheflush call.
+    static bool warned = false;
+    if (!warned) {
+      __libc_format_log(ANDROID_LOG_WARN, "libc", "cacheflush called with (start,len) instead of (start,end)");
+      warned = true;
+    }
+    end += start;
+  }
+
+  // Use the GCC builtin. This will generate inline synci instructions if available,
+  // or call _flush_cache(start, len, BCACHE) directly.
+  __builtin___clear_cache(reinterpret_cast<char*>(start), reinterpret_cast<char*>(end));
+  return 0;
 }