FAQ
I cannot find any official documentation on how to write assembly functions
with a Go fallback. Based on what I can see in the standard library, the
convention goes something like this:

foo.go
------

func Foo(int) int // Defined in assembly

func foo(int) int { // Fallback version in Go
  // ...
  return 0
}


foo_GOARCH.s
------------

// func Foo(int) int
TEXT ·Foo(SB),7,$0
  // ...
  RET


Questions:

1) How does foo() actually get associated with Foo()? Does the tooling just
automatically look for a lowercase version? When I remove the assembly
file, I get a "missing function body" error, so there must be something
about the standard library examples.

2) Is it possible to create an unexported function like this? If the
optimized function is now called foo(), what does the fallback get named?

3) Is the commented out func signature in the assembly file required by the
tools or have any significance? I think I found that it didn't work without
it.

Thanks,
Jay

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Ian Lance Taylor at Jun 6, 2013 at 8:34 pm

    On Thu, Jun 6, 2013 at 1:04 PM, Jay Weisskopf wrote:
    I cannot find any official documentation on how to write assembly functions
    with a Go fallback. Based on what I can see in the standard library, the
    convention goes something like this:

    foo.go
    ------

    func Foo(int) int // Defined in assembly

    func foo(int) int { // Fallback version in Go
    // ...
    return 0
    }


    foo_GOARCH.s
    ------------

    // func Foo(int) int
    TEXT ·Foo(SB),7,$0
    // ...
    RET


    Questions:

    1) How does foo() actually get associated with Foo()? Does the tooling just
    automatically look for a lowercase version? When I remove the assembly file,
    I get a "missing function body" error, so there must be something about the
    standard library examples.
    The standard library provides a version of Foo for every architecture.
      The ones without an architecture-specific implementation simply jump
    to foo. For example, see math/sin_*.s.
    2) Is it possible to create an unexported function like this? If the
    optimized function is now called foo(), what does the fallback get named?
    There is no fallback.
    3) Is the commented out func signature in the assembly file required by the
    tools or have any significance? I think I found that it didn't work without
    it.
    The function signature is used by go vet to check that your assembly
    code handles parameters correctly. I don't remember if it's used by
    anything else.

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jay Weisskopf at Jun 6, 2013 at 8:45 pm
    Thanks. It seems much clearer to me after reading that. I was getting mixed
    up about the fallback thing because I was previously looking at Sqrt, which
    provides an implementation for each arch, while there also exists a full
    sqrt() in Go, and I thought there was some kind of association. Maybe not
    in that case.

    So I should have all my bases covered (for now) so long as I provide a 386,
    arm, and amd64 version? That is everything I see in the math package.

    - Jay

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Ian Lance Taylor at Jun 6, 2013 at 8:50 pm

    On Thu, Jun 6, 2013 at 1:45 PM, Jay Weisskopf wrote:
    Thanks. It seems much clearer to me after reading that. I was getting mixed
    up about the fallback thing because I was previously looking at Sqrt, which
    provides an implementation for each arch, while there also exists a full
    sqrt() in Go, and I thought there was some kind of association. Maybe not in
    that case.

    So I should have all my bases covered (for now) so long as I provide a 386,
    arm, and amd64 version? That is everything I see in the math package.
    Yes, those are the only architectures that the gc toolchain currently
    support. Of course, in the future there are likely to be more
    architectures. (Note that I don't know of anybody working on more
    architectures at present, but I expect that eventually we will need at
    least an Aarch64 port.)

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dave Cheney at Jun 6, 2013 at 11:05 pm
    Have look at the bytes package circa go 1.0, if you look at the arm version you can see the Index and Equal functions branch unconditionally to the Go implementations.
    On 07/06/2013, at 6:04, Jay Weisskopf wrote:

    I cannot find any official documentation on how to write assembly functions with a Go fallback. Based on what I can see in the standard library, the convention goes something like this:

    foo.go
    ------
    func Foo(int) int // Defined in assembly

    func foo(int) int { // Fallback version in Go
    // ...
    return 0
    }

    foo_GOARCH.s
    ------------
    // func Foo(int) int
    TEXT ·Foo(SB),7,$0
    // ...
    RET

    Questions:

    1) How does foo() actually get associated with Foo()? Does the tooling just automatically look for a lowercase version? When I remove the assembly file, I get a "missing function body" error, so there must be something about the standard library examples.

    2) Is it possible to create an unexported function like this? If the optimized function is now called foo(), what does the fallback get named?

    3) Is the commented out func signature in the assembly file required by the tools or have any significance? I think I found that it didn't work without it.

    Thanks,
    Jay
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJun 6, '13 at 8:04p
activeJun 6, '13 at 11:05p
posts5
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase