From mboxrd@z Thu Jan 1 00:00:00 1970 From: Geoffrey Keating To: cgen@sources.redhat.com Subject: Improvements for GAS testcase generation Date: Wed, 13 Jun 2001 18:20:00 -0000 Message-id: <200106140120.f5E1KFo07703@thief.cygnus.com> X-SW-Source: 2001-q2/msg00087.html This patch changes the GAS testcase generator. The old generator used to pick a few random small integers or a random keyword as operands. The new generator tries to find values that actually fit in the fields, and uses some bit patterns which make it easier to verify that the testcase is correct. The patch was necessary for a Red Hat confidential port. The part had some instructions which had a field width for a register operand that couldn't actually specify all the registers; the extra registers were just not allowed for that operand. OK to commit? -- Geoff Keating ===File ~/patches/cgen-gastestfields.patch================== 2001-06-13 Geoffrey Keating * gas-test.scm (gen-gas-test): Create 8 testcases, not just 5. ( 'test-data): Involve both the index and the hardware in testcase generation. ( 'test-data): Generate test data from the underlying object. ( 'test-data): Generate test data by computing bit patterns for the field, then decoding them. ( 'test-data): Allow for new calling convention. ( 'test-data): Likewise. ( 'test-data): Convert index values into keywords. ( 'test-data): Convert index values into integer strings. Index: devo/cgen/gas-test.scm =================================================================== RCS file: /cvs/cvsfiles/devo/cgen/gas-test.scm,v retrieving revision 1.30 diff -p -u -p -r1.30 gas-test.scm --- gas-test.scm 2001/05/11 02:20:21 1.30 +++ gas-test.scm 2001/06/14 00:57:04 @@ -29,59 +29,94 @@ ; The result is a list of strings to be inserted in the assembler ; in the operand's position. +; For a general assembler operand, just turn the value into a string. (method-make! 'test-data - (lambda (self n) - ; FIXME: floating point support - (let* ((signed (list 0 1 -1 2 -2)) - (unsigned (list 0 1 2 3 4)) - (mode (elm-get self 'mode)) - (test-cases (if (eq? (mode:class mode) 'UINT) unsigned signed)) - (selection (map (lambda (z) (random (length test-cases))) (iota n)))) - ; FIXME: wider ranges. - (map number->string - (map (lambda (n) (list-ref test-cases n)) selection)))) + (lambda (self ops) + (map number->string ops)) ) +; For a keyword operand, choose the appropriate keyword. (method-make! 'test-data - (lambda (self n) + (lambda (self ops) (let* ((test-cases (elm-get self 'values)) - (selection (map (lambda (z) (random (length test-cases))) (iota n))) (prefix (elm-get self 'prefix))) (map (lambda (n) - (string-append - (if (eq? (string-ref prefix 0) #\$) "\\" "") - (elm-get self 'prefix) (car (list-ref test-cases n)))) - selection))) + (string-append + (if (and (not (string=? prefix "")) + (eq? (string-ref prefix 0) #\$)) + "\\" "") + prefix + (car (list-ref test-cases n)))) + ops))) ) (method-make! 'test-data - (lambda (self n) + (lambda (self ops) (let* ((test-cases '("foodata" "4" "footext" "-4")) + (n (length ops)) (selection (map (lambda (z) (random (length test-cases))) (iota n)))) (map (lambda (n) (list-ref test-cases n)) selection))) ) (method-make! 'test-data - (lambda (self n) + (lambda (self ops) (let* ((test-cases '("footext" "4" "foodata" "-4")) + (n (length ops)) (selection (map (lambda (z) (random (length test-cases))) (iota n)))) (map (lambda (n) (list-ref test-cases n)) selection))) ) (method-make-forward! 'indices '(test-data)) (method-make-forward! 'values '(test-data)) + +; Test data for a field is chosen firstly out of some bit patterns, +; then randomly. It is then interpreted based on whether there +; is a decode method. +(method-make! + 'test-data + (lambda (self n) + (let* ((bf-len (ifld-length self)) + (field-max (inexact->exact (round (expt 2 bf-len)))) + (highbit (quotient field-max 2)) + (values (map (lambda (n) + (case n + ((0) 0) + ((1) (- field-max 1)) + ((2) highbit) + ((3) (- highbit 1)) + ((4) 1) + (else (random field-max)))) + (iota n))) + (decode (ifld-decode self))) + (if decode + ; FIXME: need to run the decoder. + values + ; no decode method + (case (mode:class (ifld-mode self)) + ((INT) (map (lambda (n) (if (>= n highbit) (- n field-max) n)) + values)) + ((UINT) values) + (else (error "unsupported mode class" + (mode:class (ifld-mode self)))))))) +) -; This can't use method-make-forward! as we need to call op:type to -; resolve the hardware reference. +(method-make! + 'test-data + (lambda (self n) + (case (hw-index:type self) + ((ifield operand) (send (hw-index:value self) 'test-data n)) + ((constant) (hw-index:value self)) + (else nil))) +) (method-make! 'test-data (lambda (self n) - (send (op:type self) 'test-data n)) + (send (op:type self) 'test-data (send (op:index self) 'test-data n))) ) ; Given an operand, return a set of N test data. @@ -152,7 +187,7 @@ (gen-sym insn) ":\n" (let* ((syntax-list (insn-tmp insn)) (op-list (extract-operands syntax-list)) - (test-set (build-test-set op-list 5))) + (test-set (build-test-set op-list 8))) (string-map (lambda (test-data) (build-asm-testcase syntax-list test-data)) test-set)) ============================================================