diff --git a/libc/Makefile b/libc/Makefile index 25d5ead8..72aef646 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -98,6 +98,9 @@ stdlib/strtof.o \ stdlib/strtold.o \ stdlib/wcstombs.o \ stdlib/wctomb.o \ +string/ffsll.o \ +string/ffsl.o \ +string/ffs.o \ string/memccpy.o \ string/memchr.o \ string/memcmp.o \ diff --git a/libc/include/string.h b/libc/include/string.h index 7fa8f901..057926b0 100644 --- a/libc/include/string.h +++ b/libc/include/string.h @@ -34,6 +34,9 @@ __BEGIN_DECLS @include(size_t.h) @include(locale_t.h) +int ffs(int); +int ffsl(long int); +int ffsll(long long int); void* memccpy(void* __restrict, const void* __restrict, int, size_t); void* memchr(const void*, int, size_t); int memcmp(const void*, const void*, size_t); diff --git a/libc/string/ffs.cpp b/libc/string/ffs.cpp new file mode 100644 index 00000000..84b11519 --- /dev/null +++ b/libc/string/ffs.cpp @@ -0,0 +1,30 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix C Library 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. + + The Sortix C Library 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 the Sortix C Library. If not, see . + + string/ffs.cpp + Returns the index of the first set bit. + +*******************************************************************************/ + +#include + +extern "C" int ffs(int val) +{ + return __builtin_ffs(val); +} diff --git a/libc/string/ffsl.cpp b/libc/string/ffsl.cpp new file mode 100644 index 00000000..35d8173d --- /dev/null +++ b/libc/string/ffsl.cpp @@ -0,0 +1,30 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix C Library 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. + + The Sortix C Library 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 the Sortix C Library. If not, see . + + string/ffsl.cpp + Returns the index of the first set bit. + +*******************************************************************************/ + +#include + +extern "C" int ffsl(long int val) +{ + return __builtin_ffsl(val); +} diff --git a/libc/string/ffsll.cpp b/libc/string/ffsll.cpp new file mode 100644 index 00000000..30661ea9 --- /dev/null +++ b/libc/string/ffsll.cpp @@ -0,0 +1,30 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix C Library 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. + + The Sortix C Library 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 the Sortix C Library. If not, see . + + string/ffsll.cpp + Returns the index of the first set bit. + +*******************************************************************************/ + +#include + +extern "C" int ffsll(long long int val) +{ + return __builtin_ffsll(val); +}