Skip to content

Commit

Permalink
feat(internal): enable link_emu for arm64 (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marina-Sakai authored Feb 28, 2024
1 parent f210121 commit 657cf86
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 1 deletion.
4 changes: 4 additions & 0 deletions internal/atm/abi/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ var (
ABI = ArchCreateABI()
)

const (
PtrSize = 8 // pointer size
)

func alignUp(n uintptr, a int) uintptr {
return (n + uintptr(a) - 1) &^ (uintptr(a) - 1)
}
1 change: 0 additions & 1 deletion internal/atm/abi/abi_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
)

const (
PtrSize = 8 // pointer size
PtrAlign = 8 // pointer alignment
)

Expand Down
49 changes: 49 additions & 0 deletions internal/atm/abi/abi_arm64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2024 ByteDance Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package abi

import (
`reflect`
`unsafe`

`github.com/cloudwego/frugal/internal/rt`
)

// NOTE: this file is temporary and is used only for emu on arm
// TODO: delete this file after frugal supports arm

type ARM64ABI struct {}

func ArchCreateABI() *ARM64ABI {
return &ARM64ABI{}
}

func (self *ARM64ABI) RegisterMethod(id int, mt rt.Method) int {
return mt.Id
}

func (self *ARM64ABI) RegisterFunction(id int, fn interface{}) (fp unsafe.Pointer) {
vv := rt.UnpackEface(fn)
vt := vv.Type.Pack()

/* must be a function */
if vt.Kind() != reflect.Func {
panic("fn is not a function")
}

return *(*unsafe.Pointer)(vv.Value)
}
34 changes: 34 additions & 0 deletions internal/binary/decoder/linker_arm64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2024 ByteDance Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package decoder

import "github.com/cloudwego/frugal/internal/atm/hir"

// NOTE: this file is temporary and is used only for emu on arm
// TODO: delete this file after frugal supports arm

type (
LinkerARM64 struct{}
)

func init() {
SetLinker(new(LinkerARM64))
}

func (LinkerARM64) Link(p hir.Program) Decoder {
return link_emu(p)
}
28 changes: 28 additions & 0 deletions internal/binary/decoder/skipping_arm64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2024 ByteDance Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package decoder

import (
`unsafe`
)

// NOTE: this file is temporary and is used only for emu on arm
// TODO: delete this file after frugal supports arm

func archSkippingFn() unsafe.Pointer {
return nil
}
34 changes: 34 additions & 0 deletions internal/binary/encoder/linker_arm64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2024 ByteDance Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package encoder

import "github.com/cloudwego/frugal/internal/atm/hir"

// NOTE: this file is temporary and is used only for emu on arm
// TODO: delete this file after frugal supports arm

type (
LinkerARM64 struct{}
)

func init() {
SetLinker(new(LinkerARM64))
}

func (LinkerARM64) Link(p hir.Program) Encoder {
return link_emu(p)
}

0 comments on commit 657cf86

Please sign in to comment.