set_optab_libfunc (udiv_optab, HImode, "__udivhi3");
set_optab_libfunc (smod_optab, HImode, "__modhi3");
set_optab_libfunc (umod_optab, HImode, "__umodhi3");
+
+/* The comment below comes from config/mmix/mmix.cc.
+
+ Unfortunately, by default __builtin_ffs is expanded to ffs for
+ targets where INT_TYPE_SIZE < BITS_PER_WORD. That together with
+ newlib since 2017-07-04 implementing ffs as __builtin_ffs leads to
+ (newlib) ffs recursively calling itself. */
+ set_optab_libfunc (ffs_optab, HImode, "__ffshi2");
}
\f
/* Worker function for TARGET_FUNCTION_VALUE.
--- /dev/null
+/* The implementation of __ffshi2.
+ Copyright (C) 2003-2025 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC 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 General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+int __ffshi2 (int x);
+
+int
+__ffshi2 (int x)
+{
+ int i;
+
+ if (!x)
+ return 0;
+
+ i = 0;
+ for (;;)
+ {
+ if (((1 << i++) & x) != 0)
+ return i;
+ }
+ return 0;
+}
LIB2ADD = \
$(srcdir)/config/h8300/clzhi2.c \
$(srcdir)/config/h8300/ctzhi2.c \
+ $(srcdir)/config/h8300/ffshi2.c \
$(srcdir)/config/h8300/parityhi2.c \
$(srcdir)/config/h8300/popcounthi2.c \
$(srcdir)/config/h8300/fixunssfsi.c