source: trunk/libs/newlib/src/newlib/libc/machine/riscv/ffs.c @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 771 bytes
Line 
1/* Copyright (c) 2017  SiFive Inc. All rights reserved.
2
3   This copyrighted material is made available to anyone wishing to use,
4   modify, copy, or redistribute it subject to the terms and conditions
5   of the FreeBSD License.   This program is distributed in the hope that
6   it will be useful, but WITHOUT ANY WARRANTY expressed or implied,
7   including the implied warranties of MERCHANTABILITY or FITNESS FOR
8   A PARTICULAR PURPOSE.  A copy of this license is available at
9   http://www.opensource.org/licenses.
10*/
11#include <strings.h>
12
13int
14ffs (int word)
15{
16#if __riscv_xlen == 32
17  return (__builtin_ffs (word));
18#else
19  int i;
20
21  if (!word)
22    return 0;
23
24  i = 0;
25  for (;;)
26    {
27      if (((1 << i++) & word) != 0)
28       return i;
29    }
30  return 0;
31#endif
32}
Note: See TracBrowser for help on using the repository browser.