q/src/x86/Shift_test.go

72 lines
2.3 KiB
Go

package x86_test
import (
"testing"
"git.urbach.dev/cli/q/src/cpu"
"git.urbach.dev/cli/q/src/x86"
"git.urbach.dev/go/assert"
)
func TestShiftLeftNumber(t *testing.T) {
usagePatterns := []struct {
Register cpu.Register
Number int
Code []byte
}{
{x86.R0, 1, []byte{0x48, 0xC1, 0xE0, 0x01}},
{x86.R1, 1, []byte{0x48, 0xC1, 0xE1, 0x01}},
{x86.R2, 1, []byte{0x48, 0xC1, 0xE2, 0x01}},
{x86.R3, 1, []byte{0x48, 0xC1, 0xE3, 0x01}},
{x86.SP, 1, []byte{0x48, 0xC1, 0xE4, 0x01}},
{x86.R5, 1, []byte{0x48, 0xC1, 0xE5, 0x01}},
{x86.R6, 1, []byte{0x48, 0xC1, 0xE6, 0x01}},
{x86.R7, 1, []byte{0x48, 0xC1, 0xE7, 0x01}},
{x86.R8, 1, []byte{0x49, 0xC1, 0xE0, 0x01}},
{x86.R9, 1, []byte{0x49, 0xC1, 0xE1, 0x01}},
{x86.R10, 1, []byte{0x49, 0xC1, 0xE2, 0x01}},
{x86.R11, 1, []byte{0x49, 0xC1, 0xE3, 0x01}},
{x86.R12, 1, []byte{0x49, 0xC1, 0xE4, 0x01}},
{x86.R13, 1, []byte{0x49, 0xC1, 0xE5, 0x01}},
{x86.R14, 1, []byte{0x49, 0xC1, 0xE6, 0x01}},
{x86.R15, 1, []byte{0x49, 0xC1, 0xE7, 0x01}},
}
for _, pattern := range usagePatterns {
t.Logf("shl %s, %x", pattern.Register, pattern.Number)
code := x86.ShiftLeftNumber(nil, pattern.Register, byte(pattern.Number))
assert.DeepEqual(t, code, pattern.Code)
}
}
func TestShiftRightSignedNumber(t *testing.T) {
usagePatterns := []struct {
Register cpu.Register
Number int
Code []byte
}{
{x86.R0, 1, []byte{0x48, 0xC1, 0xF8, 0x01}},
{x86.R1, 1, []byte{0x48, 0xC1, 0xF9, 0x01}},
{x86.R2, 1, []byte{0x48, 0xC1, 0xFA, 0x01}},
{x86.R3, 1, []byte{0x48, 0xC1, 0xFB, 0x01}},
{x86.SP, 1, []byte{0x48, 0xC1, 0xFC, 0x01}},
{x86.R5, 1, []byte{0x48, 0xC1, 0xFD, 0x01}},
{x86.R6, 1, []byte{0x48, 0xC1, 0xFE, 0x01}},
{x86.R7, 1, []byte{0x48, 0xC1, 0xFF, 0x01}},
{x86.R8, 1, []byte{0x49, 0xC1, 0xF8, 0x01}},
{x86.R9, 1, []byte{0x49, 0xC1, 0xF9, 0x01}},
{x86.R10, 1, []byte{0x49, 0xC1, 0xFA, 0x01}},
{x86.R11, 1, []byte{0x49, 0xC1, 0xFB, 0x01}},
{x86.R12, 1, []byte{0x49, 0xC1, 0xFC, 0x01}},
{x86.R13, 1, []byte{0x49, 0xC1, 0xFD, 0x01}},
{x86.R14, 1, []byte{0x49, 0xC1, 0xFE, 0x01}},
{x86.R15, 1, []byte{0x49, 0xC1, 0xFF, 0x01}},
}
for _, pattern := range usagePatterns {
t.Logf("sar %s, %x", pattern.Register, pattern.Number)
code := x86.ShiftRightSignedNumber(nil, pattern.Register, byte(pattern.Number))
assert.DeepEqual(t, code, pattern.Code)
}
}