Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions build_defs/go.build_defs
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,22 @@ def go_library(name:str, srcs:list, resources:list=[], asm_srcs:list=None, hdrs:
'hdrs': [hdrs_rule],
'goasm': [lib_rule + '|h'],
},
outs = [name + '.o'],
outs = [name + "#" + (splitext(basename(a)))[0] + ".o" for a in asm_srcs],
building_description = 'Assembling...',
cmd = f'eval `"$TOOL" env` && mkdir include && mv $SRCS_GOASM include/go_asm.h && "$TOOL" tool asm -trimpath "$TMP_DIR" -I "$TMP_DIR"/include -I ${GOROOT}/pkg/include -D GOOS={CONFIG.OS} -D GOARCH_{CONFIG.ARCH} -p {package_path} -o "$OUT" $SRCS_ASM',
cmd = " && ".join([
'eval `"$TOOL" env`',
'mkdir include',
'mv $SRCS_GOASM include/go_asm.h',
'for ASM_FILE in $SRCS_ASM; do "$TOOL" tool asm ' + " ".join([
'-trimpath "$TMP_DIR"',
'-I "$TMP_DIR"/include',
'-I ${GOROOT}/pkg/include',
f'-D GOOS={CONFIG.OS}',
f'-D GOARCH_{CONFIG.ARCH}',
f'-p {package_path}',
f'''-o "{name}#$(basename $ASM_FILE | sed -e 's/\.[sS]$//').o"''',
]) + ' $ASM_FILE; done',
]),
env= {
"GOOS": CONFIG.OS,
"GOARCH": CONFIG.ARCH,
Expand Down
5 changes: 4 additions & 1 deletion test/asm/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ subinclude("//build_defs:go")
go_library(
name = "asm",
srcs = ["asm.go"],
asm_srcs = ["add.s"],
asm_srcs = [
"add.s",
"subtract.s",
],
deps = ["//test/asm/lib/golib"],
)

Expand Down
2 changes: 2 additions & 0 deletions test/asm/lib/add.s
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
GLOBL COLLIDINGSYMBOL<>(SB), 8, $32

// func add(x, y int64)
TEXT ·add(SB),$0-24
MOVQ x+0(FP), BX
Expand Down
8 changes: 8 additions & 0 deletions test/asm/lib/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ func add(x, y int64) int64
func Add() int {
return int(add(golib.LHS, golib.RHS))
}

// subtract is the forward declaration of the assembly implementation.
func subtract(x, y int) int64

// Subtract subtracts two numbers using assembly.
func Subtract() int {
return int(subtract(golib.LHS, golib.RHS))
}
6 changes: 5 additions & 1 deletion test/asm/lib/asm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ import (
)

func TestAssemblyAdd(t *testing.T) {
assert.Equal(t, 15, asm.Add())
assert.Equal(t, 14, asm.Add())
}

func TestAssemblySubtract(t *testing.T) {
assert.Equal(t, 6, asm.Subtract())
}
4 changes: 2 additions & 2 deletions test/asm/lib/golib/go_lib.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package golib

const LHS = 5
const RHS = 10
const LHS = 10
const RHS = 4
9 changes: 9 additions & 0 deletions test/asm/lib/subtract.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
GLOBL COLLIDINGSYMBOL<>(SB), 8, $32

// func subtract(x, y int64)
TEXT ·subtract(SB),$0-24
MOVQ x+0(FP), BX
MOVQ y+8(FP), BP
SUBQ BP, BX
MOVQ BX, ret+16(FP)
RET