version 1.19, 2015/08/14 13:51:55 |
version 1.22, 2017/08/31 09:11:04 |
|
|
* OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY |
* OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* $OpenXM: OpenXM_contrib2/asir2000/io/io.c,v 1.18 2015/08/13 00:13:03 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/io/io.c,v 1.21 2015/08/19 05:29:23 noro Exp $ |
*/ |
*/ |
#include <stdio.h> |
#include <stdio.h> |
#include "ca.h" |
#include "ca.h" |
|
|
extern int little_endian,lib_ox_need_conv; |
extern int little_endian,lib_ox_need_conv; |
extern int ox_do_copy, ox_do_count, ox_count_length, ox_file_io, ox_need_conv; |
extern int ox_do_copy, ox_do_count, ox_count_length, ox_file_io, ox_need_conv; |
extern char *ox_copy_bptr; |
extern char *ox_copy_bptr; |
|
extern int ox_get_pari_result; |
|
|
/* XXX */ |
/* XXX */ |
void write_cmo(pointer,Obj); |
void write_cmo(pointer,Obj); |
Line 63 void write_cmo(pointer,Obj); |
|
Line 64 void write_cmo(pointer,Obj); |
|
void reset_io() |
void reset_io() |
{ |
{ |
ox_file_io = 0; |
ox_file_io = 0; |
|
if ( ox_get_pari_result ) reset_ox_pari(); |
} |
} |
|
|
void endian_init() |
void endian_init() |
Line 288 void write_longarray(FILE *f,unsigned long *p,int l) |
|
Line 290 void write_longarray(FILE *f,unsigned long *p,int l) |
|
|
|
if ( l%2 ) { |
if ( l%2 ) { |
w = p[0]; hi = w>>32; |
w = p[0]; hi = w>>32; |
hi = htonl(hi); |
if ( little_endian && (ox_file_io || ox_need_conv) ) |
|
hi = htonl(hi); |
gen_fwrite((char *)&hi,sizeof(unsigned int),1,f); |
gen_fwrite((char *)&hi,sizeof(unsigned int),1,f); |
i = 1; |
i = 1; |
} else |
} else |
Line 296 void write_longarray(FILE *f,unsigned long *p,int l) |
|
Line 299 void write_longarray(FILE *f,unsigned long *p,int l) |
|
l = (l+1)/2; |
l = (l+1)/2; |
for ( ; i < l; i++ ) { |
for ( ; i < l; i++ ) { |
w = p[i]; hi = w>>32; lo = w&0xffffffff; |
w = p[i]; hi = w>>32; lo = w&0xffffffff; |
hi = htonl(hi); lo = htonl(lo); |
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
|
hi = htonl(hi); lo = htonl(lo); |
|
} |
gen_fwrite((char *)&lo,sizeof(unsigned int),1,f); |
gen_fwrite((char *)&lo,sizeof(unsigned int),1,f); |
gen_fwrite((char *)&hi,sizeof(unsigned int),1,f); |
gen_fwrite((char *)&hi,sizeof(unsigned int),1,f); |
} |
} |
} |
} |
#endif |
#endif |
|
|
|
#if defined(_WIN64) |
|
/* write l word (1word=4bytes) */ |
|
/* l even : low 32of p[0] | high32 of p[0] | ... */ |
|
/* l odd : high32 of p[0] | ... */ |
|
void write_longarray(FILE *f,unsigned long long *p,int l) |
|
{ |
|
int i; |
|
unsigned long long w; |
|
unsigned int hi,lo; |
|
|
|
if ( l%2 ) { |
|
w = p[0]; hi = w>>32; |
|
if ( little_endian && (ox_file_io || ox_need_conv) ) |
|
hi = htonl(hi); |
|
gen_fwrite((char *)&hi,sizeof(unsigned int),1,f); |
|
i = 1; |
|
} else |
|
i = 0; |
|
l = (l+1)/2; |
|
for ( ; i < l; i++ ) { |
|
w = p[i]; hi = w>>32; lo = w&0xffffffff; |
|
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
|
hi = htonl(hi); lo = htonl(lo); |
|
} |
|
gen_fwrite((char *)&lo,sizeof(unsigned int),1,f); |
|
gen_fwrite((char *)&hi,sizeof(unsigned int),1,f); |
|
} |
|
} |
|
#endif |
|
|
void write_double(FILE *f,double *p) |
void write_double(FILE *f,double *p) |
{ |
{ |
unsigned int t; |
unsigned int t; |
Line 400 void read_longarray(FILE *f,unsigned long *p,int l) |
|
Line 435 void read_longarray(FILE *f,unsigned long *p,int l) |
|
q = (unsigned int *)p; |
q = (unsigned int *)p; |
if ( l%2 ) { |
if ( l%2 ) { |
gen_fread((char *)&hi,sizeof(unsigned int),1,f); |
gen_fread((char *)&hi,sizeof(unsigned int),1,f); |
hi = ntohl(hi); |
if ( little_endian && (ox_file_io || ox_need_conv) ) |
|
hi = ntohl(hi); |
*p = (((unsigned long)hi)<<32); |
*p = (((unsigned long)hi)<<32); |
p++; l--; |
p++; l--; |
} |
} |
for ( i = 0; i < l; i += 2, p++ ) { |
for ( i = 0; i < l; i += 2, p++ ) { |
gen_fread((char *)&lo,sizeof(unsigned int),1,f); |
gen_fread((char *)&lo,sizeof(unsigned int),1,f); |
gen_fread((char *)&hi,sizeof(unsigned int),1,f); |
gen_fread((char *)&hi,sizeof(unsigned int),1,f); |
hi = ntohl(hi); lo = ntohl(lo); |
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
|
hi = ntohl(hi); lo = ntohl(lo); |
|
} |
*p = (((unsigned long)hi)<<32)|((unsigned long)lo); |
*p = (((unsigned long)hi)<<32)|((unsigned long)lo); |
|
} |
|
} |
|
#endif |
|
|
|
#if defined(_WIN64) |
|
/* read l word (1word=4bytes) */ |
|
/* pad 0 at low 32 of p[0] if l is odd */ |
|
/* low 32 of p[0] | high32 of p[0] | ... */ |
|
void read_longarray(FILE *f,unsigned long long *p,int l) |
|
{ |
|
int i; |
|
unsigned int hi,lo; |
|
unsigned int *q; |
|
|
|
q = (unsigned int *)p; |
|
if ( l%2 ) { |
|
gen_fread((char *)&hi,sizeof(unsigned int),1,f); |
|
if ( little_endian && (ox_file_io || ox_need_conv) ) |
|
hi = ntohl(hi); |
|
*p = (((unsigned long long)hi)<<32); |
|
p++; l--; |
|
} |
|
for ( i = 0; i < l; i += 2, p++ ) { |
|
gen_fread((char *)&lo,sizeof(unsigned int),1,f); |
|
gen_fread((char *)&hi,sizeof(unsigned int),1,f); |
|
if ( little_endian && (ox_file_io || ox_need_conv) ) { |
|
hi = ntohl(hi); lo = ntohl(lo); |
|
} |
|
*p = (((unsigned long long)hi)<<32)|((unsigned long long)lo); |
} |
} |
} |
} |
#endif |
#endif |