diff --git a/libgcc/ChangeLog b/libgcc/ChangeLog
index cc5d41c632bc6c23b683b523381bb5ad600ef33a..59ccf6a79342f9ed16f76a76a916a8b1aae2e560 100644
--- a/libgcc/ChangeLog
+++ b/libgcc/ChangeLog
@@ -1,3 +1,14 @@
+2007-09-17  Chao-ying Fu  <fu@mips.com>
+	    Nigel Stephens  <nigel@mips.com>
+
+	* fixed-obj.mk: New file to support fine-grain fixed-point functions.
+	* Makefile.in (fixed_point): Define.
+	Check if fixed_point is yes to build support functions.
+	* configure.ac: Check for fixed_point support.
+	* configure: Regenerated.
+	* gen-fixed.sh: New file to generate lists of fixed-point labels,
+	funcs, modes, from, to.
+
 2007-09-11  Janis Johnson  <janis187@us.ibm.com
 
 	* Makefile.in (dfp-filenames): Add bid128_noncomp.
diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in
index 6e1807f813430385fde52a9447e8e438af93f990..77c5f1ebed8a73538375f4c98f097b7e5565913c 100644
--- a/libgcc/Makefile.in
+++ b/libgcc/Makefile.in
@@ -38,6 +38,7 @@ SHELL = @SHELL@
 enable_shared = @enable_shared@
 decimal_float = @decimal_float@
 enable_decimal_float = @enable_decimal_float@
+fixed_point = @fixed_point@
 
 host_noncanonical = @host_noncanonical@
 
@@ -575,6 +576,48 @@ endif
 
 endif
 
+# Build fixed-point support.
+ifeq ($(fixed_point),yes)
+
+# Generate permutations of function name and mode
+fixed-labels := $(shell $(SHELL) $(srcdir)/gen-fixed.sh arith labels)
+fixed-funcs := $(shell $(SHELL) $(srcdir)/gen-fixed.sh arith funcs)
+fixed-modes := $(shell $(SHELL) $(srcdir)/gen-fixed.sh arith modes)
+
+# Generate the rules for each arithmetic function
+iter-items := $(fixed-funcs)
+iter-labels := $(fixed-labels)
+iter-from := $(fixed-modes)
+iter-to := $(fixed-modes)
+include $(srcdir)/empty.mk $(patsubst %,$(srcdir)/fixed-obj.mk,$(iter-items))
+
+# Add arithmetic functions to list of objects to be built
+libgcc-objects += $(patsubst %,%$(objext),$(fixed-funcs))
+ifeq ($(enable_shared),yes)
+libgcc-s-objects += $(patsubst %,%_s$(objext),$(fixed-funcs))
+endif
+
+# Convert from or to fractional
+fixed-conv-funcs := $(shell $(SHELL) $(srcdir)/gen-fixed.sh conv funcs)
+fixed-conv-labels := $(shell $(SHELL) $(srcdir)/gen-fixed.sh conv labels)
+fixed-conv-from := $(shell $(SHELL) $(srcdir)/gen-fixed.sh conv from)
+fixed-conv-to :=  $(shell $(SHELL) $(srcdir)/gen-fixed.sh conv to)
+
+# Generate the make rules for each conversion function
+iter-items := $(fixed-conv-funcs)
+iter-labels := $(fixed-conv-labels)
+iter-from := $(fixed-conv-from)
+iter-to := $(fixed-conv-to)
+include $(srcdir)/empty.mk $(patsubst %,$(srcdir)/fixed-obj.mk,$(iter-items))
+
+# Add conversion functions to list of objects to be built
+libgcc-objects += $(patsubst %,%$(objext),$(fixed-conv-funcs))
+ifeq ($(enable_shared),yes)
+libgcc-s-objects += $(patsubst %,%_s$(objext),$(fixed-conv-funcs))
+endif
+
+endif
+
 # Build LIB2ADD and LIB2ADD_ST.
 ifneq ($(filter-out %.c %.S %.asm,$(LIB2ADD) $(LIB2ADD_ST)),)
 $(error Unsupported files in LIB2ADD or LIB2ADD_ST.)
diff --git a/libgcc/configure b/libgcc/configure
index 7d9be9bfa6914b46912ce2cd7e5ee95f03e9c09e..e6bbd7230a61df3ab0254106a59afce621863b56 100644
--- a/libgcc/configure
+++ b/libgcc/configure
@@ -272,7 +272,7 @@ PACKAGE_STRING='GNU C Runtime Library 1.0'
 PACKAGE_BUGREPORT=''
 
 ac_unique_file="static-object.mk"
-ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS libgcc_topdir enable_shared slibdir INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA AWK build build_cpu build_vendor build_os host host_cpu host_vendor host_os host_noncanonical build_libsubdir build_subdir host_subdir target_subdir AR ac_ct_AR LIPO ac_ct_LIPO NM ac_ct_NM RANLIB ac_ct_RANLIB STRIP ac_ct_STRIP LN_S CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP decimal_float enable_decimal_float vis_hide set_have_cc_tls tmake_file extra_parts asm_hidden_op LIBOBJS LTLIBOBJS'
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS libgcc_topdir enable_shared slibdir INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA AWK build build_cpu build_vendor build_os host host_cpu host_vendor host_os host_noncanonical build_libsubdir build_subdir host_subdir target_subdir AR ac_ct_AR LIPO ac_ct_LIPO NM ac_ct_NM RANLIB ac_ct_RANLIB STRIP ac_ct_STRIP LN_S CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP decimal_float enable_decimal_float fixed_point vis_hide set_have_cc_tls tmake_file extra_parts asm_hidden_op LIBOBJS LTLIBOBJS'
 ac_subst_files=''
 
 # Initialize some variables set by options.
@@ -3330,6 +3330,51 @@ if test x$enable_decimal_float = xyes; then
 fi
 
 
+# Check for fixed-point support.
+echo "$as_me:$LINENO: checking whether fixed-point is supported" >&5
+echo $ECHO_N "checking whether fixed-point is supported... $ECHO_C" >&6
+if test "${libgcc_cv_fixed_point+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+_Sat _Fract x;
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  libgcc_cv_fixed_point=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+libgcc_cv_fixed_point=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $libgcc_cv_fixed_point" >&5
+echo "${ECHO_T}$libgcc_cv_fixed_point" >&6
+fixed_point=$libgcc_cv_fixed_point
+
+
 # Collect host-machine-specific information.
 . ${srcdir}/config.host
 
@@ -4152,6 +4197,7 @@ s,@OBJEXT@,$OBJEXT,;t t
 s,@CPP@,$CPP,;t t
 s,@decimal_float@,$decimal_float,;t t
 s,@enable_decimal_float@,$enable_decimal_float,;t t
+s,@fixed_point@,$fixed_point,;t t
 s,@vis_hide@,$vis_hide,;t t
 s,@set_have_cc_tls@,$set_have_cc_tls,;t t
 s,@tmake_file@,$tmake_file,;t t
diff --git a/libgcc/configure.ac b/libgcc/configure.ac
index 0a8d235a744dffbbe38d630100bee1131b0d870e..6ab7ebf3948a5e313b6871ab8df42a3ba3072bb3 100644
--- a/libgcc/configure.ac
+++ b/libgcc/configure.ac
@@ -145,6 +145,13 @@ if test x$enable_decimal_float = xyes; then
 fi
 AC_SUBST(enable_decimal_float)
 
+# Check for fixed-point support.
+AC_CACHE_CHECK([whether fixed-point is supported], [libgcc_cv_fixed_point],
+	       [AC_COMPILE_IFELSE([_Sat _Fract x;], [libgcc_cv_fixed_point=yes],
+				  [libgcc_cv_fixed_point=no])])
+fixed_point=$libgcc_cv_fixed_point
+AC_SUBST(fixed_point)
+
 # Collect host-machine-specific information.
 . ${srcdir}/config.host
 
diff --git a/libgcc/fixed-obj.mk b/libgcc/fixed-obj.mk
new file mode 100644
index 0000000000000000000000000000000000000000..3c7c2f3173eed82e3dcd64c1bd3fd8536a1fe9ff
--- /dev/null
+++ b/libgcc/fixed-obj.mk
@@ -0,0 +1,31 @@
+# This file is included several times in a row, once for each element of
+# $(iter-items).  On each inclusion, we advance $o to the next element.
+# $(iter-labels) and $(iter-from) and $(iter-to) are also advanced.
+
+o := $(firstword $(iter-items))
+iter-items := $(filter-out $o,$(iter-items))
+
+$o-label := $(firstword $(iter-labels))
+iter-labels := $(wordlist 2,$(words $(iter-labels)),$(iter-labels))
+
+$o-from := $(firstword $(iter-from))
+iter-from := $(wordlist 2,$(words $(iter-from)),$(iter-from))
+
+$o-to := $(firstword $(iter-to))
+iter-to := $(wordlist 2,$(words $(iter-to)),$(iter-to))
+
+ifeq ($($o-from),$($o-to))
+$o-opt := -D$($o-from)_MODE
+else
+$o-opt := -DFROM_$($o-from) -DTO_$($o-to)
+endif
+
+#$(info $o$(objext): -DL$($o-label) $($o-opt))
+
+$o$(objext): %$(objext): $(gcc_srcdir)/config/fixed-bit.c
+	$(gcc_compile) -DL$($*-label) $($*-opt) -c $(gcc_srcdir)/config/fixed-bit.c $(vis_hide)
+
+ifeq ($(enable_shared),yes)
+$(o)_s$(objext): %_s$(objext): $(gcc_srcdir)/config/fixed-bit.c
+	$(gcc_s_compile) -DL$($*-label) $($*-opt) -c $(gcc_srcdir)/config/fixed-bit.c
+endif
diff --git a/libgcc/gen-fixed.sh b/libgcc/gen-fixed.sh
new file mode 100644
index 0000000000000000000000000000000000000000..774996110706da973de9026b7c2f7091fedfe62c
--- /dev/null
+++ b/libgcc/gen-fixed.sh
@@ -0,0 +1,105 @@
+#!/bin/sh
+
+# Worker script for libgcc/Makefile.in
+# Generate lists of fixed-point labels, funcs, modes, from, to.
+# Usage:
+#    gen-fixed.sh arith labels
+#    gen-fixed.sh arith funcs
+#    gen-fixed.sh arith modes
+#    gen-fixed.sh conv labels
+#    gen-fixed.sh conv funcs
+#    gen-fixed.sh conv from
+#    gen-fixed.sh conv to
+
+fixed_sfract_modes="QQ HQ SQ DQ TQ HA SA DA TA"
+fixed_ufract_modes="UQQ UHQ USQ UDQ UTQ UHA USA UDA UTA"
+fixed_fract_modes="$fixed_sfract_modes $fixed_ufract_modes"
+
+fixed_signed_modes="QI HI SI DI TI SF DF"
+fixed_unsigned_modes="UQI UHI USI UDI UTI"
+
+fixed_func_names="_add _sub _neg _mul _mulhelper _divhelper _ashl _ashlhelper _cmp _saturate1 _saturate2"
+fixed_sfunc_names="_ssadd _sssub _ssneg _ssmul _ssdiv _div _ssashl _ashr"
+fixed_ufunc_names="_usadd _ussub _usneg _usmul _usdiv _udiv _usashl _lshr"
+
+# emit the function information
+# $1 = output type selector
+# $2 = base function name
+# $3 = from mode
+# $4 = to mode
+emit ()
+{
+    if [ "$3" != "$4" ]; then
+	case "$1" in
+	  labels)
+            echo $2 ;;
+	  from | modes)
+	    echo $3 ;;
+	  to)
+	    echo $4 ;;
+	  funcs)
+	    echo $2$3$4 ;;
+	esac
+    fi
+}
+
+case "$1" in
+  arith)
+    for n in $fixed_func_names; do
+	for m in $fixed_fract_modes; do
+	    emit $2 $n $m
+	done
+    done
+
+    for n in $fixed_sfunc_names; do
+	for m in $fixed_sfract_modes; do
+	    emit $2 $n $m
+	done
+    done
+
+    for n in $fixed_ufunc_names; do
+	for m in $fixed_ufract_modes; do
+	    emit $2 $n $m
+	done
+    done
+    ;;
+
+  conv)
+    for f in $fixed_fract_modes; do
+	for t in $fixed_fract_modes $fixed_signed_modes; do
+	    emit $2 _fract $f $t
+	done
+    done
+
+    for f in $fixed_signed_modes; do
+	for t in $fixed_fract_modes; do
+	    emit $2 _fract $f $t
+	done
+    done
+
+    for f in $fixed_fract_modes $fixed_signed_modes; do
+	for t in $fixed_fract_modes; do
+	    emit $2 _satfract $f $t
+	done
+    done
+
+    for f in $fixed_fract_modes; do
+	for t in $fixed_unsigned_modes; do
+	    emit $2 _fractuns $f $t
+	done
+    done
+
+    for f in $fixed_unsigned_modes; do
+	for t in $fixed_fract_modes; do
+	    emit $2 _fractuns $f $t
+	done
+    done
+
+    for f in $fixed_unsigned_modes; do
+	for t in $fixed_fract_modes; do
+	    emit $2 _satfractuns $f $t
+	done
+    done
+    ;;
+
+esac