On Thursday, 26 July 2012 11:02:59 UTC+10, Job van der Zwan wrote:
> So, am I correct in understanding that in order to make a custom assembly file, one:
> Makes a regular go file with the function one want to rewrite in assembly
> Also makes a file with the same name plus an underscore and the relevent architecture, and the .s filetype
> Follows the conventions explained in the Plan 9 assembler document, but with a · (a dot) in front of the name of the function? (If so: why?)
If you want function written in asm, then write it in asm, but you must put it in a .s file, not .go file. It does not matter what .s file name is, but it does matter what it ends as. As is described in
http://golang.org/pkg/go/build/#Build_Constraints, if your asm file is for 386, it must have _386.s at the end.
Also, all functions inside Go executable (including the ones written in C and asm) share the same namespace, therefore functions from package alex will have prefix alex., so, for example, add function in package alex will have global name of alex.add (you can use "go tool nm <an_go_executable>" to see that). A · (MIDDLE DOT) is used in C and asm to help this cause, so if you have ·add in asm in package alex, it gets renamed into alex.add (I COULD BE WRONG ABOUT DETAILS HERE, but Go team will correct me):
# go build -o a | go tool nm a | grep main.add
8048d30 T main.add
otherwise your asm add function might clash with other add functions inside you executable.
> Do I need an empty function declaration? ...
You, obviously, do:
# go build
# t
./add.go:20: undefined: add
#
> If so, how do I make a "fallback" for architectures that are supported by the compiler but don't have a special ASM files written for them. ...
Put whatever code you want for whatever arch in a file that fits file name as per
http://golang.org/pkg/go/build/#Build_Constraints. For example, if your implementation is asm for 386 and Go for amd64, you could put your 386 asm code into aaa_386.s and adm64 Go code into bbb_adm64.go.
> ... Minux also sent me this example ... Correct?
I do not know. I didn't look at
https://github.com/ziutek/blas.
> What's with the capital å before the function name (or the dot) in your add example? ...
My telnet program is ascii only :-(. It is, in fact, a · (MIDDLE DOT). Sorry.
> ..., does using custom made ASM play nicely with inlining? ...
I do not understand your question. Go language does not allow any "inlining" inside of Go code.
Alex