A simple test of m{f,t}ocrf.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@5705 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/none/tests/ppc32/Makefile.am b/none/tests/ppc32/Makefile.am
index 0fc5015..e04c7f0 100644
--- a/none/tests/ppc32/Makefile.am
+++ b/none/tests/ppc32/Makefile.am
@@ -6,6 +6,7 @@
 	jm-int.stderr.exp jm-int.stdout.exp jm-int.vgtest \
 	jm-fp.stderr.exp jm-fp.stdout.exp jm-fp.vgtest \
 	jm-vmx.stderr.exp   jm-vmx.stdout.exp   jm-vmx.vgtest \
+	mftocrf.stderr.exp mftocrf.stdout.exp mftocrf.vgtest \
 	test_fx.stderr.exp test_fx.stdout.exp test_fx.vgtest \
 	test_gx.stderr.exp test_gx.stdout.exp test_gx.vgtest \
 	testVMX.stderr.exp  testVMX.stdout.exp  testVMX.vgtest \
@@ -13,7 +14,7 @@
 	xlc_dbl_u32.stderr.exp xlc_dbl_u32.stdout.exp xlc_dbl_u32.vgtest
 
 check_PROGRAMS = \
-	lsw jm-insns test_fx test_gx testVMX twi xlc_dbl_u32
+	lsw jm-insns mftocrf test_fx test_gx testVMX twi xlc_dbl_u32
 
 AM_CFLAGS   = $(WERROR) -Winline -Wall -Wshadow -g -I$(top_srcdir)/include \
 		@FLAG_M32@
diff --git a/none/tests/ppc32/mftocrf.c b/none/tests/ppc32/mftocrf.c
new file mode 100644
index 0000000..099fbdf
--- /dev/null
+++ b/none/tests/ppc32/mftocrf.c
@@ -0,0 +1,66 @@
+
+#include <stdio.h>
+
+static
+int try_mtocrf ( int x )
+{
+  int base = 0x31415927;
+  int res;
+
+  /* pre-set CR */
+  __asm__ __volatile__(
+     "mtcr %0"
+     : /*w*/ : /*r*/ "b"(base) : /*trash*/"cc" );
+
+  /* do it */
+  __asm__ __volatile__(
+     "mtocrf 4, %0"
+     : /*w*/ : /*r*/ "b"(x) : /*trash*/"cc" );
+
+  /* get CR */
+  __asm__ __volatile__(
+     "mfcr %0"
+     : /*w*/"=b"(res) : /*r*/ );
+
+  return res;
+}
+
+static
+int try_mfocrf ( int x ) 
+{
+   int res;
+   /* CR = x */
+   __asm__ __volatile__(
+     "mtcr %0"
+     : /*w*/ : /*r*/ "b"(x) : /*trash*/"cc" );
+
+  /* do it */
+  __asm__ __volatile__(
+     "li %0,0\n\t"
+     "mfocrf %0,64"
+     : /*w*/"=b"(res) : /*r*/ );
+
+  return res;
+}
+
+/* This is a bit of a kludge since mfocrf reads the spec'd CR field,
+   but the remaining returned bits are undefined.  It seems like on
+   MPC7447A (Apple Mac Mini) mfocrf just reads the entire CR, which is
+   an acceptable implementation, but is not necessarily what other
+   implementations are going to do. */
+
+int main ( void )
+{
+  int i, j;
+  for (i = 0; i < 32; i++) {
+    printf("0x%08x\n", try_mtocrf( 1<<i ));
+  }
+  printf("\n");
+  j = 1;
+  for (i = 0; i < 32; i++) {
+    printf("0x%08x\n", try_mfocrf( j ));
+    j *= 3;
+  }
+
+  return 0;
+}
diff --git a/none/tests/ppc32/mftocrf.stderr.exp b/none/tests/ppc32/mftocrf.stderr.exp
new file mode 100644
index 0000000..139597f
--- /dev/null
+++ b/none/tests/ppc32/mftocrf.stderr.exp
@@ -0,0 +1,2 @@
+
+
diff --git a/none/tests/ppc32/mftocrf.stdout.exp b/none/tests/ppc32/mftocrf.stdout.exp
new file mode 100644
index 0000000..244cbaf
--- /dev/null
+++ b/none/tests/ppc32/mftocrf.stdout.exp
@@ -0,0 +1,65 @@
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+0x31415127
+0x31415227
+0x31415427
+0x31415827
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+0x31415027
+
+0x00000001
+0x00000003
+0x00000009
+0x0000001b
+0x00000051
+0x000000f3
+0x000002d9
+0x0000088b
+0x000019a1
+0x00004ce3
+0x0000e6a9
+0x0002b3fb
+0x00081bf1
+0x001853d3
+0x0048fb79
+0x00daf26b
+0x0290d741
+0x07b285c3
+0x17179149
+0x4546b3db
+0xcfd41b91
+0x6f7c52b3
+0x4e74f819
+0xeb5ee84b
+0xc21cb8e1
+0x46562aa3
+0xd3027fe9
+0x79077fbb
+0x6b167f31
+0x41437d93
+0xc3ca78b9
+0x4b5f6a2b
diff --git a/none/tests/ppc32/mftocrf.vgtest b/none/tests/ppc32/mftocrf.vgtest
new file mode 100644
index 0000000..43cc124
--- /dev/null
+++ b/none/tests/ppc32/mftocrf.vgtest
@@ -0,0 +1 @@
+prog: mftocrf