amd64
所属分类:嵌入式/单片机/硬件编程
开发工具:GO
文件大小:25KB
下载次数:0
上传日期:2018-03-09 08:58:07
上 传 者:
sh-1993
说明: amd64指令汇编程序
(amd64 instruction assembler)
文件列表:
.travis.yml (159, 2018-03-09)
LICENSE (11357, 2018-03-09)
assembler.go (3596, 2018-03-09)
coverage.txt (30145, 2018-03-09)
cpuid.go (2325, 2018-03-09)
cpuid_amd64.go (814, 2018-03-09)
cpuid_amd64.s (1921, 2018-03-09)
dump.go (1297, 2018-03-09)
encoding.go (2924, 2018-03-09)
instruction.go (2738, 2018-03-09)
instructions.go (4737, 2018-03-09)
modrm.go (285, 2018-03-09)
operand.go (6616, 2018-03-09)
operands.go (5862, 2018-03-09)
prefix.go (883, 2018-03-09)
test.sh (298, 2018-03-09)
tests (0, 2018-03-09)
tests\add_test.go (1378, 2018-03-09)
tests\aka.go (105, 2018-03-09)
tests\assembler_test.go (3238, 2018-03-09)
tests\dec_test.go (485, 2018-03-09)
tests\inc_test.go (3607, 2018-03-09)
tests\mov_test.go (337, 2018-03-09)
tests\movaps_test.go (1710, 2018-03-09)
tests\reg_test.go (1298, 2018-03-09)
tests\sib_test.go (1779, 2018-03-09)
tests\simd_test.go (6193, 2018-03-09)
# AMD*** Instruction Assembler
[![Sourcegraph](https://sourcegraph.com/github.com/modern-go/amd***/-/badge.svg)](https://sourcegraph.com/github.com/modern-go/amd***?badge)
[![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](http://godoc.org/github.com/modern-go/amd***)
[![Build Status](https://travis-ci.org/modern-go/amd***.svg?branch=master)](https://travis-ci.org/modern-go/amd***)
[![codecov](https://codecov.io/gh/modern-go/amd***/branch/master/graph/badge.svg)](https://codecov.io/gh/modern-go/amd***)
[![rcard](https://goreportcard.com/badge/github.com/modern-go/amd***)](https://goreportcard.com/report/github.com/modern-go/amd***)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://raw.githubusercontent.com/modern-go/amd***/master/LICENSE)
* generate code during runtime: assembler, but run in your process
* Go assembly does not support all SIMD instruction
This does not support all instructions yet.
But it has laid a ground work on instruction encoding abstraction.
New instruction will be added on demand basis.
# Tutorial
```go
import . "github.com/modern-go/amd***"
asm := &Assembler{}
asm.Assemble(
// RAX = i
MOV, RAX, QWORD(RSP, 0x08),
// j = RAX
MOV, QWORD(RSP, 0x10), RAX,
// return j
RET,
)
// ident func does nothing
// return identical value out
var ident func(i int) (j int)
asm.MakeFunc(&ident)
fmt.Println(ident(100)) // will print 100
```
# SIMD
```go
asm := &Assembler{}
asm.Assemble(
MOV, RDI, QWORD(RSP, 8),
MOV, RSI, QWORD(RSP, 16),
MOVD, XMM0, EDI,
VPBROADCASTD, XMM0, XMM0,
VPCMPEQD, XMM1, XMM0, XMMWORD(RSI, 0),
VPCMPEQD, XMM2, XMM0, XMMWORD(RSI, 0x10),
VPCMPEQD, XMM3, XMM0, XMMWORD(RSI, 0x20),
VPCMPEQD, XMM4, XMM0, XMMWORD(RSI, 0x30),
VPACKSSDW, XMM1, XMM1, XMM2,
VPACKSSDW, XMM2, XMM3, XMM4,
VPACKSSWB, XMM1, XMM1, XMM2,
VPMOVMSKB, ECX, XMM1,
VPCMPEQD, XMM1, XMM0, XMMWORD(RSI, 0x40),
VPCMPEQD, XMM2, XMM0, XMMWORD(RSI, 0x50),
VPCMPEQD, XMM3, XMM0, XMMWORD(RSI, 0x60),
VPCMPEQD, XMM4, XMM0, XMMWORD(RSI, 0x70),
VPACKSSDW, XMM1, XMM1, XMM2,
VPACKSSDW, XMM2, XMM3, XMM4,
VPACKSSWB, XMM1, XMM1, XMM2,
VPMOVMSKB, EAX, XMM1,
VPCMPEQD, XMM1, XMM0, XMMWORD(RSI, 0x80),
VPCMPEQD, XMM2, XMM0, XMMWORD(RSI, 0x90),
VPCMPEQD, XMM3, XMM0, XMMWORD(RSI, 0xa0),
VPCMPEQD, XMM4, XMM0, XMMWORD(RSI, 0xb0),
VPACKSSDW, XMM1, XMM1, XMM2,
VPACKSSDW, XMM2, XMM3, XMM4,
VPACKSSWB, XMM1, XMM1, XMM2,
VPMOVMSKB, EDX, XMM1,
VPCMPEQD, XMM1, XMM0, XMMWORD(RSI, 0xc0),
VPCMPEQD, XMM2, XMM0, XMMWORD(RSI, 0xd0),
VPCMPEQD, XMM3, XMM0, XMMWORD(RSI, 0xe0),
VPCMPEQD, XMM0, XMM0, XMMWORD(RSI, 0xf0),
VPACKSSDW, XMM1, XMM1, XMM2,
VPACKSSDW, XMM0, XMM3, XMM0,
VPACKSSWB, XMM0, XMM1, XMM0,
VPMOVMSKB, ESI, XMM0,
SHL, RSI, IMM(0x30),
SHL, RDX, IMM(0x20),
SHL, RAX, IMM(0x10),
OR, RAX, RCX,
OR, RAX, RDX,
OR, RAX, RSI,
MOV, QWORD(RSP, 0x18), RAX,
RET,
)
var compareEqual func(key uint32, elements *[***]uint32) (ret uint***)
asm.MakeFunc(&compareEqual)
v1 := [***]uint32{
3, 0, 0, 3, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 3, 3}
ret := compareEqual(3, &v1)
fmt.Println(strconv.FormatUint(uint***(ret), 2))
```
the output will be
```
1100000000000000000000000000000000000000000000000000000000001001
```
it searches the integer in the array faster by utilizing the SIMD instruction
# Acknowledgement
* Initial implementation copied from https://github.com/nelhage/gojit
* https://medium.com/kokster/writing-a-jit-compiler-in-golang-9***b61295f
近期下载者:
相关文件:
收藏者: