Implemented multiplication
This commit is contained in:
@ -14,22 +14,23 @@ func TestAddRegisterNumber(t *testing.T) {
|
||||
Number int
|
||||
Code []byte
|
||||
}{
|
||||
{x64.RAX, 1, []byte{0x48, 0x83, 0xc0, 0x01}},
|
||||
{x64.RCX, 1, []byte{0x48, 0x83, 0xc1, 0x01}},
|
||||
{x64.RDX, 1, []byte{0x48, 0x83, 0xc2, 0x01}},
|
||||
{x64.RBX, 1, []byte{0x48, 0x83, 0xc3, 0x01}},
|
||||
{x64.RSP, 1, []byte{0x48, 0x83, 0xc4, 0x01}},
|
||||
{x64.RBP, 1, []byte{0x48, 0x83, 0xc5, 0x01}},
|
||||
{x64.RSI, 1, []byte{0x48, 0x83, 0xc6, 0x01}},
|
||||
{x64.RDI, 1, []byte{0x48, 0x83, 0xc7, 0x01}},
|
||||
{x64.R8, 1, []byte{0x49, 0x83, 0xc0, 0x01}},
|
||||
{x64.R9, 1, []byte{0x49, 0x83, 0xc1, 0x01}},
|
||||
{x64.R10, 1, []byte{0x49, 0x83, 0xc2, 0x01}},
|
||||
{x64.R11, 1, []byte{0x49, 0x83, 0xc3, 0x01}},
|
||||
{x64.R12, 1, []byte{0x49, 0x83, 0xc4, 0x01}},
|
||||
{x64.R13, 1, []byte{0x49, 0x83, 0xc5, 0x01}},
|
||||
{x64.R14, 1, []byte{0x49, 0x83, 0xc6, 0x01}},
|
||||
{x64.R15, 1, []byte{0x49, 0x83, 0xc7, 0x01}},
|
||||
{x64.RAX, 1, []byte{0x48, 0x83, 0xC0, 0x01}},
|
||||
{x64.RCX, 1, []byte{0x48, 0x83, 0xC1, 0x01}},
|
||||
{x64.RDX, 1, []byte{0x48, 0x83, 0xC2, 0x01}},
|
||||
{x64.RBX, 1, []byte{0x48, 0x83, 0xC3, 0x01}},
|
||||
{x64.RSP, 1, []byte{0x48, 0x83, 0xC4, 0x01}},
|
||||
{x64.RBP, 1, []byte{0x48, 0x83, 0xC5, 0x01}},
|
||||
{x64.RSI, 1, []byte{0x48, 0x83, 0xC6, 0x01}},
|
||||
{x64.RDI, 1, []byte{0x48, 0x83, 0xC7, 0x01}},
|
||||
{x64.R8, 1, []byte{0x49, 0x83, 0xC0, 0x01}},
|
||||
{x64.R9, 1, []byte{0x49, 0x83, 0xC1, 0x01}},
|
||||
{x64.R10, 1, []byte{0x49, 0x83, 0xC2, 0x01}},
|
||||
{x64.R11, 1, []byte{0x49, 0x83, 0xC3, 0x01}},
|
||||
{x64.R12, 1, []byte{0x49, 0x83, 0xC4, 0x01}},
|
||||
{x64.R13, 1, []byte{0x49, 0x83, 0xC5, 0x01}},
|
||||
{x64.R14, 1, []byte{0x49, 0x83, 0xC6, 0x01}},
|
||||
{x64.R15, 1, []byte{0x49, 0x83, 0xC7, 0x01}},
|
||||
|
||||
{x64.RAX, 0x7FFFFFFF, []byte{0x48, 0x81, 0xC0, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
{x64.RCX, 0x7FFFFFFF, []byte{0x48, 0x81, 0xC1, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
{x64.RDX, 0x7FFFFFFF, []byte{0x48, 0x81, 0xC2, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
|
8
src/build/arch/x64/Mul.go
Normal file
8
src/build/arch/x64/Mul.go
Normal file
@ -0,0 +1,8 @@
|
||||
package x64
|
||||
|
||||
import "git.akyoto.dev/cli/q/src/build/cpu"
|
||||
|
||||
// MulRegNum multiplies a register with a number.
|
||||
func MulRegNum(code []byte, destination cpu.Register, number int) []byte {
|
||||
return numRegReg(code, 0x6B, 0x69, byte(destination), byte(destination), number)
|
||||
}
|
57
src/build/arch/x64/Mul_test.go
Normal file
57
src/build/arch/x64/Mul_test.go
Normal file
@ -0,0 +1,57 @@
|
||||
package x64_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.akyoto.dev/cli/q/src/build/arch/x64"
|
||||
"git.akyoto.dev/cli/q/src/build/cpu"
|
||||
"git.akyoto.dev/go/assert"
|
||||
)
|
||||
|
||||
func TestMulRegisterNumber(t *testing.T) {
|
||||
usagePatterns := []struct {
|
||||
Register cpu.Register
|
||||
Number int
|
||||
Code []byte
|
||||
}{
|
||||
{x64.RAX, 1, []byte{0x48, 0x6B, 0xC0, 0x01}},
|
||||
{x64.RCX, 1, []byte{0x48, 0x6B, 0xC9, 0x01}},
|
||||
{x64.RDX, 1, []byte{0x48, 0x6B, 0xD2, 0x01}},
|
||||
{x64.RBX, 1, []byte{0x48, 0x6B, 0xDB, 0x01}},
|
||||
{x64.RSP, 1, []byte{0x48, 0x6B, 0xE4, 0x01}},
|
||||
{x64.RBP, 1, []byte{0x48, 0x6B, 0xED, 0x01}},
|
||||
{x64.RSI, 1, []byte{0x48, 0x6B, 0xF6, 0x01}},
|
||||
{x64.RDI, 1, []byte{0x48, 0x6B, 0xFF, 0x01}},
|
||||
{x64.R8, 1, []byte{0x4D, 0x6B, 0xC0, 0x01}},
|
||||
{x64.R9, 1, []byte{0x4D, 0x6B, 0xC9, 0x01}},
|
||||
{x64.R10, 1, []byte{0x4D, 0x6B, 0xD2, 0x01}},
|
||||
{x64.R11, 1, []byte{0x4D, 0x6B, 0xDB, 0x01}},
|
||||
{x64.R12, 1, []byte{0x4D, 0x6B, 0xE4, 0x01}},
|
||||
{x64.R13, 1, []byte{0x4D, 0x6B, 0xED, 0x01}},
|
||||
{x64.R14, 1, []byte{0x4D, 0x6B, 0xF6, 0x01}},
|
||||
{x64.R15, 1, []byte{0x4D, 0x6B, 0xFF, 0x01}},
|
||||
|
||||
{x64.RAX, 0x7FFFFFFF, []byte{0x48, 0x69, 0xC0, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
{x64.RCX, 0x7FFFFFFF, []byte{0x48, 0x69, 0xC9, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
{x64.RDX, 0x7FFFFFFF, []byte{0x48, 0x69, 0xD2, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
{x64.RBX, 0x7FFFFFFF, []byte{0x48, 0x69, 0xDB, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
{x64.RSP, 0x7FFFFFFF, []byte{0x48, 0x69, 0xE4, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
{x64.RBP, 0x7FFFFFFF, []byte{0x48, 0x69, 0xED, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
{x64.RSI, 0x7FFFFFFF, []byte{0x48, 0x69, 0xF6, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
{x64.RDI, 0x7FFFFFFF, []byte{0x48, 0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
{x64.R8, 0x7FFFFFFF, []byte{0x4D, 0x69, 0xC0, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
{x64.R9, 0x7FFFFFFF, []byte{0x4D, 0x69, 0xC9, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
{x64.R10, 0x7FFFFFFF, []byte{0x4D, 0x69, 0xD2, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
{x64.R11, 0x7FFFFFFF, []byte{0x4D, 0x69, 0xDB, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
{x64.R12, 0x7FFFFFFF, []byte{0x4D, 0x69, 0xE4, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
{x64.R13, 0x7FFFFFFF, []byte{0x4D, 0x69, 0xED, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
{x64.R14, 0x7FFFFFFF, []byte{0x4D, 0x69, 0xF6, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
{x64.R15, 0x7FFFFFFF, []byte{0x4D, 0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
}
|
||||
|
||||
for _, pattern := range usagePatterns {
|
||||
t.Logf("mul %s, %x", pattern.Register, pattern.Number)
|
||||
code := x64.MulRegNum(nil, pattern.Register, pattern.Number)
|
||||
assert.DeepEqual(t, code, pattern.Code)
|
||||
}
|
||||
}
|
@ -30,6 +30,7 @@ func TestSubRegisterNumber(t *testing.T) {
|
||||
{x64.R13, 1, []byte{0x49, 0x83, 0xED, 0x01}},
|
||||
{x64.R14, 1, []byte{0x49, 0x83, 0xEE, 0x01}},
|
||||
{x64.R15, 1, []byte{0x49, 0x83, 0xEF, 0x01}},
|
||||
|
||||
{x64.RAX, 0x7FFFFFFF, []byte{0x48, 0x81, 0xE8, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
{x64.RCX, 0x7FFFFFFF, []byte{0x48, 0x81, 0xE9, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
{x64.RDX, 0x7FFFFFFF, []byte{0x48, 0x81, 0xEA, 0xFF, 0xFF, 0xFF, 0x7F}},
|
||||
|
Reference in New Issue
Block a user