OSDN Git Service

2011-10-26 Paolo Carlini <paolo.carlini@oracle.com>
[pf3gnuchains/gcc-fork.git] / gcc / libgcc2.c
index 0966ac2..57c40c5 100644 (file)
@@ -1,34 +1,29 @@
 /* More subroutines needed by GCC output code on some machines.  */
 /* Compile this one with gcc.  */
 /* Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
+   2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
    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 2, or (at your option) any later
+Software Foundation; either version 3, or (at your option) any later
 version.
 
-In addition to the permissions in the GNU General Public License, the
-Free Software Foundation gives you unlimited permission to link the
-compiled version of this file into combinations with other programs,
-and to distribute those combinations without any restriction coming
-from the use of this file.  (The General Public License restrictions
-do apply in other respects; for example, they cover modification of
-the file, and distribution when not linked into a combine
-executable.)
-
 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.
 
-You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING.  If not, write to the Free
-Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301, USA.  */
+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/>.  */
 
 #include "tconfig.h"
 #include "tsystem.h"
@@ -41,15 +36,11 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
 #define ATTRIBUTE_HIDDEN
 #endif
 
-#ifndef MIN_UNITS_PER_WORD
-#define MIN_UNITS_PER_WORD UNITS_PER_WORD
-#endif
-
 /* Work out the largest "word" size that we can deal with on this target.  */
 #if MIN_UNITS_PER_WORD > 4
 # define LIBGCC2_MAX_UNITS_PER_WORD 8
 #elif (MIN_UNITS_PER_WORD > 2 \
-       || (MIN_UNITS_PER_WORD > 1 && LONG_LONG_TYPE_SIZE > 32))
+       || (MIN_UNITS_PER_WORD > 1 && __SIZEOF_LONG_LONG__ > 4))
 # define LIBGCC2_MAX_UNITS_PER_WORD 4
 #else
 # define LIBGCC2_MAX_UNITS_PER_WORD MIN_UNITS_PER_WORD
@@ -416,7 +407,7 @@ __lshrdi3 (DWtype u, shift_count_type b)
     return u;
 
   const DWunion uu = {.ll = u};
-  const shift_count_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
+  const shift_count_type bm = W_TYPE_SIZE - b;
   DWunion w;
 
   if (bm <= 0)
@@ -444,7 +435,7 @@ __ashldi3 (DWtype u, shift_count_type b)
     return u;
 
   const DWunion uu = {.ll = u};
-  const shift_count_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
+  const shift_count_type bm = W_TYPE_SIZE - b;
   DWunion w;
 
   if (bm <= 0)
@@ -472,13 +463,13 @@ __ashrdi3 (DWtype u, shift_count_type b)
     return u;
 
   const DWunion uu = {.ll = u};
-  const shift_count_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
+  const shift_count_type bm = W_TYPE_SIZE - b;
   DWunion w;
 
   if (bm <= 0)
     {
       /* w.s.high = 1..1 or 0..0 */
-      w.s.high = uu.s.high >> (sizeof (Wtype) * BITS_PER_UNIT - 1);
+      w.s.high = uu.s.high >> (W_TYPE_SIZE - 1);
       w.s.low = uu.s.high >> -bm;
     }
   else
@@ -543,7 +534,7 @@ __ffsDI2 (DWtype u)
   if (uu.s.low != 0)
     word = uu.s.low, add = 0;
   else if (uu.s.high != 0)
-    word = uu.s.high, add = BITS_PER_UNIT * sizeof (Wtype);
+    word = uu.s.high, add = W_TYPE_SIZE;
   else
     return 0;
 
@@ -771,7 +762,50 @@ __ctzDI2 (UDWtype x)
   return ret + add;
 }
 #endif
+\f
+#ifdef L_clrsbsi2
+#undef int
+int
+__clrsbSI2 (Wtype x)
+{
+  Wtype ret;
 
+  if (x < 0)
+    x = ~x;
+  if (x == 0)
+    return W_TYPE_SIZE - 1;
+  count_leading_zeros (ret, x);
+  return ret - 1;
+}
+#endif
+\f
+#ifdef L_clrsbdi2
+#undef int
+int
+__clrsbDI2 (DWtype x)
+{
+  const DWunion uu = {.ll = x};
+  UWtype word;
+  Wtype ret, add;
+
+  if (uu.s.high == 0)
+    word = uu.s.low, add = W_TYPE_SIZE;
+  else if (uu.s.high == -1)
+    word = ~uu.s.low, add = W_TYPE_SIZE;
+  else if (uu.s.high >= 0)
+    word = uu.s.high, add = 0;
+  else
+    word = ~uu.s.high, add = 0;
+
+  if (word == 0)
+    ret = W_TYPE_SIZE;
+  else
+    count_leading_zeros (ret, word);
+
+  return ret + add - 1;
+}
+#endif
+\f
 #ifdef L_popcount_tab
 const UQItype __popcount_tab[256] =
 {
@@ -1807,7 +1841,7 @@ NAME (TYPE x, int m)
 #define isfinite(x)    __builtin_expect (!isnan((x) - (x)), 1)
 #define isinf(x)       __builtin_expect (!isnan(x) & !isfinite(x), 0)
 
-#define INFINITY       CONCAT2(__builtin_inf, CEXT) ()
+#define INFINITY       CONCAT2(__builtin_huge_val, CEXT) ()
 #define I              1i
 
 /* Helpers to make the following code slightly less gross.  */
@@ -2036,24 +2070,14 @@ __clear_cache (char *beg __attribute__((__unused__)),
 
 #endif /* L_clear_cache */
 \f
-#ifdef L_enable_execute_stack
-/* Attempt to turn on execute permission for the stack.  */
-
-#ifdef ENABLE_EXECUTE_STACK
-  ENABLE_EXECUTE_STACK
-#else
-void
-__enable_execute_stack (void *addr __attribute__((__unused__)))
-{}
-#endif /* ENABLE_EXECUTE_STACK */
-
-#endif /* L_enable_execute_stack */
-\f
 #ifdef L_trampoline
 
 /* Jump to a trampoline, loading the static chain address.  */
 
 #if defined(WINNT) && ! defined(__CYGWIN__)
+#include <windows.h>
+int getpagesize (void);
+int mprotect (char *,int, int);
 
 int
 getpagesize (void)
@@ -2068,7 +2092,7 @@ getpagesize (void)
 int
 mprotect (char *addr, int len, int prot)
 {
-  int np, op;
+  DWORD np, op;
 
   if (prot == 7)
     np = 0x40;
@@ -2082,6 +2106,8 @@ mprotect (char *addr, int len, int prot)
     np = 0x02;
   else if (prot == 0)
     np = 0x01;
+  else
+    return -1;
 
   if (VirtualProtect (addr, len, np, &op))
     return 0;