Renamed x64 to x86
This commit is contained in:
71
src/x86/Shift_test.go
Normal file
71
src/x86/Shift_test.go
Normal file
@ -0,0 +1,71 @@
|
||||
package x86_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.akyoto.dev/cli/q/src/cpu"
|
||||
"git.akyoto.dev/cli/q/src/x86"
|
||||
"git.akyoto.dev/go/assert"
|
||||
)
|
||||
|
||||
func TestShiftLeftNumber(t *testing.T) {
|
||||
usagePatterns := []struct {
|
||||
Register cpu.Register
|
||||
Number int
|
||||
Code []byte
|
||||
}{
|
||||
{x86.RAX, 1, []byte{0x48, 0xC1, 0xE0, 0x01}},
|
||||
{x86.RCX, 1, []byte{0x48, 0xC1, 0xE1, 0x01}},
|
||||
{x86.RDX, 1, []byte{0x48, 0xC1, 0xE2, 0x01}},
|
||||
{x86.RBX, 1, []byte{0x48, 0xC1, 0xE3, 0x01}},
|
||||
{x86.RSP, 1, []byte{0x48, 0xC1, 0xE4, 0x01}},
|
||||
{x86.RBP, 1, []byte{0x48, 0xC1, 0xE5, 0x01}},
|
||||
{x86.RSI, 1, []byte{0x48, 0xC1, 0xE6, 0x01}},
|
||||
{x86.RDI, 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.RAX, 1, []byte{0x48, 0xC1, 0xF8, 0x01}},
|
||||
{x86.RCX, 1, []byte{0x48, 0xC1, 0xF9, 0x01}},
|
||||
{x86.RDX, 1, []byte{0x48, 0xC1, 0xFA, 0x01}},
|
||||
{x86.RBX, 1, []byte{0x48, 0xC1, 0xFB, 0x01}},
|
||||
{x86.RSP, 1, []byte{0x48, 0xC1, 0xFC, 0x01}},
|
||||
{x86.RBP, 1, []byte{0x48, 0xC1, 0xFD, 0x01}},
|
||||
{x86.RSI, 1, []byte{0x48, 0xC1, 0xFE, 0x01}},
|
||||
{x86.RDI, 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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user