Automate the SME and SME2 instruction check

You inspected the example binary with two disassemblers and checked both comparison binaries for Scalable Matrix Extension (SME) and SME2 instructions. You can now combine the llvm-objdump and awk steps in a reusable script.

Return to the project directory:

    

        
        
cd "$HOME/arm64-extension-inspection"

    

Create verify-static-sme2.sh and make it executable:

    

        
        
cat > verify-static-sme2.sh <<'EOF'
#!/usr/bin/env bash
set -euo pipefail

if [[ $# -lt 1 || $# -gt 2 ]]; then
    printf 'Usage: %s <Mach-O binary> [output directory]\n' "$0" >&2
    exit 2
fi

script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
artifact=$1
evidence_dir=${2:-static-disassembly-evidence}
decoder=${LLVM_OBJDUMP:-$(xcrun -f llvm-objdump)}

mkdir -p "$evidence_dir"

"$decoder" --version > "$evidence_dir/decoder-version.txt"

"$decoder" -d --macho --arch=arm64 --mattr=+sme,+sme2 "$artifact" \
    > "$evidence_dir/llvm-objdump.txt"

awk -f "$script_dir/strict-sme2.awk" \
    "$evidence_dir/llvm-objdump.txt" \
    > "$evidence_dir/strict-sme2-hits.txt"

if [[ ! -s "$evidence_dir/strict-sme2-hits.txt" ]]; then
    printf 'FAIL: no matching SME or SME2 instructions found in %s\n' "$artifact" >&2
    exit 1
fi

printf 'PASS: matching SME or SME2 instructions found in %s\n' "$artifact"
printf 'Results saved to: %s\n' "$evidence_dir"
EOF
chmod +x verify-static-sme2.sh

    

Run the script on the example binary:

    

        
        
./verify-static-sme2.sh sme2-positive evidence-positive

    

The script returns exit status 0 to indicate that it found matching instructions.

The expected output is:

    

        
        PASS: matching SME or SME2 instructions found in sme2-positive
Results saved to: evidence-positive

        
    

Now, run the same check on the string-only comparison binary:

    

        
        
./verify-static-sme2.sh string-only-control evidence-string-only

    

The script returns exit status 1.

The expected output is:

    

        
        FAIL: no matching SME or SME2 instructions found in string-only-control

        
    

This FAIL result is expected because the comparison binary contains no matching instructions. Exit status 1 indicates that the filter found no matches.

These runs create evidence-positive and evidence-string-only inside $HOME/arm64-extension-inspection. The evidence-string-only directory still contains the disassembler version in decoder-version.txt, the disassembly in llvm-objdump.txt, and an empty strict-sme2-hits.txt file.

The positive-control run confirms that the example binary contains matching instructions. It doesn’t show whether the application runs them or whether they improve performance.

Check another binary

To inspect another binary, complete the following steps:

  1. Select the executable or library you plan to distribute.
  2. Select the architecture slice and sections containing executable code.
  3. Decode the instructions with a disassembler configured to recognize the instruction group that you want to check.
  4. Filter the decoded instructions by checking both their names and operands.
  5. Inspect the surrounding function and its symbols.
  6. Summarize which instructions you found and what the checks don’t establish.

In the example binary, both disassemblers found SME and SME2 instructions at matching addresses. These checks don’t show whether the application runs those instructions or whether they improve performance.

Check for other instruction groups

You can apply the same method to other instruction groups such as Scalable Vector Extension (SVE), SVE2, and Dot Product instructions.

To check another instruction group, update the filter to recognize its instruction names and operands. Check the documentation for those instructions rather than relying on names alone.

Test the filter with the following comparison binaries:

  • A binary containing instructions that you want to detect
  • A binary containing similar instructions that shouldn’t match
  • A binary containing related strings and symbol names, but no matching instructions

Compare executable formats

The inspection method also applies to Linux and Windows binaries, but the commands need to match the binary format:

Binary formatCommon platformsWhat to inspect
Mach-OmacOS and iOSThe arm64 slice and sections containing executable code
ELFLinux and AndroidThe AArch64 executable or shared library and its executable code sections
PE/COFFWindows on ArmThe ARM64 executable or library and its executable code sections

Inspect the executable or library that you plan to distribute. Checking the macOS binary doesn’t establish what a separately built Linux or Windows binary contains.

(Optional) Analyze runtime performance with Arm Performix

After disassembling binaries to evaluate whether they contain SME or SME2 instructions, you might need to analyze runtime performance. To do so, use Arm Performix, which is a performance-analysis environment.

Start with static inspection to confirm that the binary contains the instructions that you’re looking for. Then, use Arm Performix on the supported Arm Linux target to learn whether the application ran that code path. Use findings to identify where to focus performance work.

For more information, see the Arm Performix install guide and Arm Performix user guide .

What you’ve accomplished

You’ve automated the check for SME and SME2 instructions in the example binaries with a reusable script.

Apply this workflow to your own executable or library. Remember that finding instructions in a binary doesn’t establish whether your application runs them or whether they improve performance.

Back
Next