Source file src/simd/archsimd/_gen/simdgen/sve/analyze_test.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package sve
     6  
     7  import (
     8  	"flag"
     9  	"strings"
    10  	"testing"
    11  )
    12  
    13  // svePath points at an extracted ARM64 ISA XML directory (see the download
    14  // instructions in the package doc / TestRealXMLNoAnomalies). When unset, the
    15  // corpus tests are skipped so the package still tests offline.
    16  var svePath = flag.String("svePath", "", "path to extracted ISA_A64 XML directory")
    17  
    18  // TestRealXMLNoAnomalies runs the loader across the whole SVE instruction set
    19  // and fails if any instruction is classified as an anomaly — a form the loader
    20  // does not understand. Deferred-but-recognized skips (memory, immediate, etc.)
    21  // are allowed. This mirrors how instgen validates against the real XML.
    22  //
    23  // Download the data once:
    24  //
    25  //	curl -L -o isa.tgz https://developer.arm.com/-/cdn-downloads/permalink/Exploration-Tools-A64-ISA/ISA_A64/ISA_A64_xml_A_profile-2025-12.tar.gz
    26  //	tar xzf isa.tgz
    27  //
    28  // then run:
    29  //
    30  //	go test ./simdgen/sve/ -run TestRealXML -svePath ./ISA_A64_xml_A_profile-2025-12 -v
    31  func TestRealXMLNoAnomalies(t *testing.T) {
    32  	if *svePath == "" {
    33  		t.Skip("set -svePath to an extracted ISA_A64 XML directory")
    34  	}
    35  	r, err := analyze(*svePath)
    36  	if err != nil {
    37  		t.Fatal(err)
    38  	}
    39  	t.Logf("\n%s", r.String())
    40  	if len(r.Anomalies) > 0 {
    41  		t.Errorf("loader did not understand %d instruction form(s):\n  %s",
    42  			len(r.Anomalies), strings.Join(r.Anomalies, "\n  "))
    43  	}
    44  }
    45  
    46  // TestRealXMLAddFamily checks that the core Add-family instructions are emitted
    47  // with the expected arrangements against the real XML.
    48  func TestRealXMLAddFamily(t *testing.T) {
    49  	if *svePath == "" {
    50  		t.Skip("set -svePath to an extracted ISA_A64 XML directory")
    51  	}
    52  	insts, err := parseInstructions(*svePath)
    53  	if err != nil {
    54  		t.Fatal(err)
    55  	}
    56  	// mnemonic -> whether we saw it emit at least one def.
    57  	want := map[string]bool{"ADD": false, "FADD": false, "SQADD": false, "UQADD": false}
    58  	for _, inst := range insts {
    59  		m := inst.mnemonic()
    60  		if _, ok := want[m]; !ok {
    61  			continue
    62  		}
    63  		if len(inst.emitAll()) > 0 {
    64  			want[m] = true
    65  		}
    66  	}
    67  	for m, ok := range want {
    68  		if !ok {
    69  			t.Errorf("expected %s to emit at least one def", m)
    70  		}
    71  	}
    72  }
    73  

View as plain text