gitee.com/quant1x/num@v0.3.2/asm/c2goasm/test/clib_amd64.s (about) 1 #include "textflag.h" 2 3 // void *memcpy(void *dst, const void *src, size_t n) 4 // DI = dst, SI = src, DX = size 5 TEXT clib·_memcpy(SB), NOSPLIT|NOFRAME, $16-0 6 PUSHQ R8 7 PUSHQ CX 8 XORQ CX, CX // clear register 9 10 MEMCPY_QUAD_LOOP: 11 ADDQ $8, CX 12 CMPQ CX, DX 13 JA MEMCPY_QUAD_DONE 14 MOVQ -8(SI)(CX*1), R8 15 MOVQ R8, -8(DI)(CX*1) 16 JMP MEMCPY_QUAD_LOOP 17 18 MEMCPY_QUAD_DONE: 19 SUBQ $4, CX 20 CMPQ CX, DX 21 JA MEMCPY_LONG_DONE 22 MOVL -4(SI)(CX*1), R8 23 MOVL R8, -4(DI)(CX*1) 24 ADDQ $4, CX 25 26 MEMCPY_LONG_DONE: 27 SUBQ $2, CX 28 CMPQ CX, DX 29 JA MEMCPY_WORD_DONE 30 MOVW -2(SI)(CX*1), R8 31 MOVW R8, -2(DI)(CX*1) 32 ADDQ $2, CX 33 34 MEMCPY_WORD_DONE: 35 SUBQ $1, CX 36 CMPQ CX, DX 37 JA MEMCPY_BYTE_DONE 38 MOVB -1(SI)(CX*1), R8 39 MOVB R8, -1(DI)(CX*1) 40 41 MEMCPY_BYTE_DONE: 42 MOVQ DI, AX // set return value 43 POPQ CX 44 POPQ R8 45 RET 46 47 // func _ClibMemcpy(dst, src unsafe.Pointer, n uint) unsafe.Pointer 48 TEXT ·_ClibMemcpy(SB), NOSPLIT|NOFRAME, $16-24 49 MOVQ arg1+0(FP), DI 50 MOVQ arg2+8(FP), SI 51 MOVQ arg3+16(FP), DX 52 CALL clib·_memcpy(SB) 53 MOVQ AX, ret+24(FP) 54 RET 55 56 // void *memset(void *str, int c, size_t n) 57 // DI = str, SI = c, DX = size 58 TEXT clib·_memset(SB), NOSPLIT|NOFRAME, $16-0 59 PUSHQ CX 60 LONG $0x0101f669; WORD $0x0101 // imul esi, 0x1010101 61 MOVQ SI, CX 62 ROLQ $32, CX 63 ORQ CX, SI 64 XORQ CX, CX // clear register 65 66 MEMSET_QUAD_LOOP: 67 ADDQ $8, CX 68 CMPQ CX, DX 69 JA MEMSET_QUAD_DONE 70 MOVQ SI, -8(DI)(CX*1) 71 JMP MEMSET_QUAD_LOOP 72 73 MEMSET_QUAD_DONE: 74 SUBQ $4, CX 75 CMPQ CX, DX 76 JA MEMSET_LONG_DONE 77 MOVL SI, -4(DI)(CX*1) 78 ADDQ $4, CX 79 80 MEMSET_LONG_DONE: 81 SUBQ $2, CX 82 CMPQ CX, DX 83 JA MEMSET_WORD_DONE 84 MOVW SI, -2(DI)(CX*1) 85 ADDQ $2, CX 86 87 MEMSET_WORD_DONE: 88 SUBQ $1, CX 89 CMPQ CX, DX 90 JA MEMSET_BYTE_DONE 91 MOVB SI, -1(DI)(CX*1) 92 93 MEMSET_BYTE_DONE: 94 MOVQ DI, AX // set return value 95 POPQ CX 96 RET 97 98 // func _ClibMemset(dst unsafe.Pointer, c int, n uint) unsafe.Pointer 99 TEXT ·_ClibMemset(SB), NOSPLIT|NOFRAME, $16-24 100 MOVQ arg1+0(FP), DI 101 MOVQ arg2+8(FP), SI 102 MOVQ arg3+16(FP), DX 103 CALL clib·_memset(SB) 104 MOVQ AX, ret+24(FP) 105 RET 106 107 // float floor (float x); 108 // DI = x 109 TEXT clib·_floor(SB), NOSPLIT|NOFRAME, $16-0 110 MOVQ X0, -16(SP) // save X0 111 MOVL DI, X0 112 LONG $0x0a3a0f66; WORD $0x01c0 // roundss xmm0, xmm0, 1 113 MOVL X0, AX 114 MOVQ -16(SP), X0 // restore X0 115 RET 116 117 // func _ClibFloor32(fl float32) float32 118 TEXT ·_ClibFloor32(SB), NOSPLIT|NOFRAME, $16-16 119 MOVL arg1+0(FP), DI 120 CALL clib·_floor(SB) 121 MOVL AX, ret+8(FP) 122 RET 123 124 // double floor (double x); 125 // DI = x 126 TEXT clib·_floor64(SB), NOSPLIT|NOFRAME, $16-0 127 MOVQ X0, -16(SP) // save X0 128 MOVQ DI, X0 129 LONG $0x0b3a0f66; WORD $0x01c0 // roundsd xmm0, xmm0, 1 130 MOVQ X0, AX 131 MOVQ -16(SP), X0 // restore X0 132 RET 133 134 // func _ClibFloor64(fl float64) float64 135 TEXT ·_ClibFloor64(SB), NOSPLIT|NOFRAME, $16-16 136 MOVQ arg1+0(FP), DI 137 CALL clib·_floor64(SB) 138 MOVQ AX, ret+8(FP) 139 RET