Thanks! Didn't know that the assembler is able to do this. TBH, for me, 
it's not desired behaviour when an assembler program does something extra 
to a low-level code. I have already observed that Go asm strips a series of 
NOPs, which is highly unexpected.

A directive for alignment is way clearer. Not to mention that sometimes we 
don't need to align jump targets.

w.
On Friday, February 25, 2022 at 9:35:10 AM UTC+1 Brian Candler wrote:

> It seems to me that there is automatic alignment for loops:
>
> https://github.com/golang/go/blob/go1.17.7/src/cmd/internal/obj/x86/asm6.go#L51-L67
>
>
> On Friday, 25 February 2022 at 06:42:23 UTC Wojciech Muła wrote:
>
>> The directive is not documented on 
>> https://pkg.go.dev/cmd/internal/obj/x86. `grep -l -R PCALIGN *` run in 
>> `cmd/interal/obj` shows for the freshest master:
>>
>> arm64/doc.go
>> arm64/asm7.go
>> arm64/asm_arm64_test.go
>> link.go
>> ppc64/doc.go
>> ppc64/asm9.go
>> ppc64/asm_test.go
>> util.go
>>
>> Seems it's not implemented. When tried to use it, I got the following 
>> error:
>>
>> # main
>> asm: asmins: missing op 00000 (<unknown line number>)        PCALIGN     
>>    $16
>> asm: assembly failed
>>
>> Sample asm code to check this:
>>
>> ---asmfun_amd64.s---
>> #include "textflag.h"
>>
>> TEXT ·asmfun(SB), NOSPLIT, $0
>>     PCALIGN $16
>>     RET
>> ---eof---
>>
>> ---main.go---
>> package main
>>
>> // go:noescape
>> func asmfun()
>> func main() { asmfun() }
>> ---eof---
>>
>> w.
>>
>> On Friday, February 25, 2022 at 2:21:41 AM UTC+1 Ian Lance Taylor wrote:
>>
>>> On Thu, Feb 24, 2022 at 9:40 AM Wojciech Muła <wojte...@gmail.com> 
>>> wrote: 
>>> > 
>>> > I'm writing an implementation in x86 assembler and I need to force a 
>>> certain alignment of blocks of code (as it affects performance). I found 
>>> that there's PCALIGN directive, but it's only available for the PPC 
>>> architecture. It does not work for x86. 
>>> > 
>>> > Is there any easy way to achieve this for x86? If I had one loop, it 
>>> won't be a problem --- I'd just put a few `BYTE $0x90` and move on. The 
>>> problem is my code is huge, partially autogenerated with few variants. 
>>> > 
>>> > Any hints? 
>>>
>>> As far as I can tell PCALIGN is implemented for all architectures. 
>>>
>>> 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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/c6821872-a99d-45af-b119-6b56bdd0fd3cn%40googlegroups.com.

Reply via email to