From bug-octave-request at bevo dot che dot wisc dot edu Tue May 15 17:00:05 2001 Subject: New feature: Native file io support for TMS C3X format From: "Martin Lang" To: Date: Tue, 15 May 2001 16:59:56 -0500 This is a multi-part message in MIME format. ------=_NextPart_000_000E_01C0D738.0C91DC40 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Description: ----------- Native file io support for TMS C3X format. This eables C3/4X developers to directly read and write files in the native processor format. Repeat-By: --------- N.A. Fix: --- The following files have been changed for the support: (see ChangeLogs for a detailed description of the changes) - src/ChangeLog - liboctave/ChangeLog - test/ChangeLog - src/file-io.cc - liboctave/dMatrix.cc - liboctave/data-conv.cc - liboctave/data-conv.h - liboctave/mach-info.cc - liboctave/mach-info.h - test/octave.test/io/fopen-1.m - test/octave.test/io/io.exp - test/octave.test/io/tmsio.m The patch for version 2.1.33 is added as an appendix. I hope the patch is useful. Martin Lang (Germay) Configuration (please do not edit this section): ----------------------------------------------- uname output: CYGWIN_95-4.0 PC1 1.1.8(0.34/3/2) 2001-01-31 10:08 i586 unknown configure opts: Fortran compiler: g77 FFLAGS: -O F2C: F2CFLAGS: FLIBS: -lg2c -L/usr/lib/gcc-lib/i686-pc-cygwin/2.95.2 -lcygwin -l user32 -lkernel32 -ladvapi32 -lshell32 CPPFLAGS: INCFLAGS: -I. -I. -I./liboctave -I./src -I./libcruft/misc -I./glob -I./glob C compiler: gcc, version 2.95.3-3 (cygwin special) CFLAGS: -g -O2 -Wall CPICFLAG: -fPIC C++ compiler: c++, version 2.95.3-3 (cygwin special) CXXFLAGS: -g -O2 -Wall CXXPICFLAG: -fPIC LDFLAGS: -g LIBFLAGS: -L. RLD_FLAG: TERMLIBS: -ltermcap LIBS: -lz -lm LEXLIB: LIBPLPLOT: LIBDLFCN: LIBGLOB: ./glob/glob.o ./glob/fnmatch.o DEFS: -DOCTAVE_SOURCE=1 -DSEPCHAR=':' -DSEPCHAR_STR=":" -DUSE_READLINE=1 -D__NO_MATH_INLINES=1 -DCXX_NEW_FRIEND_TEMPLATE_DECL=1 -DCXX_PREPENDS_UNDERSCORE=1 -DHAVE_LIBM=1 -DHAVE_LIBZ=1 -DF77_APPEND_UNDERSCORE=1 -DSIZEOF_SHORT=2 -DSIZEOF_INT=4 -DSIZEOF_LONG=4 -DSIZEOF_LONG_LONG=8 -DHAVE_ALLOCA=1 -DNPOS=std::string::npos -DSTDC_HEADERS=1 -DHAVE_DIRENT_H=1 -DTIME_WITH_SYS_TIME=1 -DHAVE_SYS_WAIT_H=1 -DHAVE_ASSERT_H=1 -DHAVE_DLFCN_H=1 -DHAVE_FCNTL_H=1 -DHAVE_FLOAT_H=1 -DHAVE_FNMATCH_H=1 -DHAVE_GLOB_H=1 -DHAVE_GRP_H=1 -DHAVE_IEEEFP_H=1 -DHAVE_LIMITS_H=1 -DHAVE_MEMORY_H=1 -DHAVE_PWD_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_SYS_IOCTL_H=1 -DHAVE_SYS_PARAM_H=1 -DHAVE_SYS_RESOURCE_H=1 -DHAVE_SYS_SELECT_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_SYS_TIME_H=1 -DHAVE_SYS_TIMES_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_UTSNAME_H=1 -DHAVE_TERMCAP_H=1 -DHAVE_TERMIO_H=1 -DHAVE_UNISTD_H=1 -DHAVE_VARARGS_H=1 -DHAVE_ATEXIT=1 -DHAVE_BCOPY=1 -DHAVE_BZERO=1 -DHAVE_DUP2=1 -DHAVE_ENDGRENT=1 -DHAVE_ENDPWENT=1 -DHAVE_EXECVP=1 -DHAVE_FCNTL=1 -DHAVE_FORK=1 -DHAVE_GETCWD=1 -DHAVE_GETEGID=1 -DHAVE_GETEUID=1 -DHAVE_GETGID=1 -DHAVE_GETGRENT=1 -DHAVE_GETGRGID=1 -DHAVE_GETGRNAM=1 -DHAVE_GETHOSTNAME=1 -DHAVE_GETPGRP=1 -DHAVE_GETPID=1 -DHAVE_GETPPID=1 -DHAVE_GETPWENT=1 -DHAVE_GETPWNAM=1 -DHAVE_GETPWUID=1 -DHAVE_GETTIMEOFDAY=1 -DHAVE_GETUID=1 -DHAVE_GETWD=1 -DHAVE_LINK=1 -DHAVE_LSTAT=1 -DHAVE_PIPE=1 -DHAVE_PUTENV=1 -DHAVE_READLINK=1 -DHAVE_RENAME=1 -DHAVE_RINDEX=1 -DHAVE_RMDIR=1 -DHAVE_SELECT=1 -DHAVE_SETGRENT=1 -DHAVE_SETPWENT=1 -DHAVE_SETVBUF=1 -DHAVE_SIGACTION=1 -DHAVE_SIGPENDING=1 -DHAVE_SIGPROCMASK=1 -DHAVE_SIGSUSPEND=1 -DHAVE_STAT=1 -DHAVE_STRCASECMP=1 -DHAVE_STRDUP=1 -DHAVE_STRERROR=1 -DHAVE_STRFTIME=1 -DHAVE_STRNCASECMP=1 -DHAVE_SYMLINK=1 -DHAVE_TEMPNAM=1 -DHAVE_UMASK=1 -DHAVE_UNLINK=1 -DHAVE_USLEEP=1 -DHAVE_VFPRINTF=1 -DHAVE_VSPRINTF=1 -DHAVE_VSNPRINTF=1 -DHAVE_WAITPID=1 -DSMART_PUTENV=1 -DHAVE_DLOPEN=1 -DHAVE_DLSYM=1 -DHAVE_DLERROR=1 -DHAVE_DLCLOSE=1 -DWITH_DL=1 -DWITH_DYNAMIC_LINKING=1 -DHAVE_TIMEVAL=1 -DHAVE_FINITE=1 -DHAVE_ISNAN=1 -DHAVE_ISINF=1 -DHAVE_ACOSH=1 -DHAVE_ASINH=1 -DHAVE_ATANH=1 -DHAVE_ERF=1 -DHAVE_ERFC=1 -DHAVE_ST_BLKSIZE=1 -DHAVE_ST_BLOCKS=1 -DHAVE_ST_RDEV=1 -DHAVE_GR_PASSWD=1 -DEXCEPTION_IN_MATH=1 -DRETSIGTYPE=void -DHAVE_POSIX_SIGNALS=1 -DHAVE_GETRUSAGE=1 -DHAVE_TIMES=1 ------=_NextPart_000_000E_01C0D738.0C91DC40 Content-Type: application/octet-stream; name="tms_patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="tms_patch" diff --recursive -x *.[aod] -x *.texi -x *.info* -x *.df -x *~ -x *.lo = -x Makefile -cp octave-2.1.33.org/liboctave/ChangeLog = octave-2.1.33/liboctave/ChangeLog *** octave-2.1.33.org/liboctave/ChangeLog Tue May 1 20:26:28 2001 --- octave-2.1.33/liboctave/ChangeLog Mon May 7 19:26:42 2001 *************** *** 1,3 **** --- 1,55 ---- + 2001-04-30 Martin Lang +=20 + * data-conv.cc (tms2ieee, ieee2tms): New functions. + (TMS_C3X_big_float_to_IEEE_little_float): New function.=20 + Used to convert format as decribed in function name. + (TMS_C3X_little_float_to_IEEE_little_float): Likewise. + (TMS_C3X_big_float_to_IEEE_big_float): Likewise. + (TMS_C3X_little_float_to_IEEE_big_float): Likewise. + (TMS_C3X_big_float_to_VAX_D_float): Likewise. + (TMS_C3X_little_float_to_VAX_D_float): Likewise. + (TMS_C3X_big_float_to_VAX_G_float): Likewise. + (TMS_C3X_little_float_to_VAX_G_float): Likewise. + (IEEE_little_float_to_TMS_C3X_little_float): Likewise. + (IEEE_big_float_to_TMS_C3X_little_float): Likewise. + (VAX_D_float_to_TMS_C3X_little_float): Likewise. + (VAX_G_float_to_TMS_C3X_little_float): Likewise. + (Cray_to_TMS_C3X_little_float): Likewise. + (TMS_C3X_big_float_to_TMS_C3X_little_float): Likewise. + (IEEE_little_float_to_TMS_C3X_big_float): Likewise. + (IEEE_big_float_to_TMS_C3X_big_float): Likewise. + (VAX_D_float_to_TMS_C3X_big_float): Likewise. + (VAX_G_float_to_TMS_C3X_big_float): Likewise. + (Cray_to_TMS_C3X_big_float): Likewise. + (TMS_C3X_little_float_to_TMS_C3X_big_float): Likewise. + (do_double_format_conversion): Replaced arg + (oct_mach_info::float_format fmt) + by=20 + (oct_mach_info::float_format in_fmt, + oct_mach_info::float_format out_fmt) + to specify the exact input and output format. The out_fmt + was formerly derived by a function call to=20 + oct_mach_info::native_float_format (). However this did=20 + not cover all possible conversion paths.=20 + (do_float_format_conversion): Likewise. Added switch cases + for TMS C3X format. + (read_doubles): adopted to changed prototypes of functions=20 + do_double_format_conversion and do_float_format_conversion +=20 + * data-conv.h (do_double_format_conversion,=20 + do_float_format_conversion): Changed prototypes. +=20 + * mach-info.cc (oct_mach_info::string_to_float_format):=20 + Added support for TMS C3X formats +=20 + * mach-info.h (enum float_format):=20 + Added tms_c3x_little_endian and tms_c3x_big_endian +=20 + * dMatrix.cc (do_read, do_write):=20 + adopted to changed prototypes of functions=20 + do_double_format_conversion and do_float_format_conversion + (Matrix::read, Matrix::write): Added support for TMS C3X formats +=20 2001-01-02 John W. Eaton =20 * CMatrix.cc (operator * (const ComplexMatrix&, const = ComplexMatrix&): diff --recursive -x *.[aod] -x *.texi -x *.info* -x *.df -x *~ -x *.lo = -x Makefile -cp octave-2.1.33.org/src/ChangeLog = octave-2.1.33/src/ChangeLog *** octave-2.1.33.org/src/ChangeLog Tue May 1 20:26:28 2001 --- octave-2.1.33/src/ChangeLog Sun May 6 15:26:10 2001 *************** *** 1,3 **** --- 1,8 ---- + 2001-04-30 Martin Lang +=20 + * file-io.cc (fopen): Added availability of TMS C3X/C4X data + format to doc string +=20 2001-01-05 John W. Eaton =20 * error.cc (vwarning): Write to output_buf, then send formatted diff --recursive -x *.[aod] -x *.texi -x *.info* -x *.df -x *~ -x *.lo = -x Makefile -cp octave-2.1.33.org/test/ChangeLog = octave-2.1.33/test/ChangeLog *** octave-2.1.33.org/test/ChangeLog Thu Jun 8 15:45:56 2000 --- octave-2.1.33/test/ChangeLog Mon May 7 19:31:36 2001 *************** *** 1,3 **** --- 1,10 ---- + 2001-04-30 Martin Lang +=20 + * octave.test/io/fopen-1.m: Added support tmsc3x-be and + tmsc3x-le format + * octave.test/io/tmsio.exp: New test for TMS C3X io + * octave.test/io/io.exp: Include tmsio.exp +=20 2000-06-07 Ben Sapp =20 * octave.test/quad/quad-1.m: Use absolute value of difference *** octave-2.1.33.org/test/octave.test/io/fopen-1.m Thu Feb 27 00:23:20 = 1997 --- octave-2.1.33/test/octave.test/io/fopen-1.m Sun Apr 29 16:00:38 2001 *************** *** 1,8 **** ! arch_list =3D ["native"; "ieee-le"; "ieee-be"; "vaxd"; "vaxg"; = "cray"]; !=20 status =3D 1; !=20 ! for i =3D 1:6 arch =3D deblank (arch_list (i,:)) for j =3D 1:2 if (j =3D=3D 1) --- 1,8 ---- ! arch_list =3D ["native"; "ieee-le"; "ieee-be"; "vaxd"; "vaxg"; "cray"; = "tmsc3x-be"; "tmsc3x-le"]; ! =20 status =3D 1; ! =20 ! for i =3D 1:8 arch =3D deblank (arch_list (i,:)) for j =3D 1:2 if (j =3D=3D 1) diff -N --recursive -x *.[aod] -x *.texi -x *.info* -x *.df -x *~ -x = *.lo -x Makefile -cp octave-2.1.33.org/test/octave.test/io/io.exp = octave-2.1.33/test/octave.test/io/io.exp *** octave-2.1.33.org/test/octave.test/io/io.exp Fri Mar 24 21:01:34 = 2000 --- octave-2.1.33/test/octave.test/io/io.exp Sun Apr 29 16:01:42 2001 *************** *** 277,279 **** --- 277,283 ---- set test frewind-3 set prog_output "error:.*" do_test frewind-3.m +=20 + set test tmsio + set prog_output "Number Errors =3D 0" + do_test tmsio.m diff -N --recursive -x *.[aod] -x *.texi -x *.info* -x *.df -x *~ -x = *.lo -x Makefile -cp octave-2.1.33.org/test/octave.test/io/tmsio.m = octave-2.1.33/test/octave.test/io/tmsio.m *** octave-2.1.33.org/test/octave.test/io/tmsio.m Thu Jan 1 01:00:00 = 1970 --- octave-2.1.33/test/octave.test/io/tmsio.m Mon Apr 16 13:01:28 2001 *************** *** 0 **** --- 1,57 ---- + test_vec_out =3D [NaN, -Inf, +Inf, 0, 1, -3, +3] +=20 + test_vec_ref(1) =3D 2147483648; # 0x80000000 NaN + test_vec_ref(2) =3D 2139095040; # 0x7f800000 -Inf + test_vec_ref(3) =3D 2139095039; # 0x7f7fffff +Inf + test_vec_ref(4) =3D 2147483648; # 0x80000000 0 + test_vec_ref(5) =3D 0 ; # 0x00000000 1 + test_vec_ref(6) =3D 29360128 ; # 0x01c00000 -3 + test_vec_ref(7) =3D 20971520 ; # 0x01400000 +3 +=20 + error_count =3D 0; + tms_type =3D str2mat("tmsc3x-be", "tmsc3x-le"); +=20 + for t =3D 1:2 + fid=3Dfopen(strcat(tms_type(t,:),".dat"),"wb",tms_type(t,:)); + if (fid > 0) + fwrite(fid,test_vec_out,"float",0,tms_type(t,:)); + fclose(fid); +=20 + fid=3Dfopen(strcat(tms_type(t,:),".dat"),"rb",tms_type(t,:)); + if (fid > 0) + = test_vec_in=3Dfread(fid,size(test_vec_out),"float",0,tms_type(t,:)) + fclose(fid); +=20 + for i =3D 2:size(test_vec_in,2) # ommit NaN + if (test_vec_in(i) !=3D test_vec_out(i)) + error_count++; + endif + endfor +=20 + fid=3Dfopen(strcat(tms_type(t,:),".dat"),"rb",tms_type(t,:)); + if (fid > 0) + test_vec_in=3Dfread(fid,size(test_vec_out),"unsigned long") + fclose(fid); +=20 + for i =3D 1:(size(test_vec_in,2)-2) # ommit -3, +3 + if (test_vec_in(i) !=3D test_vec_ref(i)) + error_count++; + endif + endfor +=20 + else + error_count++; + endif +=20 + else + error_count++; + endif + unlink(strcat(tms_type(t,:),".dat")); + else + error_count++; + endif + endfor +=20 + printf("Number Errors =3D %d\n", error_count); +=20 +=20 diff --recursive -x *.[aod] -x *.texi -x *.info* -x *.df -x *~ -x *.lo = -x Makefile -cp octave-2.1.33.org/src/file-io.cc = octave-2.1.33/src/file-io.cc *** octave-2.1.33.org/src/file-io.cc Tue May 1 20:26:06 2001 --- octave-2.1.33/src/file-io.cc Sun May 6 14:51:12 2001 *************** VAX G floating format.\n\ *** 439,449 **** \n\ at samp{cray}\n\ Cray floating format.\n\ at end table\n\ \n\ at noindent\n\ ! however, conversions are currently only supported for at samp{native}\n\ ! at samp{ieee-be}, and @samp{ieee-le} formats.\n\ at end deftypefn") { octave_value_list retval; --- 439,458 ---- \n\ at samp{cray}\n\ Cray floating format.\n\ + \n\ + at samp{tmsc3x-le}\n\ + TMS C3X/C4X floating format little endian. The maschine storing the\n\ + TMS C3X/C4X data determines, whether the data is stored in little = or\n\ + big endian.\n\ + \n\ + at samp{tmsc3x-be}\n\ + TMS C3X/C4X floating format big endian.\n\ at end table\n\ \n\ at noindent\n\ ! however, conversions are currently only supported for \n\ ! at samp{native}, @samp{ieee-be}, @samp{ieee-le}, \n\ ! at samp{tmsc3x-be} and @samp{tmsc3x-le} formats.\n\ at end deftypefn") { octave_value_list retval; diff --recursive -x *.[aod] -x *.texi -x *.info* -x *.df -x *~ -x *.lo = -x Makefile -cp octave-2.1.33.org/liboctave/dMatrix.cc = octave-2.1.33/liboctave/dMatrix.cc *** octave-2.1.33.org/liboctave/dMatrix.cc Tue May 1 20:26:28 2001 --- octave-2.1.33/liboctave/dMatrix.cc Sun Apr 29 13:20:10 2001 *************** do_read (std::istream& is, oct_data_conv *** 2536,2542 **** is.read (X_CAST (char *, &f), sizeof (float)); =20 if (do_float_conversion) ! do_float_format_conversion (&f, 1, flt_fmt); =20 val =3D f; } --- 2536,2543 ---- is.read (X_CAST (char *, &f), sizeof (float)); =20 if (do_float_conversion) ! do_float_format_conversion (&f, 1, flt_fmt, ! = oct_mach_info::native_float_format ()); =20 val =3D f; } *************** do_read (std::istream& is, oct_data_conv *** 2547,2553 **** is.read (X_CAST (char *, &val), sizeof (double)); =20 if (do_float_conversion) ! do_double_format_conversion (&val, 1, flt_fmt); } break; =20 --- 2548,2555 ---- is.read (X_CAST (char *, &val), sizeof (double)); =20 if (do_float_conversion) ! do_double_format_conversion (&val, 1, flt_fmt, ! = oct_mach_info::native_float_format ()); } break; =20 *************** Matrix::read (std::istream& is, int nr,=20 *** 2612,2620 **** if (oct_mach_info::words_big_endian ()) swap_bytes =3D (flt_fmt =3D=3D oct_mach_info::ieee_little_endian || flt_fmt =3D=3D oct_mach_info::vax_g ! || flt_fmt =3D=3D oct_mach_info::vax_g); else ! swap_bytes =3D (flt_fmt =3D=3D oct_mach_info::ieee_big_endian); =20 for (;;) { --- 2614,2624 ---- if (oct_mach_info::words_big_endian ()) swap_bytes =3D (flt_fmt =3D=3D oct_mach_info::ieee_little_endian || flt_fmt =3D=3D oct_mach_info::vax_g ! || flt_fmt =3D=3D oct_mach_info::vax_g ! || flt_fmt =3D=3D = oct_mach_info::tms_c3x_little_endian); else ! swap_bytes =3D (flt_fmt =3D=3D oct_mach_info::ieee_big_endian ! || flt_fmt =3D=3D oct_mach_info::tms_c3x_big_endian); =20 for (;;) { *************** do_write (std::ostream& os, double d, oc *** 2805,2811 **** float f =3D d; =20 if (do_float_conversion) ! do_float_format_conversion (&f, 1, flt_fmt); =20 os.write (X_CAST (char *, &f), sizeof (float)); } --- 2809,2817 ---- float f =3D d; =20 if (do_float_conversion) ! do_float_format_conversion (&f, 1,=20 ! = oct_mach_info::native_float_format (), ! flt_fmt); =20 os.write (X_CAST (char *, &f), sizeof (float)); } *************** do_write (std::ostream& os, double d, oc *** 2814,2820 **** case oct_data_conv::dt_double: { if (do_float_conversion) ! do_double_format_conversion (&d, 1, flt_fmt); =20 os.write (X_CAST (char *, &d), sizeof (double)); } --- 2820,2828 ---- case oct_data_conv::dt_double: { if (do_float_conversion) ! do_double_format_conversion (&d, 1,=20 ! = oct_mach_info::native_float_format (), ! flt_fmt); =20 os.write (X_CAST (char *, &d), sizeof (double)); } *************** Matrix::write (std::ostream& os, oct_dat *** 2856,2864 **** if (oct_mach_info::words_big_endian ()) swap_bytes =3D (flt_fmt =3D=3D oct_mach_info::ieee_little_endian || flt_fmt =3D=3D oct_mach_info::vax_g ! || flt_fmt =3D=3D oct_mach_info::vax_g); else ! swap_bytes =3D (flt_fmt =3D=3D oct_mach_info::ieee_big_endian); =20 for (int i =3D 0; i < n; i++) { --- 2864,2874 ---- if (oct_mach_info::words_big_endian ()) swap_bytes =3D (flt_fmt =3D=3D oct_mach_info::ieee_little_endian || flt_fmt =3D=3D oct_mach_info::vax_g ! || flt_fmt =3D=3D oct_mach_info::vax_g ! || flt_fmt =3D=3D = oct_mach_info::tms_c3x_little_endian); else ! swap_bytes =3D (flt_fmt =3D=3D oct_mach_info::ieee_big_endian ! || flt_fmt =3D=3D oct_mach_info::tms_c3x_big_endian); =20 for (int i =3D 0; i < n; i++) { diff --recursive -x *.[aod] -x *.texi -x *.info* -x *.df -x *~ -x *.lo = -x Makefile -cp octave-2.1.33.org/liboctave/data-conv.cc = octave-2.1.33/liboctave/data-conv.cc *** octave-2.1.33.org/liboctave/data-conv.cc Wed Feb 2 00:11:58 2000 --- octave-2.1.33/liboctave/data-conv.cc Sun Apr 29 13:41:30 2001 *************** Software Foundation, 59 Temple Place - S *** 28,33 **** --- 28,38 ---- =20 #include =20 + #include + #include + #include + #include +=20 #include "byte-swap.h" #include "data-conv.h" #include "lo-error.h" *************** oct_data_conv::string_to_data_type (cons *** 183,188 **** --- 188,270 ---- return retval; } =20 + /*=20 +=20 + The following two functions have been taken from the c4x=20 + simulator C4XSIM for the gdb +=20 + The functions were original written by: + Herman A.J. ten Brugge (Haj dot Ten dot Brugge at net dot HCC dot nl) + The functions have been extended by: + Martin O.R. Lang (Martin dot Lang at LanaTech dot de) +=20 + C4XSIM is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. +=20 + The functions have been slightly modified for a correct treatment + of NaN, +Inf and -Inf. +=20 + The functions have been renamed to allow a clear data conversion + naming convention.=20 + tosingledouble -> tms2ieee + fromsingledouble -> ieee2tms +=20 + */ +=20 + /* Notes: + There is no +Inf/-Inf representation in the TMS C3X/C4X format. + However, whenever a overflow occurs, the DSP returns the + biggest or smallest number. + - biggest tms number -> return +Inf + - smallest tms number -> return -Inf + */ + double tms2ieee (long s)=20 + { + int e; + double t; +=20 + if (s =3D=3D 0x7f7fffffL) return(infinity()); + if (s =3D=3D 0x7f800000L) return(-infinity()); + e =3D s >> 24; + if (e & 0x80) e |=3D ~0x7f; else e &=3D 0x7f; + if (e =3D=3D -128) return(0.0); + t =3D s & 0x800000L ? (((double)(~s & 0x7fffffL))+8388609.0) / = -8388608.0 + : (((double)( s & 0x7fffffL))+8388608.0) / 8388608.0; + return (ldexp(t,e)); + } +=20 + /* Notes: + There is no +Inf/-Inf representation in the TMS C3X/C4X format. + However, whenever a overflow occurs, the DSP returns the + biggest or smallest number. + - +Inf -> return biggest tms number; + - -Inf -> return smallest tms number; + - no +NaN representation in tms format -> return 0; + */ + long ieee2tms (double d)=20 + { + int e; + long sign; +=20 + if (d =3D=3D 0.0) { return(0x80000000L); } + if (isnanf(d)) { return(0x80000000L); } /* */ + if (d < 0.0) { d =3D -d; sign =3D 0x800000L; } else { sign =3D 0; } + if (isinff(d)) { return(sign ? 0x7f800000L : 0x7f7fffffL); } + d =3D frexp((double)d,&e) * 16777216.0 - 8388608.0; + if (sign && (long)d =3D=3D 0) e -=3D 2; else e--; + sign =3D sign ? sign | ((~((long)d)+1) & 0x7fffffL) + : ((long)d & 0x7fffffL); + if (e < -127) { + return(0x80000000L); + } + else if (e > 127) { + return(sign ? 0x7f800000L : 0x7f7fffffL); + } + return(sign | ((long)e << 24)); + } +=20 #define swap_1_bytes(x, y) =20 #define LS_DO_READ(TYPE, swap, data, size, len, stream) \ *************** Cray_to_VAX_G_float (float * /* d */, in *** 432,445 **** gripe_data_conversion ("VAX G float", "VAX G"); } =20 void do_double_format_conversion (double *data, int len, ! oct_mach_info::float_format fmt) { ! switch (oct_mach_info::native_float_format ()) { case oct_mach_info::ieee_little_endian: ! switch (fmt) { case oct_mach_info::ieee_little_endian: break; --- 514,700 ---- gripe_data_conversion ("VAX G float", "VAX G"); } =20 + static void + TMS_C3X_big_float_to_IEEE_little_float (float *d, int len) + { + long *tms =3D (long *)d; + =20 + swap_4_bytes ((char *) d, len); +=20 + while (len-- > 0) + { + *d++ =3D (float) tms2ieee (*tms++) ; + } + } +=20 + static void + TMS_C3X_little_float_to_IEEE_little_float (float *d, int len) + { + long *tms =3D (long *)d; + =20 + while (len-- > 0) + { + *d++ =3D (float) tms2ieee (*tms++) ; + } + } +=20 + static void + TMS_C3X_big_float_to_IEEE_big_float (float *d, int len) + { + long *tms =3D (long *)d; + =20 + while (len-- > 0) + { + *d++ =3D (float) tms2ieee (*tms++) ; + } + } +=20 + static void + TMS_C3X_little_float_to_IEEE_big_float (float *d, int len) + { + long *tms =3D (long *)d; + =20 + swap_4_bytes ((char *) d, len); +=20 + while (len-- > 0) + { + *d++ =3D (float) tms2ieee (*tms++) ; + } + } +=20 + static void + TMS_C3X_big_float_to_VAX_D_float (float *d, int len) + { + gripe_data_conversion ("TMSC3X big endian", "VAX D"); + } +=20 + static void + TMS_C3X_little_float_to_VAX_D_float (float *d, int len) + { + gripe_data_conversion ("TMSC3X little endian", "VAX D"); + } +=20 + static void + TMS_C3X_big_float_to_VAX_G_float (float *d, int len) + { + gripe_data_conversion ("TMSC3X big endian", "VAX G"); + } +=20 + static void + TMS_C3X_little_float_to_VAX_G_float (float *d, int len) + { + gripe_data_conversion ("TMSC3X little endian", "VAX G"); + } +=20 + static void + IEEE_little_float_to_TMS_C3X_little_float (float *d, int len) + { + long *tms =3D (long *)d; + =20 + while (len-- > 0) + { + *tms++ =3D ieee2tms ((float)*d++) ; + } + } +=20 + static void + IEEE_big_float_to_TMS_C3X_little_float (float *d, int len) + { + long *tms =3D (long *)d; + int tlen =3D len; + =20 + while (len-- > 0) + { + *tms++ =3D ieee2tms ((float)*d++) ; + } +=20 + d -=3D tlen; + swap_4_bytes ((char *) d, tlen); + } +=20 + static void + VAX_D_float_to_TMS_C3X_little_float (float *d, int len) + { + gripe_data_conversion ("VAX D", "TMSC3X little endian"); + } +=20 + static void + VAX_G_float_to_TMS_C3X_little_float (float *d, int len) + { + gripe_data_conversion ("VAX G", "TMSC3X little endian"); + } +=20 + static void + Cray_to_TMS_C3X_little_float (float *d, int len) + { + gripe_data_conversion ("Cray", "TMSC3X little endian"); + } +=20 + static void + TMS_C3X_big_float_to_TMS_C3X_little_float (float *d, int len) + { + swap_4_bytes ((char *) d, len); + } +=20 + static void + IEEE_little_float_to_TMS_C3X_big_float (float *d, int len) + { + long *tms =3D (long *)d; + int tlen =3D len; + =20 + while (len-- > 0) + { + *tms++ =3D ieee2tms ((float)*d++) ; + } +=20 + d -=3D tlen; + swap_4_bytes ((char *) d, tlen); + } +=20 + static void + IEEE_big_float_to_TMS_C3X_big_float (float *d, int len) + { + long *tms =3D (long *)d; + =20 + while (len-- > 0) + { + *tms++ =3D ieee2tms ((float)*d++) ; + } + } +=20 + static void + VAX_D_float_to_TMS_C3X_big_float (float *d, int len) + { + gripe_data_conversion ("VAX D", "TMSC3X big endian"); + } +=20 + static void + VAX_G_float_to_TMS_C3X_big_float (float *d, int len) + { + gripe_data_conversion ("VAX G", "TMSC3X big endian"); + } +=20 + static void + Cray_to_TMS_C3X_big_float (float *d, int len) + { + gripe_data_conversion ("Cray", "TMSC3X big endian"); + } +=20 + static void + TMS_C3X_little_float_to_TMS_C3X_big_float (float *d, int len) + { + swap_4_bytes ((char *) d, len); + } +=20 void do_double_format_conversion (double *data, int len, ! oct_mach_info::float_format in_fmt, ! oct_mach_info::float_format out_fmt) { ! switch (out_fmt) { case oct_mach_info::ieee_little_endian: ! switch (in_fmt) { case oct_mach_info::ieee_little_endian: break; *************** do_double_format_conversion (double *dat *** 467,473 **** break; =20 case oct_mach_info::ieee_big_endian: ! switch (fmt) { case oct_mach_info::ieee_little_endian: IEEE_little_double_to_IEEE_big_double (data, len); --- 722,728 ---- break; =20 case oct_mach_info::ieee_big_endian: ! switch (in_fmt) { case oct_mach_info::ieee_little_endian: IEEE_little_double_to_IEEE_big_double (data, len); *************** do_double_format_conversion (double *dat *** 495,501 **** break; =20 case oct_mach_info::vax_d: ! switch (fmt) { case oct_mach_info::ieee_little_endian: IEEE_little_double_to_VAX_D_double (data, len); --- 750,756 ---- break; =20 case oct_mach_info::vax_d: ! switch (in_fmt) { case oct_mach_info::ieee_little_endian: IEEE_little_double_to_VAX_D_double (data, len); *************** do_double_format_conversion (double *dat *** 523,529 **** break; =20 case oct_mach_info::vax_g: ! switch (fmt) { case oct_mach_info::ieee_little_endian: IEEE_little_double_to_VAX_G_double (data, len); --- 778,784 ---- break; =20 case oct_mach_info::vax_g: ! switch (in_fmt) { case oct_mach_info::ieee_little_endian: IEEE_little_double_to_VAX_G_double (data, len); *************** do_double_format_conversion (double *dat *** 560,571 **** =20 void do_float_format_conversion (float *data, int len, ! oct_mach_info::float_format fmt) { ! switch (oct_mach_info::native_float_format ()) { case oct_mach_info::ieee_little_endian: ! switch (fmt) { case oct_mach_info::ieee_little_endian: break; --- 815,827 ---- =20 void do_float_format_conversion (float *data, int len, ! oct_mach_info::float_format in_fmt, ! oct_mach_info::float_format out_fmt) { ! switch (out_fmt) { case oct_mach_info::ieee_little_endian: ! switch (in_fmt) { case oct_mach_info::ieee_little_endian: break; *************** do_float_format_conversion (float *data, *** 586,591 **** --- 842,855 ---- Cray_to_IEEE_little_float (data, len); break; =20 + case oct_mach_info::tms_c3x_big_endian: + TMS_C3X_big_float_to_IEEE_little_float (data, len); + break; +=20 + case oct_mach_info::tms_c3x_little_endian: + TMS_C3X_little_float_to_IEEE_little_float (data, len); + break; +=20 default: gripe_unrecognized_float_fmt (); break; *************** do_float_format_conversion (float *data, *** 593,599 **** break; =20 case oct_mach_info::ieee_big_endian: ! switch (fmt) { case oct_mach_info::ieee_little_endian: IEEE_little_float_to_IEEE_big_float (data, len); --- 857,863 ---- break; =20 case oct_mach_info::ieee_big_endian: ! switch (in_fmt) { case oct_mach_info::ieee_little_endian: IEEE_little_float_to_IEEE_big_float (data, len); *************** do_float_format_conversion (float *data, *** 614,619 **** --- 878,891 ---- Cray_to_IEEE_big_float (data, len); break; =20 + case oct_mach_info::tms_c3x_big_endian: + TMS_C3X_big_float_to_IEEE_big_float (data, len); + break; +=20 + case oct_mach_info::tms_c3x_little_endian: + TMS_C3X_little_float_to_IEEE_big_float (data, len); + break; +=20 default: gripe_unrecognized_float_fmt (); break; *************** do_float_format_conversion (float *data, *** 621,627 **** break; =20 case oct_mach_info::vax_d: ! switch (fmt) { case oct_mach_info::ieee_little_endian: IEEE_little_float_to_VAX_D_float (data, len); --- 893,899 ---- break; =20 case oct_mach_info::vax_d: ! switch (in_fmt) { case oct_mach_info::ieee_little_endian: IEEE_little_float_to_VAX_D_float (data, len); *************** do_float_format_conversion (float *data, *** 642,647 **** --- 914,927 ---- Cray_to_VAX_D_float (data, len); break; =20 + case oct_mach_info::tms_c3x_big_endian: + TMS_C3X_big_float_to_VAX_D_float (data, len); + break; +=20 + case oct_mach_info::tms_c3x_little_endian: + TMS_C3X_little_float_to_VAX_D_float (data, len); + break; +=20 default: gripe_unrecognized_float_fmt (); break; *************** do_float_format_conversion (float *data, *** 649,655 **** break; =20 case oct_mach_info::vax_g: ! switch (fmt) { case oct_mach_info::ieee_little_endian: IEEE_little_float_to_VAX_G_float (data, len); --- 929,935 ---- break; =20 case oct_mach_info::vax_g: ! switch (in_fmt) { case oct_mach_info::ieee_little_endian: IEEE_little_float_to_VAX_G_float (data, len); *************** do_float_format_conversion (float *data, *** 670,675 **** --- 950,1035 ---- Cray_to_VAX_G_float (data, len); break; =20 + case oct_mach_info::tms_c3x_big_endian: + TMS_C3X_big_float_to_VAX_G_float (data, len); + break; +=20 + case oct_mach_info::tms_c3x_little_endian: + TMS_C3X_little_float_to_VAX_G_float (data, len); + break; +=20 + default: + gripe_unrecognized_float_fmt (); + break; + } + break; +=20 + case oct_mach_info::tms_c3x_little_endian: + switch (in_fmt) + { + case oct_mach_info::ieee_little_endian: + IEEE_little_float_to_TMS_C3X_little_float (data, len); + break; +=20 + case oct_mach_info::ieee_big_endian: + IEEE_big_float_to_TMS_C3X_little_float (data, len); + break; +=20 + case oct_mach_info::vax_d: + VAX_D_float_to_TMS_C3X_little_float (data, len); + break; +=20 + case oct_mach_info::vax_g: + VAX_G_float_to_TMS_C3X_little_float (data, len); + break; +=20 + case oct_mach_info::cray: + Cray_to_TMS_C3X_little_float (data, len); + break; +=20 + case oct_mach_info::tms_c3x_big_endian: + TMS_C3X_big_float_to_TMS_C3X_little_float (data, len); + break; +=20 + case oct_mach_info::tms_c3x_little_endian: + break; +=20 + default: + gripe_unrecognized_float_fmt (); + break; + } + break; +=20 + case oct_mach_info::tms_c3x_big_endian: + switch (in_fmt) + { + case oct_mach_info::ieee_little_endian: + IEEE_little_float_to_TMS_C3X_big_float (data, len); + break; +=20 + case oct_mach_info::ieee_big_endian: + IEEE_big_float_to_TMS_C3X_big_float (data, len); + break; +=20 + case oct_mach_info::vax_d: + VAX_D_float_to_TMS_C3X_big_float (data, len); + break; +=20 + case oct_mach_info::vax_g: + VAX_G_float_to_TMS_C3X_big_float (data, len); + break; +=20 + case oct_mach_info::cray: + Cray_to_TMS_C3X_big_float (data, len); + break; +=20 + case oct_mach_info::tms_c3x_big_endian: + break; +=20 + case oct_mach_info::tms_c3x_little_endian: + TMS_C3X_little_float_to_TMS_C3X_big_float (data, len); + break; +=20 default: gripe_unrecognized_float_fmt (); break; *************** read_doubles (std::istream& is, double * *** 718,724 **** { volatile float *ptr =3D X_CAST (float *, data); is.read (X_CAST (char *, data), 4 * len); ! do_float_format_conversion (X_CAST (float *, data), len, fmt); float tmp =3D ptr[0]; for (int i =3D len - 1; i > 0; i--) data[i] =3D ptr[i]; --- 1078,1085 ---- { volatile float *ptr =3D X_CAST (float *, data); is.read (X_CAST (char *, data), 4 * len); ! do_float_format_conversion (X_CAST (float *, data), len, fmt, ! oct_mach_info::native_float_format = ()); float tmp =3D ptr[0]; for (int i =3D len - 1; i > 0; i--) data[i] =3D ptr[i]; *************** read_doubles (std::istream& is, double * *** 728,734 **** =20 case LS_DOUBLE: // No conversion necessary. is.read (X_CAST (char *, data), 8 * len); ! do_double_format_conversion (data, len, fmt); break; =20 default: --- 1089,1096 ---- =20 case LS_DOUBLE: // No conversion necessary. is.read (X_CAST (char *, data), 8 * len); ! do_double_format_conversion (data, len, fmt, ! oct_mach_info::native_float_format = ()); break; =20 default: diff --recursive -x *.[aod] -x *.texi -x *.info* -x *.df -x *~ -x *.lo = -x Makefile -cp octave-2.1.33.org/liboctave/data-conv.h = octave-2.1.33/liboctave/data-conv.h *** octave-2.1.33.org/liboctave/data-conv.h Tue May 1 20:26:04 2001 --- octave-2.1.33/liboctave/data-conv.h Sun Apr 29 13:45:36 2001 *************** enum save_type *** 105,115 **** =20 extern void do_double_format_conversion (double *data, int len, ! oct_mach_info::float_format fmt); !=20 extern void do_float_format_conversion (float *data, int len, ! oct_mach_info::float_format fmt); =20 extern void read_doubles (std::istream& is, double *data, save_type type, int len, --- 105,117 ---- =20 extern void do_double_format_conversion (double *data, int len, ! oct_mach_info::float_format in_fmt, ! oct_mach_info::float_format out_fmt); ! =20 extern void do_float_format_conversion (float *data, int len, ! oct_mach_info::float_format in_fmt, ! oct_mach_info::float_format out_fmt); =20 extern void read_doubles (std::istream& is, double *data, save_type type, int len, diff --recursive -x *.[aod] -x *.texi -x *.info* -x *.df -x *~ -x *.lo = -x Makefile -cp octave-2.1.33.org/liboctave/mach-info.cc = octave-2.1.33/liboctave/mach-info.cc *** octave-2.1.33.org/liboctave/mach-info.cc Tue Feb 1 11:07:16 2000 --- octave-2.1.33/liboctave/mach-info.cc Sun Apr 29 13:47:42 2001 *************** oct_mach_info::string_to_float_format (c *** 202,207 **** --- 202,211 ---- retval =3D oct_mach_info::vax_g; else if (s =3D=3D "cray" || s =3D=3D "c") retval =3D oct_mach_info::cray; + else if (s =3D=3D "tmsc3x-be" || s =3D=3D "t") + retval =3D oct_mach_info::tms_c3x_big_endian; + else if (s =3D=3D "tmsc3x-le" || s =3D=3D "t") + retval =3D oct_mach_info::tms_c3x_little_endian; else if (s =3D=3D "unknown") retval =3D oct_mach_info::unknown; else *************** oct_mach_info::float_format_as_string (f *** 240,245 **** --- 244,257 ---- =20 case cray: retval =3D "cray"; + break; +=20 + case tms_c3x_little_endian: + retval =3D "tms_c3x_little_endian"; + break; +=20 + case tms_c3x_big_endian: + retval =3D "tms_c3x_big_endian"; break; =20 default: diff --recursive -x *.[aod] -x *.texi -x *.info* -x *.df -x *~ -x *.lo = -x Makefile -cp octave-2.1.33.org/liboctave/mach-info.h = octave-2.1.33/liboctave/mach-info.h *** octave-2.1.33.org/liboctave/mach-info.h Tue Feb 1 11:07:16 2000 --- octave-2.1.33/liboctave/mach-info.h Sun Apr 29 13:48:32 2001 *************** public: *** 42,48 **** ieee_big_endian, vax_d, vax_g, ! cray }; =20 static bool instance_ok (void); --- 42,50 ---- ieee_big_endian, vax_d, vax_g, ! cray, ! tms_c3x_little_endian, ! tms_c3x_big_endian }; =20 static bool instance_ok (void); ------=_NextPart_000_000E_01C0D738.0C91DC40-- ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------