From 391de71c54552c10552a8e62cc7226ebd15635bb Mon Sep 17 00:00:00 2001
From: "Mirar (Pontus Hagland)" <pike@sort.mirar.org>
Date: Mon, 1 Nov 1999 17:53:39 +0100
Subject: [PATCH] added xor

Rev: src/modules/Gmp/Makefile.in:1.10
Rev: src/modules/Gmp/mpz_glue.c:1.65
Rev: src/modules/Gmp/my_gmp.h:1.6
Rev: src/modules/Gmp/my_mpz_xor.c:1.1
---
 .gitattributes               |  1 +
 src/modules/Gmp/Makefile.in  |  4 +--
 src/modules/Gmp/mpz_glue.c   |  5 +++-
 src/modules/Gmp/my_gmp.h     |  3 +-
 src/modules/Gmp/my_mpz_xor.c | 54 ++++++++++++++++++++++++++++++++++++
 5 files changed, 63 insertions(+), 4 deletions(-)
 create mode 100644 src/modules/Gmp/my_mpz_xor.c

diff --git a/.gitattributes b/.gitattributes
index 82a1b7eb0e..05a10a9edd 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -183,6 +183,7 @@ testfont binary
 /src/modules/Gmp/gmp_machine.h.in foreign_ident
 /src/modules/Gmp/mpz_glue.c foreign_ident
 /src/modules/Gmp/my_gmp.h foreign_ident
+/src/modules/Gmp/my_mpz_xor.c foreign_ident
 /src/modules/Gmp/next_prime.c foreign_ident
 /src/modules/Gmp/prime_table.c foreign_ident
 /src/modules/Gmp/testsuite.in foreign_ident
diff --git a/src/modules/Gmp/Makefile.in b/src/modules/Gmp/Makefile.in
index 50c74675fd..63947e5cbe 100644
--- a/src/modules/Gmp/Makefile.in
+++ b/src/modules/Gmp/Makefile.in
@@ -1,8 +1,8 @@
-# $Id: Makefile.in,v 1.9 1999/04/24 12:56:47 grubba Exp $
+# $Id: Makefile.in,v 1.10 1999/11/01 16:53:36 mirar Exp $
 SRCDIR=@srcdir@
 VPATH=@srcdir@:@srcdir@/../..:../..
 MODULE_LDFLAGS=@LDFLAGS@ @LIBS@
-OBJS=mpz_glue.o next_prime.o
+OBJS=mpz_glue.o next_prime.o my_mpz_xor.o
 
 PRIME_LIMIT=1024
 
diff --git a/src/modules/Gmp/mpz_glue.c b/src/modules/Gmp/mpz_glue.c
index 042fd4d4cb..b898f4d916 100644
--- a/src/modules/Gmp/mpz_glue.c
+++ b/src/modules/Gmp/mpz_glue.c
@@ -4,7 +4,7 @@
 ||| See the files COPYING and DISCLAIMER for more information.
 \*/
 #include "global.h"
-RCSID("$Id: mpz_glue.c,v 1.64 1999/11/01 15:21:57 mirar Exp $");
+RCSID("$Id: mpz_glue.c,v 1.65 1999/11/01 16:53:37 mirar Exp $");
 #include "gmp_machine.h"
 
 #if defined(HAVE_GMP2_GMP_H) && defined(HAVE_LIBGMP2)
@@ -901,6 +901,7 @@ static void name(INT32 args)				\
 
 BINFUN(mpzmod_and,mpz_and)
 BINFUN(mpzmod_or,mpz_ior)
+BINFUN(mpzmod_xor,my_mpz_xor)
 
 static void mpzmod_compl(INT32 args)
 {
@@ -1263,6 +1264,8 @@ void pike_module_exit(void)
   ADD_FUNCTION("``&",mpzmod_and,tMpz_binop_type,0);			\
   ADD_FUNCTION("`|",mpzmod_or,tMpz_binop_type,0);			\
   ADD_FUNCTION("``|",mpzmod_or,tMpz_binop_type,0);			\
+  ADD_FUNCTION("`^",mpzmod_xor,tMpz_binop_type,0);			\
+  ADD_FUNCTION("``^",mpzmod_xor,tMpz_binop_type,0);			\
   ADD_FUNCTION("`~",mpzmod_compl,tFunc(tNone,tObj),0);			\
 									\
   add_function("`<<",mpzmod_lsh,MPZ_SHIFT_TYPE,0);			\
diff --git a/src/modules/Gmp/my_gmp.h b/src/modules/Gmp/my_gmp.h
index d9ce549843..69211674d3 100644
--- a/src/modules/Gmp/my_gmp.h
+++ b/src/modules/Gmp/my_gmp.h
@@ -1,4 +1,4 @@
-/* $Id: my_gmp.h,v 1.5 1999/08/08 13:06:58 grubba Exp $
+/* $Id: my_gmp.h,v 1.6 1999/11/01 16:53:38 mirar Exp $
  *
  * These functions or something similar will hopefully be included
  * with Gmp-2.1 .
@@ -23,5 +23,6 @@
 unsigned long mpz_small_factor(mpz_t n, int limit);
 
 void mpz_next_prime(mpz_t p, mpz_t n, int count, int prime_limit);
+void my_mpz_xor _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
 
 #endif /* MY_GMP_H_INCLUDED */
diff --git a/src/modules/Gmp/my_mpz_xor.c b/src/modules/Gmp/my_mpz_xor.c
new file mode 100644
index 0000000000..e1ac0b6066
--- /dev/null
+++ b/src/modules/Gmp/my_mpz_xor.c
@@ -0,0 +1,54 @@
+/* $Id: my_mpz_xor.c,v 1.1 1999/11/01 16:53:39 mirar Exp $
+ *
+ * since xor isn't implemented by gmp (for some odd reason)
+ */
+
+#include "global.h"
+
+RCSID("$Id: my_mpz_xor.c,v 1.1 1999/11/01 16:53:39 mirar Exp $");
+
+#include "gmp_machine.h"
+
+#if defined(HAVE_GMP2_GMP_H) && defined(HAVE_LIBGMP2)
+#define USE_GMP2
+#else /* !HAVE_GMP2_GMP_H || !HAVE_LIBGMP2 */
+#if defined(HAVE_GMP_H) && defined(HAVE_LIBGMP)
+#define USE_GMP
+#endif /* HAVE_GMP_H && HAVE_LIBGMP */
+#endif /* HAVE_GMP2_GMP_H && HAVE_LIBGMP2 */
+
+#if defined(USE_GMP) || defined(USE_GMP2)
+
+#include "gmp.h"
+
+void my_mpz_xor (mpz_ptr res, mpz_srcptr a, mpz_srcptr b)
+{
+   /* (a&~b)|(~a&b) for now */
+
+   mpz_t t1;
+   mpz_t t2;
+   mpz_t not;
+   
+   mpz_init(t1);
+   mpz_init(t2);
+   mpz_init(not);
+   
+   /* t1=(a&~b) */
+   mpz_com(not,b);
+   mpz_and(t1,a,not);
+
+   /* t2=(~a&b) */
+   mpz_com(not,a);
+   mpz_and(t2,not,b);
+
+   /* res=t1|t2 */
+   mpz_ior(res,t1,t2);
+
+   /* bye bye */
+   mpz_clear(t1);
+   mpz_clear(t2);
+   mpz_clear(not);
+}
+
+
+#endif
-- 
GitLab