From 4bac7e77ee9b720b5f00aade614a36d0f748e2c4 Mon Sep 17 00:00:00 2001
From: Per Hedbor <ph@opera.com>
Date: Fri, 23 May 2014 17:02:42 +0200
Subject: [PATCH] Removed the support for mmx.h

This was a header file that existed back in ye good old time, allowing
usage of MMX without much in the way of compiler support.

However, it is not really available anywhere any more, and almost all
code that used it was disabled.

If we do feel the need for MMX (or rather SSE3+, really, MMX is rather
old-school these days) we should use compiler intrinsics.
---
 src/acconfig.h                 |  6 ---
 src/configure.in               | 83 +-------------------------------
 src/modules/Image/layer_oper.h | 10 ++--
 src/modules/Image/layers.c     |  9 ----
 src/pike_embed.h               |  4 --
 src/port.c                     | 87 +---------------------------------
 src/port.h                     |  7 +--
 7 files changed, 10 insertions(+), 196 deletions(-)

diff --git a/src/acconfig.h b/src/acconfig.h
index 35d3013ed8..c9eb79e0c4 100644
--- a/src/acconfig.h
+++ b/src/acconfig.h
@@ -79,9 +79,6 @@
 /* Define this to enable the internal bignum conversion */
 #undef AUTO_BIGNUM
 
-/* Define this to enable experimental code for multicpu machines */
-#undef PIKE_RUN_UNLOCKED
-
 /* Define this if you want to enable the shared nodes mode of the optimizer. */
 #undef SHARED_NODES
 
@@ -567,9 +564,6 @@
 /* The last argument to accept() is an ACCEPT_SIZE_T * */
 #define ACCEPT_SIZE_T	int
 
-/* Can we compile in MMX support? */
-#undef TRY_USE_MMX
-
 /* Define if you have the <sys/resource.h> header file.  */
 #undef HAVE_SYS_RESOURCE_H
 
diff --git a/src/configure.in b/src/configure.in
index ba0f915c8c..0aca2ac9d6 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -1082,28 +1082,6 @@ AC_SUBST(LC_REQ)
 
 #############################################################################
 
-AC_ARG_WITH(extra_debug_checks,
-	    MY_DESCR([--with-extra-debug-checks],
-		     [enable some extra (possibly verbose) debug checks.]),
-	    [], [
-  if test "x$pike_cv_sys_os" = "xOSF1"; then
-    # Attempt to detect the cause for test_resolv to fail on Unicode.so.
-    with_extra_debug_checks="yes"
-  elif test "x$pike_cv_sys_os" = "xOpenBSD"; then
-    # Attempt to detect cause of dmalloc failure on OpenBSD.
-    with_extra_debug_checks="yes"
-  else
-    with_extra_debug_checks=no
-  fi
-  ])
-
-if test "x$with_extra_debug_checks" = "xno"; then :; else
-  AC_MSG_WARN([Enabling extra debug checks.])
-  AC_DEFINE([PIKE_EXTRA_DEBUG])
-fi
-
-#############################################################################
-
 AC_ARG_WITH(patch_gcc, MY_DESCR([--with-patch-gcc],
 				[attempt to patch the UA32 relocation bug.]),
 	    [], [with_patch_gcc=no])
@@ -1643,14 +1621,6 @@ MY_AC_ARG_WITH(portable-bytecode,
 	       [AC_DEFINE(PIKE_PORTABLE_BYTECODE)],[],
 	       [AC_DEFINE(PIKE_PORTABLE_BYTECODE)])
 
-MY_AC_ARG_WITH(lock,
-	       MY_DESCR([--without-lock],
-	  [enable experimental code for multicpu machines (EXPERIMENTAL).]),
-		[],[AC_DEFINE(PIKE_RUN_UNLOCKED)])
-
-AC_ARG_WITH(pike-type, MY_DESCR([--without-pike-type],
-				[disable struct pike_type (IGNORED).]))
-
 if test "x$with_pike_type" = "xno"; then
   PIKE_MSG_WARN([Disabling of USE_PIKE_TYPE is no longer supported.])
 fi
@@ -3340,7 +3310,7 @@ AC_CHECK_HEADERS(winsock2.h sys/rusage.h time.h sys/time.h sys/types.h \
 		 passwd.h group.h winsock.h signal.h sys/file.h poll.h \
 		 sys/poll.h socket.h ieeefp.h fp_class.h floatingpoint.h \
 		 float.h sys/priocntl.h sys/sched.h winbase.h errno.h \
-		 stddef.h mmx.h asm/mmx.h sys/termio.h sys/termios.h \
+		 stddef.h sys/termio.h sys/termios.h \
 		 ws2tcpip.h valgrind/memcheck.h memcheck.h valgrind.h \
 		 sys/prctl.h sys/ioctl.h mach/task_info.h mach/task.h \
 		 mach/mach_init.h syscall.h sys/syscall.h devices/timer.h \
@@ -6177,51 +6147,6 @@ else
   AC_MSG_RESULT(not by cast)
 fi
 
-#############################################################################
-AC_ARG_WITH(mmx, MY_DESCR([--without-mmx], [disable MMX usage]), [], [with_mmx=])
-
-mmx_reason=' (no mmx.h found)'
-if test "x$with_mmx" = xno; then
-   mmx_reason=' (--without-mmx)'
-   unset pike_cv_sys_has_working_mmx
-elif test "x$ac_cv_header_mmx_h" = xyes -o "x$ac_cv_header_asm_mmx_h" = xyes; then
-  AC_MSG_CHECKING(for working MMX)
-  mmx_reason=' (mmx.h found, but mmx operations failed)'
-
-  AC_CACHE_VAL(pike_cv_sys_has_working_mmx,
-  [
-    AC_TRY_LINK([
-#ifdef HAVE_MMX_H
-#include <mmx.h>
-#endif
-#ifdef HAVE_ASM_MMX_H
-#include <asm/mmx.h>
-#endif
-    ],[
-    {
-      int try_use_mmx;
-      char a[8];
-      movq_m2r( *a, mm0 );
-      paddb_r2r( mm0, mm0 );
-      movq_r2m( mm0, *a );
-      try_use_mmx=mmx_ok();
-    }
-    ],pike_cv_sys_has_working_mmx=yes,pike_cv_sys_has_working_mmx=no)
-  ])
-
-  AC_MSG_RESULT($pike_cv_sys_has_working_mmx)
-
-  if test "x$pike_cv_sys_has_working_mmx" = xyes ; then
-    AC_DEFINE(TRY_USE_MMX)
-    mmx_reason=''
-  else :; fi
-
-  if test "x$with_copt" = "xno"; then
-    PIKE_MSG_WARN([--without-mmx is advisable when using --without-copt.])
-  fi
-else :; fi
-
-#############################################################################
 
 AC_MSG_CHECKING(if float conversion can cause SIGFPE)
 AC_CACHE_VAL(pike_cv_sys_idiot_sigfpe,
@@ -8762,11 +8687,6 @@ fi
 if test "x$with_dmalloc" = x; then
   with_dmalloc=no
 fi
-with_mmx=$pike_cv_sys_has_working_mmx
-if test "x$with_mmx" = x; then
-  with_mmx=no
-fi
-
 if test "x$with_copt" = xno ; then 
   opt_reasons="  ($OPT_NOT_USED turned off with --without-copt)"
 else
@@ -8852,7 +8772,6 @@ PAD_FEATURE([cdebug])$with_cdebug
 PAD_FEATURE([rtldebug])$with_rtldebug
 PAD_FEATURE([dmalloc])$with_dmalloc
 PAD_FEATURE([dlmalloc])$enable_dlmalloc
-PAD_FEATURE([mmx])$with_mmx$mmx_reason
 PAD_FEATURE([byte code format])$byte_code_format
 PAD_FEATURE([module reloc])${with_relocatable_dumped_modules:-no}
 PAD_FEATURE([use machine code])$with_machine_code
diff --git a/src/modules/Image/layer_oper.h b/src/modules/Image/layer_oper.h
index 76832cfbdd..e25e3958d2 100644
--- a/src/modules/Image/layer_oper.h
+++ b/src/modules/Image/layer_oper.h
@@ -31,6 +31,10 @@ static void LM_FUNC(rgb_group *s,rgb_group *l,rgb_group *d,
       {
 #ifdef L_MMX_OPER
 #ifdef TRY_USE_MMX
+/* Intentionally left here.
+
+   FIXME: Switch to intrinsics
+*/
 	extern int try_use_mmx;
 	if(try_use_mmx)
 	{
@@ -38,7 +42,7 @@ static void LM_FUNC(rgb_group *s,rgb_group *l,rgb_group *d,
 	  unsigned char *source=(unsigned char *)s;
 	  unsigned char *dest=(unsigned char *)d;
 	  unsigned char *sourcel=(unsigned char *)l;
-	  
+
 	  while (num-->0 && (7&(int)dest))
 	  {
 	    *dest=L_TRUNC(L_OPER(*source,*sourcel));
@@ -46,8 +50,8 @@ static void LM_FUNC(rgb_group *s,rgb_group *l,rgb_group *d,
 	    sourcel++;
 	    dest++;
 	  }
-	  
-	  
+
+
 	  while(num > 16)
 	  {
 	    movq_m2r(*source, mm0);
diff --git a/src/modules/Image/layers.c b/src/modules/Image/layers.c
index d7f10d2013..f65c7d6401 100644
--- a/src/modules/Image/layers.c
+++ b/src/modules/Image/layers.c
@@ -31,15 +31,6 @@
 
 #include "image.h"
 
-#ifdef TRY_USE_MMX
-#ifdef HAVE_MMX_H
-#include <mmx.h>
-#else
-#include <asm/mmx.h>
-#endif
-#endif
-
-
 extern struct program *image_program;
 extern struct program *image_layer_program;
 extern struct program *image_colortable_program;
diff --git a/src/pike_embed.h b/src/pike_embed.h
index 8ae757d6a8..68cf86a45f 100644
--- a/src/pike_embed.h
+++ b/src/pike_embed.h
@@ -10,10 +10,6 @@
 #include "global.h"
 #include "callback.h"
 
-#ifdef TRY_USE_MMX
-extern int try_use_mmx;
-#endif /* TRY_USE_MMX */
-
 PMOD_EXPORT extern int d_flag, a_flag, l_flag, c_flag, p_flag;
 PMOD_EXPORT extern int debug_options, runtime_options;
 PMOD_EXPORT extern int default_t_flag;
diff --git a/src/port.c b/src/port.c
index 3352bb662d..42b05b7c22 100644
--- a/src/port.c
+++ b/src/port.c
@@ -394,96 +394,15 @@ void *MEMSET(void *s,int c,size_t n)
 }
 #endif
 
-#if (0 && defined(TRY_USE_MMX)) || !defined(HAVE_MEMCPY) && !defined(HAVE_BCOPY)
-#ifdef TRY_USE_MMX
-#ifdef HAVE_MMX_H
-#include <mmx.h>
-#else
-#include <asm/mmx.h>
-#endif
-#endif
+#if !defined(HAVE_MEMCPY) && !defined(HAVE_BCOPY)
 PMOD_EXPORT void MEMCPY(void *bb,const void *aa,size_t s)
 {
   if(!s) return;
-#ifdef TRY_USE_MMX
   {
-    extern int try_use_mmx;
-    if( (s>64) && !(((int)bb)&7) && !(((int)aa)&7) && try_use_mmx )
-    {
-      unsigned char *source=(char *)aa;
-      unsigned char *dest=(char *)bb;
-
-/*       fprintf(stderr, "mmx memcpy[%d]\n",s); */
-      while( s > 64 )
-      {
-        movq_m2r(*source, mm0);      source += 8;
-        movq_m2r(*source, mm1);      source += 8;
-        movq_m2r(*source, mm2);      source += 8;
-        movq_m2r(*source, mm3);      source += 8;
-        movq_m2r(*source, mm4);      source += 8;
-        movq_m2r(*source, mm5);      source += 8;
-        movq_m2r(*source, mm6);      source += 8;
-        movq_m2r(*source, mm7);      source += 8;
-        movq_r2m(mm0,*dest);         dest += 8;
-        movq_r2m(mm1,*dest);         dest += 8;
-        movq_r2m(mm2,*dest);         dest += 8;
-        movq_r2m(mm3,*dest);         dest += 8;
-        movq_r2m(mm4,*dest);         dest += 8;
-        movq_r2m(mm5,*dest);         dest += 8;
-        movq_r2m(mm6,*dest);         dest += 8;
-        movq_r2m(mm7,*dest);         dest += 8;
-        s -= 64;
-      }
-      if( s > 31 )
-      {
-        movq_m2r(*source, mm0);      source += 8;
-        movq_m2r(*source, mm1);      source += 8;
-        movq_m2r(*source, mm2);      source += 8;
-        movq_m2r(*source, mm3);      source += 8;
-        movq_r2m(mm0,*dest);         dest += 8;
-        movq_r2m(mm1,*dest);         dest += 8;
-        movq_r2m(mm2,*dest);         dest += 8;
-        movq_r2m(mm3,*dest);         dest += 8;
-        s -= 32;
-      }
-      if( s > 15 )
-      {
-        movq_m2r(*source, mm0);      source += 8;
-        movq_m2r(*source, mm1);      source += 8;
-        movq_r2m(mm0,*dest);         dest += 8;
-        movq_r2m(mm1,*dest);         dest += 8;
-        s -= 16;
-      }
-      if( s > 7 )
-      {
-        movq_m2r(*source, mm0);      source += 8;
-        movq_r2m(mm0,*dest);         dest += 8;
-        s -= 8;
-      }
-      emms();
-      while( s )
-      {
-        *(dest++) = *(source++);
-        s-=1;
-      }
-    }
-    else 
-    {
-#endif
-#ifdef HAVE_MEMCPY
-      /*     fprintf(stderr, "plain ol' memcpy\n"); */
-      memcpy( bb, aa, s );
-#else
-      {
 	char *b=(char *)bb;
 	char *a=(char *)aa;
 	for(;s;s--) *(b++)=*(a++);
-      }
-#endif
-#ifdef TRY_USE_MMX
-    }
   }
-#endif
 }
 #endif
 
@@ -679,10 +598,6 @@ PMOD_EXPORT double STRTOD(const char * nptr, char **endptr)
 
  underflow:
   /* Return an underflow error.  */
-#if 0
-  if (endptr != NULL)
-    *endptr = (char *) nptr;
-#endif
   errno = ERANGE;
   return 0.0;
   
diff --git a/src/port.h b/src/port.h
index 8bfe131d94..5ba498fd73 100644
--- a/src/port.h
+++ b/src/port.h
@@ -198,11 +198,7 @@ void *MEMSET (void *s,int c,size_t n);
 #  define MEMSET memset
 #endif
 
-#if 0 && defined(TRY_USE_MMX)
-PMOD_EXPORT void MEMCPY(void *b,const void *a,size_t s);
-# define __builtin_memcpy MEMCPY
-#else
-# ifndef HAVE_MEMCPY
+#ifndef HAVE_MEMCPY
 #  ifdef HAVE_BCOPY
 #    define MEMCPY(X,Y,Z) bcopy(Y,X,Z)
 #    define __builtin_memcpy(X,Y,Z) bcopy(Y,X,Z)
@@ -212,7 +208,6 @@ void MEMCPY(void *b,const void *a,size_t s);
 #  endif
 # else
 #  define MEMCPY(X,Y,Z) memcpy((char*)(X),(char*)(Y),(Z))
-# endif
 #endif
 
 #ifndef HAVE_MEMMOVE
-- 
GitLab