diff options
Diffstat (limited to 'rgo/src')
-rw-r--r-- | rgo/src/fndbyte.S | 44 | ||||
-rw-r--r-- | rgo/src/fndchr.S | 8 | ||||
-rw-r--r-- | rgo/src/memcpy.S | 14 | ||||
-rw-r--r-- | rgo/src/memdup.c | 6 | ||||
-rw-r--r-- | rgo/src/memeq.S | 60 | ||||
-rw-r--r-- | rgo/src/memfill.S | 8 | ||||
-rw-r--r-- | rgo/src/strcpy.S | 39 | ||||
-rw-r--r-- | rgo/src/strdup.c | 6 | ||||
-rw-r--r-- | rgo/src/streq.S | 45 | ||||
-rw-r--r-- | rgo/src/strfill.c | 6 | ||||
-rw-r--r-- | rgo/src/strlen.S | 6 |
11 files changed, 215 insertions, 27 deletions
diff --git a/rgo/src/fndbyte.S b/rgo/src/fndbyte.S new file mode 100644 index 0000000..2e0ed8b --- /dev/null +++ b/rgo/src/fndbyte.S @@ -0,0 +1,44 @@ +/* + Copyright 2022 Gabriel Jensen + + This file is part of rgo. + + rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <rgo.h> + +.global rgo_fndbyte + +rgo_fndbyte: +#if defined(__x86_64__) + /* + rdi: void const * ptr + rsi: size_t num + dl: uint8_t byte + */ + /* rax: Address of the current element. */ + movq %rdi,%rax + /* rcx: Address of the element after the last element. */ + movq %rdi,%rcx + addq %rsi,%rcx + /* r8b: Current element. */ +.loop: + cmpq %rax,%rcx + je .nfnd /* We have went through the entire array without finding the byte. */ + movb (%rax),%r8b + cmpb %r8b,%dl + je .fnd /* We have found the byte. */ + incq %rax + jmp .loop +.fnd: + subq %rdi,%rax + ret +.nfnd: + movq $0xFFFFFFFFFFFFFFFF,%rax + ret +#endif diff --git a/rgo/src/fndchr.S b/rgo/src/fndchr.S index 97c3768..cacea5e 100644 --- a/rgo/src/fndchr.S +++ b/rgo/src/fndchr.S @@ -3,11 +3,11 @@ This file is part of rgo. - rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>. + You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>. */ #include <rgo.h> @@ -28,7 +28,7 @@ rgo_fndchr: cmpb %dl,%sil je .done /* Exit loop if we have found the character. */ testb %dl,%dl - je .err /* We encounted the null-terminator but not the specified character. */ + je .err /* We encountered the null-terminator but not the specified character. */ incq %rax jmp .loop .done: diff --git a/rgo/src/memcpy.S b/rgo/src/memcpy.S index d20e9d6..51d82f9 100644 --- a/rgo/src/memcpy.S +++ b/rgo/src/memcpy.S @@ -3,11 +3,11 @@ This file is part of rgo. - rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>. + You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>. */ #include <rgo.h> @@ -29,11 +29,11 @@ rgo_memcpy: movq %rsi,%r9 /* r10: Temporary. */ /* xmm0: Temporary. */ -.big128cpy: /* SSE2 is a part of AMD64. */ +.big128cpy: cmpq $0x10,%r9 jl .wrdcpy - movdqu (%rcx),%xmm0 - movdqu %xmm0,(%r8) + movups (%rcx),%xmm0 + movups %xmm0,(%r8) addq $0x10,%rcx addq $0x10,%r8 subq $0x10,%r9 @@ -49,7 +49,7 @@ rgo_memcpy: jmp .wrdcpy .bytecpy: testq %r9,%r9 - je .done + jz .done movb (%rcx),%r10b movb %r10b,(%r8) incq %rcx diff --git a/rgo/src/memdup.c b/rgo/src/memdup.c index 0d166f0..97eefd6 100644 --- a/rgo/src/memdup.c +++ b/rgo/src/memdup.c @@ -3,11 +3,11 @@ This file is part of rgo. - rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>. + You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>. */ #include <rgo.h> diff --git a/rgo/src/memeq.S b/rgo/src/memeq.S new file mode 100644 index 0000000..c3a9a63 --- /dev/null +++ b/rgo/src/memeq.S @@ -0,0 +1,60 @@ +/* + Copyright 2022 Gabriel Jensen + + This file is part of rgo. + + rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <rgo.h> + +.global rgo_memeq + +rgo_memeq: +#if defined(__x86_64__) + /* + rdi: void const * lptr + rsi: size_t num + rdx: void const * rptr + */ + /* rcx: Address of the current left element. */ + movq %rdi,%rcx + /* r8: Address of the current right element. */ + movq %rdx,%r8 + /* r9: Number of remaining elements. */ + movq %rsi,%r9 + /* r10: Temporary. */ + /* r11: Temporary. */ +.wrdeq: + cmpq $0x8,%r9 + jl .byteeq + movq (%rcx),%r10 + movq (%r8),%r11 + cmpq %r10,%r11 + jz .neq + addq $0x8,%rcx + addq $0x8,%r8 + subq $0x8,%r9 + jmp .wrdeq +.byteeq: + testq %r9,%r9 + jz .eq /* If we have reached the final element, all previous elements have compared equal, and the memory sequences are equal. */ + movb (%rcx),%r10b + movb (%r8),%r11b + cmpb %r10b,%r11b + jne .neq + incq %rcx + incq %r8 + decq %r9 + jmp .byteeq +.eq: + mov $0x1,%rax + ret +.neq: + mov $0x0,%rax + ret +#endif diff --git a/rgo/src/memfill.S b/rgo/src/memfill.S index 3c4fb1f..d131c48 100644 --- a/rgo/src/memfill.S +++ b/rgo/src/memfill.S @@ -3,11 +3,11 @@ This file is part of rgo. - rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>. + You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>. */ #include <rgo.h> @@ -24,7 +24,7 @@ rgo_memfill: /* We don't need to preserve any of the registers we use according to the ABI. */ /* rcx: Address of the current element. */ movq %rdi,%rcx - /* r8: Address of the last element. */ + /* rcx: Address of the element after the last element. */ movq %rdi,%r8 addq %rsi,%r8 .loop: diff --git a/rgo/src/strcpy.S b/rgo/src/strcpy.S new file mode 100644 index 0000000..f2fbc36 --- /dev/null +++ b/rgo/src/strcpy.S @@ -0,0 +1,39 @@ +/* + Copyright 2022 Gabriel Jensen + + This file is part of rgo. + + rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <rgo.h> + +.global rgo_strcpy + +rgo_strcpy: +#if defined(__x86_64__) + /* + rdi: char const * lstr + rsi: char const * rstr + */ + /* rax: Address of the current input character. */ + movq %rdi,%rax + /* rdx: Address of the current output character. */ + movq %rsi,%rdx + /* cl: Current character. */ +.loop: + movb (%rax),%cl + movb %cl,(%rdx) + testb %cl,%cl + jz .done + incq %rax + incq %rdx + jmp .loop +.done: + subq %rdi,%rax + ret +#endif diff --git a/rgo/src/strdup.c b/rgo/src/strdup.c index f10ef84..8608187 100644 --- a/rgo/src/strdup.c +++ b/rgo/src/strdup.c @@ -3,11 +3,11 @@ This file is part of rgo. - rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>. + You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>. */ #include <rgo.h> diff --git a/rgo/src/streq.S b/rgo/src/streq.S new file mode 100644 index 0000000..f530d54 --- /dev/null +++ b/rgo/src/streq.S @@ -0,0 +1,45 @@ +/* + Copyright 2022 Gabriel Jensen + + This file is part of rgo. + + rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <rgo.h> + +.global rgo_streq + +rgo_streq: +#if defined(__x86_64__) + /* + rdi: char const * lstr + rsi: char const * rstr + */ + /* rdx: Address of the current input character. */ + movq %rdi,%rdx + /* rcx: Address of the current output character. */ + movq %rsi,%rcx + /* r8b: Current input character. */ + /* r9b: Current output character. */ +.loop: + movb (%rdx),%r8b + movb (%rcx),%r9b + cmpb %r8b,%r9b + jne .neq + testb %r8b,%r8b /* Check if we have reached the null-terminator. */ + jz .eq + incq %rdx + incq %rcx + jmp .loop +.eq: + mov $0x1,%rax + ret +.neq: + mov $0x0,%rax + ret +#endif diff --git a/rgo/src/strfill.c b/rgo/src/strfill.c index 4d73c11..6fb3d4f 100644 --- a/rgo/src/strfill.c +++ b/rgo/src/strfill.c @@ -3,11 +3,11 @@ This file is part of rgo. - rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>. + You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>. */ #include <rgo.h> diff --git a/rgo/src/strlen.S b/rgo/src/strlen.S index ff6ed70..7508be9 100644 --- a/rgo/src/strlen.S +++ b/rgo/src/strlen.S @@ -3,11 +3,11 @@ This file is part of rgo. - rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>. + You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>. */ #include <rgo.h> |