Lines Matching full:code
9 …s a quick outline of the unusual form of assembly language used by the <code>gc</code> Go compiler.
19 describes the peculiarities that apply when writing assembly code to interact with Go.
29 and instruction selection occurs partly after code generation.
31 when you see an instruction like <code>MOV</code>
46 <a href="/pkg/runtime/"><code>runtime</code></a> and
47 <a href="/pkg/math/big/"><code>math/big</code></a>.
48 You can also examine what the compiler emits as assembly code
90 The <code>FUNCDATA</code> and <code>PCDATA</code> directives contain information
95 To see what gets put in the binary after linking, use <code>go tool objdump</code>:
128 Thus <code>3&1<<2</code> is 4, not 0—it parses as <code>(3&1)<<2</code>
129 not <code>3&(1<<2)</code>.
131 Thus <code>-2</code> is not the integer value minus two,
141 Some symbols, such as <code>R1</code> or <code>LR</code>,
156 <code>FP</code>: Frame pointer: arguments and locals.
160 <code>PC</code>: Program counter:
165 <code>SB</code>: Static base pointer: global symbols.
169 <code>SP</code>: Stack pointer: the highest address within the local stack frame.
176 <code>FP</code> (arguments and locals) and <code>SB</code> (globals).
180 The <code>SB</code> pseudo-register can be thought of as the origin of memory, so the symbol <code>…
181 is the name <code>foo</code> as an address in memory.
183 Adding <code><></code> to the name, as in <span style="white-space: nowrap"><code>foo<>…
184 visible only in the current source file, like a top-level <code>static</code> declaration in a C fi…
186 <code>foo+4(SB)</code> is four bytes past the start of <code>foo</code>.
190 The <code>FP</code> pseudo-register is a virtual frame pointer
193 Thus <code>0(FP)</code> is the first argument to the function,
194 <code>8(FP)</code> is the second (on a 64-bit machine), and so on.
196 at the beginning, as in <code>first_arg+0(FP)</code> and <code>second_arg+8(FP)</code>.
198 from its use with <code>SB</code>, where it is an offset from the symbol.)
199 The assembler enforces this convention, rejecting plain <code>0(FP)</code> and <code>8(FP)</code>.
202 It is worth stressing that <code>FP</code> is always a
208 For assembly functions with Go prototypes, <code>go</code> <code>vet</code> will check that the arg…
211 a <code>_lo</code> or <code>_hi</code> suffix to the name, as in <code>arg_lo+0(FP)</code> or <code…
212 If a Go prototype does not name its result, the expected assembly name is <code>ret</code>.
216 The <code>SP</code> pseudo-register is a virtual stack pointer
221 <code>x-8(SP)</code>, <code>y-4(SP)</code>, and so on.
225 On architectures with a hardware register named <code>SP</code>,
228 <code>SP</code> register.
229 That is, <code>x-8(SP)</code> and <code>-8(SP)</code>
233 hardware's <code>SP</code> register.
237 On machines where <code>SP</code> and <code>PC</code> are
239 in the Go assembler the names <code>SP</code> and <code>PC</code>
241 for instance, references to <code>SP</code> require a symbol,
242 much like <code>FP</code>.
243 To access the actual hardware register use the true <code>R</code> name.
245 <code>SP</code> and <code>PC</code> are accessible as
246 <code>R13</code> and <code>R15</code>.
265 such as <code>name(SB)</code>, but not offsets from symbols,
266 such as <code>name+4(SB)</code>.
272 (Exception: the <code>g</code> register renaming on ARM.)
278 <code>fmt.Printf</code> or <code>math/rand.Int</code>.
285 <code>fmt·Printf</code> and <code>math∕rand·Int</code>.
286 The assembly listings generated by the compilers when using the <code>-S</code> flag
296 the package's Int function can be referred to as <code>·Int</code>.
297 This convention avoids the need to hard-code a package's import path in its
298 own source code, making it easier to move the code from one location to another.
305 For example, here is a simple complete function definition. The <code>TEXT</code>
306 directive declares the symbol <code>runtime·profileloop</code> and the instructions
308 The last instruction in a <code>TEXT</code> block must be some sort of jump, usually a <code>RET</c…
309 …he linker will append a jump-to-itself instruction; there is no fallthrough in <code>TEXTs</code>.)
325 The frame size <code>$24-8</code> states that the function has a 24-byte frame
327 If <code>NOSPLIT</code> is not specified for the <code>TEXT</code>,
329 For assembly functions with Go prototypes, <code>go</code> <code>vet</code> will check that the
335 static base pseudo-register <code>SB</code>.
336 This function would be called from Go source for package <code>runtime</code> using the
337 simple name <code>profileloop</code>.
342 <code>DATA</code> directives followed by a <code>GLOBL</code> directive.
343 Each <code>DATA</code> directive initializes a section of the
346 The general form of the <code>DATA</code> directive is
354 The <code>DATA</code> directives for a given symbol must be written with increasing offsets.
358 The <code>GLOBL</code> directive declares a symbol to be global.
360 which will have initial value all zeros unless a <code>DATA</code> directive
362 The <code>GLOBL</code> directive must follow any corresponding <code>DATA</code> directives.
380 declares and initializes <code>divtab<></code>, a read-only 64-byte table of 4-byte integer v…
381 and declares <code>runtime·tlsoffset</code>, a 4-byte, implicitly zeroed variable that
390 Their values, defined in the standard <code>#include</code> file <code>textflag.h</code>, are:
395 <code>NOPROF</code> = 1
397 (For <code>TEXT</code> items.)
401 <code>DUPOK</code> = 2
407 <code>NOSPLIT</code> = 4
409 (For <code>TEXT</code> items.)
413 Used to protect routines such as the stack splitting code itself.
416 <code>RODATA</code> = 8
418 (For <code>DATA</code> and <code>GLOBL</code> items.)
422 <code>NOPTR</code> = 16
424 (For <code>DATA</code> and <code>GLOBL</code> items.)
429 <code>WRAPPER</code> = 32
431 (For <code>TEXT</code> items.)
432 This is a wrapper function and should not count as disabling <code>recover</code>.
435 <code>NEEDCTXT</code> = 64
437 (For <code>TEXT</code> items.)
441 <code>LOCAL</code> = 128
446 <code>TLSBSS</code> = 256
448 (For <code>DATA</code> and <code>GLOBL</code> items.)
452 <code>NOFRAME</code> = 512
454 (For <code>TEXT</code> items.)
460 <code>TOPFRAME</code> = 2048
462 (For <code>TEXT</code> items.)
470 The <code>PCALIGN</code> pseudo-instruction is used to indicate that the next instruction should be…
477 For example, the start of the <code>MOVD</code> instruction below is aligned to 32 bytes:
487 If a package has any .s files, then <code>go build</code> will direct
488 the compiler to emit a special header called <code>go_asm.h</code>,
489 which the .s files can then <code>#include</code>.
490 The file contains symbolic <code>#define</code> constants for the
492 Go <code>const</code> declarations defined in the current package.
495 This improves the readability of assembly code, and keeps it robust to
501 Constants are of the form <code>const_<i>name</i></code>.
502 For example, given the Go declaration <code>const bufSize =
503 1024</code>, assembly code can refer to the value of this constant
504 as <code>const_bufSize</code>.
508 Field offsets are of the form <code><i>type</i>_<i>field</i></code>.
509 Struct sizes are of the form <code><i>type</i>__size</code>.
522 as <code>reader__size</code> and the offsets of the two fields
523 as <code>reader_buf</code> and <code>reader_r</code>.
524 Hence, if register <code>R1</code> contains a pointer to
525 a <code>reader</code>, assembly can reference the <code>r</code> field
526 as <code>reader_r(R1)</code>.
530 If any of these <code>#define</code> names are ambiguous (for example,
531 a struct with a <code>_size</code> field), <code>#include
532 "go_asm.h"</code> will fail with a "redefinition of macro" error.
545 A data symbol marked with the <code>NOPTR</code> flag (see above)
547 A data symbol with the <code>RODATA</code> flag
549 as implicitly marked <code>NOPTR</code>.
551 is also treated as implicitly marked <code>NOPTR</code>.
555 even without <code>DATA</code> and <code>GLOBL</code> directives.
556 A good general rule of thumb is to define all non-<code>RODATA</code>
568 function <code>Syscall</code> in package <code>syscall</code> should
569 use the name <code>·Syscall</code> instead of the equivalent name
570 <code>syscall·Syscall</code> in its <code>TEXT</code> directive).
573 <code>#include</code> file <code>funcdata.h</code>.
579 This is indicated by an argument size annotation of <code>$<i>n</i>-0</code>
580 on the <code>TEXT</code> instruction.
584 (The prototype will also let <code>go</code> <code>vet</code> check the argument references.)
589 executing the pseudo-instruction <code>GO_RESULTS_INITIALIZED</code>.
595 <code>GO_RESULTS_INITIALIZED</code>.
601 This is indicated by a local frame size annotation of <code>$0-<i>n</i></code>
602 on the <code>TEXT</code> instruction.
607 pseudo-instruction <code>NO_LOCAL_POINTERS</code>.
616 and to let <code>go</code> <code>vet</code> check that
625 look in the source for the <code>obj</code> support library for
626 that architecture, located in the directory <code>src/cmd/internal/obj/arm</code>.
627 In that directory is a file <code>a.out.go</code>; it contains
628 a long list of constants starting with <code>A</code>, like this:
643 Each instruction begins with an initial capital <code>A</code> in this list, so <code>AAND</code>
645 <code>AND</code> (without the leading <code>A</code>),
646 and is written in assembly source as <code>AND</code>.
648 (The architecture-independent <code>AXXX</code>, defined in the
649 <code>cmd/internal/obj</code> package,
651 The sequence of the <code>A</code> names has nothing to do with the actual
653 The <code>cmd/internal/obj</code> package takes care of that detail.
658 <code>cmd/internal/obj/x86/a.out.go</code>.
663 <code>(R1)</code> (register indirect),
664 <code>4(R1)</code> (register indirect with offset), and
665 <code>$foo(SB)</code> (absolute address).
673 <code>MOVQ</code> <code>$0,</code> <code>CX</code> clears <code>CX</code>.
684 The runtime pointer to the <code>g</code> structure is maintained
686 In the runtime package, assembly code can include <code>go_tls.h</code>, which defines
687 an OS- and architecture-dependent macro <code>get_tls</code> for accessing this register.
688 The <code>get_tls</code> macro takes one argument, which is the register to load the
689 <code>g</code> pointer into.
693 For example, the sequence to load <code>g</code> and <code>m</code>
694 using <code>CX</code> looks like this:
707 The <code>get_tls</code> macro is also defined on <a href="#amd64">amd64</a>.
717 <code>(DI)(BX*2)</code>: The location at address <code>DI</code> plus <code>BX*2</code>.
721 <code>64(DI)(BX*2)</code>: The location at address <code>DI</code> plus <code>BX*2</code> plus 64.
729 <code>-dynlink</code> or <code>-shared</code> modes,
731 must be assumed to overwrite <code>CX</code>.
740 Assembly code to access the <code>m</code> and <code>g</code>
742 except it uses <code>MOVQ</code> rather than <code>MOVL</code>:
752 Register <code>BP</code> is callee-save.
753 The assembler automatically inserts <code>BP</code> save/restore when frame size is larger than zer…
754 Using <code>BP</code> as a general purpose register is allowed,
761 The registers <code>R10</code> and <code>R11</code>
766 <code>R10</code> points to the <code>g</code> (goroutine) structure.
767 Within assembler source code, this pointer must be referred to as <code>g</code>;
768 the name <code>R10</code> is not recognized.
773 allows general addressing forms and pseudo-operations like <code>DIV</code> or <code>MOD</code>
775 It implements these forms as multiple instructions, often using the <code>R11</code> register
777 Hand-written assembly can use <code>R11</code>, but doing so requires
783 When defining a <code>TEXT</code>, specifying frame size <code>$-4</code>
784 tells the linker that this is a leaf function that does not need to save <code>LR</code> on entry.
788 The name <code>SP</code> always refers to the virtual stack pointer described earlier.
789 For the hardware register, use <code>R13</code>.
793 Condition code syntax is to append a period and the one- or two-letter code to the instruction,
794 as in <code>MOVW.EQ</code>.
795 Multiple codes may be appended: <code>MOVM.IA.W</code>.
796 The order of the code modifiers is irrelevant.
806 <code>R0->16</code>
808 <code>R0>>16</code>
810 <code>R0<<16</code>
812 <code>R0@>16</code>:
813 For <code><<</code>, left shift <code>R0</code> by 16 bits.
814 The other codes are <code>-></code> (arithmetic right shift),
815 <code>>></code> (logical right shift), and
816 <code>@></code> (rotate right).
820 <code>R0->R1</code>
822 <code>R0>>R1</code>
824 <code>R0<<R1</code>
826 <code>R0@>R1</code>:
827 For <code><<</code>, left shift <code>R0</code> by the count in <code>R1</code>.
828 The other codes are <code>-></code> (arithmetic right shift),
829 <code>>></code> (logical right shift), and
830 <code>@></code> (rotate right).
835 <code>[R0,g,R12-R15]</code>: For multi-register instructions, the set comprising
836 <code>R0</code>, <code>g</code>, and <code>R12</code> through <code>R15</code> inclusive.
840 <code>(R5, R6)</code>: Destination register pair.
848 <code>R18</code> is the "platform register", reserved on the Apple platform.
849 To prevent accidental misuse, the register is named <code>R18_PLATFORM</code>.
850 <code>R27</code> and <code>R28</code> are reserved by the compiler and linker.
851 <code>R29</code> is the frame pointer.
852 <code>R30</code> is the link register.
857 The only modifiers are <code>P</code> (postincrement) and <code>W</code>
859 <code>MOVW.P</code>, <code>MOVW.W</code>
869 <code>R0->16</code>
871 <code>R0>>16</code>
873 <code>R0<<16</code>
875 <code>R0@>16</code>:
880 <code>$(8<<12)</code>:
881 Left shift the immediate value <code>8</code> by <code>12</code> bits.
885 <code>8(R0)</code>:
886 Add the value of <code>R0</code> and <code>8</code>.
890 <code>(R2)(R0)</code>:
891 The location at <code>R0</code> plus <code>R2</code>.
895 <code>R0.UXTB</code>
897 <code>R0.UXTB<<imm</code>:
898 <code>UXTB</code>: extract an 8-bit value from the low-order bits of <code>R0</code> and zero-exten…
899 <code>R0.UXTB<<imm</code>: left shift the result of <code>R0.UXTB</code> by <code>imm</code> …
900 The <code>imm</code> value can be 0, 1, 2, 3, or 4.
901 The other extensions include <code>UXTH</code> (16-bit), <code>UXTW</code> (32-bit), and <code>UXTX…
905 <code>R0.SXTB</code>
907 <code>R0.SXTB<<imm</code>:
908 <code>SXTB</code>: extract an 8-bit value from the low-order bits of <code>R0</code> and sign-exten…
909 <code>R0.SXTB<<imm</code>: left shift the result of <code>R0.SXTB</code> by <code>imm</code> …
910 The <code>imm</code> value can be 0, 1, 2, 3, or 4.
911 The other extensions include <code>SXTH</code> (16-bit), <code>SXTW</code> (32-bit), and <code>SXTX…
915 <code>(R5, R6)</code>: Register pair for <code>LDAXP</code>/<code>LDP</code>/<code>LDXP</code>/<cod…
937 The registers <code>R10</code> and <code>R11</code> are reserved.
942 <code>R13</code> points to the <code>g</code> (goroutine) structure.
943 This register must be referred to as <code>g</code>; the name <code>R13</code> is not recognized.
947 <code>R15</code> points to the stack frame and should typically only be accessed using the
948 virtual registers <code>SP</code> and <code>FP</code>.
954 For example, <code>LMG</code> <code>(R9),</code> <code>R5,</code> <code>R7</code> would load
955 <code>R5</code>, <code>R6</code> and <code>R7</code> with the 64-bit values at
956 <code>0(R9)</code>, <code>8(R9)</code> and <code>16(R9)</code> respectively.
960 Storage-and-storage instructions such as <code>MVC</code> and <code>XC</code> are written
962 For example, <code>XC</code> <code>$8,</code> <code>(R9),</code> <code>(R9)</code> would clear
963 eight bytes at the address specified in <code>R9</code>.
969 For example, <code>VLEIF</code> <code>$1,</code> <code>$16,</code> <code>V2</code> will load
970 the value sixteen into index one of <code>V2</code>.
976 to a <code>NOP</code> instruction).
986 <code>(R5)(R6*1)</code>: The location at <code>R5</code> plus <code>R6</code>.
987 It is a scaled mode as on the x86, but the only scale allowed is <code>1</code>.
995 General purpose registers are named <code>R0</code> through <code>R31</code>,
996 floating point registers are <code>F0</code> through <code>F31</code>.
1000 <code>R30</code> is reserved to point to <code>g</code>.
1001 <code>R23</code> is used as a temporary register.
1005 In a <code>TEXT</code> directive, the frame size <code>$-4</code> for MIPS or
1006 <code>$-8</code> for MIPS64 instructs the linker not to save <code>LR</code>.
1010 <code>SP</code> refers to the virtual stack pointer.
1011 For the hardware register, use <code>R29</code>.
1021 <code>16(R1)</code>: The location at <code>R1</code> plus 16.
1025 <code>(R1)</code>: Alias for <code>0(R1)</code>.
1031 The value of <code>GOMIPS</code> environment variable (<code>hardfloat</code> or
1032 <code>softfloat</code>) is made available to assembly code by predefining either
1033 <code>GOMIPS_hardfloat</code> or <code>GOMIPS_softfloat</code>.
1037 The value of <code>GOMIPS64</code> environment variable (<code>hardfloat</code> or
1038 <code>softfloat</code>) is made available to assembly code by predefining either
1039 <code>GOMIPS64_hardfloat</code> or <code>GOMIPS64_softfloat</code>.
1050 Instead, for simple one-off cases, it's possible to use the <code>BYTE</code>
1051 and <code>WORD</code> directives
1052 to lay down explicit data into the instruction stream within a <code>TEXT</code>.