From: Julian Seward Date: Mon, 8 May 2006 12:08:49 +0000 (+0000) Subject: Tests for 16/32 bit byte reversed loads and stores. X-Git-Tag: svn/VALGRIND_3_2_0~72 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=93ee683509694d39de6416b7c733bd40fb6968f4;p=thirdparty%2Fvalgrind.git Tests for 16/32 bit byte reversed loads and stores. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@5887 --- diff --git a/none/tests/ppc32/Makefile.am b/none/tests/ppc32/Makefile.am index 3fcfdb24cb..ba028f32e2 100644 --- a/none/tests/ppc32/Makefile.am +++ b/none/tests/ppc32/Makefile.am @@ -2,6 +2,7 @@ noinst_SCRIPTS = filter_stderr EXTRA_DIST = $(noinst_SCRIPTS) \ + ldstrev.stderr.exp ldstrev.stdout.exp ldstrev.vgtest \ lsw.stderr.exp lsw.stdout.exp lsw.vgtest \ jm-int.stderr.exp jm-int.stdout.exp jm-int.vgtest \ jm-fp.stderr.exp jm-fp.stdout.exp jm-fp.vgtest \ @@ -15,7 +16,8 @@ EXTRA_DIST = $(noinst_SCRIPTS) \ xlc_dbl_u32.stderr.exp xlc_dbl_u32.stdout.exp xlc_dbl_u32.vgtest check_PROGRAMS = \ - lsw jm-insns mftocrf round test_fx test_gx testVMX twi xlc_dbl_u32 + ldstrev lsw jm-insns mftocrf round 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/ldstrev.c b/none/tests/ppc32/ldstrev.c new file mode 100644 index 0000000000..b29ed6e501 --- /dev/null +++ b/none/tests/ppc32/ldstrev.c @@ -0,0 +1,116 @@ + +#include + +typedef unsigned int UInt; +typedef unsigned short UShort; + +UInt read16le ( void* a ) +{ + UInt res; + __asm volatile( + " lhbrx %0,0,%1 \n" // Get half word and reverse the bytes + : "=b" (res) // %0 - Output operand + : "b" (a) // %1 - Input operand + : "memory" // Consider memory clobberred for aliasing + ); + return res; +} + +UInt read16be ( void* a ) +{ + UInt res; + __asm volatile( + " lhzx %0,0,%1 \n" // Get half word and reverse the bytes + : "=b" (res) // %0 - Output operand + : "b" (a) // %1 - Input operand + : "memory" // Consider memory clobberred for aliasing + ); + return res; +} + +UInt read32le ( void* a ) +{ + UInt res; + __asm volatile( + " lwbrx %0,0,%1 \n" // Get half word and reverse the bytes + : "=b" (res) // %0 - Output operand + : "b" (a) // %1 - Input operand + : "memory" // Consider memory clobberred for aliasing + ); + return res; +} + +UInt read32be ( void* a ) +{ + UInt res; + __asm volatile( + " lwzx %0,0,%1 \n" // Get half word and reverse the bytes + : "=b" (res) // %0 - Output operand + : "b" (a) // %1 - Input operand + : "memory" // Consider memory clobberred for aliasing + ); + return res; +} + +void write16be ( void* a, UInt data ) +{ + __asm volatile( + " sthx %0,0,%1\n" + : + : "b" (data), "b" (a) + : "memory" + ); +} + +void write16le ( void* a, UInt data ) +{ + __asm volatile( + " sthbrx %0,0,%1\n" + : + : "b" (data), "b" (a) + : "memory" + ); +} + +void write32be ( void* a, UInt data ) +{ + __asm volatile( + " stwx %0,0,%1\n" + : + : "b" (data), "b" (a) + : "memory" + ); +} + +void write32le ( void* a, UInt data ) +{ + __asm volatile( + " stwbrx %0,0,%1\n" + : + : "b" (data), "b" (a) + : "memory" + ); +} + +int main ( void ) +{ + UInt foo = 0x12345678; + printf("ld be16 0x%08x\n", read16be( &foo )); + printf("ld le16 0x%08x\n", read16le( &foo )); + printf("ld be32 0x%08x\n", read32be( &foo )); + printf("ld le32 0x%08x\n", read32le( &foo )); + + foo = 0x12345678; write16be( &foo, 0xABCD ); + printf("st be16 0x%08x\n", foo); + + foo = 0x12345678; write16le( &foo, 0xABCD ); + printf("st le16 0x%08x\n", foo); + + foo = 0x12345678; write32be( &foo, 0xABCD1425 ); + printf("st be32 0x%08x\n", foo); + + foo = 0x12345678; write32le( &foo, 0xABCD1425 ); + printf("st le32 0x%08x\n", foo); + + return 0; +} diff --git a/none/tests/ppc32/ldstrev.stderr.exp b/none/tests/ppc32/ldstrev.stderr.exp new file mode 100644 index 0000000000..139597f9cb --- /dev/null +++ b/none/tests/ppc32/ldstrev.stderr.exp @@ -0,0 +1,2 @@ + + diff --git a/none/tests/ppc32/ldstrev.stdout.exp b/none/tests/ppc32/ldstrev.stdout.exp new file mode 100644 index 0000000000..2e079917ef --- /dev/null +++ b/none/tests/ppc32/ldstrev.stdout.exp @@ -0,0 +1,8 @@ +ld be16 0x00001234 +ld le16 0x00003412 +ld be32 0x12345678 +ld le32 0x78563412 +st be16 0xabcd5678 +st le16 0xcdab5678 +st be32 0xabcd1425 +st le32 0x2514cdab diff --git a/none/tests/ppc32/ldstrev.vgtest b/none/tests/ppc32/ldstrev.vgtest new file mode 100644 index 0000000000..0a2dff4c93 --- /dev/null +++ b/none/tests/ppc32/ldstrev.vgtest @@ -0,0 +1 @@ +prog: ldstrev