Added x86 package
All checks were successful
/ test (push) Successful in 14s

This commit is contained in:
Eduard Urbach 2025-06-23 11:45:57 +02:00
parent 31c5ed614c
commit bac5986425
Signed by: akyoto
GPG key ID: 49226B848C78F6C8
61 changed files with 2745 additions and 0 deletions

71
src/x86/Shift_test.go Normal file
View file

@ -0,0 +1,71 @@
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)
}
}