github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/engine/wazevo/backend/isa/amd64/reg_test.go (about)

     1  package amd64
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/tetratelabs/wazero/internal/engine/wazevo/backend/regalloc"
     7  	"github.com/tetratelabs/wazero/internal/testing/require"
     8  )
     9  
    10  func Test_formatVRegSize(t *testing.T) {
    11  	tests := []struct {
    12  		r   regalloc.VReg
    13  		_64 bool
    14  		exp string
    15  	}{
    16  		// Real registers.
    17  		{r: raxVReg, _64: true, exp: "%rax"},
    18  		{r: raxVReg, _64: false, exp: "%eax"},
    19  		{r: r15VReg, _64: true, exp: "%r15"},
    20  		{r: r15VReg, _64: false, exp: "%r15d"},
    21  		{r: xmm0VReg, _64: true, exp: "%xmm0"},
    22  		{r: xmm0VReg, _64: false, exp: "%xmm0"},
    23  		{r: xmm15VReg, _64: true, exp: "%xmm15"},
    24  		{r: xmm15VReg, _64: false, exp: "%xmm15"},
    25  		// Non-real registers.
    26  		{r: regalloc.VReg(5555).SetRegType(regalloc.RegTypeInt), _64: true, exp: "%r5555?"},
    27  		{r: regalloc.VReg(5555).SetRegType(regalloc.RegTypeInt), _64: false, exp: "%r5555d?"},
    28  		{r: regalloc.VReg(123).SetRegType(regalloc.RegTypeFloat), _64: true, exp: "%xmm123?"},
    29  		{r: regalloc.VReg(432).SetRegType(regalloc.RegTypeFloat), _64: false, exp: "%xmm432?"},
    30  	}
    31  	for _, tt := range tests {
    32  		t.Run(tt.exp, func(t *testing.T) {
    33  			require.Equal(t, tt.exp, formatVRegSized(tt.r, tt._64))
    34  		})
    35  	}
    36  }