Skip to content

Commit 6f2d8ef

Browse files
committed
implement ffs
1 parent f5d2996 commit 6f2d8ef

File tree

14 files changed

+264
-0
lines changed

14 files changed

+264
-0
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ set(TARGET_LIBC_ENTRYPOINTS
9393
libc.src.strings.bcmp
9494
libc.src.strings.bcopy
9595
libc.src.strings.bzero
96+
libc.src.strings.ffs
97+
libc.src.strings.ffsl
98+
libc.src.strings.ffsll
9699
libc.src.strings.index
97100
libc.src.strings.rindex
98101
libc.src.strings.strcasecmp

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ set(TARGET_LIBC_ENTRYPOINTS
9393
libc.src.strings.bcmp
9494
libc.src.strings.bcopy
9595
libc.src.strings.bzero
96+
libc.src.strings.ffs
97+
libc.src.strings.ffsl
98+
libc.src.strings.ffsll
9699
libc.src.strings.index
97100
libc.src.strings.rindex
98101
libc.src.strings.strcasecmp

libc/include/strings.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ functions:
2929
arguments:
3030
- type: void *
3131
- type: size_t
32+
- name: ffs
33+
standards:
34+
- POSIX
35+
return_type: int
36+
arguments:
37+
- int
38+
- name: ffsl
39+
standards:
40+
- POSIX
41+
return_type: int
42+
arguments:
43+
- long
44+
- name: ffsll
45+
standards:
46+
- POSIX
47+
return_type: int
48+
arguments:
49+
- long long
3250
- name: index
3351
standards:
3452
- BSDExtensions

libc/src/strings/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,30 @@ add_entrypoint_object(
5454
bcopy.h
5555
)
5656

57+
add_entrypoint_object(
58+
ffs
59+
SRCS
60+
ffs.cpp
61+
HDRS
62+
ffs.h
63+
)
64+
65+
add_entrypoint_object(
66+
ffsl
67+
SRCS
68+
ffsl.cpp
69+
HDRS
70+
ffsl.h
71+
)
72+
73+
add_entrypoint_object(
74+
ffsll
75+
SRCS
76+
ffsll.cpp
77+
HDRS
78+
ffsll.h
79+
)
80+
5781
add_entrypoint_object(
5882
index
5983
SRCS

libc/src/strings/ffs.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===-- Implementation of ffs ---------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/strings/ffs.h"
10+
#include "src/__support/common.h"
11+
#include "src/__support/macros/config.h"
12+
13+
namespace LIBC_NAMESPACE_DECL {
14+
15+
LLVM_LIBC_FUNCTION(int, ffs, (int i)) { return __builtin_ffs(i); }
16+
17+
} // namespace LIBC_NAMESPACE_DECL

libc/src/strings/ffs.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for ffs ---------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_STRINGS_FFS_H
10+
#define LLVM_LIBC_SRC_STRINGS_FFS_H
11+
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
int ffs(int i);
17+
18+
} // namespace LIBC_NAMESPACE_DECL
19+
20+
#endif // LLVM_LIBC_SRC_STRINGS_FFS_H

libc/src/strings/ffsl.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===-- Implementation of ffsl --------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/strings/ffsl.h"
10+
#include "src/__support/common.h"
11+
#include "src/__support/macros/config.h"
12+
13+
namespace LIBC_NAMESPACE_DECL {
14+
15+
LLVM_LIBC_FUNCTION(int, ffsl, (long i)) { return __builtin_ffsl(i); }
16+
17+
} // namespace LIBC_NAMESPACE_DECL

libc/src/strings/ffsl.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for ffsl --------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_STRINGS_FFSL_H
10+
#define LLVM_LIBC_SRC_STRINGS_FFSL_H
11+
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
int ffsl(long i);
17+
18+
} // namespace LIBC_NAMESPACE_DECL
19+
20+
#endif // LLVM_LIBC_SRC_STRINGS_FFSL_H

libc/src/strings/ffsll.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===-- Implementation of ffsll -------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/strings/ffsll.h"
10+
#include "src/__support/common.h"
11+
#include "src/__support/macros/config.h"
12+
13+
namespace LIBC_NAMESPACE_DECL {
14+
15+
LLVM_LIBC_FUNCTION(int, ffsll, (long long i)) { return __builtin_ffsll(i); }
16+
17+
} // namespace LIBC_NAMESPACE_DECL

libc/src/strings/ffsll.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for ffsll -------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_STRINGS_FFSLL_H
10+
#define LLVM_LIBC_SRC_STRINGS_FFSLL_H
11+
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
int ffsll(long long i);
17+
18+
} // namespace LIBC_NAMESPACE_DECL
19+
20+
#endif // LLVM_LIBC_SRC_STRINGS_FFSLL_H

0 commit comments

Comments
 (0)