| 1 |
// Copyright 2017 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 x86 |
| 6 |
|
| 7 |
// argListMax specifies upper arg count limit expected to be carried by obj.Prog. |
| 8 |
// Max len(obj.Prog.RestArgs) can be inferred from this to be 4. |
| 9 |
const argListMax int = 6 |
| 10 |
|
| 11 |
type argList [argListMax]uint8 |
| 12 |
|
| 13 |
type ytab struct { |
| 14 |
zcase uint8 |
| 15 |
zoffset uint8 |
| 16 |
|
| 17 |
// Last arg is usually destination. |
| 18 |
// For unary instructions unaryDst is used to determine |
| 19 |
// if single argument is a source or destination. |
| 20 |
args argList |
| 21 |
} |
| 22 |
|
| 23 |
// Returns true if yt is compatible with args. |
| 24 |
// |
| 25 |
// Elements from args and yt.args are used |
| 26 |
// to index ycover table like `ycover[args[i]+yt.args[i]]`. |
| 27 |
// This means that args should contain values that already |
| 28 |
// multiplied by Ymax. |
| 29 |
func (yt *ytab) match(args []int) bool { |
| 30 |
// Trailing Yxxx check is required to avoid a case |
| 31 |
// where shorter arg list is matched. |
| 32 |
// If we had exact yt.args length, it could be `yt.argc != len(args)`. |
| 33 |
if len(args) < len(yt.args) && yt.args[len(args)] != Yxxx { |
| 34 |
return false |
| 35 |
} |
| 36 |
|
| 37 |
for i := range args { |
| 38 |
if ycover[args[i]+int(yt.args[i])] == 0 { |
| 39 |
return false |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
return true |
| 44 |
} |