Helge Deller | 83af58f | 2019-02-06 23:21:10 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * PA-RISC assembly string functions |
| 4 | * |
| 5 | * Copyright (C) 2019 Helge Deller <deller@gmx.de> |
| 6 | */ |
| 7 | |
| 8 | #include <asm/assembly.h> |
| 9 | #include <linux/linkage.h> |
| 10 | |
| 11 | .section .text.hot |
| 12 | .level PA_ASM_LEVEL |
| 13 | |
| 14 | t0 = r20 |
| 15 | t1 = r21 |
| 16 | t2 = r22 |
| 17 | |
| 18 | ENTRY_CFI(strlen, frame=0,no_calls) |
| 19 | or,COND(<>) arg0,r0,ret0 |
| 20 | b,l,n .Lstrlen_null_ptr,r0 |
| 21 | depwi 0,31,2,ret0 |
| 22 | cmpb,COND(<>) arg0,ret0,.Lstrlen_not_aligned |
| 23 | ldw,ma 4(ret0),t0 |
| 24 | cmpib,tr 0,r0,.Lstrlen_loop |
| 25 | uxor,nbz r0,t0,r0 |
| 26 | .Lstrlen_not_aligned: |
| 27 | uaddcm arg0,ret0,t1 |
| 28 | shladd t1,3,r0,t1 |
| 29 | mtsar t1 |
| 30 | depwi -1,%sar,32,t0 |
| 31 | uxor,nbz r0,t0,r0 |
| 32 | .Lstrlen_loop: |
| 33 | b,l,n .Lstrlen_end_loop,r0 |
| 34 | ldw,ma 4(ret0),t0 |
| 35 | cmpib,tr 0,r0,.Lstrlen_loop |
| 36 | uxor,nbz r0,t0,r0 |
| 37 | .Lstrlen_end_loop: |
| 38 | extrw,u,<> t0,7,8,r0 |
| 39 | addib,tr,n -3,ret0,.Lstrlen_out |
| 40 | extrw,u,<> t0,15,8,r0 |
| 41 | addib,tr,n -2,ret0,.Lstrlen_out |
| 42 | extrw,u,<> t0,23,8,r0 |
| 43 | addi -1,ret0,ret0 |
| 44 | .Lstrlen_out: |
| 45 | bv r0(rp) |
| 46 | uaddcm ret0,arg0,ret0 |
| 47 | .Lstrlen_null_ptr: |
| 48 | bv,n r0(rp) |
| 49 | ENDPROC_CFI(strlen) |
| 50 | |
| 51 | |
| 52 | ENTRY_CFI(strcpy, frame=0,no_calls) |
| 53 | ldb 0(arg1),t0 |
| 54 | stb t0,0(arg0) |
| 55 | ldo 0(arg0),ret0 |
| 56 | ldo 1(arg1),t1 |
| 57 | cmpb,= r0,t0,2f |
| 58 | ldo 1(arg0),t2 |
| 59 | 1: ldb 0(t1),arg1 |
| 60 | stb arg1,0(t2) |
| 61 | ldo 1(t1),t1 |
| 62 | cmpb,<> r0,arg1,1b |
| 63 | ldo 1(t2),t2 |
| 64 | 2: bv,n r0(rp) |
| 65 | ENDPROC_CFI(strcpy) |
| 66 | |
| 67 | |
| 68 | ENTRY_CFI(strncpy, frame=0,no_calls) |
| 69 | ldb 0(arg1),t0 |
| 70 | stb t0,0(arg0) |
| 71 | ldo 1(arg1),t1 |
| 72 | ldo 0(arg0),ret0 |
| 73 | cmpb,= r0,t0,2f |
| 74 | ldo 1(arg0),arg1 |
| 75 | 1: ldo -1(arg2),arg2 |
| 76 | cmpb,COND(=),n r0,arg2,2f |
| 77 | ldb 0(t1),arg0 |
| 78 | stb arg0,0(arg1) |
| 79 | ldo 1(t1),t1 |
| 80 | cmpb,<> r0,arg0,1b |
| 81 | ldo 1(arg1),arg1 |
| 82 | 2: bv,n r0(rp) |
| 83 | ENDPROC_CFI(strncpy) |
| 84 | |
| 85 | |
| 86 | ENTRY_CFI(strcat, frame=0,no_calls) |
| 87 | ldb 0(arg0),t0 |
| 88 | cmpb,= t0,r0,2f |
| 89 | ldo 0(arg0),ret0 |
| 90 | ldo 1(arg0),arg0 |
| 91 | 1: ldb 0(arg0),t1 |
| 92 | cmpb,<>,n r0,t1,1b |
| 93 | ldo 1(arg0),arg0 |
| 94 | 2: ldb 0(arg1),t2 |
| 95 | stb t2,0(arg0) |
| 96 | ldo 1(arg0),arg0 |
| 97 | ldb 0(arg1),t0 |
| 98 | cmpb,<> r0,t0,2b |
| 99 | ldo 1(arg1),arg1 |
| 100 | bv,n r0(rp) |
| 101 | ENDPROC_CFI(strcat) |
| 102 | |
| 103 | |
| 104 | ENTRY_CFI(memset, frame=0,no_calls) |
| 105 | copy arg0,ret0 |
| 106 | cmpb,COND(=) r0,arg0,4f |
| 107 | copy arg0,t2 |
| 108 | cmpb,COND(=) r0,arg2,4f |
| 109 | ldo -1(arg2),arg3 |
| 110 | subi -1,arg3,t0 |
| 111 | subi 0,t0,t1 |
| 112 | cmpiclr,COND(>=) 0,t1,arg2 |
| 113 | ldo -1(t1),arg2 |
| 114 | extru arg2,31,2,arg0 |
| 115 | 2: stb arg1,0(t2) |
| 116 | ldo 1(t2),t2 |
| 117 | addib,>= -1,arg0,2b |
| 118 | ldo -1(arg3),arg3 |
| 119 | cmpiclr,COND(<=) 4,arg2,r0 |
| 120 | b,l,n 4f,r0 |
| 121 | #ifdef CONFIG_64BIT |
| 122 | depd,* r0,63,2,arg2 |
| 123 | #else |
| 124 | depw r0,31,2,arg2 |
| 125 | #endif |
| 126 | ldo 1(t2),t2 |
| 127 | 3: stb arg1,-1(t2) |
| 128 | stb arg1,0(t2) |
| 129 | stb arg1,1(t2) |
| 130 | stb arg1,2(t2) |
| 131 | addib,COND(>) -4,arg2,3b |
| 132 | ldo 4(t2),t2 |
| 133 | 4: bv,n r0(rp) |
| 134 | ENDPROC_CFI(memset) |
| 135 | |
| 136 | .end |