2005-09-09 10:39:18 +02:00
|
|
|
/* This file contains 16-bit versions of some of the functions found in
|
|
|
|
libgcc2.c. Really libgcc ought to be moved out of the gcc directory
|
|
|
|
and into its own top level directory, and then split up into multiple
|
|
|
|
files. On this glorious day maybe this code can be integrated into
|
|
|
|
it too. */
|
|
|
|
|
Move libgcc_tm_file to toplevel libgcc
gcc:
* configure.ac (libgcc_tm_file_list, libgcc_tm_include_list):
Remove.
* configure: Regenerate.
* Makefile.in (libgcc_tm_file_list, libgcc_tm_include_list): Remove.
(TM_H): Remove libgcc_tm.h, $(libgcc_tm_file_list).
(libgcc_tm.h, cs-libgcc_tm.h): Remove.
(clean): Remove libgcc_tm.h
* mkconfig.sh: Don't include libgcc_tm.h in tm.h.
* config.gcc (libgcc_tm_file): Remove.
(arm*-*-linux*): Remove libgcc_tm_file for arm*-*-linux-*eabi.
(arm*-*-uclinux*): Remove libgcc_tm_file for arm*-*-uclinux*eabi.
(arm*-*-eabi*, arm*-*-symbianelf*): Remove libgcc_tm_file.
(avr-*-rtems*): Likewise.
(avr-*-*): Likewise.
(frv-*-elf): Likewise.
(frv-*-*linux*): Likewise.
(h8300-*-rtems*): Likewise.
(h8300-*-elf*): Likewise.
(i[34567]86-*-darwin*): Likewise.
(x86_64-*-darwin*): Likewise.
(rx-*-elf*): Likewise.
(tic6x-*-elf): Likewise.
(tic6x-*-uclinux): Likewise.
(i[34567]86-*-linux*, x86_64-*-linux*): Likewise.
libgcc:
* configure.ac (tm_file_): New variable.
Determine from tm_file.
(tm_file, tm_defines): Substitute.
* configure: Regenerate.
* mkheader.sh: New file.
* Makefile.in (clean): Remove libgcc_tm.h.
($(objects)): Depend on libgcc_tm.h.
(libgcc_tm_defines, libgcc_tm_file): New variables.
(libgcc_tm.h, libgcc_tm.stamp): New targets.
($(libgcc-objects), $(libgcc-s-objects), $(libgcc-eh-objects))
($(libgcov-objects), $(libunwind-objects), $(libunwind-s-objects))
($(extra-parts)): Depend on libgcc_tm.h.
* config.host (tm_defines, tm_file): New variable.
(arm*-*-linux*): Set tm_file for arm*-*-linux-*eabi.
(arm*-*-uclinux*): Set tm_file for arm*-*-uclinux*eabi.
(arm*-*-eabi*, arm*-*-symbianelf*): Set tm_file.
(avr-*-rtems*): Likewise.
(avr-*-*): Likewise.
(frv-*-elf): Likewise.
(frv-*-*linux*): Likewise.
(h8300-*-rtems*): Likewise.
(h8300-*-elf*): Likewise.
(i[34567]86-*-darwin*): Likewise.
(x86_64-*-darwin*): Likewise.
(rx-*-elf): Likewise.
(tic6x-*-uclinux): Likewise.
(tic6x-*-elf): Likewise.
(i[34567]86-*-linux*, x86_64-*-linux*): Likewise.
* config/alpha/gthr-posix.c: Include libgcc_tm.h.
* config/i386/cygming-crtbegin.c: Likewise.
* config/i386/cygming-crtend.c: Likewise.
* config/ia64/fde-vms.c: Likewise.
* config/ia64/unwind-ia64.c: Likewise.
* config/libbid/bid_gcc_intrinsics.h: Likewise.
* config/rs6000/darwin-fallback.c: Likewise.
* config/stormy16/lib2funcs.c: Likewise.
* config/xtensa/unwind-dw2-xtensa.c: Likewise.
* crtstuff.c: Likewise.
* dfp-bit.h: Likewise.
* emutls.c: Likewise.
* fixed-bit.c: Likewise.
* fp-bit.c: Likewise.
* generic-morestack-thread.c: Likewise.
* generic-morestack.c: Likewise.
* libgcc2.c: Likewise.
* libgcov.c: Likewise.
* unwind-dw2-fde-dip.c: Likewise.
* unwind-dw2-fde.c: Likewise.
* unwind-dw2.c: Likewise.
* unwind-sjlj.c: Likewise.
Co-Authored-By: Paolo Bonzini <bonzini@gnu.org>
From-SVN: r180775
2011-11-02 16:26:35 +01:00
|
|
|
/* Copyright (C) 2005, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
2005-09-09 10:39:18 +02:00
|
|
|
|
|
|
|
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
|
2009-04-09 17:00:19 +02:00
|
|
|
Software Foundation; either version 3, or (at your option) any later
|
2005-09-09 10:39:18 +02:00
|
|
|
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.
|
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
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/>. */
|
2005-09-09 10:39:18 +02:00
|
|
|
|
|
|
|
#include "tconfig.h"
|
|
|
|
#include "tsystem.h"
|
|
|
|
#include "coretypes.h"
|
|
|
|
#include "tm.h"
|
Move libgcc_tm_file to toplevel libgcc
gcc:
* configure.ac (libgcc_tm_file_list, libgcc_tm_include_list):
Remove.
* configure: Regenerate.
* Makefile.in (libgcc_tm_file_list, libgcc_tm_include_list): Remove.
(TM_H): Remove libgcc_tm.h, $(libgcc_tm_file_list).
(libgcc_tm.h, cs-libgcc_tm.h): Remove.
(clean): Remove libgcc_tm.h
* mkconfig.sh: Don't include libgcc_tm.h in tm.h.
* config.gcc (libgcc_tm_file): Remove.
(arm*-*-linux*): Remove libgcc_tm_file for arm*-*-linux-*eabi.
(arm*-*-uclinux*): Remove libgcc_tm_file for arm*-*-uclinux*eabi.
(arm*-*-eabi*, arm*-*-symbianelf*): Remove libgcc_tm_file.
(avr-*-rtems*): Likewise.
(avr-*-*): Likewise.
(frv-*-elf): Likewise.
(frv-*-*linux*): Likewise.
(h8300-*-rtems*): Likewise.
(h8300-*-elf*): Likewise.
(i[34567]86-*-darwin*): Likewise.
(x86_64-*-darwin*): Likewise.
(rx-*-elf*): Likewise.
(tic6x-*-elf): Likewise.
(tic6x-*-uclinux): Likewise.
(i[34567]86-*-linux*, x86_64-*-linux*): Likewise.
libgcc:
* configure.ac (tm_file_): New variable.
Determine from tm_file.
(tm_file, tm_defines): Substitute.
* configure: Regenerate.
* mkheader.sh: New file.
* Makefile.in (clean): Remove libgcc_tm.h.
($(objects)): Depend on libgcc_tm.h.
(libgcc_tm_defines, libgcc_tm_file): New variables.
(libgcc_tm.h, libgcc_tm.stamp): New targets.
($(libgcc-objects), $(libgcc-s-objects), $(libgcc-eh-objects))
($(libgcov-objects), $(libunwind-objects), $(libunwind-s-objects))
($(extra-parts)): Depend on libgcc_tm.h.
* config.host (tm_defines, tm_file): New variable.
(arm*-*-linux*): Set tm_file for arm*-*-linux-*eabi.
(arm*-*-uclinux*): Set tm_file for arm*-*-uclinux*eabi.
(arm*-*-eabi*, arm*-*-symbianelf*): Set tm_file.
(avr-*-rtems*): Likewise.
(avr-*-*): Likewise.
(frv-*-elf): Likewise.
(frv-*-*linux*): Likewise.
(h8300-*-rtems*): Likewise.
(h8300-*-elf*): Likewise.
(i[34567]86-*-darwin*): Likewise.
(x86_64-*-darwin*): Likewise.
(rx-*-elf): Likewise.
(tic6x-*-uclinux): Likewise.
(tic6x-*-elf): Likewise.
(i[34567]86-*-linux*, x86_64-*-linux*): Likewise.
* config/alpha/gthr-posix.c: Include libgcc_tm.h.
* config/i386/cygming-crtbegin.c: Likewise.
* config/i386/cygming-crtend.c: Likewise.
* config/ia64/fde-vms.c: Likewise.
* config/ia64/unwind-ia64.c: Likewise.
* config/libbid/bid_gcc_intrinsics.h: Likewise.
* config/rs6000/darwin-fallback.c: Likewise.
* config/stormy16/lib2funcs.c: Likewise.
* config/xtensa/unwind-dw2-xtensa.c: Likewise.
* crtstuff.c: Likewise.
* dfp-bit.h: Likewise.
* emutls.c: Likewise.
* fixed-bit.c: Likewise.
* fp-bit.c: Likewise.
* generic-morestack-thread.c: Likewise.
* generic-morestack.c: Likewise.
* libgcc2.c: Likewise.
* libgcov.c: Likewise.
* unwind-dw2-fde-dip.c: Likewise.
* unwind-dw2-fde.c: Likewise.
* unwind-dw2.c: Likewise.
* unwind-sjlj.c: Likewise.
Co-Authored-By: Paolo Bonzini <bonzini@gnu.org>
From-SVN: r180775
2011-11-02 16:26:35 +01:00
|
|
|
#include "libgcc_tm.h"
|
2005-09-09 10:39:18 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_GAS_HIDDEN
|
|
|
|
#define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
|
|
|
|
#else
|
|
|
|
#define ATTRIBUTE_HIDDEN
|
|
|
|
#endif
|
|
|
|
|
2008-01-25 12:23:44 +01:00
|
|
|
#ifndef MIN_UNITS_PER_WORD
|
|
|
|
#define MIN_UNITS_PER_WORD UNITS_PER_WORD
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef LIBGCC2_UNITS_PER_WORD
|
|
|
|
# if MIN_UNITS_PER_WORD > 4
|
|
|
|
# define LIBGCC2_UNITS_PER_WORD 8
|
|
|
|
# elif (MIN_UNITS_PER_WORD > 2 \
|
|
|
|
|| (MIN_UNITS_PER_WORD > 1 && LONG_LONG_TYPE_SIZE > 32))
|
|
|
|
# define LIBGCC2_UNITS_PER_WORD 4
|
|
|
|
# else
|
|
|
|
# define LIBGCC2_UNITS_PER_WORD MIN_UNITS_PER_WORD
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define word_type Wtype
|
|
|
|
|
2005-09-09 10:39:18 +02:00
|
|
|
#include "libgcc2.h"
|
|
|
|
#undef int
|
|
|
|
|
|
|
|
/* These prototypes would normally live in libgcc2.h, but this can
|
|
|
|
only happen once the code below is integrated into libgcc2.c. */
|
|
|
|
|
|
|
|
extern USItype udivmodsi4 (USItype, USItype, word_type);
|
|
|
|
extern SItype __divsi3 (SItype, SItype);
|
|
|
|
extern SItype __modsi3 (SItype, SItype);
|
|
|
|
extern SItype __udivsi3 (SItype, SItype);
|
|
|
|
extern SItype __umodsi3 (SItype, SItype);
|
|
|
|
extern SItype __ashlsi3 (SItype, SItype);
|
|
|
|
extern SItype __ashrsi3 (SItype, SItype);
|
|
|
|
extern USItype __lshrsi3 (USItype, USItype);
|
|
|
|
extern int __popcounthi2 (UHWtype);
|
|
|
|
extern int __parityhi2 (UHWtype);
|
|
|
|
extern int __clzhi2 (UHWtype);
|
|
|
|
extern int __ctzhi2 (UHWtype);
|
|
|
|
|
2001-08-25 19:14:36 +02:00
|
|
|
|
2009-11-27 19:56:10 +01:00
|
|
|
#ifdef XSTORMY16_UDIVMODSI4
|
2001-08-25 19:14:36 +02:00
|
|
|
USItype
|
2005-09-09 10:39:18 +02:00
|
|
|
udivmodsi4 (USItype num, USItype den, word_type modwanted)
|
2001-08-25 19:14:36 +02:00
|
|
|
{
|
|
|
|
USItype bit = 1;
|
|
|
|
USItype res = 0;
|
|
|
|
|
2005-09-09 10:39:18 +02:00
|
|
|
while (den < num && bit && !(den & (1L << 31)))
|
2001-08-25 19:14:36 +02:00
|
|
|
{
|
2005-09-09 10:39:18 +02:00
|
|
|
den <<= 1;
|
|
|
|
bit <<= 1;
|
2001-08-25 19:14:36 +02:00
|
|
|
}
|
|
|
|
while (bit)
|
|
|
|
{
|
|
|
|
if (num >= den)
|
|
|
|
{
|
|
|
|
num -= den;
|
|
|
|
res |= bit;
|
|
|
|
}
|
2005-09-09 10:39:18 +02:00
|
|
|
bit >>= 1;
|
|
|
|
den >>= 1;
|
2001-08-25 19:14:36 +02:00
|
|
|
}
|
2005-09-09 10:39:18 +02:00
|
|
|
|
|
|
|
if (modwanted)
|
|
|
|
return num;
|
2001-08-25 19:14:36 +02:00
|
|
|
return res;
|
|
|
|
}
|
2009-11-27 19:56:10 +01:00
|
|
|
#endif
|
2001-08-25 19:14:36 +02:00
|
|
|
|
2009-11-27 19:56:10 +01:00
|
|
|
#ifdef XSTORMY16_DIVSI3
|
2001-08-25 19:14:36 +02:00
|
|
|
SItype
|
|
|
|
__divsi3 (SItype a, SItype b)
|
|
|
|
{
|
|
|
|
word_type neg = 0;
|
|
|
|
SItype res;
|
|
|
|
|
|
|
|
if (a < 0)
|
|
|
|
{
|
|
|
|
a = -a;
|
|
|
|
neg = !neg;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (b < 0)
|
|
|
|
{
|
|
|
|
b = -b;
|
|
|
|
neg = !neg;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = udivmodsi4 (a, b, 0);
|
|
|
|
|
|
|
|
if (neg)
|
|
|
|
res = -res;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2009-11-27 19:56:10 +01:00
|
|
|
#endif
|
2001-08-25 19:14:36 +02:00
|
|
|
|
2009-11-27 19:56:10 +01:00
|
|
|
#ifdef XSTORMY16_MODSI3
|
2001-08-25 19:14:36 +02:00
|
|
|
SItype
|
|
|
|
__modsi3 (SItype a, SItype b)
|
|
|
|
{
|
|
|
|
word_type neg = 0;
|
|
|
|
SItype res;
|
|
|
|
|
|
|
|
if (a < 0)
|
|
|
|
{
|
|
|
|
a = -a;
|
|
|
|
neg = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (b < 0)
|
|
|
|
b = -b;
|
|
|
|
|
|
|
|
res = udivmodsi4 (a, b, 1);
|
|
|
|
|
|
|
|
if (neg)
|
|
|
|
res = -res;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2009-11-27 19:56:10 +01:00
|
|
|
#endif
|
2001-08-25 19:14:36 +02:00
|
|
|
|
2009-11-27 19:56:10 +01:00
|
|
|
#ifdef XSTORMY16_UDIVSI3
|
2001-08-25 19:14:36 +02:00
|
|
|
SItype
|
|
|
|
__udivsi3 (SItype a, SItype b)
|
|
|
|
{
|
|
|
|
return udivmodsi4 (a, b, 0);
|
|
|
|
}
|
2009-11-27 19:56:10 +01:00
|
|
|
#endif
|
2001-08-25 19:14:36 +02:00
|
|
|
|
2009-11-27 19:56:10 +01:00
|
|
|
#ifdef XSTORMY16_UMODSI3
|
2001-08-25 19:14:36 +02:00
|
|
|
SItype
|
|
|
|
__umodsi3 (SItype a, SItype b)
|
|
|
|
{
|
|
|
|
return udivmodsi4 (a, b, 1);
|
|
|
|
}
|
2009-11-27 19:56:10 +01:00
|
|
|
#endif
|
2001-08-25 19:14:36 +02:00
|
|
|
|
2009-11-27 19:56:10 +01:00
|
|
|
#ifdef XSTORMY16_ASHLSI3
|
2001-08-25 19:14:36 +02:00
|
|
|
SItype
|
|
|
|
__ashlsi3 (SItype a, SItype b)
|
|
|
|
{
|
|
|
|
word_type i;
|
|
|
|
|
|
|
|
if (b & 16)
|
|
|
|
a <<= 16;
|
|
|
|
if (b & 8)
|
|
|
|
a <<= 8;
|
|
|
|
for (i = (b & 0x7); i > 0; --i)
|
|
|
|
a <<= 1;
|
|
|
|
return a;
|
|
|
|
}
|
2009-11-27 19:56:10 +01:00
|
|
|
#endif
|
2001-08-25 19:14:36 +02:00
|
|
|
|
2009-11-27 19:56:10 +01:00
|
|
|
#ifdef XSTORMY16_ASHRSI3
|
2001-08-25 19:14:36 +02:00
|
|
|
SItype
|
|
|
|
__ashrsi3 (SItype a, SItype b)
|
|
|
|
{
|
|
|
|
word_type i;
|
|
|
|
|
|
|
|
if (b & 16)
|
|
|
|
a >>= 16;
|
|
|
|
if (b & 8)
|
|
|
|
a >>= 8;
|
|
|
|
for (i = (b & 0x7); i > 0; --i)
|
|
|
|
a >>= 1;
|
|
|
|
return a;
|
|
|
|
}
|
2009-11-27 19:56:10 +01:00
|
|
|
#endif
|
2001-08-25 19:14:36 +02:00
|
|
|
|
2009-11-27 19:56:10 +01:00
|
|
|
#ifdef XSTORMY16_LSHRSI3
|
2001-08-25 19:14:36 +02:00
|
|
|
USItype
|
|
|
|
__lshrsi3 (USItype a, USItype b)
|
|
|
|
{
|
|
|
|
word_type i;
|
|
|
|
|
|
|
|
if (b & 16)
|
|
|
|
a >>= 16;
|
|
|
|
if (b & 8)
|
|
|
|
a >>= 8;
|
|
|
|
for (i = (b & 0x7); i > 0; --i)
|
|
|
|
a >>= 1;
|
|
|
|
return a;
|
|
|
|
}
|
2009-11-27 19:56:10 +01:00
|
|
|
#endif
|
2005-09-02 16:17:36 +02:00
|
|
|
|
2009-11-27 19:56:10 +01:00
|
|
|
#ifdef XSTORMY16_POPCOUNTHI2
|
2005-09-09 10:39:18 +02:00
|
|
|
/* Returns the number of set bits in X.
|
2009-11-27 19:56:10 +01:00
|
|
|
FIXME: The return type really should be "unsigned int"
|
2005-09-09 10:39:18 +02:00
|
|
|
but this is not how the builtin is prototyped. */
|
2005-09-02 16:17:36 +02:00
|
|
|
int
|
2005-09-09 10:39:18 +02:00
|
|
|
__popcounthi2 (UHWtype x)
|
2005-09-02 16:17:36 +02:00
|
|
|
{
|
2005-09-09 10:39:18 +02:00
|
|
|
int ret;
|
2005-09-02 16:17:36 +02:00
|
|
|
|
|
|
|
ret = __popcount_tab [x & 0xff];
|
|
|
|
ret += __popcount_tab [(x >> 8) & 0xff];
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2009-11-27 19:56:10 +01:00
|
|
|
#endif
|
2005-09-02 16:17:36 +02:00
|
|
|
|
2009-11-27 19:56:10 +01:00
|
|
|
#ifdef XSTORMY16_PARITYHI2
|
2005-09-09 10:39:18 +02:00
|
|
|
/* Returns the number of set bits in X, modulo 2.
|
2009-11-27 19:56:10 +01:00
|
|
|
FIXME: The return type really should be "unsigned int"
|
2005-09-09 10:39:18 +02:00
|
|
|
but this is not how the builtin is prototyped. */
|
|
|
|
|
2005-09-02 16:17:36 +02:00
|
|
|
int
|
2005-09-09 10:39:18 +02:00
|
|
|
__parityhi2 (UHWtype x)
|
2005-09-02 16:17:36 +02:00
|
|
|
{
|
|
|
|
x ^= x >> 8;
|
|
|
|
x ^= x >> 4;
|
|
|
|
x &= 0xf;
|
|
|
|
return (0x6996 >> x) & 1;
|
|
|
|
}
|
2009-11-27 19:56:10 +01:00
|
|
|
#endif
|
2005-09-02 16:17:36 +02:00
|
|
|
|
2009-11-27 19:56:10 +01:00
|
|
|
#ifdef XSTORMY16_CLZHI2
|
2009-11-30 11:10:52 +01:00
|
|
|
/* Returns the number of zero-bits from the most significant bit to the
|
|
|
|
first nonzero bit in X. Returns 16 for X == 0. Implemented as a
|
|
|
|
simple for loop in order to save space by removing the need for
|
|
|
|
the __clz_tab array.
|
|
|
|
FIXME: The return type really should be "unsigned int" but this is
|
|
|
|
not how the builtin is prototyped. */
|
|
|
|
#undef unsigned
|
2005-09-02 16:17:36 +02:00
|
|
|
int
|
2005-09-09 10:39:18 +02:00
|
|
|
__clzhi2 (UHWtype x)
|
2005-09-02 16:17:36 +02:00
|
|
|
{
|
2009-11-30 11:10:52 +01:00
|
|
|
unsigned int i;
|
|
|
|
unsigned int c;
|
|
|
|
unsigned int value = x;
|
|
|
|
|
|
|
|
for (c = 0, i = 1 << 15; i; i >>= 1, c++)
|
|
|
|
if (i & value)
|
|
|
|
break;
|
|
|
|
return c;
|
2005-09-02 16:17:36 +02:00
|
|
|
}
|
2009-11-27 19:56:10 +01:00
|
|
|
#endif
|
2005-09-02 16:17:36 +02:00
|
|
|
|
2009-11-27 19:56:10 +01:00
|
|
|
#ifdef XSTORMY16_CTZHI2
|
2005-09-09 10:39:18 +02:00
|
|
|
/* Returns the number of trailing zero bits in X.
|
2009-11-27 19:56:10 +01:00
|
|
|
FIXME: The return type really should be "signed int" since
|
|
|
|
ctz(0) returns -1, but this is not how the builtin is prototyped. */
|
2005-09-09 10:39:18 +02:00
|
|
|
|
2005-09-02 16:17:36 +02:00
|
|
|
int
|
2005-09-09 10:39:18 +02:00
|
|
|
__ctzhi2 (UHWtype x)
|
2005-09-02 16:17:36 +02:00
|
|
|
{
|
2005-09-09 10:39:18 +02:00
|
|
|
/* This is cunning. It converts X into a number with only the one bit
|
2009-11-27 19:56:10 +01:00
|
|
|
set, the bit that was the least significant bit in X. From this we
|
|
|
|
can use the count_leading_zeros to compute the number of trailing
|
|
|
|
bits. */
|
2005-09-09 10:39:18 +02:00
|
|
|
x &= - x;
|
|
|
|
|
2009-11-30 11:10:52 +01:00
|
|
|
return 15 - __builtin_clz (x);
|
2009-11-27 19:56:10 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XSTORMY16_FFSHI2
|
|
|
|
/* Returns one plus the index of the least significant 1-bit of X,
|
|
|
|
or if X is zero, returns zero. FIXME: The return type really
|
|
|
|
should be "unsigned int" but this is not how the builtin is
|
|
|
|
prototyped. */
|
|
|
|
|
|
|
|
int
|
|
|
|
__ffshi2 (UHWtype u)
|
|
|
|
{
|
|
|
|
UHWtype count;
|
|
|
|
|
|
|
|
if (u == 0)
|
|
|
|
return 0;
|
|
|
|
|
2009-11-30 11:10:52 +01:00
|
|
|
return 16 - __builtin_clz (u & - u);
|
2009-11-27 19:56:10 +01:00
|
|
|
}
|
|
|
|
#endif
|
2010-04-22 13:05:12 +02:00
|
|
|
|
2012-07-31 11:09:29 +02:00
|
|
|
#ifdef XSTORMY16_CLRSBHI2
|
|
|
|
/* Returns the number of leading redundant sign bits in X.
|
|
|
|
I.e. the number of bits following the most significant bit which are
|
|
|
|
identical to it. There are no special cases for 0 or other values. */
|
|
|
|
|
|
|
|
int
|
|
|
|
__clrsbhi2 (HWtype x)
|
|
|
|
{
|
|
|
|
if (x < 0)
|
|
|
|
x = ~x;
|
|
|
|
if (x == 0)
|
|
|
|
return 15;
|
|
|
|
return __builtin_clz (x) - 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-04-22 13:05:12 +02:00
|
|
|
#ifdef XSTORMY16_UCMPSI2
|
|
|
|
/* Performs an unsigned comparison of two 32-bit values: A and B.
|
|
|
|
If A is less than B, then 0 is returned. If A is greater than B,
|
|
|
|
then 2 is returned. Otherwise A and B are equal and 1 is returned. */
|
|
|
|
|
|
|
|
word_type
|
|
|
|
__ucmpsi2 (USItype a, USItype b)
|
|
|
|
{
|
2010-04-22 16:28:16 +02:00
|
|
|
word_type hi_a = (a >> 16);
|
|
|
|
word_type hi_b = (b >> 16);
|
2010-04-22 13:05:12 +02:00
|
|
|
|
|
|
|
if (hi_a == hi_b)
|
|
|
|
{
|
2010-04-22 16:28:16 +02:00
|
|
|
word_type low_a = (a & 0xffff);
|
|
|
|
word_type low_b = (b & 0xffff);
|
2010-04-22 13:05:12 +02:00
|
|
|
|
|
|
|
return low_a < low_b ? 0 : (low_a > low_b ? 2 : 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hi_a < hi_b ? 0 : 2;
|
|
|
|
}
|
|
|
|
#endif
|
2010-08-11 13:56:15 +02:00
|
|
|
|
|
|
|
#ifdef XSTORMY16_CMPSI2
|
|
|
|
/* Performs an signed comparison of two 32-bit values: A and B.
|
|
|
|
If A is less than B, then 0 is returned. If A is greater than B,
|
|
|
|
then 2 is returned. Otherwise A and B are equal and 1 is returned. */
|
|
|
|
|
|
|
|
word_type
|
|
|
|
__cmpsi2 (SItype a, SItype b)
|
|
|
|
{
|
|
|
|
word_type hi_a = (a >> 16);
|
|
|
|
word_type hi_b = (b >> 16);
|
|
|
|
|
|
|
|
if (hi_a == hi_b)
|
|
|
|
{
|
|
|
|
word_type low_a = (a & 0xffff);
|
|
|
|
word_type low_b = (b & 0xffff);
|
|
|
|
|
|
|
|
return low_a < low_b ? 0 : (low_a > low_b ? 2 : 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hi_a < hi_b ? 0 : 2;
|
|
|
|
}
|
|
|
|
#endif
|