Source file test/codegen/scaledidx.go
1 // asmcheck 2 3 // Copyright 2026 The Go Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 7 package codegen 8 9 // This file contains codegen tests for scaled index addressing 10 // with non-power-of-two slice strides (issue #80639). 11 12 //go:noinline 13 func idx3(p []uint32, x int) uint32 { 14 // arm64: `MOVWU\s*\(R[0-9]+\)\(R[0-9]+<<2\)` 15 // amd64: `MOVL\s*\([A-Z0-9]+\)\([A-Z0-9]+\*4\)` 16 return p[3*x] 17 } 18 19 //go:noinline 20 func idx7(p []uint32, x int) uint32 { 21 // arm64: `MOVWU\s*\(R[0-9]+\)\(R[0-9]+<<2\)` -`SUB\s*R[0-9]+<<2` 22 // amd64: `MOVL\s*\([A-Z0-9]+\)\([A-Z0-9]+\*4\)` 23 return p[7*x] 24 } 25 26 //go:noinline 27 func idx11(p []uint32, x int) uint32 { 28 // arm64: `MOVWU\s*\(R[0-9]+\)\(R[0-9]+<<2\)` 29 // amd64: `MOVL\s*\([A-Z0-9]+\)\([A-Z0-9]+\*4\)` 30 return p[11*x] 31 } 32 33 //go:noinline 34 func idx5_64(p []uint64, x int) uint64 { 35 // arm64: `MOVD\s*\(R[0-9]+\)\(R[0-9]+<<3\)` 36 // amd64: `MOVQ\s*\([A-Z0-9]+\)\([A-Z0-9]+\*8\)` 37 return p[5*x] 38 } 39 40 //go:noinline 41 func idx7_16(p []uint16, x int) uint16 { 42 // arm64: `MOVHU\s*\(R[0-9]+\)\(R[0-9]+<<1\)` -`SUB\s*R[0-9]+<<1` 43 // amd64: `MOVW(L|Q)?ZX\s*\([A-Z0-9]+\)\([A-Z0-9]+\*2\)` 44 return p[7*x] 45 } 46 47 //go:noinline 48 func store7(p []uint32, x int, v uint32) { 49 // arm64: `MOVW\s*R[0-9]+,\s*\(R[0-9]+\)\(R[0-9]+<<2\)` -`SUB\s*R[0-9]+<<2` 50 // amd64: `MOVL\s*[A-Z0-9]+,\s*\([A-Z0-9]+\)\([A-Z0-9]+\*4\)` 51 p[7*x] = v 52 } 53 54 //go:noinline 55 func cse7(p []uint32, x int) uint32 { 56 // arm64: `MOVWU\s*\(R[0-9]+\)\(R[0-9]+<<2\)` -`SUB\s*R[0-9]+<<2` 57 // amd64: `MOVL\s*\([A-Z0-9]+\)\([A-Z0-9]+\*4\)` 58 return p[7*x] + p[7*x+1] 59 } 60 61 //go:noinline 62 func genMath(x int) int { 63 // amd64: `IMUL3?Q\s*[$]28` -`SHLQ\s*[$]2` 64 // arm64: `SUB\s*R[0-9]+<<2` `LSL\s*[$]5` -`LSL\s*[$]2` 65 // riscv64: `(MUL|MADD)` -`SLLI\s*.*,\s*2` 66 return 4 * (7 * x) 67 } 68 69