From: Florian Krohm Date: Mon, 6 Aug 2012 00:10:53 +0000 (+0000) Subject: Add a testcase for the cu41 insn. Update opcode list, NEWS and bugstatus. X-Git-Tag: svn/VALGRIND_3_8_0~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1d7df01e1841e68fdc069f976b120ae0f714c89;p=thirdparty%2Fvalgrind.git Add a testcase for the cu41 insn. Update opcode list, NEWS and bugstatus. #289839 is finally fixed. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12851 --- diff --git a/NEWS b/NEWS index 9dcf525ab5..10bfa1de50 100644 --- a/NEWS +++ b/NEWS @@ -182,6 +182,7 @@ where XXXXXX is the bug number as listed below. 289656 == 273475 (Add support for AVX instructions) 289699 vgdb connection in relay mode erroneously closed due to buffer overrun 289823 == 293754 (PCMPxSTRx not implemented for 16-bit characters) +289839 s390x: Provide support for unicode conversion instructions 289939 monitor cmd 'leak_check' with details about leaked or reachable blocks 290006 memcheck doesn't mark %xmm as initialized after "pcmpeqw %xmm %xmm" 290655 Add support for AESKEYGENASSIST instruction diff --git a/docs/internals/3_7_BUGSTATUS.txt b/docs/internals/3_7_BUGSTATUS.txt index 80e1a51a8d..a86836fd04 100644 --- a/docs/internals/3_7_BUGSTATUS.txt +++ b/docs/internals/3_7_BUGSTATUS.txt @@ -71,10 +71,6 @@ get fixed. 289836 Unhanded instructions mfatbu and mfatbl ppc e500 insns -289839 s390x:Provide support for unicode conversion instruction - like cu21,cu12,cu42 etc. - s390 This will not be ready for 3.8.0 - 289912 link_tool_exe_darwin should not use relative paths unsupported build configuration; low prio diff --git a/docs/internals/s390-opcodes.csv b/docs/internals/s390-opcodes.csv index ff6f1352ac..e5bdbd0b85 100644 --- a/docs/internals/s390-opcodes.csv +++ b/docs/internals/s390-opcodes.csv @@ -662,7 +662,7 @@ lptea,"load page-table-entry address",N/A,"privileged instruction" cu24,"convert utf-16 to utf-32",implemented cu21,"convert utf-16 to utf-8",implemented cu42,"convert utf-32 to utf-16",implemented -cu41,"convert utf-32 to utf-8","not implemented","open bugzilla" +cu41,"convert utf-32 to utf-8",implemented cu12,"convert utf-8 to utf-16",implemented cu14,"convert utf-8 to utf-32",implemented srstu,"search string unicode","not implemented", diff --git a/none/tests/s390x/Makefile.am b/none/tests/s390x/Makefile.am index e32bfd6909..399a8295c7 100644 --- a/none/tests/s390x/Makefile.am +++ b/none/tests/s390x/Makefile.am @@ -8,7 +8,7 @@ INSN_TESTS = clc clcle cvb cvd icm lpr tcxb lam_stam xc mvst add sub mul \ op_exception fgx stck stckf stcke stfle cksm mvcl clcl troo \ trto trot trtt tr tre cij cgij clij clgij crj cgrj clrj clgrj \ cs csg cds cdsg cu21 cu21_1 cu24 cu24_1 cu42 cu12 cu12_1 \ - ex_sig ex_clone cu14 cu14_1 + ex_sig ex_clone cu14 cu14_1 cu41 check_PROGRAMS = $(INSN_TESTS) \ allexec \ diff --git a/none/tests/s390x/cu41.c b/none/tests/s390x/cu41.c new file mode 100644 index 0000000000..d6a2f7aeba --- /dev/null +++ b/none/tests/s390x/cu41.c @@ -0,0 +1,259 @@ +#include +#include +#include +#include +#include +#include +#include "opcodes.h" + +/* The abstracted result of an CU41 insn */ +typedef struct { + uint64_t addr1; // target + uint64_t len1; + uint64_t addr2; // source + uint64_t len2; + uint32_t cc; +} cu41_t; + +/* Define various input buffers. */ + +/* 0000 to 00ff: Result is 1 byte for each uint32_t */ +uint32_t pattern1[] = { + 0x0000, 0x007f, /* corner cases */ + 0x0001, 0x007e, 0x0030, 0x005e /* misc */ +}; + +/* 0080 to 07ff: Result is 2 bytes for each uint32_t */ +uint32_t pattern2[] = { + 0x0080, 0x07ff, /* corner cases */ + 0x0081, 0x07fe, 0x100, 0x333, 0x555, 0x6aa /* misc */ +}; + +/* 0800 to d7ff: Result is 3 bytes for each uint32_t */ +/* dc00 to ffff: Result is 3 bytes for each uint32_t */ +uint32_t pattern3[] = { + 0x0800, 0xd7ff, /* corner cases */ + 0xdc00, 0xffff, /* corner cases */ + 0xdc01, 0xfffe, 0xdea0, 0xd00d, 0xe555 /* misc */ +}; + +/* 10000 to 10ffff: Result is 4 bytes for each uint32_t */ +uint32_t pattern4[] = { + 0x10000, 0x10ffff, /* corner cases */ + 0x10001, 0x10fffe, 0x12345, 0x23456, 0xfedcb /* misc */ +}; + +/* Invalid UTF-32 character */ +uint32_t invalid[] = { + 0x0000d800, 0x0000dbff, /* corner cases */ + 0x00110000, 0xffffffff, /* corner cases */ + 0x0000daad, 0x0000d901, 0x0000d8ff, /* misc */ + 0x00110011, 0x01000000, 0x10000000, 0xdeadbeef /* misc */ +}; + +/* Mixed bytes */ +uint32_t mixed[] = { + 0x00000078 /* 1 byte */, + 0x00000111 /* 2 bytes */, + 0x00001234 /* 3 bytes */, + 0x00040404 /* 4 bytes */, +}; + +/* This is the buffer for the converted bytes. */ +uint8_t buff[1000]; /* Large so we con'don't have to worry about it */ + +void write_and_check(uint32_t *, unsigned, unsigned); + + +static cu41_t +do_cu41(uint8_t *dst, uint64_t dst_len, uint32_t *src, uint64_t src_len) +{ + int cc = 42; + cu41_t regs; + + /* build up the register pairs */ + register uint32_t *source asm("4") = src; + register uint64_t source_len asm("5") = src_len; + register uint8_t *dest asm("2") = dst; + register uint64_t dest_len asm("3") = dst_len; + + asm volatile( + CU41(2,4) + "ipm %2\n\t" + "srl %2,28\n\t" + : "+d"(dest), "+d"(source), "=d"(cc), + "+d"(source_len), "+d"(dest_len) + : + : "memory", "cc"); + + /* Capture register contents at end of cu41 */ + regs.addr1 = (uint64_t)dest; + regs.len1 = dest_len; + regs.addr2 = (uint64_t)source; + regs.len2 = source_len; + regs.cc = cc; + + return regs; +} + +void +run_test(uint8_t *dst, uint64_t dst_len, uint32_t *src, uint64_t src_len) +{ + int i; + cu41_t result; + + result = do_cu41(dst, dst_len, src, src_len); + + // Write out the converted values, if any + printf("UTF8: "); + if (dst_len - result.len1 == 0) + printf(" "); + else + for (i = 0; i < dst_len - result.len1; ++i) { + printf(" %02x", dst[i]); + } + printf("\n"); + + printf(" cc = %d\n", result.cc); + if (dst != NULL) + printf(" dst address difference: %"PRId64, result.addr1 - (uint64_t)dst); + printf(" dst len: %"PRId64"\n", result.len1); + + if (src != NULL) + printf(" src address difference: %"PRId64, result.addr2 - (uint64_t)src); + printf(" src len: %"PRId64"\n", result.len2); +} + +int main() +{ + int i; + + /* Length == 0, no memory should be read or written */ + printf("\n------------- test1 ----------------\n"); + run_test(NULL, 0, NULL, 0); + + /* Test exhaustion of source length (source bytes are valid) */ + printf("\n------------- test2.1 ----------------\n"); + + /* No character will be written to BUFF, i.e. loop in jitted code + is not iterated */ + run_test(buff, sizeof buff, NULL, 0); + run_test(buff, sizeof buff, NULL, 1); + run_test(buff, sizeof buff, NULL, 2); + run_test(buff, sizeof buff, NULL, 3); + run_test(buff, sizeof buff, pattern1, 0); + run_test(buff, sizeof buff, pattern1, 1); + run_test(buff, sizeof buff, pattern1, 2); + run_test(buff, sizeof buff, pattern1, 3); + + printf("\n------------- test2.2 ----------------\n"); + /* At least one character will be written to BUFF, i.e. loop in jitted + code is iterated */ + run_test(buff, sizeof buff, pattern1, 4); /* 1 utf32 -> 1 1-byte utf8 */ + run_test(buff, sizeof buff, pattern2, 10); /* 2 utf32 -> 2 2-byte utf8 */ + run_test(buff, sizeof buff, pattern3, 5); /* 1 utf32 -> 1 3-byte utf8 */ + run_test(buff, sizeof buff, pattern4, 21); /* 5 utf32 -> 5 4-byte utf8 */ + + /* Test exhaustion of destination length (source bytes are valid) */ + printf("\n------------- test3.1 ----------------\n"); + + /* No character will be written to BUFF, i.e. loop in jitted code + is not iterated */ + + /* Want to write at least 1 byte */ + run_test(NULL, 0, pattern1, sizeof pattern1); + + /* Want to write at least 2 bytes */ + run_test(NULL, 0, pattern2, sizeof pattern2); + run_test(NULL, 1, pattern2, sizeof pattern2); + + /* Want to write at least 3 bytes */ + run_test(NULL, 0, pattern3, sizeof pattern3); + run_test(NULL, 1, pattern3, sizeof pattern3); + + /* Want to write at least 4 bytes */ + run_test(NULL, 0, pattern4, sizeof pattern4); + run_test(NULL, 1, pattern4, sizeof pattern4); + run_test(NULL, 2, pattern4, sizeof pattern4); + run_test(NULL, 3, pattern4, sizeof pattern4); + + /* When both operands are exhausted, cc=0 takes precedence. + (test1 tests this for len == 0) */ + printf("\n------------- test4 ----------------\n"); + run_test(buff, 2, pattern1, 8); + + /* Input contains invalid characters */ + + // As conversion stops upon encountering an invalid character, we + // need to test each invalid character separately, to make sure it + // is recognized as invalid. + + printf("\n------------- test5 ----------------\n"); + for (i = 0; i < sizeof invalid / 4; ++i) { + run_test(buff, sizeof buff, invalid + i, 4); + } + run_test(buff, 0, invalid, sizeof invalid); // cc = 2 + run_test(buff, 100, invalid, sizeof invalid); + + /* Convert all pattern buffers */ + printf("\n------------- test6 ----------------\n"); + run_test(buff, sizeof buff, pattern1, sizeof pattern1); + run_test(buff, sizeof buff, pattern2, sizeof pattern2); + run_test(buff, sizeof buff, pattern3, sizeof pattern3); + run_test(buff, sizeof buff, pattern4, sizeof pattern4); + run_test(buff, sizeof buff, mixed, sizeof mixed); + + /* Make sure we only write the exact number of bytes (and not more) */ + + /* Write 1 byte */ + printf("\n------------- test7.0 ----------------\n"); + write_and_check(pattern1 + 2, 4, 1); + + /* Write 2 bytes */ + printf("\n------------- test7.1 ----------------\n"); + write_and_check(pattern2 + 3, 4, 2); + + /* Write 3 bytes */ + printf("\n------------- test7.2 ----------------\n"); + write_and_check(pattern3 + 6, 4, 3); + + /* Write 4 bytes */ + printf("\n------------- test7.3 ----------------\n"); + write_and_check(pattern4 + 5, 4, 4); + + return 0; +} + + +void +write_and_check_aux(uint32_t *input, unsigned num_input_bytes, + unsigned num_expected_output_bytes, + unsigned fill_byte) +{ + int num_errors, i; + + /* Fill output buffer with FILL_BYTE */ + memset(buff, fill_byte, sizeof buff); + + /* Execute cu41 */ + run_test(buff, sizeof buff, input, num_input_bytes); + + /* Make sure the rest of the buffer is unmodified. */ + num_errors = 0; + for (i = num_expected_output_bytes; i < sizeof buff; ++i) + if (((unsigned char *)buff)[i] != fill_byte) ++num_errors; + if (num_errors) + fprintf(stderr, "*** wrote more than %d bytes\n", + num_expected_output_bytes); +} + +void +write_and_check(uint32_t *input, unsigned num_input_bytes, + unsigned num_expected_output_bytes) +{ + write_and_check_aux(input, num_input_bytes, num_expected_output_bytes, 0x0); + + /* Run again with different fill pattern to make sure we did not write + an extra 0x0 byte */ + write_and_check_aux(input, num_input_bytes, num_expected_output_bytes, 0xFF); +} diff --git a/none/tests/s390x/cu41.stderr.exp b/none/tests/s390x/cu41.stderr.exp new file mode 100644 index 0000000000..139597f9cb --- /dev/null +++ b/none/tests/s390x/cu41.stderr.exp @@ -0,0 +1,2 @@ + + diff --git a/none/tests/s390x/cu41.stdout.exp b/none/tests/s390x/cu41.stdout.exp new file mode 100644 index 0000000000..c7fa41f463 --- /dev/null +++ b/none/tests/s390x/cu41.stdout.exp @@ -0,0 +1,218 @@ + +------------- test1 ---------------- +UTF8: + cc = 0 + dst len: 0 + src len: 0 + +------------- test2.1 ---------------- +UTF8: + cc = 0 + dst address difference: 0 dst len: 1000 + src len: 0 +UTF8: + cc = 0 + dst address difference: 0 dst len: 1000 + src len: 1 +UTF8: + cc = 0 + dst address difference: 0 dst len: 1000 + src len: 2 +UTF8: + cc = 0 + dst address difference: 0 dst len: 1000 + src len: 3 +UTF8: + cc = 0 + dst address difference: 0 dst len: 1000 + src address difference: 0 src len: 0 +UTF8: + cc = 0 + dst address difference: 0 dst len: 1000 + src address difference: 0 src len: 1 +UTF8: + cc = 0 + dst address difference: 0 dst len: 1000 + src address difference: 0 src len: 2 +UTF8: + cc = 0 + dst address difference: 0 dst len: 1000 + src address difference: 0 src len: 3 + +------------- test2.2 ---------------- +UTF8: 00 + cc = 0 + dst address difference: 1 dst len: 999 + src address difference: 4 src len: 0 +UTF8: c2 80 df bf + cc = 0 + dst address difference: 4 dst len: 996 + src address difference: 8 src len: 2 +UTF8: e0 a0 80 + cc = 0 + dst address difference: 3 dst len: 997 + src address difference: 4 src len: 1 +UTF8: f0 90 80 80 f4 8f bf bf f0 90 80 81 f4 8f bf be f0 92 8d 85 + cc = 0 + dst address difference: 20 dst len: 980 + src address difference: 20 src len: 1 + +------------- test3.1 ---------------- +UTF8: + cc = 1 + dst len: 0 + src address difference: 0 src len: 24 +UTF8: + cc = 1 + dst len: 0 + src address difference: 0 src len: 32 +UTF8: + cc = 1 + dst len: 1 + src address difference: 0 src len: 32 +UTF8: + cc = 1 + dst len: 0 + src address difference: 0 src len: 36 +UTF8: + cc = 1 + dst len: 1 + src address difference: 0 src len: 36 +UTF8: + cc = 1 + dst len: 0 + src address difference: 0 src len: 28 +UTF8: + cc = 1 + dst len: 1 + src address difference: 0 src len: 28 +UTF8: + cc = 1 + dst len: 2 + src address difference: 0 src len: 28 +UTF8: + cc = 1 + dst len: 3 + src address difference: 0 src len: 28 + +------------- test4 ---------------- +UTF8: 00 7f + cc = 0 + dst address difference: 2 dst len: 0 + src address difference: 8 src len: 0 + +------------- test5 ---------------- +UTF8: + cc = 2 + dst address difference: 0 dst len: 1000 + src address difference: 0 src len: 4 +UTF8: + cc = 2 + dst address difference: 0 dst len: 1000 + src address difference: 0 src len: 4 +UTF8: + cc = 2 + dst address difference: 0 dst len: 1000 + src address difference: 0 src len: 4 +UTF8: + cc = 2 + dst address difference: 0 dst len: 1000 + src address difference: 0 src len: 4 +UTF8: + cc = 2 + dst address difference: 0 dst len: 1000 + src address difference: 0 src len: 4 +UTF8: + cc = 2 + dst address difference: 0 dst len: 1000 + src address difference: 0 src len: 4 +UTF8: + cc = 2 + dst address difference: 0 dst len: 1000 + src address difference: 0 src len: 4 +UTF8: + cc = 2 + dst address difference: 0 dst len: 1000 + src address difference: 0 src len: 4 +UTF8: + cc = 2 + dst address difference: 0 dst len: 1000 + src address difference: 0 src len: 4 +UTF8: + cc = 2 + dst address difference: 0 dst len: 1000 + src address difference: 0 src len: 4 +UTF8: + cc = 2 + dst address difference: 0 dst len: 1000 + src address difference: 0 src len: 4 +UTF8: + cc = 2 + dst address difference: 0 dst len: 0 + src address difference: 0 src len: 44 +UTF8: + cc = 2 + dst address difference: 0 dst len: 100 + src address difference: 0 src len: 44 + +------------- test6 ---------------- +UTF8: 00 7f 01 7e 30 5e + cc = 0 + dst address difference: 6 dst len: 994 + src address difference: 24 src len: 0 +UTF8: c2 80 df bf c2 81 df be c4 80 cc b3 d5 95 da aa + cc = 0 + dst address difference: 16 dst len: 984 + src address difference: 32 src len: 0 +UTF8: e0 a0 80 ed 9f bf ed b0 80 ef bf bf ed b0 81 ef bf be ed ba a0 ed 80 8d ee 95 95 + cc = 0 + dst address difference: 27 dst len: 973 + src address difference: 36 src len: 0 +UTF8: f0 90 80 80 f4 8f bf bf f0 90 80 81 f4 8f bf be f0 92 8d 85 f0 a3 91 96 f3 be b7 8b + cc = 0 + dst address difference: 28 dst len: 972 + src address difference: 28 src len: 0 +UTF8: 78 c4 91 e1 88 b4 f1 80 90 84 + cc = 0 + dst address difference: 10 dst len: 990 + src address difference: 16 src len: 0 + +------------- test7.0 ---------------- +UTF8: 01 + cc = 0 + dst address difference: 1 dst len: 999 + src address difference: 4 src len: 0 +UTF8: 01 + cc = 0 + dst address difference: 1 dst len: 999 + src address difference: 4 src len: 0 + +------------- test7.1 ---------------- +UTF8: df be + cc = 0 + dst address difference: 2 dst len: 998 + src address difference: 4 src len: 0 +UTF8: df be + cc = 0 + dst address difference: 2 dst len: 998 + src address difference: 4 src len: 0 + +------------- test7.2 ---------------- +UTF8: ed ba a0 + cc = 0 + dst address difference: 3 dst len: 997 + src address difference: 4 src len: 0 +UTF8: ed ba a0 + cc = 0 + dst address difference: 3 dst len: 997 + src address difference: 4 src len: 0 + +------------- test7.3 ---------------- +UTF8: f0 a3 91 96 + cc = 0 + dst address difference: 4 dst len: 996 + src address difference: 4 src len: 0 +UTF8: f0 a3 91 96 + cc = 0 + dst address difference: 4 dst len: 996 + src address difference: 4 src len: 0 diff --git a/none/tests/s390x/cu41.vgtest b/none/tests/s390x/cu41.vgtest new file mode 100644 index 0000000000..815e59445e --- /dev/null +++ b/none/tests/s390x/cu41.vgtest @@ -0,0 +1 @@ +prog: cu41