]> www.ginac.de Git - cln.git/blobdiff - src/polynomial/elem/cl_UP_GF2.h
Cater to the fact that g++ 4.3 will use a different naming for
[cln.git] / src / polynomial / elem / cl_UP_GF2.h
index 71caa2166bd143b15c07d2b3899f3db6a57ff736..0fb5e658eb4a4bf06ea15a86d7e14262c66c208f 100644 (file)
@@ -4,7 +4,7 @@
 #include "cln/modinteger.h"
 #include "cln/GV_integer.h"
 #include "cl_DS.h"
-#include "cln/abort.h"
+#include "cln/exception.h"
 
 namespace cln {
 
@@ -13,7 +13,7 @@ struct cl_heap_GV_I_bits1 : public cl_heap_GV_I {
        uintD data[1];
 };
 
-static cl_boolean gf2_equal (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const _cl_UP& y)
+static bool gf2_equal (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const _cl_UP& y)
 {{
        DeclarePoly(cl_GV_MI,x);
        DeclarePoly(cl_GV_MI,y);
@@ -23,12 +23,12 @@ static cl_boolean gf2_equal (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const
        var uintL xlen = xv->v.length();
        var uintL ylen = yv->v.length();
        if (!(xlen == ylen))
-               return cl_false;
+               return false;
        // We can compare full words since unused bits in the last word are 0.
        var uintL count = ceiling(xlen,intDsize);
        if (compare_loop_up(xv->data,yv->data,count) != 0)
-               return cl_false;
-       return cl_true;
+               return false;
+       return true;
 }}
 
 static const _cl_UP gf2_plus (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const _cl_UP& y)
@@ -95,7 +95,7 @@ static const _cl_UP gf2_uminus (cl_heap_univpoly_ring* UPR, const _cl_UP& x)
        return x;
 }
 
-#if !(defined(__sparc__) || defined(__sparc64__))
+#if !defined(__sparc__) || defined(__sparc64__)
 // Multiplication of polynomials over GF(2) can unfortunately not profit
 // from hardware multiply instructions. Use a table instead.
 // This is a 2^8 x 2^4 table. Maybe a 2^6 x 2^6 table would be better?
@@ -966,7 +966,7 @@ static const _cl_UP gf2_square (cl_heap_univpoly_ring* UPR, const _cl_UP& x)
 // Scalar multiplication of GF(2)-polynomials is trivial: 0*y = 0, 1*y = y.
 static const _cl_UP gf2_scalmul (cl_heap_univpoly_ring* UPR, const cl_ring_element& x, const _cl_UP& y)
 {
-       if (!(UPR->basering() == x.ring())) cl_abort();
+       if (!(UPR->basering() == x.ring())) throw runtime_exception();
  {
        DeclarePoly(_cl_MI,x);
        var cl_heap_modint_ring* R = TheModintRing(UPR->basering());
@@ -981,7 +981,7 @@ static const _cl_UP gf2_scalmul (cl_heap_univpoly_ring* UPR, const cl_ring_eleme
 static const cl_ring_element gf2_eval (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const cl_ring_element& y)
 {{
        DeclarePoly(cl_GV_MI,x);
-       if (!(UPR->basering() == y.ring())) cl_abort();
+       if (!(UPR->basering() == y.ring())) throw runtime_exception();
   {    DeclarePoly(_cl_MI,y);
        var cl_heap_modint_ring* R = TheModintRing(UPR->basering());
        var const cl_heap_GV_I_bits1 * xv = (const cl_heap_GV_I_bits1 *) x.heappointer;
@@ -992,7 +992,7 @@ static const cl_ring_element gf2_eval (cl_heap_univpoly_ring* UPR, const _cl_UP&
                return cl_MI(R, x[0]);
        else {
                var uintL count = ceiling(len,intDsize);
-               var uintL bitcount = 0;
+               var uintC bitcount = 0;
                do {
                        count--;
                        bitcount += logcountD(xv->data[count]);
@@ -1028,6 +1028,7 @@ static cl_univpoly_modulops gf2_modulops = {
 
 static cl_univpoly_polyops gf2_polyops = {
        modint_degree,
+       modint_ldegree,
        modint_monomial,
        modint_coeff,
        modint_create,
@@ -1040,8 +1041,26 @@ class cl_heap_gf2_univpoly_ring : public cl_heap_univpoly_ring {
        SUBCLASS_cl_heap_univpoly_ring()
 public:
        // Constructor.
-       cl_heap_gf2_univpoly_ring (const cl_ring& r)
-               : cl_heap_univpoly_ring (r, &gf2_setops, &gf2_addops, &gf2_mulops, &gf2_modulops, &gf2_polyops) {}
+       cl_heap_gf2_univpoly_ring (const cl_ring& r);
+       // Destructor.
+       ~cl_heap_gf2_univpoly_ring () {}
 };
 
+static void cl_heap_gf2_univpoly_ring_destructor (cl_heap* pointer)
+{
+       (*(cl_heap_gf2_univpoly_ring*)pointer).~cl_heap_gf2_univpoly_ring();
+}
+
+cl_class cl_class_gf2_univpoly_ring = {
+       cl_heap_gf2_univpoly_ring_destructor,
+       cl_class_flags_univpoly_ring
+};
+
+// Constructor.
+inline cl_heap_gf2_univpoly_ring::cl_heap_gf2_univpoly_ring (const cl_ring& r)
+       : cl_heap_univpoly_ring (r, &gf2_setops, &gf2_addops, &gf2_mulops, &gf2_modulops, &gf2_polyops)
+{
+       type = &cl_class_gf2_univpoly_ring;
+}
+
 }  // namespace cln