• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- Unittests for 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 
11 #include "src/__support/macros/config.h"
12 #include "test/UnitTest/Test.h"
13 
14 namespace LIBC_NAMESPACE_DECL {
15 
TEST(LlvmLibcFfslTest,SimpleFfsl)16 TEST(LlvmLibcFfslTest, SimpleFfsl) {
17   ASSERT_EQ(ffsl(0x00000000L), 0);
18   ASSERT_EQ(ffsl(0x00000001L), 1);
19   ASSERT_EQ(ffsl(0x00000020L), 6);
20   ASSERT_EQ(ffsl(0x00000400L), 11);
21   ASSERT_EQ(ffsl(0x00008000L), 16);
22   ASSERT_EQ(ffsl(0x00010000L), 17);
23   ASSERT_EQ(ffsl(0x00200000L), 22);
24   ASSERT_EQ(ffsl(0x04000000L), 27);
25   ASSERT_EQ(ffsl(0x80000000L), 32);
26 #ifdef __LP64__
27   ASSERT_EQ(ffsl(0x0000000100000000L), 33);
28   ASSERT_EQ(ffsl(0x0000002000000000L), 38);
29   ASSERT_EQ(ffsl(0x0000040000000000L), 43);
30   ASSERT_EQ(ffsl(0x0000800000000000L), 48);
31   ASSERT_EQ(ffsl(0x0001000000000000L), 49);
32   ASSERT_EQ(ffsl(0x0020000000000000L), 54);
33   ASSERT_EQ(ffsl(0x0400000000000000L), 59);
34   ASSERT_EQ(ffsl(0x8000000000000000L), 64);
35 #endif
36   ASSERT_EQ(ffsl(0xfbe71L), 1);
37   ASSERT_EQ(ffsl(0xfbe70L), 5);
38   ASSERT_EQ(ffsl(0x10L), 5);
39   ASSERT_EQ(ffsl(0x100L), 9);
40 }
41 
42 } // namespace LIBC_NAMESPACE_DECL
43