Bugzilla bug #85673: added assembly implementation of the atomic routines
authorwtc%netscape.com
Sat, 23 Jun 2001 04:09:19 +0000
changeset 1967 dd3e59318f06ae04e02b7c83338bd469d6ca5f69
parent 1965 eaa11da5e5827c3d0b0a3f896b6dace0c408a2da
child 1968 688924831b0477ea58ab096e3b734356cb972e0d
push idunknown
push userunknown
push dateunknown
bugs85673
Bugzilla bug #85673: added assembly implementation of the atomic routines for OS/2 contributed by Michael Kaply of IBM. Modified files: configure configure.in autoconf.mk.in rules.mk _os2.h pr/src/md/os2/Makefile.in pr/src/md/os2/objs.mk os2misc.c
config/autoconf.mk.in
config/rules.mk
configure
configure.in
pr/include/md/_os2.h
pr/src/md/os2/Makefile.in
pr/src/md/os2/objs.mk
pr/src/md/os2/os2misc.c
--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -20,16 +20,17 @@ dist_libdir	= @dist_libdir@
 DIST		= $(dist_prefix)
 
 RELEASE_OBJDIR_NAME = @RELEASE_OBJDIR_NAME@
 OBJDIR_NAME	= @OBJDIR_NAME@
 OBJDIR		= @OBJDIR@
 OBJ_SUFFIX	= @OBJ_SUFFIX@
 LIB_SUFFIX	= @LIB_SUFFIX@
 DLL_SUFFIX	= @DLL_SUFFIX@
+ASM_SUFFIX	= @ASM_SUFFIX@
 MOD_NAME	= @NSPR_MODNAME@
 
 MOD_MAJOR_VERSION = @MOD_MAJOR_VERSION@
 MOD_MINOR_VERSION = @MOD_MINOR_VERSION@
 MOD_REVISION_VERSION = @MOD_REVISION_VERSION@
 
 LIBNSPR		= @LIBNSPR@
 LIBPLC		= @LIBPLC@
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -140,17 +140,17 @@ endif
 #
 # OBJS is the list of object files.  It can be constructed by
 # specifying CSRCS (list of C source files) and ASFILES (list
 # of assembly language source files).
 #
 
 ifndef OBJS
 OBJS		= $(addprefix $(OBJDIR)/,$(CSRCS:.c=.$(OBJ_SUFFIX))) \
-		  $(addprefix $(OBJDIR)/,$(ASFILES:.s=.$(OBJ_SUFFIX)))
+		  $(addprefix $(OBJDIR)/,$(ASFILES:.$(ASM_SUFFIX)=.$(OBJ_SUFFIX)))
 endif
 
 ifeq ($(OS_ARCH), WINNT)
 OBJS += $(RES)
 endif
 
 ifeq ($(MOZ_OS2_TOOLS),VACPP)
 EXTRA_LIBS := $(patsubst -l%,$(DIST)/lib/%.$(LIB_SUFFIX),$(EXTRA_LIBS))
@@ -383,16 +383,22 @@ else
 endif
 endif
 
 
 $(OBJDIR)/%.$(OBJ_SUFFIX): %.s
 	@$(MAKE_OBJDIR)
 	$(AS) -o $@ $(ASFLAGS) -c $<
 
+ifeq ($(MOZ_OS2_TOOLS),VACPP)
+$(OBJDIR)/%.$(OBJ_SUFFIX): %.asm
+	@$(MAKE_OBJDIR)
+	$(AS) -Fdo:./$(OBJDIR) $(ASFLAGS) $<
+endif
+
 %.i: %.c
 	$(CC) -C -E $(CFLAGS) $< > $*.i
 
 %: %.pl
 	rm -f $@; cp $< $@; chmod +x $@
 
 #
 # HACK ALERT
--- a/configure
+++ b/configure
@@ -2590,16 +2590,17 @@ test -n "$PERL" || PERL="echo not_perl"
 
 elif test -z "$PERL"; then
     PERL=perl
 fi
 
 OBJ_SUFFIX=o
 LIB_SUFFIX=a
 DLL_SUFFIX=so
+ASM_SUFFIX=s
 MKSHLIB='$(LD) $(DSO_LDOPTS) -o $@'
 PR_MD_ASFILES=
 PR_MD_CSRCS=
 PR_MD_ARCH_DIR=unix
 AR_FLAGS='cr $@'
 AS='$(CC)'
 ASFLAGS='$(CFLAGS)'
 
@@ -2770,27 +2771,27 @@ EOF
 
     cat >> confdefs.h <<\EOF
 #define SYSV 1
 EOF
 
     DSO_LDOPTS='-brtl -bM:SRE -bnoentry -bexpall'
     ac_safe=`echo "sys/atomic_op.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for sys/atomic_op.h""... $ac_c" 1>&6
-echo "configure:2779: checking for sys/atomic_op.h" >&5
+echo "configure:2780: checking for sys/atomic_op.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2784 "configure"
+#line 2785 "configure"
 #include "confdefs.h"
 #include <sys/atomic_op.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:2789: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:2790: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
   eval "ac_cv_header_$ac_safe=yes"
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
@@ -3999,27 +4000,27 @@ EOF
 EOF
 
     cat >> confdefs.h <<\EOF
 #define _REENTRANT 1
 EOF
 
     ac_safe=`echo "machine/builtins.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for machine/builtins.h""... $ac_c" 1>&6
-echo "configure:4008: checking for machine/builtins.h" >&5
+echo "configure:4009: checking for machine/builtins.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4013 "configure"
+#line 4014 "configure"
 #include "confdefs.h"
 #include <machine/builtins.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:4018: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:4019: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
   eval "ac_cv_header_$ac_safe=yes"
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
@@ -4446,16 +4447,17 @@ EOF
 
     cat >> confdefs.h <<\EOF
 #define _PR_GLOBAL_THREADS_ONLY 1
 EOF
 
     OBJ_SUFFIX=obj
     LIB_SUFFIX=lib
     DLL_SUFFIX=dll
+    ASM_SUFFIX=asm
     DLLTOOL=''
     RC=rc.exe
     PR_MD_ARCH_DIR=os2
     PROG_SUFFIX=.exe
     NSINSTALL=nsinstall
     MDCPUCFG_H=_os2.cfg
     RESOLVE_LINK_SYMBOLS=1
 
@@ -4503,16 +4505,18 @@ EOF
         cat >> confdefs.h <<\EOF
 #define TCPV40HDRS 1
 EOF
 
         cat >> confdefs.h <<\EOF
 #define _X86_ 1
 EOF
 
+        AS=alp
+        ASFLAGS='-Mb'
         AR=-ilib
         AR_FLAGS='/NOL /NOI /O:$(subst /,\\,$@)'
         CFLAGS='/Q /qlibansi /Gd+ /Gm+ /Su4 /Mp /Tl-'
         HOST_CFLAGS="$CFLAGS"
         OS_CFLAGS='/Q /qlibansi /Gd+ /Gm+ /Su4 /Ge- /Tl-'
         OS_EXE_CFLAGS='/Q /qlibansi /Gd+ /Gm+ /Su4 /Ge+ /Tl-'
         CXXFLAGS='/Q /qlibansi /Gd+ /Gm+ /Su4 /Mp /Tl-'
         OS_LIBS='so32dll.lib tcp32dll.lib'
@@ -4544,22 +4548,22 @@ EOF
 
     ;;
    
 esac
 
 if test -z "$SKIP_LIBRARY_CHECKS"; then
 
 echo $ac_n "checking for dlopen""... $ac_c" 1>&6
-echo "configure:4553: checking for dlopen" >&5
+echo "configure:4557: checking for dlopen" >&5
 if eval "test \"`echo '$''{'ac_cv_func_dlopen'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4558 "configure"
+#line 4562 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char dlopen(); below.  */
 #include <assert.h>
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char dlopen();
@@ -4572,17 +4576,17 @@ int main() {
 #if defined (__stub_dlopen) || defined (__stub___dlopen)
 choke me
 #else
 dlopen();
 #endif
 
 ; return 0; }
 EOF
-if { (eval echo configure:4581: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4585: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_dlopen=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_func_dlopen=no"
 fi
@@ -4591,36 +4595,36 @@ fi
 
 if eval "test \"`echo '$ac_cv_func_'dlopen`\" = yes"; then
   echo "$ac_t""yes" 1>&6
   :
 else
   echo "$ac_t""no" 1>&6
 
     echo $ac_n "checking for dlopen in -ldl""... $ac_c" 1>&6
-echo "configure:4600: checking for dlopen in -ldl" >&5
+echo "configure:4604: checking for dlopen in -ldl" >&5
 ac_lib_var=`echo dl'_'dlopen | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   ac_save_LIBS="$LIBS"
 LIBS="-ldl  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 4608 "configure"
+#line 4612 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char dlopen();
 
 int main() {
 dlopen()
 ; return 0; }
 EOF
-if { (eval echo configure:4619: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4623: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=no"
 fi
@@ -4638,23 +4642,23 @@ fi
 
 fi
 
 
 
 
 if test $ac_cv_prog_gcc = yes; then
     echo $ac_n "checking whether ${CC-cc} needs -traditional""... $ac_c" 1>&6
-echo "configure:4647: checking whether ${CC-cc} needs -traditional" >&5
+echo "configure:4651: checking whether ${CC-cc} needs -traditional" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gcc_traditional'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
     ac_pattern="Autoconf.*'x'"
   cat > conftest.$ac_ext <<EOF
-#line 4653 "configure"
+#line 4657 "configure"
 #include "confdefs.h"
 #include <sgtty.h>
 Autoconf TIOCGETP
 EOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
   egrep "$ac_pattern" >/dev/null 2>&1; then
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=yes
@@ -4662,17 +4666,17 @@ else
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=no
 fi
 rm -f conftest*
 
 
   if test $ac_cv_prog_gcc_traditional = no; then
     cat > conftest.$ac_ext <<EOF
-#line 4671 "configure"
+#line 4675 "configure"
 #include "confdefs.h"
 #include <termio.h>
 Autoconf TCGETA
 EOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
   egrep "$ac_pattern" >/dev/null 2>&1; then
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=yes
@@ -4686,22 +4690,22 @@ echo "$ac_t""$ac_cv_prog_gcc_traditional
   if test $ac_cv_prog_gcc_traditional = yes; then
     CC="$CC -traditional"
   fi
 fi
 
 for ac_func in lchown strerror
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:4695: checking for $ac_func" >&5
+echo "configure:4699: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4700 "configure"
+#line 4704 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
 #include <assert.h>
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char $ac_func();
@@ -4714,17 +4718,17 @@ int main() {
 #if defined (__stub_$ac_func) || defined (__stub___$ac_func)
 choke me
 #else
 $ac_func();
 #endif
 
 ; return 0; }
 EOF
-if { (eval echo configure:4723: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4727: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=no"
 fi
@@ -4745,17 +4749,17 @@ done
 
 
 
 
 
 
 
 echo $ac_n "checking for pthread_create in -lpthreads""... $ac_c" 1>&6
-echo "configure:4754: checking for pthread_create in -lpthreads" >&5
+echo "configure:4758: checking for pthread_create in -lpthreads" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { int a = 1;  } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -4767,17 +4771,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthreads"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lpthread""... $ac_c" 1>&6
-echo "configure:4776: checking for pthread_create in -lpthread" >&5
+echo "configure:4780: checking for pthread_create in -lpthread" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { int a = 1;  } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -4789,17 +4793,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthread"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lc_r""... $ac_c" 1>&6
-echo "configure:4798: checking for pthread_create in -lc_r" >&5
+echo "configure:4802: checking for pthread_create in -lc_r" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { int a = 1;  } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -4811,17 +4815,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lc_r"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lc""... $ac_c" 1>&6
-echo "configure:4820: checking for pthread_create in -lc" >&5
+echo "configure:4824: checking for pthread_create in -lc" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { int a = 1;  } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -4961,33 +4965,33 @@ EOF
     fi
 fi
 
 
 if test -n "$USE_PTHREADS"; then
       rm -f conftest*
    ac_cv_have_dash_pthread=no
    echo $ac_n "checking whether ${CC-cc} accepts -pthread""... $ac_c" 1>&6
-echo "configure:4970: checking whether ${CC-cc} accepts -pthread" >&5
+echo "configure:4974: checking whether ${CC-cc} accepts -pthread" >&5
    echo 'int main() { return 0; }' | cat > conftest.c
    ${CC-cc} -pthread -o conftest conftest.c > conftest.out 2>&1
    if test $? -eq 0; then
 	if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthread`" && test -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
 	    ac_cv_have_dash_pthread=yes
 	    CFLAGS="$CFLAGS -pthread"
 	    CXXFLAGS="$CXXFLAGS -pthread"
 	fi
     fi
     rm -f conftest*
     echo "$ac_t""$ac_cv_have_dash_pthread" 1>&6
 
 			    ac_cv_have_dash_pthreads=no
     if test "$ac_cv_have_dash_pthread" = "no"; then
 	    echo $ac_n "checking whether ${CC-cc} accepts -pthreads""... $ac_c" 1>&6
-echo "configure:4986: checking whether ${CC-cc} accepts -pthreads" >&5
+echo "configure:4990: checking whether ${CC-cc} accepts -pthreads" >&5
     	echo 'int main() { return 0; }' | cat > conftest.c
 	    ${CC-cc} -pthreads -o conftest conftest.c > conftest.out 2>&1
     	if test $? -eq 0; then
 	    	if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthreads`" && test -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
 			    ac_cv_have_dash_pthreads=yes
 			    CFLAGS="$CFLAGS -pthreads"
 			    CXXFLAGS="$CXXFLAGS -pthreads"
 		    fi
@@ -5318,16 +5322,17 @@ RELEASE_OBJDIR_NAME="${OS_CONFIG}${CPU_A
 
 
 
 
 
 
 
 
+
 MAKEFILES="
 Makefile 
 config/Makefile
 config/autoconf.mk
 config/nsprincl.mk
 config/nsprincl.sh
 config/nspr-config
 lib/Makefile 
@@ -5568,16 +5573,17 @@ s%@NSPR_MODNAME@%$NSPR_MODNAME%g
 s%@MDCPUCFG_H@%$MDCPUCFG_H%g
 s%@PR_MD_CSRCS@%$PR_MD_CSRCS%g
 s%@PR_MD_ASFILES@%$PR_MD_ASFILES%g
 s%@PR_MD_ARCH_DIR@%$PR_MD_ARCH_DIR%g
 s%@CPU_ARCH@%$CPU_ARCH%g
 s%@OBJ_SUFFIX@%$OBJ_SUFFIX%g
 s%@LIB_SUFFIX@%$LIB_SUFFIX%g
 s%@DLL_SUFFIX@%$DLL_SUFFIX%g
+s%@ASM_SUFFIX@%$ASM_SUFFIX%g
 s%@MKSHLIB@%$MKSHLIB%g
 s%@DSO_CFLAGS@%$DSO_CFLAGS%g
 s%@DSO_LDOPTS@%$DSO_LDOPTS%g
 s%@OS_TARGET@%$OS_TARGET%g
 s%@OS_ARCH@%$OS_ARCH%g
 s%@OS_RELEASE@%$OS_RELEASE%g
 s%@OS_TEST@%$OS_TEST%g
 s%@DEFINES@%$DEFINES%g
--- a/configure.in
+++ b/configure.in
@@ -442,16 +442,17 @@ elif test -z "$PERL"; then
 fi
 
 dnl ========================================================
 dnl Default platform specific options
 dnl ========================================================
 OBJ_SUFFIX=o
 LIB_SUFFIX=a
 DLL_SUFFIX=so
+ASM_SUFFIX=s
 MKSHLIB='$(LD) $(DSO_LDOPTS) -o $@'
 PR_MD_ASFILES=
 PR_MD_CSRCS=
 PR_MD_ARCH_DIR=unix
 AR_FLAGS='cr $@'
 AS='$(CC)'
 ASFLAGS='$(CFLAGS)'
 
@@ -1627,16 +1628,17 @@ mips-sony-newsos*)
 *-os2*)
     AC_DEFINE(XP_OS2)
     AC_DEFINE(BSD_SELECT)
     AC_DEFINE(XP_PC)
     AC_DEFINE(_PR_GLOBAL_THREADS_ONLY)
     OBJ_SUFFIX=obj
     LIB_SUFFIX=lib
     DLL_SUFFIX=dll
+    ASM_SUFFIX=asm
     DLLTOOL=''
     RC=rc.exe
     PR_MD_ARCH_DIR=os2
     PROG_SUFFIX=.exe
     NSINSTALL=nsinstall
     MDCPUCFG_H=_os2.cfg
     RESOLVE_LINK_SYMBOLS=1
 
@@ -1666,16 +1668,18 @@ mips-sony-newsos*)
           DSO_LDOPTS='-Zomf -Zdll -Zmt -Zcrtdll -Zlinker /NOO'
         fi
         ;;
     *-os2_vacpp)
         AC_DEFINE(XP_OS2_VACPP)
         AC_DEFINE(OS2,4)
         AC_DEFINE(TCPV40HDRS)
         AC_DEFINE(_X86_)
+        AS=alp
+        ASFLAGS='-Mb'
         AR=-ilib
         AR_FLAGS='/NOL /NOI /O:$(subst /,\\,$@)'
         CFLAGS='/Q /qlibansi /Gd+ /Gm+ /Su4 /Mp /Tl-'
         HOST_CFLAGS="$CFLAGS"
         OS_CFLAGS='/Q /qlibansi /Gd+ /Gm+ /Su4 /Ge- /Tl-'
         OS_EXE_CFLAGS='/Q /qlibansi /Gd+ /Gm+ /Su4 /Ge+ /Tl-'
         CXXFLAGS='/Q /qlibansi /Gd+ /Gm+ /Su4 /Mp /Tl-'
         OS_LIBS='so32dll.lib tcp32dll.lib'
@@ -2158,16 +2162,17 @@ AC_SUBST(MDCPUCFG_H)
 AC_SUBST(PR_MD_CSRCS)
 AC_SUBST(PR_MD_ASFILES)
 AC_SUBST(PR_MD_ARCH_DIR)
 AC_SUBST(CPU_ARCH)
 
 AC_SUBST(OBJ_SUFFIX)
 AC_SUBST(LIB_SUFFIX)
 AC_SUBST(DLL_SUFFIX)
+AC_SUBST(ASM_SUFFIX)
 AC_SUBST(MKSHLIB)
 AC_SUBST(DSO_CFLAGS)
 AC_SUBST(DSO_LDOPTS)
 
 AC_SUBST(OS_TARGET)
 AC_SUBST(OS_ARCH)
 AC_SUBST(OS_RELEASE)
 AC_SUBST(OS_TEST)
--- a/pr/include/md/_os2.h
+++ b/pr/include/md/_os2.h
@@ -66,17 +66,17 @@
  */
 
 #define PR_LINKER_ARCH      "os2"
 #define _PR_SI_SYSNAME        "OS2"
 #define _PR_SI_ARCHITECTURE   "x86"    /* XXXMB hardcode for now */
 
 #define HAVE_DLL
 #undef  HAVE_THREAD_AFFINITY
-#undef  _PR_HAVE_ATOMIC_OPS
+#define _PR_HAVE_ATOMIC_OPS
 
 #define HANDLE unsigned long
 #define HINSTANCE HMODULE
 
 /* --- Common User-Thread/Native-Thread Definitions --------------------- */
 
 /* --- Globals --- */
 extern struct PRLock                      *_pr_schedLock;
@@ -275,21 +275,21 @@ extern PRInt32 _MD_SELECT(int nfds, fd_s
                                     fd_set *exceptfds, struct timeval *timeout);
 #else
 #define _MD_SELECT                    select
 #endif
 
 #define _MD_FSYNC                     _PR_MD_FSYNC
 #define _MD_SET_FD_INHERITABLE        (_PR_MD_SET_FD_INHERITABLE)
 
-#define _MD_INIT_ATOMIC               _PR_MD_INIT_ATOMIC
-#define _MD_ATOMIC_INCREMENT(x)       _PR_MD_ATOMIC_INCREMENT(x)
-#define _MD_ATOMIC_ADD(x,y)			  _PR_MD_ATOMIC_ADD(x,y)
-#define _MD_ATOMIC_DECREMENT(x)       _PR_MD_ATOMIC_DECREMENT(x)
-#define _MD_ATOMIC_SET(x,y)           _PR_MD_ATOMIC_SET(x, y)
+#define _MD_INIT_ATOMIC()
+#define _MD_ATOMIC_INCREMENT          _PR_MD_ATOMIC_INCREMENT
+#define _MD_ATOMIC_ADD                _PR_MD_ATOMIC_ADD
+#define _MD_ATOMIC_DECREMENT          _PR_MD_ATOMIC_DECREMENT
+#define _MD_ATOMIC_SET                _PR_MD_ATOMIC_SET
 
 #define _MD_INIT_IO                   (_PR_MD_INIT_IO)
 #define _MD_PR_POLL                   (_PR_MD_PR_POLL)
 
 /* win95 doesn't have async IO */
 #define _MD_SOCKET                    (_PR_MD_SOCKET)
 extern PRInt32 _MD_SocketAvailable(PRFileDesc *fd);
 #define _MD_SOCKETAVAILABLE           _MD_SocketAvailable
--- a/pr/src/md/os2/Makefile.in
+++ b/pr/src/md/os2/Makefile.in
@@ -53,16 +53,20 @@ CSRCS = \
     os2cv.c \
     os2sock.c \
     os2_errors.c \
     os2poll.c \
     os2rng.c \
     $(NULL)
 endif
 
+ifeq ($(MOZ_OS2_TOOLS),VACPP)
+ASFILES = os2vacpp.asm
+endif
+
 TARGETS	= $(OBJS)
 
 INCLUDES = -I$(dist_includedir) -I$(topsrcdir)/pr/include -I$(topsrcdir)/pr/include/private
 
 DEFINES	+= -D_NSPR_BUILD_
 
 include $(topsrcdir)/config/rules.mk
 
--- a/pr/src/md/os2/objs.mk
+++ b/pr/src/md/os2/objs.mk
@@ -13,25 +13,29 @@
 # Communications Corporation.  Portions created by Netscape are
 # Copyright (C) 1998 Netscape Communications Corporation.  All Rights
 # Reserved.
 #
 
 # This makefile appends to the variable OBJS the platform-dependent
 # object modules that will be part of the nspr20 library.
 
-CSRCS =      \
-  os2io.c    \
-	os2sock.c  \
-	os2thred.c \
-	os2cv.c    \
-	os2gc.c    \
-	os2misc.c  \
-	os2inrval.c \
-	os2sem.c	  \
+CSRCS = \
+	os2io.c      \
+	os2sock.c    \
+	os2thred.c   \
+	os2cv.c      \
+	os2gc.c      \
+	os2misc.c    \
+	os2inrval.c  \
+	os2sem.c     \
 	os2_errors.c \
-	os2poll.c  \
-	os2rng.c   \
+	os2poll.c    \
+	os2rng.c     \
 	$(NULL)
 
+ifeq ($(MOZ_OS2_TOOLS),VACPP)
+ASFILES = os2vacpp.asm
+endif
+
 OBJS += $(addprefix md/os2/$(OBJDIR)/,$(CSRCS:.c=.$(OBJ_SUFFIX)))  \
-	$(addprefix md/os2/$(OBJDIR)/,$(ASFILES:.s=.$(OBJ_SUFFIX)))
+	$(addprefix md/os2/$(OBJDIR)/,$(ASFILES:.asm=.$(OBJ_SUFFIX)))
 
--- a/pr/src/md/os2/os2misc.c
+++ b/pr/src/md/os2/os2misc.c
@@ -571,8 +571,49 @@ unsigned long _System _DLL_InitTerm( uns
    {
       __ctordtorTerm(0);
       _CRT_term();
       rc = 1;
    }
 
    return rc;
 }
+
+#ifndef XP_OS2_VACPP
+
+PRInt32 _PR_MD_ATOMIC_SET(PRInt32 *intp, PRInt32 val)
+{
+  PRInt32 result;
+  asm volatile ("lock ; xchg %0, %1" 
+                : "=r"(result), "=m"(intp)
+                : "0"(val), "m"(intp));
+  return result;
+}
+
+PRInt32 _PR_MD_ATOMIC_ADD(PRInt32 *intp, PRInt32 val)
+{
+  PRInt32 result;
+  asm volatile ("lock ; xadd %0, %1" 
+                : "=r"(result), "=m"(intp)
+                : "0"(val), "m"(intp));
+  return result + val;
+}
+
+PRInt32 _PR_MD_ATOMIC_INCREMENT(PRInt32 *val)
+{    
+  PRInt32 result;
+  asm volatile ("lock ; xadd %0, %1" 
+                : "=r"(result), "=m"(*val)
+                : "0"(1), "m"(*val));
+  return result + 1;
+}
+
+PRInt32 _PR_MD_ATOMIC_DECREMENT(PRInt32 *val)
+{
+  PRInt32 result;
+  asm volatile ("lock ; xadd %0, %1" 
+                : "=r"(result), "=m"(*val)
+                : "0"(1), "m"(*val));
+  return result - 1;
+}
+
+#endif
+