Black Lives Matter. Support the Equal Justice Initiative.

Text file src/runtime/memmove_wasm.s

Documentation: runtime

     1  // Copyright 2018 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  #include "textflag.h"
     6  
     7  // See memmove Go doc for important implementation constraints.
     8  
     9  // func memmove(to, from unsafe.Pointer, n uintptr)
    10  TEXT runtime·memmove(SB), NOSPLIT, $0-24
    11  	MOVD to+0(FP), R0
    12  	MOVD from+8(FP), R1
    13  	MOVD n+16(FP), R2
    14  
    15  	Get R0
    16  	Get R1
    17  	I64LtU
    18  	If // forward
    19  exit_forward_64:
    20  		Block
    21  loop_forward_64:
    22  			Loop
    23  				Get R2
    24  				I64Const $8
    25  				I64LtU
    26  				BrIf exit_forward_64
    27  
    28  				MOVD 0(R1), 0(R0)
    29  
    30  				Get R0
    31  				I64Const $8
    32  				I64Add
    33  				Set R0
    34  
    35  				Get R1
    36  				I64Const $8
    37  				I64Add
    38  				Set R1
    39  
    40  				Get R2
    41  				I64Const $8
    42  				I64Sub
    43  				Set R2
    44  
    45  				Br loop_forward_64
    46  			End
    47  		End
    48  
    49  loop_forward_8:
    50  		Loop
    51  			Get R2
    52  			I64Eqz
    53  			If
    54  				RET
    55  			End
    56  
    57  			Get R0
    58  			I32WrapI64
    59  			I64Load8U (R1)
    60  			I64Store8 $0
    61  
    62  			Get R0
    63  			I64Const $1
    64  			I64Add
    65  			Set R0
    66  
    67  			Get R1
    68  			I64Const $1
    69  			I64Add
    70  			Set R1
    71  
    72  			Get R2
    73  			I64Const $1
    74  			I64Sub
    75  			Set R2
    76  
    77  			Br loop_forward_8
    78  		End
    79  
    80  	Else
    81  		// backward
    82  		Get R0
    83  		Get R2
    84  		I64Add
    85  		Set R0
    86  
    87  		Get R1
    88  		Get R2
    89  		I64Add
    90  		Set R1
    91  
    92  exit_backward_64:
    93  		Block
    94  loop_backward_64:
    95  			Loop
    96  				Get R2
    97  				I64Const $8
    98  				I64LtU
    99  				BrIf exit_backward_64
   100  
   101  				Get R0
   102  				I64Const $8
   103  				I64Sub
   104  				Set R0
   105  
   106  				Get R1
   107  				I64Const $8
   108  				I64Sub
   109  				Set R1
   110  
   111  				Get R2
   112  				I64Const $8
   113  				I64Sub
   114  				Set R2
   115  
   116  				MOVD 0(R1), 0(R0)
   117  
   118  				Br loop_backward_64
   119  			End
   120  		End
   121  
   122  loop_backward_8:
   123  		Loop
   124  			Get R2
   125  			I64Eqz
   126  			If
   127  				RET
   128  			End
   129  
   130  			Get R0
   131  			I64Const $1
   132  			I64Sub
   133  			Set R0
   134  
   135  			Get R1
   136  			I64Const $1
   137  			I64Sub
   138  			Set R1
   139  
   140  			Get R2
   141  			I64Const $1
   142  			I64Sub
   143  			Set R2
   144  
   145  			Get R0
   146  			I32WrapI64
   147  			I64Load8U (R1)
   148  			I64Store8 $0
   149  
   150  			Br loop_backward_8
   151  		End
   152  	End
   153  
   154  	UNDEF
   155  

View as plain text