[BACK]Return to cmo-gmp.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / kan96xx / plugin

Annotation of OpenXM/src/kan96xx/plugin/cmo-gmp.c, Revision 1.4

1.4     ! takayama    1: /*$OpenXM: OpenXM/src/kan96xx/plugin/cmo-gmp.c,v 1.3 1999/11/18 00:54:17 takayama Exp $ */
1.1       maekawa     2: #include <stdio.h>
                      3: #include <string.h>
1.2       takayama    4: /* #include <netinet/in.h> */
1.1       maekawa     5: #include "datatype.h"
                      6: #include "stackm.h"
                      7: #include "extern.h"
                      8: #include "extern2.h"
                      9: #include "mathcap.h"
                     10: #include "kclass.h"
                     11:
                     12: #include "gmp.h"
1.4     ! takayama   13: #include "gmp-impl.h"
        !            14:
1.1       maekawa    15:
                     16: #include "file2.h"
                     17: #include "cmo.h"
                     18:
                     19: extern int OxVersion;
                     20: size_t cmoOutGMPCoeff_old(mpz_srcptr x);
                     21: size_t cmoOutGMPCoeff_new(mpz_srcptr x);
                     22: size_t
                     23: cmoOutGMPCoeff(mpz_srcptr x) {
                     24:   if (OxVersion >= 199907170)
                     25:     return(cmoOutGMPCoeff_new(x));
                     26:   else
                     27:     return(cmoOutGMPCoeff_old(x));
                     28: }
                     29:
                     30: cmoGetGMPCoeff(MP_INT *x, struct cmoBuffer *cb) {
                     31:   if (OxVersion >= 199907170)
                     32:     return(cmoGetGMPCoeff_new(x,cb));
                     33:   else
                     34:     return(cmoGetGMPCoeff_old(x,cb));
                     35: }
                     36:
                     37:
                     38: /* From gmp/mpz/out_raw.c and inp_raw.c */
                     39:
                     40: /* mpz_out_raw -- Output a mpz_t in binary.  Use an endianess and word size
                     41:    independent format.
                     42:
                     43: Copyright (C) 1995 Free Software Foundation, Inc.
                     44:
                     45: This file is part of the GNU MP Library.
                     46:
                     47: The GNU MP Library is free software; you can redistribute it and/or modify
                     48: it under the terms of the GNU Library General Public License as published by
                     49: the Free Software Foundation; either version 2 of the License, or (at your
                     50: option) any later version.
                     51:
                     52: The GNU MP Library is distributed in the hope that it will be useful, but
                     53: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     54: or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
                     55: License for more details.
                     56:
                     57: You should have received a copy of the GNU Library General Public License
                     58: along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
                     59: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
                     60: MA 02111-1307, USA. */
                     61:
                     62: static int myfputc(int i) {
                     63:   char tmp[1];
                     64:   tmp[0] = i;
                     65:   cmoOutputToBuf(CMOPUT,tmp,1);
                     66: }
                     67: static outRawInt32(int k)
                     68: {
                     69:   int tmp[1];
                     70:   tmp[0] = htonl((int) k);
                     71:   cmoOutputToBuf(CMOPUT,tmp,4);
                     72: }
                     73:
                     74: size_t
                     75: cmoOutGMPCoeff_old(mpz_srcptr x)
                     76: {
1.4     ! takayama   77:   fprintf(stderr,"cmoOutGMPCoeff_old is no longer supported.\n");
        !            78:   exit(10);
1.1       maekawa    79: }
                     80:
                     81:
                     82: /* mpz_inp_raw -- Input a mpz_t in raw, but endianess, and wordsize
                     83:    independent format (as output by mpz_out_raw).
                     84:
                     85: Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc.
                     86:
                     87: This file is part of the GNU MP Library.
                     88:
                     89: The GNU MP Library is free software; you can redistribute it and/or modify
                     90: it under the terms of the GNU Library General Public License as published by
                     91: the Free Software Foundation; either version 2 of the License, or (at your
                     92: option) any later version.
                     93:
                     94: The GNU MP Library is distributed in the hope that it will be useful, but
                     95: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     96: or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
                     97: License for more details.
                     98:
                     99: You should have received a copy of the GNU Library General Public License
                    100: along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
                    101: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
                    102: MA 02111-1307, USA. */
                    103:
                    104:
                    105: static int myfgetc(struct cmoBuffer *cb)
                    106: {
                    107:   int k;
                    108:   if (cb->isStream) {
                    109:     k = fp2fgetc(cb->fp);
                    110:   }else{
                    111:     k = ((unsigned char *)(cb->buf))[cb->rpos];
                    112:     cb->rpos++;
                    113:     if (cb->rpos > cb->pos) {
                    114:       cb->rpos--;
                    115:       errorCmo(" cmo-gmp.c : myfgetc(): no data in the buffer.");
                    116:     }
                    117:   }
1.3       takayama  118:   return(k);
1.1       maekawa   119: }
                    120: static int getRawInt32(struct cmoBuffer *cb)
                    121: {
                    122:   char d[4];
                    123:   int i;
1.3       takayama  124:   int r;
1.1       maekawa   125:   for (i=0; i<4; i++) {
                    126:     d[i] = myfgetc(cb);
                    127:   }
1.3       takayama  128:   return( ntohl(* ( (int *)d)));
1.1       maekawa   129: }
                    130:
                    131: cmoGetGMPCoeff_old(MP_INT *x, struct cmoBuffer *cb)
                    132: {
1.4     ! takayama  133:   fprintf(stderr,"cmoGetGMPCoeff_old is no longer supported.\n");
        !           134:   exit(10);
1.1       maekawa   135: }
                    136:
                    137: /*****************************************************/
                    138: /*****   new version for CMO_ZZ  *********************/
                    139: /*****************************************************/
                    140: size_t
                    141: cmoOutGMPCoeff_new(mpz_srcptr x)
                    142: {
                    143:   int i;
                    144:   mp_size_t s;
                    145:   mp_size_t xsize = ABS (x->_mp_size);
                    146:   mp_srcptr xp = x->_mp_d;
                    147:   mp_size_t out_bytesize;
                    148:   mp_limb_t hi_limb;
                    149:   int n_bytes_in_hi_limb;
                    150:   cmoint tmp[1];
                    151:   tmp[0] = htonl(CMO_ZZ);
                    152:   cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint));
                    153:
                    154:   if (BYTES_PER_MP_LIMB != 4) {
                    155:     fprintf(stderr,"BYTES_PER_MP_LIMB = %d\n",BYTES_PER_MP_LIMB);
                    156:     fprintf(stderr,"cmo-gmp.c does not work on this CPU.\n");
                    157:     fprintf(stderr,"Read the GMP source code and rewrite cmo-gmp.c.\n");
                    158:     exit(10);
                    159:   }
                    160:   if (BITS_PER_CHAR != 8) {
                    161:     fprintf(stderr,"BITS_PER_CHAR = %d\n",BITS_PER_CHAR);
                    162:     fprintf(stderr,"cmo-gmp.c does not work on this CPU.\n");
                    163:     fprintf(stderr,"Read the GMP source code and rewrite cmo-gmp.c.\n");
                    164:     exit(10);
                    165:   }
                    166:
                    167:   if (xsize == 0)
                    168:     {
                    169:       outRawInt32(0);
                    170:       return  1;
                    171:     }
                    172:
                    173:   if (x->_mp_size >= 0)
                    174:     outRawInt32(xsize);
                    175:   else
                    176:     outRawInt32(-xsize);
                    177:
                    178:
                    179:   /* Output from the least significant limb to the most significant limb */
                    180:   /* We assume that the size of limb is 4. */
                    181:
                    182:   for (s = 0; s < xsize; s++)
                    183:     {
                    184:       outRawInt32((int) xp[s]);
                    185:     }
                    186:   return ( ABS (xsize) );
                    187: }
                    188:
                    189: cmoGetGMPCoeff_new(MP_INT *x, struct cmoBuffer *cb)
                    190: {
                    191:   int i;
                    192:   mp_size_t s;
                    193:   mp_size_t xsize;
                    194:   mp_ptr xp;
                    195:   unsigned int c;
                    196:   mp_limb_t x_limb;
                    197:   mp_size_t in_bytesize;
                    198:   int neg_flag;
                    199:
                    200:   if (BYTES_PER_MP_LIMB != 4) {
                    201:     fprintf(stderr,"BYTES_PER_MP_LIMB = %d\n",BYTES_PER_MP_LIMB);
                    202:     fprintf(stderr,"cmo-gmp.c does not work on this CPU.\n");
                    203:     fprintf(stderr,"Read the GMP source code and rewrite cmo-gmp.c.\n");
                    204:     exit(10);
                    205:   }
                    206:   if (BITS_PER_CHAR != 8) {
                    207:     fprintf(stderr,"BITS_PER_CHAR = %d\n",BITS_PER_CHAR);
                    208:     fprintf(stderr,"cmo-gmp.c does not work on this CPU.\n");
                    209:     fprintf(stderr,"Read the GMP source code and rewrite cmo-gmp.c.\n");
                    210:     exit(10);
                    211:   }
                    212:
                    213:   /* Read 4-byte size */
                    214:
                    215:   xsize = getRawInt32(cb);
                    216:   neg_flag = xsize < 0;
                    217:   xsize = ABS(xsize);
                    218:
                    219:   if (xsize == 0)
                    220:     {
                    221:       x->_mp_size = 0;
                    222:       return 1;                        /* we've read 4 bytes */
                    223:     }
                    224:
                    225:   if (x->_mp_alloc < xsize)
                    226:     _mpz_realloc (x, xsize);
                    227:   xp = x->_mp_d;
                    228:
                    229:   for (i=0; i<xsize; i++) {
                    230:     xp[i] = getRawInt32(cb);
                    231:   }
                    232:
                    233:   MPN_NORMALIZE (xp, xsize);
                    234:   x->_mp_size = neg_flag ? -xsize : xsize;
                    235:   return( xsize );
                    236: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>