Definitive guide to go-c and go-asm

230 views
Skip to first unread message

Pawel Kraszewski

unread,
Nov 19, 2013, 12:20:44 PM11/19/13
to golan...@googlegroups.com
Hello!
Is there any guide to go-asm? Esspecially for the go ABI: how to pass arguments, how to return results, which registers to preserve, etc. Source code of packages math and syscall helps slightly, but is not enough for my project.

The cgo solution with embedded assembly gives way too much overhead. I managed to implement RDTSC both via direct asm and via cgo - the difference is overwhelming. Call-to-call in go-asm gives avg 90 cycles while in cgo-asm about 1300 cycles...

Moreover, is there a way to allocate memory with specific alignment (16 bytes to be precise) ? One solution I see is to allocate it in cgo and pass back as unsafe.Pointer. Is this the way?

All this is necessary for me to implement ultra low latency interface to Via Padlock cryptographic coprocessor.

Aram Hăvărneanu

unread,
Nov 19, 2013, 12:23:14 PM11/19/13
to Pawel Kraszewski, golang-nuts
http://tip.golang.org/doc/asm

--
Aram Hăvărneanu

Gustavo Niemeyer

unread,
Nov 19, 2013, 12:30:37 PM11/19/13
to Pawel Kraszewski, golan...@googlegroups.com
On Tue, Nov 19, 2013 at 3:20 PM, Pawel Kraszewski <pa...@kraszewscy.net> wrote:
> Moreover, is there a way to allocate memory with specific alignment (16 bytes to be precise) ? One solution I see is to allocate it in cgo and pass back as unsafe.Pointer. Is this the way?

You can always align it yourself by allocating 15 bytes more than you
need and sliding the start as necessary.


gustavo @ http://niemeyer.net

Pawel Kraszewski

unread,
Nov 19, 2013, 3:50:36 PM11/19/13
to golan...@googlegroups.com
Thanks for valuable answers.

+Aram: How did you find this? I'm travelling the Go docs all the way across for the last few days - but asm guide didn't catch my eye...

+Gustavo: Yes, I know overallocation technique. I just hoped to have some sort of __aligned__ equivalent. Obvious problem is that Go has no pointer arithmetic to snap to the 16 boundary, so this leaves the unsafe.Pointer manipulations as a way to go.

Best regards

Gustavo Niemeyer

unread,
Nov 19, 2013, 3:55:25 PM11/19/13
to Pawel Kraszewski, golan...@googlegroups.com
On Tue, Nov 19, 2013 at 6:50 PM, Pawel Kraszewski <pa...@kraszewscy.net> wrote:
> +Gustavo: Yes, I know overallocation technique. I just hoped to have some
> sort of __aligned__ equivalent. Obvious problem is that Go has no pointer
> arithmetic to snap to the 16 boundary, so this leaves the unsafe.Pointer
> manipulations as a way to go.

unsafe.Pointer != cgo, which was your actual suggestion.


gustavo @ http://niemeyer.net

Dan Kortschak

unread,
Nov 19, 2013, 5:05:44 PM11/19/13
to Pawel Kraszewski, golan...@googlegroups.com
On Tue, 2013-11-19 at 12:50 -0800, Pawel Kraszewski wrote:
> +Aram: How did you find this? I'm travelling the Go docs all the way
> across for the last few days - but asm guide didn't catch my eye...

It's a very recent addition (note it's in tip).

Reply all
Reply to author
Forward
0 new messages