From 363dbb9e44d0101f29ec34cadd001893daab3fc6 Mon Sep 17 00:00:00 2001 From: Kito Cheng Date: Thu, 27 Jul 2017 16:44:22 +0800 Subject: Add RISC-V port for newlib Contributor list: - Andrew Waterman - Palmer Dabbelt - Kito Cheng - Scott Beamer --- newlib/libc/machine/riscv/ffs.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 newlib/libc/machine/riscv/ffs.c (limited to 'newlib/libc/machine/riscv/ffs.c') diff --git a/newlib/libc/machine/riscv/ffs.c b/newlib/libc/machine/riscv/ffs.c new file mode 100644 index 000000000..652207722 --- /dev/null +++ b/newlib/libc/machine/riscv/ffs.c @@ -0,0 +1,32 @@ +/* Copyright (c) 2017 SiFive Inc. All rights reserved. + + This copyrighted material is made available to anyone wishing to use, + modify, copy, or redistribute it subject to the terms and conditions + of the BSD License. This program is distributed in the hope that + it will be useful, but WITHOUT ANY WARRANTY expressed or implied, + including the implied warranties of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. A copy of this license is available at + http://www.opensource.org/licenses. +*/ +#include + +int +ffs (int word) +{ +#if __riscv_xlen == 32 + return (__builtin_ffs (word)); +#else + int i; + + if (!word) + return 0; + + i = 0; + for (;;) + { + if (((1 << i++) & word) != 0) + return i; + } + return 0; +#endif +} -- cgit v1.2.3