github.com/cloudwego/iasm@v0.2.0/x86_64/instructions_test.go (about) 1 // 2 // Copyright 2024 CloudWeGo Authors 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 package x86_64 18 19 import ( 20 `testing` 21 22 `github.com/davecgh/go-spew/spew` 23 ) 24 25 func TestInstr_Encode(t *testing.T) { 26 m := []byte(nil) 27 a := CreateArch() 28 p := a.CreateProgram() 29 p.VPERMIL2PD(7, Sib(R8, R9, 1, 12345), YMM1, YMM2, YMM3).encode(&m) 30 spew.Dump(m) 31 } 32 33 func TestInstr_EncodeSegment(t *testing.T) { 34 m := []byte(nil) 35 a := CreateArch() 36 p := a.CreateProgram() 37 p.MOVQ(Abs(0x30), RCX).GS().encode(&m) 38 spew.Dump(m) 39 } 40 41 func BenchmarkInstr_Encode(b *testing.B) { 42 a := CreateArch() 43 m := make([]byte, 0, 16) 44 p := a.CreateProgram() 45 p.VPERMIL2PD(7, Sib(R8, R9, 1, 12345), YMM1, YMM2, YMM3).encode(&m) 46 p.Free() 47 b.SetBytes(int64(len(m))) 48 b.ResetTimer() 49 for i := 0; i < b.N; i++ { 50 m = m[:0] 51 p = a.CreateProgram() 52 p.VPERMIL2PD(7, Sib(R8, R9, 1, 12345), YMM1, YMM2, YMM3).encode(&m) 53 p.Free() 54 } 55 }