From f621e39141afef65fb504cd8a8a9d30fe96b1e53 Mon Sep 17 00:00:00 2001 From: Gerardo Tauriello <gerardo.tauriello@unibas.ch> Date: Mon, 17 Feb 2020 18:53:10 +0100 Subject: [PATCH] Get rid of unused VAX conversion files. Relevant VAX conversion code is in convert.cc. --- modules/io/src/convert.cc | 3 + modules/io/src/img/CMakeLists.txt | 3 - modules/io/src/img/convert_vax_data.c | 1408 ----------------- modules/io/src/img/convert_vax_data.h | 263 --- modules/io/src/img/image_format_conversion.cc | 110 -- 5 files changed, 3 insertions(+), 1784 deletions(-) delete mode 100755 modules/io/src/img/convert_vax_data.c delete mode 100755 modules/io/src/img/convert_vax_data.h delete mode 100644 modules/io/src/img/image_format_conversion.cc diff --git a/modules/io/src/convert.cc b/modules/io/src/convert.cc index b30501291..19a7bfe65 100644 --- a/modules/io/src/convert.cc +++ b/modules/io/src/convert.cc @@ -150,6 +150,9 @@ public: // specialization for source!=target vax conversion integer types +// NOTE: the VAX conversion is based on the libvaxdata code by L. M. Baker +// -> a copy of Baker's code was included until OST 1.11 and removed as unused + // byte swapping for int types if local is big endian template<class VALUETYPE> class ConvertHelper<OST_BIG_ENDIAN,OST_VAX_DATA,VALUETYPE>{ diff --git a/modules/io/src/img/CMakeLists.txt b/modules/io/src/img/CMakeLists.txt index d17f46e8e..d3fea543a 100644 --- a/modules/io/src/img/CMakeLists.txt +++ b/modules/io/src/img/CMakeLists.txt @@ -12,7 +12,6 @@ map_io_jpk_handler.cc map_io_nanoscope_handler.cc map_io_png_handler.cc map_io_df3_handler.cc -convert_vax_data.c image_format.cc tiff_util.cc PARENT_SCOPE @@ -22,7 +21,6 @@ set(OST_IO_IMG_HEADERS load_map.hh map_io_df3_handler.hh image_format.hh -image_format_conversion.cc map_io_dx_handler.hh map_io_spi_handler.hh map_io_situs_handler.hh @@ -35,7 +33,6 @@ map_io_nanoscope_handler.hh map_io_png_handler.hh map_io_dm3_handler.hh map_io_tiff_handler.hh -convert_vax_data.h tiff_util.hh jpk_util.hh PARENT_SCOPE diff --git a/modules/io/src/img/convert_vax_data.c b/modules/io/src/img/convert_vax_data.c deleted file mode 100755 index cab50f2ae..000000000 --- a/modules/io/src/img/convert_vax_data.c +++ /dev/null @@ -1,1408 +0,0 @@ -/****************************************************************************** - * * - * convert_vax_data.c - Convert VAX-format data to/from Unix (IEEE) format. * - * * - * from_vax_i2() - Byte swap Integer*2 * - * from_vax_i4() - Byte reverse Integer*4 * - * from_vax_r4() - 32-bit VAX F_floating to IEEE S_floating * - * from_vax_d8() - 64-bit VAX D_floating to IEEE T_floating * - * from_vax_g8() - 64-bit VAX G_floating to IEEE T_floating * - * from_vax_h16() - 128-bit VAX H_floating to Alpha X_floating * - * * - * to_vax_i2() - Byte swap Integer*2 * - * to_vax_i4() - Byte reverse Integer*4 * - * to_vax_r4() - 32-bit IEEE S_floating to VAX F_floating * - * to_vax_d8() - 64-bit IEEE T_floating to VAX D_floating * - * to_vax_g8() - 64-bit IEEE T_floating to VAX G_floating * - * to_vax_h16() - 128-bit Alpha X_floating to VAX H_floating * - * * - * All calls take 3 arguments: * - * * - * C declaration: #include "convert_vax_data.h" * - * usage: name( in_array, out_array, &count ); * - * * - * Fortran usage: Call NAME( in_array, out_array, count ) * - * * - * The in_array and out_array parameters may refer to the same object. * - * * - * * - * See convert_vax_data.h for a description of the VAX and Unix (IEEE) data * - * formats and the compilation options available. * - * * - * * - * References: ANSI/IEEE Std 754-1985, IEEE Standard for Binary Floating- * - * Point Arithmetic, Institute of Electrical and Electronics * - * Engineers * - * Brunner, Richard A., Ed., 1991, VAX Architecture Reference * - * Manual, Second Edition, Digital Press * - * Sites, Richard L., and Witek, Richard T., 1995, Alpha AXP * - * Architecture Reference Manual, Second Edition, Digital * - * Press * - * * - * Author: Lawrence M. Baker * - * U.S. Geological Survey * - * 345 Middlefield Road MS977 * - * Menlo Park, CA 94025 * - * baker@usgs.gov * - * * - * Citation: Baker, L.M., 2005, libvaxdata: VAX Data Format Conversion * - * Routines: U.S. Geological Survey Open-File Report 2005- * - * 1424 (http://pubs.usgs.gov/of/2005/1424/). * - * * - * * - * Disclaimer * - * * - * Although this program has been used by the USGS, no warranty, expressed or * - * implied, is made by the USGS or the United States Government as to the * - * accuracy and functioning of the program and related program material, nor * - * shall the fact of distribution constitute any such warranty, and no * - * responsibility is assumed by the USGS in connection therewith. * - * * - * * - * Modification History: * - * * - * 8-Sep-1992 L. M. Baker Original version. * - * 12-Jan-1993 L. M. Baker Convert Fortran data conversion routines to * - * C. * - * Force underflows to 0 (as the VAX hardware * - * does) to avoid IEEE Not-a-Numbers (NaNs). * - * 14-Jan-1993 L. M. Baker Define forward and backward conversions for * - * all numeric data types (not all implemen- * - * ted yet). * - * 20-Jan-1993 L. M. Baker Convert VAX extrema to subnormal/infinities. * - * 22-Jan-1993 L. M. Baker Allow for little-endian and big-endian * - * machines. * - * Define register variables for Microsoft C (2 * - * max). * - * 25-Jan-1993 L. M. Baker Provide for Fortran naming with underscores. * - * Provide for separate compilation for librar- * - * ies. * - * 27-Jan-1993 L. M. Baker Swap (16-bit) words in floating-point for- * - * mats for little-endian machines. * - * 16-May-2000 L. M. Baker Add conditionals for DEC C, Microsoft Visual * - * C++. * - * Convert VAX dirty zero (s=e=0, m<>0) to true * - * zero. * - * raise( SIGFPE ) for VAX reserved operands. * - * Implement to_vax_r4(), to_vax_d8(), * - * to_vax_g8(). * - * Add const specifier where appropriate. * - * 1-Feb-2001 L. M. Baker Change long to int (long's are 64 bits on * - * Compaq's Tru64 UNIX). * - * Add __alpha to the list of predefined macros * - * that set IS_LITTLE_ENDIAN to 1. * - * 5-Feb-2001 L. M. Baker Add prototypes for all functions (Matlab's * - * MrC command on Macintosh requires them). * - * 9-Mar-2001 L. M. Baker #include "convert_vax_data.h". * - * 12-Aug-2005 L. M. Baker Add conditionals for GNU C and Portland * - * Group C on AMD Opteron/Intel EM64T 64-bit * - * x86 machines. * - * 16-Sep-2005 L. M. Baker IEEE X_floating exponent is 15 bits, not 11 * - * bits (fix from_vax_h16()). * - * Correct recognition of +-0, +-Inf and +-NaN * - * in to_vax_d8(), to_vax_g8(). * - * Implement to_vax_h16(). * - * 17-Sep-2005 L. M. Baker Add macro definitions for every float type. * - * 19-Sep-2005 L. M. Baker Add fixups for IEEE-to-VAX conversion * - * faults (+-infinity, +-NaN, overflow). * - * 22-Sep-2005 L. M. Baker Change LITTLE_ENDIAN to IS_LITTLE_ENDIAN to * - * avoid conflict with GCC/BSD predefined * - * macro named LITTLE_ENDIAN. * - * 12-Oct-2005 L. M. Baker Remove unreferenced variables. * - * 8-Nov-2005 L. M. Baker Move #define const if not __STDC__ to * - * convert_vax_data.h * - * * - ******************************************************************************/ - -/* - adapted for IPLT: removed SIGFPE signal -*/ - -#include "convert_vax_data.h" /* UPCASE, APPEND_UNDERSCORE, FORTRAN_LINKAGE */ - -#ifndef IS_LITTLE_ENDIAN - -/* VAX C, GNU C on a VAX or an Alpha, or DEC C */ - -#if defined( vax ) || defined( __vax ) || defined( vms ) || \ - defined( __vms ) || defined( __alpha ) -#define IS_LITTLE_ENDIAN 1 -#endif - -/* Microsoft 80x86 C or Microsoft Visual C++ on an 80x86 or an Alpha */ - -#if defined( M_I86 ) || defined( _M_IX86 ) || defined( __M_ALPHA ) -#define IS_LITTLE_ENDIAN 1 -#endif - -/* Sun C, GNU C, or Intel C on an 80x86 */ - -#if defined( i386 ) || defined( __i386 ) -#define IS_LITTLE_ENDIAN 1 -#endif - -/* GNU C or Portland Group C on an AMD Opteron or Intel EM64T */ - -#if defined( __x86_64 ) || defined( __x86_64__ ) -#define IS_LITTLE_ENDIAN 1 -#endif - -/* Otherwise, assume big-endian machine */ - -#ifndef IS_LITTLE_ENDIAN -#define IS_LITTLE_ENDIAN 0 -#endif - -#endif - -#if !defined( MAKE_FROM_VAX_I2 ) && !defined( MAKE_FROM_VAX_I4 ) && \ - !defined( MAKE_FROM_VAX_R4 ) && !defined( MAKE_FROM_VAX_D8 ) && \ - !defined( MAKE_FROM_VAX_G8 ) && !defined( MAKE_FROM_VAX_H16 ) && \ - !defined( MAKE_TO_VAX_I2 ) && !defined( MAKE_TO_VAX_I4 ) && \ - !defined( MAKE_TO_VAX_R4 ) && !defined( MAKE_TO_VAX_D8 ) && \ - !defined( MAKE_TO_VAX_G8 ) && !defined( MAKE_TO_VAX_H16 ) - -#define MAKE_FROM_VAX_I2 -#define MAKE_FROM_VAX_I4 -#define MAKE_FROM_VAX_R4 -#define MAKE_FROM_VAX_D8 -#define MAKE_FROM_VAX_G8 -#define MAKE_FROM_VAX_H16 - -#define MAKE_TO_VAX_I2 -#define MAKE_TO_VAX_I4 -#define MAKE_TO_VAX_R4 -#define MAKE_TO_VAX_D8 -#define MAKE_TO_VAX_G8 -#define MAKE_TO_VAX_H16 - -#endif - -#include <limits.h> /* UCHAR_MAX, USHRT_MAX, UINT_MAX */ - -#if UCHAR_MAX != 255U || USHRT_MAX != 65535U || UINT_MAX != 4294967295U -#error convert_vax_data.c requires 8-bit chars, 16-bit shorts, and 32-bit ints -#endif - -#if defined( MAKE_FROM_VAX_R4 ) || defined( MAKE_FROM_VAX_D8 ) || \ - defined( MAKE_FROM_VAX_G8 ) || defined( MAKE_FROM_VAX_H16 ) || \ - defined( MAKE_TO_VAX_R4 ) || defined( MAKE_TO_VAX_D8 ) || \ - defined( MAKE_TO_VAX_G8 ) || defined( MAKE_TO_VAX_H16 ) -#include <signal.h> /* SIGFPE, raise() */ -#endif - -/* FLoating point data format invariants */ - -#define SIGN_BIT 0x80000000 - -/* VAX floating point data formats (see VAX Architecture Reference Manual) */ - -#define VAX_F_SIGN_BIT SIGN_BIT -#define VAX_F_EXPONENT_MASK 0x7F800000 -#define VAX_F_EXPONENT_SIZE 8 -#define VAX_F_EXPONENT_BIAS ( 1 << ( VAX_F_EXPONENT_SIZE - 1 ) ) -#define VAX_F_MANTISSA_MASK 0x007FFFFF -#define VAX_F_MANTISSA_SIZE 23 -#define VAX_F_HIDDEN_BIT ( 1 << VAX_F_MANTISSA_SIZE ) - -#define VAX_D_SIGN_BIT SIGN_BIT -#define VAX_D_EXPONENT_MASK 0x7F800000 -#define VAX_D_EXPONENT_SIZE 8 -#define VAX_D_EXPONENT_BIAS ( 1 << ( VAX_D_EXPONENT_SIZE - 1 ) ) -#define VAX_D_MANTISSA_MASK 0x007FFFFF -#define VAX_D_MANTISSA_SIZE 23 -#define VAX_D_HIDDEN_BIT ( 1 << VAX_D_MANTISSA_SIZE ) - -#define VAX_G_SIGN_BIT SIGN_BIT -#define VAX_G_EXPONENT_MASK 0x7FF00000 -#define VAX_G_EXPONENT_SIZE 11 -#define VAX_G_EXPONENT_BIAS ( 1 << ( VAX_G_EXPONENT_SIZE - 1 ) ) -#define VAX_G_MANTISSA_MASK 0x000FFFFF -#define VAX_G_MANTISSA_SIZE 20 -#define VAX_G_HIDDEN_BIT ( 1 << VAX_G_MANTISSA_SIZE ) - -#define VAX_H_SIGN_BIT SIGN_BIT -#define VAX_H_EXPONENT_MASK 0x7FFF0000 -#define VAX_H_EXPONENT_SIZE 15 -#define VAX_H_EXPONENT_BIAS ( 1 << ( VAX_H_EXPONENT_SIZE - 1 ) ) -#define VAX_H_MANTISSA_MASK 0x0000FFFF -#define VAX_H_MANTISSA_SIZE 16 -#define VAX_H_HIDDEN_BIT ( 1 << VAX_H_MANTISSA_SIZE ) - -/* IEEE floating point data formats (see Alpha Architecture Reference Manual) */ - -#define IEEE_S_SIGN_BIT SIGN_BIT -#define IEEE_S_EXPONENT_MASK 0x7F800000 -#define IEEE_S_EXPONENT_SIZE 8 -#define IEEE_S_EXPONENT_BIAS ( ( 1 << ( IEEE_S_EXPONENT_SIZE - 1 ) ) - 1 ) -#define IEEE_S_MANTISSA_MASK 0x007FFFFF -#define IEEE_S_MANTISSA_SIZE 23 -#define IEEE_S_HIDDEN_BIT ( 1 << IEEE_S_MANTISSA_SIZE ) - -#define IEEE_T_SIGN_BIT SIGN_BIT -#define IEEE_T_EXPONENT_MASK 0x7FF00000 -#define IEEE_T_EXPONENT_SIZE 11 -#define IEEE_T_EXPONENT_BIAS ( ( 1 << ( IEEE_T_EXPONENT_SIZE - 1 ) ) - 1 ) -#define IEEE_T_MANTISSA_MASK 0x000FFFFF -#define IEEE_T_MANTISSA_SIZE 20 -#define IEEE_T_HIDDEN_BIT ( 1 << IEEE_T_MANTISSA_SIZE ) - -#define IEEE_X_SIGN_BIT SIGN_BIT -#define IEEE_X_EXPONENT_MASK 0x7FFF0000 -#define IEEE_X_EXPONENT_SIZE 15 -#define IEEE_X_EXPONENT_BIAS ( ( 1 << ( IEEE_X_EXPONENT_SIZE - 1 ) ) - 1 ) -#define IEEE_X_MANTISSA_MASK 0x0000FFFF -#define IEEE_X_MANTISSA_SIZE 16 -#define IEEE_X_HIDDEN_BIT ( 1 << IEEE_X_MANTISSA_SIZE ) - -/************************************************************** from_vax_i2() */ - -#ifdef MAKE_FROM_VAX_I2 - -void FORTRAN_LINKAGE from_vax_i2( const void *inbuf, void *outbuf, - const int *count ) { - -#if IS_LITTLE_ENDIAN - - register const unsigned short *in; /* Microsoft C: up to 2 register vars */ - register unsigned short *out; /* Microsoft C: up to 2 register vars */ - int n; - - - in = (const unsigned short *) inbuf; - out = (unsigned short *) outbuf; - - if ( in != out ) { - for ( n = *count; n > 0; n-- ) { - *out++ = *in++; - } - } - -#else - - const unsigned char *in; - unsigned char *out; - int n; - unsigned char c1; - - - in = (const unsigned char *) inbuf; - out = (unsigned char *) outbuf; - - for ( n = *count; n > 0; n-- ) { - c1 = *in++; - *out++ = *in++; - *out++ = c1; - } - -#endif - -} - -#endif /* #ifdef MAKE_FROM_VAX_I2 */ - -/************************************************************** from_vax_i4() */ - -#ifdef MAKE_FROM_VAX_I4 - -void FORTRAN_LINKAGE from_vax_i4( const void *inbuf, void *outbuf, - const int *count ) { - -#if IS_LITTLE_ENDIAN - - register const unsigned int *in; /* Microsoft C: up to 2 register vars */ - register unsigned int *out; /* Microsoft C: up to 2 register vars */ - int n; - - - in = (const unsigned int *) inbuf; - out = (unsigned int *) outbuf; - - if ( in != out ) { - for ( n = *count; n > 0; n-- ) { - *out++ = *in++; - } - } - -#else - - const unsigned char *in; - unsigned char *out; - int n; - unsigned char c1, c2, c3; - - - in = (unsigned char *) inbuf; - out = (unsigned char *) outbuf; - - for ( n = *count; n > 0; n-- ) { - c1 = *in++; - c2 = *in++; - c3 = *in++; - *out++ = *in++; - *out++ = c3; - *out++ = c2; - *out++ = c1; - } - -#endif - -} - -#endif /* #ifdef MAKE_FROM_VAX_I4 */ - -/************************************************************** from_vax_r4() */ - -#ifdef MAKE_FROM_VAX_R4 - -/* Assert the mantissa in a VAX F_float is the same as in an IEEE S_float */ -#if VAX_F_MANTISSA_MASK != IEEE_S_MANTISSA_MASK -#error MANTISSA_MASK mismatch in from_vax_r4() -#endif -#define MANTISSA_MASK VAX_F_MANTISSA_MASK -/* If the mantissas are the same, then so are the no. of bits and the hidden */ -/* normalization bit */ -#define MANTISSA_SIZE VAX_F_MANTISSA_SIZE -#define HIDDEN_BIT VAX_F_HIDDEN_BIT - -/* Assert the VAX F_float exponent bias is greater than the IEEE S_float */ -/* exponent bias (overflow is not possible) */ -#define EXPONENT_ADJUSTMENT ( 1 + VAX_F_EXPONENT_BIAS - IEEE_S_EXPONENT_BIAS ) -#if EXPONENT_ADJUSTMENT < 2 -#error EXPONENT_ADJUSTMENT assertion failure in from_vax_r4() -#endif -#define IN_PLACE_EXPONENT_ADJUSTMENT \ - ( EXPONENT_ADJUSTMENT << IEEE_S_MANTISSA_SIZE ) - -void FORTRAN_LINKAGE from_vax_r4( const void *inbuf, void *outbuf, - const int *count ) { - -#if IS_LITTLE_ENDIAN - register const unsigned short *in; /* Microsoft C: up to 2 register vars */ - union { unsigned short i[2]; unsigned int l; } part; -#else - const unsigned char *in; - union { unsigned char c[4]; unsigned int l; } part; -#endif - register unsigned int *out; /* Microsoft C: up to 2 register vars */ - unsigned int part1; - int n; - int e; - - -#if IS_LITTLE_ENDIAN - in = (const unsigned short *) inbuf; -#else - in = (const unsigned char *) inbuf; -#endif - out = (unsigned int *) outbuf; - - for ( n = *count; n > 0; n-- ) { -#if IS_LITTLE_ENDIAN - part.i[1] = *in++; - part.i[0] = *in++; - part1 = part.l; -#else - part.c[1] = *in++; - part.c[0] = *in++; - part.c[3] = *in++; - part.c[2] = *in++; - part1 = part.l; -#endif - if ( ( e = ( part1 & VAX_F_EXPONENT_MASK ) ) == 0 ) { - /* If the biased VAX exponent is zero [e=0] */ - - if ( ( part1 & SIGN_BIT ) == SIGN_BIT ) { /* If negative [s=1] */ - //raise( SIGFPE );/* VAX reserved operand fault; fixup to IEEE zero */ - return; - } - /* Set VAX dirty [m<>0] or true [m=0] zero to IEEE +zero [s=e=m=0] */ - *out++ = 0; - - } else { /* The biased VAX exponent is non-zero [e<>0] */ - - e >>= MANTISSA_SIZE; /* Obtain the biased VAX exponent */ - - /* The biased VAX exponent has to be adjusted to account for the */ - /* right shift of the IEEE mantissa binary point and the difference */ - /* between the biases in their "excess n" exponent representations. */ - /* If the resulting biased IEEE exponent is less than or equal to */ - /* zero, the converted IEEE S_float must use subnormal form. */ - - if ( ( e - EXPONENT_ADJUSTMENT ) > 0 ) { - /* Use IEEE normalized form [e>0] */ - - /* Both mantissas are 23 bits; adjust the exponent field in place */ - *out++ = part1 - IN_PLACE_EXPONENT_ADJUSTMENT; - - } else { /* Use IEEE subnormal form [e=0, m>0] */ - - *out++ = ( part1 & SIGN_BIT ) | - ( ( HIDDEN_BIT | ( part1 & MANTISSA_MASK ) ) >> - ( 1 - e ) ); - - } - } - } - -} - -#undef MANTISSA_MASK -#undef MANTISSA_SIZE -#undef HIDDEN_BIT -#undef EXPONENT_ADJUSTMENT -#undef IN_PLACE_EXPONENT_ADJUSTMENT - -#endif /* #ifdef MAKE_FROM_VAX_R4 */ - -/************************************************************** from_vax_d8() */ - -#ifdef MAKE_FROM_VAX_D8 - -/* Assert the IEEE T_float exponent bias is so much larger than the VAX */ -/* D_float exponent bias that it is not possible for this conversion to */ -/* overflow or underflow */ -#define EXPONENT_ADJUSTMENT ( 1 + VAX_D_EXPONENT_BIAS - IEEE_T_EXPONENT_BIAS ) -#if ( EXPONENT_ADJUSTMENT + VAX_D_MANTISSA_SIZE + 1 ) > 0 -#error EXPONENT_ADJUSTMENT assertion failure in from_vax_d8() -#endif -#define IN_PLACE_EXPONENT_ADJUSTMENT \ - ( EXPONENT_ADJUSTMENT << IEEE_T_MANTISSA_SIZE ) - -/* Assert the VAX D_float mantissa is wider than the IEEE T_float mantissa */ -#define EXPONENT_RIGHT_SHIFT ( VAX_D_MANTISSA_SIZE - IEEE_T_MANTISSA_SIZE ) -#if EXPONENT_RIGHT_SHIFT <= 0 -#error EXPONENT_RIGHT_SHIFT assertion failure in from_vax_d8() -#endif - -void FORTRAN_LINKAGE from_vax_d8( const void *inbuf, void *outbuf, - const int *count ) { - -#if IS_LITTLE_ENDIAN - register const unsigned short *in; /* Microsoft C: up to 2 register vars */ - union { unsigned short i[2]; unsigned int l; } part; -#else - const unsigned char *in; - union { unsigned char c[4]; unsigned int l; } part; -#endif - register unsigned int *out; /* Microsoft C: up to 2 register vars */ - unsigned int part1, part2; - int n; - - -#if IS_LITTLE_ENDIAN - in = (const unsigned short *) inbuf; -#else - in = (const unsigned char *) inbuf; -#endif - out = (unsigned int *) outbuf; - - for ( n = *count; n > 0; n-- ) { -#if IS_LITTLE_ENDIAN - part.i[1] = *in++; - part.i[0] = *in++; - part1 = part.l; - part.i[1] = *in++; - part.i[0] = *in++; - part2 = part.l; -#else - part.c[1] = *in++; - part.c[0] = *in++; - part.c[3] = *in++; - part.c[2] = *in++; - part1 = part.l; - part.c[1] = *in++; - part.c[0] = *in++; - part.c[3] = *in++; - part.c[2] = *in++; - part2 = part.l; -#endif - if ( ( part1 & VAX_D_EXPONENT_MASK ) == 0 ) { - /* If the biased VAX exponent is zero [e=0] */ - - if ( ( part1 & SIGN_BIT ) == SIGN_BIT ) { /* If negative [s=1] */ - //raise( SIGFPE );/* VAX reserved operand fault; fixup to IEEE zero */ - return; - } - /* Set VAX dirty [m<>0] or true [m=0] zero to IEEE +zero [s=e=m=0] */ - *out++ = 0; - *out++ = 0; - - } else { /* The biased VAX exponent is non-zero [e<>0] */ - - /* Because the range of an IEEE T_float is so much larger than a VAX */ - /* D_float, the converted IEEE T_float will never be subnormal form. */ - - /* Use IEEE normalized form [e>0]; truncate the mantissa from 55 to */ - /* 52 bits, then adjust the exponent field in place */ - *out++ = ( ( part1 & SIGN_BIT ) | - ( ( part1 & ~SIGN_BIT ) >> EXPONENT_RIGHT_SHIFT ) ) - - IN_PLACE_EXPONENT_ADJUSTMENT; - *out++ = ( part1 << ( 32 - EXPONENT_RIGHT_SHIFT ) ) | - ( part2 >> EXPONENT_RIGHT_SHIFT ); - - } - } - -} - -#undef EXPONENT_ADJUSTMENT -#undef IN_PLACE_EXPONENT_ADJUSTMENT -#undef EXPONENT_RIGHT_SHIFT - -#endif /* #ifdef MAKE_FROM_VAX_D8 */ - -/************************************************************** from_vax_g8() */ - -#ifdef MAKE_FROM_VAX_G8 - -/* Assert the mantissa in a VAX G_float is the same as in an IEEE T_float */ -#if VAX_G_MANTISSA_MASK != IEEE_T_MANTISSA_MASK -#error MANTISSA_MASK mismatch in from_vax_g8() -#endif -#define MANTISSA_MASK VAX_G_MANTISSA_MASK -/* If the mantissas are the same, then so are the no. of bits and the hidden */ -/* normalization bit */ -#define MANTISSA_SIZE VAX_G_MANTISSA_SIZE -#define HIDDEN_BIT VAX_G_HIDDEN_BIT - -/* Assert the VAX G_float exponent bias is greater than the IEEE T_float */ -/* exponent bias (overflow is not possible) */ -#define EXPONENT_ADJUSTMENT ( 1 + VAX_G_EXPONENT_BIAS - IEEE_T_EXPONENT_BIAS ) -#if EXPONENT_ADJUSTMENT < 2 -#error EXPONENT_ADJUSTMENT assertion failure in from_vax_g8() -#endif -#define IN_PLACE_EXPONENT_ADJUSTMENT \ - ( EXPONENT_ADJUSTMENT << IEEE_T_MANTISSA_SIZE ) - -void FORTRAN_LINKAGE from_vax_g8( const void *inbuf, void *outbuf, - const int *count ) { - -#if IS_LITTLE_ENDIAN - register const unsigned short *in; /* Microsoft C: up to 2 register vars */ - union { unsigned short i[2]; unsigned int l; } part; -#else - const unsigned char *in; - union { unsigned char c[4]; unsigned int l; } part; -#endif - register unsigned int *out; /* Microsoft C: up to 2 register vars */ - unsigned int part1, part2; - int n; - int e; - - -#if IS_LITTLE_ENDIAN - in = (const unsigned short *) inbuf; -#else - in = (const unsigned char *) inbuf; -#endif - out = (unsigned int *) outbuf; - - for ( n = *count; n > 0; n-- ) { -#if IS_LITTLE_ENDIAN - part.i[1] = *in++; - part.i[0] = *in++; - part1 = part.l; - part.i[1] = *in++; - part.i[0] = *in++; - part2 = part.l; -#else - part.c[1] = *in++; - part.c[0] = *in++; - part.c[3] = *in++; - part.c[2] = *in++; - part1 = part.l; - part.c[1] = *in++; - part.c[0] = *in++; - part.c[3] = *in++; - part.c[2] = *in++; - part2 = part.l; -#endif - if ( ( e = ( part1 & VAX_G_EXPONENT_MASK ) ) == 0 ) { - /* If the biased VAX exponent is zero [e=0] */ - - if ( ( part1 & SIGN_BIT ) == SIGN_BIT ) { /* If negative [s=1] */ - //raise( SIGFPE );/* VAX reserved operand fault; fixup to IEEE zero */ - return; - } - /* Set VAX dirty [m<>0] or true [m=0] zero to IEEE +zero [s=e=m=0] */ - *out++ = 0; - *out++ = 0; - - } else { /* The biased VAX exponent is non-zero [e<>0] */ - - e >>= MANTISSA_SIZE; /* Obtain the biased VAX exponent */ - - /* The biased VAX exponent has to be adjusted to account for the */ - /* right shift of the IEEE mantissa binary point and the difference */ - /* between the biases in their "excess n" exponent representations. */ - /* If the resulting biased IEEE exponent is less than or equal to */ - /* zero, the converted IEEE T_float must use subnormal form. */ - - if ( ( e - EXPONENT_ADJUSTMENT ) > 0 ) { - /* Use IEEE normalized form [e>0] */ - - /* Both mantissas are 52 bits; adjust the exponent field in place */ - *out++ = part1 - IN_PLACE_EXPONENT_ADJUSTMENT; - *out++ = part2; - - } else { /* Use IEEE subnormal form [e=0, m>0] */ - - part1 = ( part1 & ( SIGN_BIT | MANTISSA_MASK ) ) | HIDDEN_BIT; - *out++ = ( part1 & SIGN_BIT ) | - ( ( part1 & ( HIDDEN_BIT | MANTISSA_MASK ) ) >> - ( 1 - e ) ); - *out++ = ( part1 << ( 31 + e ) ) | ( part2 >> ( 1 - e ) ); - - } - } - } - -} - -#undef MANTISSA_MASK -#undef MANTISSA_SIZE -#undef HIDDEN_BIT -#undef EXPONENT_ADJUSTMENT -#undef IN_PLACE_EXPONENT_ADJUSTMENT - -#endif /* #ifdef MAKE_FROM_VAX_G8 */ - -/************************************************************* from_vax_h16() */ - -#ifdef MAKE_FROM_VAX_H16 - -/* Assert the mantissa in a VAX H_float is the same as in an IEEE X_float */ -#if VAX_H_MANTISSA_MASK != IEEE_X_MANTISSA_MASK -#error MANTISSA_MASK mismatch in from_vax_h16() -#endif -#define MANTISSA_MASK VAX_H_MANTISSA_MASK -/* If the mantissas are the same, then so are the no. of bits and the hidden */ -/* normalization bit */ -#define MANTISSA_SIZE VAX_H_MANTISSA_SIZE -#define HIDDEN_BIT VAX_H_HIDDEN_BIT - -/* Assert the VAX H_float exponent bias is greater than the IEEE X_float */ -/* exponent bias (overflow is not possible) */ -#define EXPONENT_ADJUSTMENT ( 1 + VAX_H_EXPONENT_BIAS - IEEE_X_EXPONENT_BIAS ) -#if EXPONENT_ADJUSTMENT < 2 -#error EXPONENT_ADJUSTMENT assertion failure in from_vax_H16() -#endif -#define IN_PLACE_EXPONENT_ADJUSTMENT \ - ( EXPONENT_ADJUSTMENT << IEEE_X_MANTISSA_SIZE ) - -void FORTRAN_LINKAGE from_vax_h16( const void *inbuf, void *outbuf, - const int *count ) { - -#if IS_LITTLE_ENDIAN - register const unsigned short *in; /* Microsoft C: up to 2 register vars */ - union { unsigned short i[2]; unsigned int l; } part; -#else - const unsigned char *in; - union { unsigned char c[4]; unsigned int l; } part; -#endif - register unsigned int *out; /* Microsoft C: up to 2 register vars */ - unsigned int part1, part2, part3, part4; - int n; - int e; - - -#if IS_LITTLE_ENDIAN - in = (const unsigned short *) inbuf; -#else - in = (const unsigned char *) inbuf; -#endif - out = (unsigned int *) outbuf; - - for ( n = *count; n > 0; n-- ) { -#if IS_LITTLE_ENDIAN - part.i[1] = *in++; - part.i[0] = *in++; - part1 = part.l; - part.i[1] = *in++; - part.i[0] = *in++; - part2 = part.l; - part.i[1] = *in++; - part.i[0] = *in++; - part3 = part.l; - part.i[1] = *in++; - part.i[0] = *in++; - part4 = part.l; -#else - part.c[1] = *in++; - part.c[0] = *in++; - part.c[3] = *in++; - part.c[2] = *in++; - part1 = part.l; - part.c[1] = *in++; - part.c[0] = *in++; - part.c[3] = *in++; - part.c[2] = *in++; - part2 = part.l; - part.c[1] = *in++; - part.c[0] = *in++; - part.c[3] = *in++; - part.c[2] = *in++; - part3 = part.l; - part.c[1] = *in++; - part.c[0] = *in++; - part.c[3] = *in++; - part.c[2] = *in++; - part4 = part.l; -#endif - if ( ( e = ( part1 & VAX_H_EXPONENT_MASK ) ) == 0 ) { - /* If the biased VAX exponent is zero [e=0] */ - - if ( ( part1 & SIGN_BIT ) == SIGN_BIT ) { /* If negative [s=1] */ - //raise( SIGFPE );/* VAX reserved operand fault; fixup to IEEE zero */ - return; - } - /* Set VAX dirty [m<>0] or true [m=0] zero to IEEE +zero [s=e=m=0] */ - *out++ = 0; - *out++ = 0; - *out++ = 0; - *out++ = 0; - - } else { /* The biased VAX exponent is non-zero [e<>0] */ - - e >>= MANTISSA_SIZE; /* Obtain the biased VAX exponent */ - - /* The biased VAX exponent has to be adjusted to account for the */ - /* right shift of the IEEE mantissa binary point and the difference */ - /* between the biases in their "excess n" exponent representations. */ - /* If the resulting biased IEEE exponent is less than or equal to */ - /* zero, the converted IEEE X_float must use subnormal form. */ - - if ( ( e - EXPONENT_ADJUSTMENT ) > 0 ) { - /* Use IEEE normalized form [e>0] */ - - /* Both mantissas are 112 bits; adjust the exponent field in place */ - *out++ = part1 - IN_PLACE_EXPONENT_ADJUSTMENT; - *out++ = part2; - *out++ = part3; - *out++ = part4; - - } else { /* Use IEEE subnormal form [e=0, m>0] */ - - part1 = ( part1 & ( SIGN_BIT | MANTISSA_MASK ) ) | HIDDEN_BIT; - *out++ = ( part1 & SIGN_BIT ) | - ( ( part1 & ( HIDDEN_BIT | MANTISSA_MASK ) ) >> - ( 1 - e ) ); - *out++ = ( part1 << ( 31 + e ) ) | ( part2 >> ( 1 - e ) ); - *out++ = ( part2 << ( 31 + e ) ) | ( part3 >> ( 1 - e ) ); - *out++ = ( part3 << ( 31 + e ) ) | ( part4 >> ( 1 - e ) ); - - } - } - } - -} - -#undef MANTISSA_MASK -#undef MANTISSA_SIZE -#undef HIDDEN_BIT -#undef EXPONENT_ADJUSTMENT -#undef IN_PLACE_EXPONENT_ADJUSTMENT - -#endif /* #ifdef MAKE_FROM_VAX_H16 */ - -/**************************************************************** to_vax_i2() */ - -#ifdef MAKE_TO_VAX_I2 - -void FORTRAN_LINKAGE to_vax_i2( const void *inbuf, void *outbuf, - const int *count ) { - -#if IS_LITTLE_ENDIAN - - register const unsigned short *in; /* Microsoft C: up to 2 register vars */ - register unsigned short *out; /* Microsoft C: up to 2 register vars */ - int n; - - - in = (const unsigned short *) inbuf; - out = (unsigned short *) outbuf; - - if ( in != out ) { - for ( n = *count; n > 0; n-- ) { - *out++ = *in++; - } - } - -#else - - const unsigned char *in; - unsigned char *out; - int n; - unsigned char c1; - - - in = (const unsigned char *) inbuf; - out = (unsigned char *) outbuf; - - for ( n = *count; n > 0; n-- ) { - c1 = *in++; - *out++ = *in++; - *out++ = c1; - } - -#endif - -} - -#endif /* #ifdef MAKE_TO_VAX_I2 */ - -/**************************************************************** to_vax_i4() */ - -#ifdef MAKE_TO_VAX_I4 - -void FORTRAN_LINKAGE to_vax_i4( const void *inbuf, void *outbuf, - const int *count ) { - -#if IS_LITTLE_ENDIAN - - register const unsigned int *in; /* Microsoft C: up to 2 register vars */ - register unsigned int *out; /* Microsoft C: up to 2 register vars */ - int n; - - - in = (const unsigned int *) inbuf; - out = (unsigned int *) outbuf; - - if ( in != out ) { - for ( n = *count; n > 0; n-- ) { - *out++ = *in++; - } - } - -#else - - const unsigned char *in; - unsigned char *out; - int n; - unsigned char c1, c2, c3; - - - in = (const unsigned char *) inbuf; - out = (unsigned char *) outbuf; - - for ( n = *count; n > 0; n-- ) { - c1 = *in++; - c2 = *in++; - c3 = *in++; - *out++ = *in++; - *out++ = c3; - *out++ = c2; - *out++ = c1; - } - -#endif - -} - -#endif /* #ifdef MAKE_TO_VAX_I4 */ - -/**************************************************************** to_vax_r4() */ - -#ifdef MAKE_TO_VAX_R4 - -/* Assert the mantissa in a VAX F_float is the same as in an IEEE S_float */ -#if VAX_F_MANTISSA_MASK != IEEE_S_MANTISSA_MASK -#error MANTISSA_MASK mismatch in to_vax_r4() -#endif -#define MANTISSA_MASK VAX_F_MANTISSA_MASK -/* If the mantissas are the same, then so are the no. of bits and the hidden */ -/* normalization bit */ -#define MANTISSA_SIZE VAX_F_MANTISSA_SIZE -#define HIDDEN_BIT VAX_F_HIDDEN_BIT - -#define EXPONENT_ADJUSTMENT ( 1 + VAX_F_EXPONENT_BIAS - IEEE_S_EXPONENT_BIAS ) - -void FORTRAN_LINKAGE to_vax_r4( const void *inbuf, void *outbuf, - const int *count ) { - - register const unsigned int *in; /* Microsoft C: up to 2 register vars */ -#if IS_LITTLE_ENDIAN - register unsigned short *out; /* Microsoft C: up to 2 register vars */ - union { unsigned short i[2]; unsigned int l; } part; -#else - unsigned char *out; - union { unsigned char c[4]; unsigned int l; } part; -#endif - unsigned int part1; - unsigned int m; - int n; - int e; - - - in = (const unsigned int *) inbuf; -#if IS_LITTLE_ENDIAN - out = (unsigned short *) outbuf; -#else - out = (unsigned char *) outbuf; -#endif - - for ( n = *count; n > 0; n-- ) { - part1 = *in++; - if ( ( part1 & ~SIGN_BIT ) == 0 ) { - - part.l = 0; /* Set IEEE +-zero [e=m=0] to VAX zero [s=e=m=0] */ - - } else if ( ( e = ( part1 & IEEE_S_EXPONENT_MASK ) ) == - IEEE_S_EXPONENT_MASK ) { - - /* VAX's have no equivalents for IEEE +-Infinity and +-NaN [e=all-1's] */ - //raise( SIGFPE ); - return; - - /* Fixup to VAX +-extrema [e=all-1's] with zero mantissa [m=0] */ - part.l = ( part1 & SIGN_BIT ) | VAX_F_EXPONENT_MASK; - - } else { - - e >>= MANTISSA_SIZE; /* Obtain the biased IEEE exponent */ - m = part1 & MANTISSA_MASK; /* Obtain the IEEE mantissa */ - - if ( e == 0 ) { /* Denormalized [e=0, m<>0] */ - m <<= 1; /* Adjust representation from 2**(1-bias) to 2**(e-bias) */ - while ( ( m & HIDDEN_BIT ) == 0 ) { - m <<= 1; - e -= 1; /* Adjust exponent */ - } - m &= MANTISSA_MASK; /* Adjust mantissa to hidden-bit form */ - } - - if ( ( e += EXPONENT_ADJUSTMENT ) <= 0 ) { - - part.l = 0; /* Silent underflow */ - - } else if ( e > ( 2 * VAX_F_EXPONENT_BIAS - 1 ) ) { - - //raise( SIGFPE );/* Overflow; fixup to VAX +-extrema [e=m=all-1's] */ - return; - part.l = ( part1 & SIGN_BIT ) | ~SIGN_BIT; - - } else { - - /* VAX normalized form [e>0] (both mantissas are 23 bits) */ - part.l = ( part1 & SIGN_BIT ) | ( e << MANTISSA_SIZE ) | m; - - } - - } -#if IS_LITTLE_ENDIAN - *out++ = part.i[1]; - *out++ = part.i[0]; -#else - *out++ = part.c[1]; - *out++ = part.c[0]; - *out++ = part.c[3]; - *out++ = part.c[2]; -#endif - } - -} - -#undef MANTISSA_MASK -#undef MANTISSA_SIZE -#undef HIDDEN_BIT -#undef EXPONENT_ADJUSTMENT - -#endif /* #ifdef MAKE_TO_VAX_R4 */ - -/**************************************************************** to_vax_d8() */ - -#ifdef MAKE_TO_VAX_D8 - -#define EXPONENT_ADJUSTMENT ( 1 + VAX_D_EXPONENT_BIAS - IEEE_T_EXPONENT_BIAS ) - -/* Assert the VAX D_float mantissa is wider than the IEEE T_float mantissa */ -#define EXPONENT_LEFT_SHIFT ( VAX_D_MANTISSA_SIZE - IEEE_T_MANTISSA_SIZE ) -#if EXPONENT_LEFT_SHIFT <= 0 -#error EXPONENT_LEFT_SHIFT assertion failure in to_vax_d8() -#endif - -void FORTRAN_LINKAGE to_vax_d8( const void *inbuf, void *outbuf, - const int *count ) { - - register const unsigned int *in; /* Microsoft C: up to 2 register vars */ -#if IS_LITTLE_ENDIAN - register unsigned short *out; /* Microsoft C: up to 2 register vars */ - union { unsigned short i[2]; unsigned int l; } part; -#else - unsigned char *out; - union { unsigned char c[4]; unsigned int l; } part; -#endif - unsigned int part1, part2; - unsigned int m; - int n; - int e; - - - in = (const unsigned int *) inbuf; -#if IS_LITTLE_ENDIAN - out = (unsigned short *) outbuf; -#else - out = (unsigned char *) outbuf; -#endif - - for ( n = *count; n > 0; n-- ) { - part1 = *in++; - part2 = *in++; - if ( ( ( part1 & ~SIGN_BIT ) | part2 ) == 0 ) { - - part.l = 0; /* Set IEEE +-zero [e=m=0] to VAX zero [s=e=m=0] */ - /* part2 = 0; */ /* part2 is already zero */ - - } else if ( ( e = ( part1 & IEEE_T_EXPONENT_MASK ) ) == - IEEE_T_EXPONENT_MASK ) { - - /* VAX's have no equivalents for IEEE +-Infinity and +-NaN [e=all-1's] */ - //raise( SIGFPE ); - return; - /* Fixup to VAX +-extrema [e=all-1's] with zero mantissa [m=0] */ - part.l = ( part1 & SIGN_BIT ) | VAX_D_EXPONENT_MASK; - part2 = 0; - - } else { - - e >>= IEEE_T_MANTISSA_SIZE; /* Obtain the biased IEEE exponent */ - m = part1 & IEEE_T_MANTISSA_MASK; /* Obtain the IEEE mantissa */ - - if ( e == 0 ) { /* Denormalized [e=0, m<>0] */ - /* Adjust representation from 2**(1-bias) to 2**(e-bias) */ - m = ( m << 1 ) | ( part2 >> 31 ); - part2 <<= 1; - while ( ( m & IEEE_T_HIDDEN_BIT ) == 0 ) { - m = ( m << 1 ) | ( part2 >> 31 ); - part2 <<= 1; - e -= 1; /* Adjust exponent */ - } - m &= IEEE_T_MANTISSA_MASK; /* Adjust mantissa to hidden-bit form */ - } - - if ( ( e += EXPONENT_ADJUSTMENT ) <= 0 ) { - - part.l = 0; /* Silent underflow */ - part2 = 0; - - } else if ( e > ( 2 * VAX_D_EXPONENT_BIAS - 1 ) ) { - - //raise( SIGFPE );/* Overflow; fixup to VAX +-extrema [e=m=all-1's] */ - return; - part.l = ( part1 & SIGN_BIT ) | ~SIGN_BIT; - part2 = ~0; - - } else { - - /* VAX normalized form [e>0]; zero pad mantissa from 52 to 55 bits */ - part.l = ( part1 & SIGN_BIT ) | - ( e << ( VAX_D_MANTISSA_SIZE + EXPONENT_LEFT_SHIFT ) ) | - ( m << EXPONENT_LEFT_SHIFT ) | - ( part2 >> ( 32 - EXPONENT_LEFT_SHIFT ) ); - part2 <<= EXPONENT_LEFT_SHIFT; - - } - - } -#if IS_LITTLE_ENDIAN - *out++ = part.i[1]; - *out++ = part.i[0]; - part.l = part2; - *out++ = part.i[1]; - *out++ = part.i[0]; -#else - *out++ = part.c[1]; - *out++ = part.c[0]; - *out++ = part.c[3]; - *out++ = part.c[2]; - part.l = part2; - *out++ = part.c[1]; - *out++ = part.c[0]; - *out++ = part.c[3]; - *out++ = part.c[2]; -#endif - } - -} - -#undef EXPONENT_ADJUSTMENT -#undef EXPONENT_RIGHT_SHIFT - -#endif /* #ifdef MAKE_TO_VAX_D8 */ - -/**************************************************************** to_vax_g8() */ - -#ifdef MAKE_TO_VAX_G8 - -/* Assert the mantissa in a VAX G_float is the same as in an IEEE T_float */ -#if VAX_G_MANTISSA_MASK != IEEE_T_MANTISSA_MASK -#error MANTISSA_MASK mismatch in to_vax_g8() -#endif -#define MANTISSA_MASK VAX_G_MANTISSA_MASK -/* If the mantissas are the same, then so are the no. of bits and the hidden */ -/* normalization bit */ -#define MANTISSA_SIZE VAX_G_MANTISSA_SIZE -#define HIDDEN_BIT VAX_G_HIDDEN_BIT - -#define EXPONENT_ADJUSTMENT ( 1 + VAX_G_EXPONENT_BIAS - IEEE_T_EXPONENT_BIAS ) - -void FORTRAN_LINKAGE to_vax_g8( const void *inbuf, void *outbuf, - const int *count ) { - - register const unsigned int *in; /* Microsoft C: up to 2 register vars */ -#if IS_LITTLE_ENDIAN - register unsigned short *out; /* Microsoft C: up to 2 register vars */ - union { unsigned short i[2]; unsigned int l; } part; -#else - unsigned char *out; - union { unsigned char c[4]; unsigned int l; } part; -#endif - unsigned int part1, part2; - unsigned int m; - int n; - int e; - - - in = (const unsigned int *) inbuf; -#if IS_LITTLE_ENDIAN - out = (unsigned short *) outbuf; -#else - out = (unsigned char *) outbuf; -#endif - - for ( n = *count; n > 0; n-- ) { - part1 = *in++; - part2 = *in++; - if ( ( ( part1 & ~SIGN_BIT ) | part2 ) == 0 ) { - - part.l = 0; /* Set IEEE +-zero [e=m=0] to VAX zero [s=e=m=0] */ - /* part2 = 0; */ /* part2 is already zero */ - - } else if ( ( e = ( part1 & IEEE_T_EXPONENT_MASK ) ) == - IEEE_T_EXPONENT_MASK ) { - - /* VAX's have no equivalents for IEEE +-Infinity and +-NaN [e=all-1's] */ - //raise( SIGFPE ); - return; - /* Fixup to VAX +-extrema [e=all-1's] with zero mantissa [m=0] */ - part.l = ( part1 & SIGN_BIT ) | VAX_G_EXPONENT_MASK; - part2 = 0; - - } else { - - e >>= MANTISSA_SIZE; /* Obtain the biased IEEE exponent */ - m = part1 & MANTISSA_MASK; /* Obtain the IEEE mantissa */ - - if ( e == 0 ) { /* Denormalized [e=0, m<>0] */ - /* Adjust representation from 2**(1-bias) to 2**(e-bias) */ - m = ( m << 1 ) | ( part2 >> 31 ); - part2 <<= 1; - while ( ( m & HIDDEN_BIT ) == 0 ) { - m = ( m << 1 ) | ( part2 >> 31 ); - part2 <<= 1; - e -= 1; /* Adjust exponent */ - } - m &= MANTISSA_MASK; /* Adjust mantissa to hidden-bit form */ - } - - if ( ( e += EXPONENT_ADJUSTMENT ) <= 0 ) { - - part.l = 0; /* Silent underflow */ - part2 = 0; - - } else if ( e > ( 2 * VAX_D_EXPONENT_BIAS - 1 ) ) { - - //raise( SIGFPE );/* Overflow; fixup to VAX +-extrema [e=m=all-1's] */ - return; - part.l = ( part1 & SIGN_BIT ) | ~SIGN_BIT; - part2 = ~0; - - } else { - - /* VAX normalized form [e>0] (both mantissas are 52 bits) */ - part.l = ( part1 & SIGN_BIT ) | ( e << MANTISSA_SIZE ) | m; - /* part2 is already correct */ - - } - - } -#if IS_LITTLE_ENDIAN - *out++ = part.i[1]; - *out++ = part.i[0]; - part.l = part2; - *out++ = part.i[1]; - *out++ = part.i[0]; -#else - *out++ = part.c[1]; - *out++ = part.c[0]; - *out++ = part.c[3]; - *out++ = part.c[2]; - part.l = part2; - *out++ = part.c[1]; - *out++ = part.c[0]; - *out++ = part.c[3]; - *out++ = part.c[2]; -#endif - } - -} - -#undef MANTISSA_MASK -#undef MANTISSA_SIZE -#undef HIDDEN_BIT -#undef EXPONENT_ADJUSTMENT - -#endif /* #ifdef MAKE_TO_VAX_G8 */ - -/*************************************************************** to_vax_h16() */ - -#ifdef MAKE_TO_VAX_H16 - -/* Assert the mantissa in a VAX H_float is the same as in an IEEE X_float */ -#if VAX_H_MANTISSA_MASK != IEEE_X_MANTISSA_MASK -#error MANTISSA_MASK mismatch in to_vax_h16() -#endif -#define MANTISSA_MASK VAX_H_MANTISSA_MASK -/* If the mantissas are the same, then so are the no. of bits and the hidden */ -/* normalization bit */ -#define MANTISSA_SIZE VAX_H_MANTISSA_SIZE -#define HIDDEN_BIT VAX_H_HIDDEN_BIT - -#define EXPONENT_ADJUSTMENT ( 1 + VAX_H_EXPONENT_BIAS - IEEE_X_EXPONENT_BIAS ) - -void FORTRAN_LINKAGE to_vax_h16( const void *inbuf, void *outbuf, - const int *count ) { - - register const unsigned int *in; /* Microsoft C: up to 2 register vars */ -#if IS_LITTLE_ENDIAN - register unsigned short *out; /* Microsoft C: up to 2 register vars */ - union { unsigned short i[2]; unsigned int l; } part; -#else - unsigned char *out; - union { unsigned char c[4]; unsigned int l; } part; -#endif - unsigned int part1, part2, part3, part4; - unsigned int m; - int n; - int e; - - - in = (const unsigned int *) inbuf; -#if IS_LITTLE_ENDIAN - out = (unsigned short *) outbuf; -#else - out = (unsigned char *) outbuf; -#endif - - for ( n = *count; n > 0; n-- ) { - part1 = *in++; - part2 = *in++; - part3 = *in++; - part4 = *in++; - if ( ( ( part1 & ~SIGN_BIT ) | part2 | part3 | part4 ) == 0 ) { - - part.l = 0; /* Set IEEE +-zero [e=m=0] to VAX zero [s=e=m=0] */ - /* part2 = 0; */ /* part2, part3, and part4 are already zero */ - /* part3 = 0; */ - /* part4 = 0; */ - - } else if ( ( e = ( part1 & IEEE_X_EXPONENT_MASK ) ) == - IEEE_X_EXPONENT_MASK ) { - - /* VAX's have no equivalents for IEEE +-Infinity and +-NaN [e=all-1's] */ - //raise( SIGFPE ); - return; - /* Fixup to VAX +-extrema [e=all-1's] with zero mantissa [m=0] */ - part.l = ( part1 & SIGN_BIT ) | VAX_H_EXPONENT_MASK; - part2 = 0; - part3 = 0; - part4 = 0; - - } else { - - e >>= MANTISSA_SIZE; /* Obtain the biased IEEE exponent */ - m = part1 & MANTISSA_MASK; /* Obtain the IEEE mantissa */ - - if ( e == 0 ) { /* Denormalized [e=0, m<>0] */ - /* Adjust representation from 2**(1-bias) to 2**(e-bias) */ - m = ( m << 1 ) | ( part2 >> 31 ); - part2 <<= 1; - while ( ( m & HIDDEN_BIT ) == 0 ) { - m = ( m << 1 ) | ( part2 >> 31 ); - part2 = ( part2 << 1 ) | ( part3 >> 31 ); - part3 = ( part3 << 1 ) | ( part4 >> 31 ); - part4 <<= 1; - e -= 1; /* Adjust exponent */ - } - m &= MANTISSA_MASK; /* Adjust mantissa to hidden-bit form */ - } - - if ( ( e += EXPONENT_ADJUSTMENT ) <= 0 ) { - - part.l = 0; /* Silent underflow */ - part2 = 0; - part3 = 0; - part4 = 0; - - } else if ( e > ( 2 * VAX_H_EXPONENT_BIAS - 1 ) ) { - - //raise( SIGFPE );/* Overflow; fixup to VAX +-extrema [e=m=all-1's] */ - return; - part.l = ( part1 & SIGN_BIT ) | ~SIGN_BIT; - part2 = ~0; - part3 = ~0; - part4 = ~0; - - } else { - - /* VAX normalized form [e>0] (both mantissas are 112 bits) */ - part.l = ( part1 & SIGN_BIT ) | ( e << MANTISSA_SIZE ) | m; - /* part2, part3, and part4 are already correct */ - - } - - } -#if IS_LITTLE_ENDIAN - *out++ = part.i[1]; - *out++ = part.i[0]; - part.l = part2; - *out++ = part.i[1]; - *out++ = part.i[0]; - part.l = part3; - *out++ = part.i[1]; - *out++ = part.i[0]; - part.l = part4; - *out++ = part.i[1]; - *out++ = part.i[0]; -#else - *out++ = part.c[1]; - *out++ = part.c[0]; - *out++ = part.c[3]; - *out++ = part.c[2]; - part.l = part2; - *out++ = part.c[1]; - *out++ = part.c[0]; - *out++ = part.c[3]; - *out++ = part.c[2]; - part.l = part3; - *out++ = part.c[1]; - *out++ = part.c[0]; - *out++ = part.c[3]; - *out++ = part.c[2]; - part.l = part4; - *out++ = part.c[1]; - *out++ = part.c[0]; - *out++ = part.c[3]; - *out++ = part.c[2]; -#endif - } - -} - -#undef MANTISSA_MASK -#undef MANTISSA_SIZE -#undef HIDDEN_BIT -#undef EXPONENT_ADJUSTMENT - -#endif /* #ifdef MAKE_TO_VAX_H16 */ diff --git a/modules/io/src/img/convert_vax_data.h b/modules/io/src/img/convert_vax_data.h deleted file mode 100755 index e8e057780..000000000 --- a/modules/io/src/img/convert_vax_data.h +++ /dev/null @@ -1,263 +0,0 @@ -/****************************************************************************** - * * - * convert_vax_data.h - Convert VAX-format data to/from Unix (IEEE) format. * - * * - * from_vax_i2() - Byte swap Integer*2 * - * from_vax_i4() - Byte reverse Integer*4 * - * from_vax_r4() - 32-bit VAX F_floating to IEEE S_floating * - * from_vax_d8() - 64-bit VAX D_floating to IEEE T_floating * - * from_vax_g8() - 64-bit VAX G_floating to IEEE T_floating * - * from_vax_h16() - 128-bit VAX H_floating to Alpha X_floating * - * * - * to_vax_i2() - Byte swap Integer*2 * - * to_vax_i4() - Byte reverse Integer*4 * - * to_vax_r4() - 32-bit IEEE S_floating to VAX F_floating * - * to_vax_d8() - 64-bit IEEE T_floating to VAX D_floating * - * to_vax_g8() - 64-bit IEEE T_floating to VAX G_floating * - * to_vax_h16() - 128-bit Alpha X_floating to VAX H_floating * - * * - * All calls take 3 arguments: * - * * - * C declaration: #include "convert_vax_data.h" * - * usage: name( in_array, out_array, &count ); * - * * - * Fortran usage: Call NAME( in_array, out_array, count ) * - * * - * The in_array and out_array parameters may refer to the same object. * - * * - * * - * VAXes (as well as the Intel 80x86 family) store integers in 2's complement * - * format, ordering the bytes in memory from low-order to high-order (collo- * - * quially called little-endian format). Most Unix machines (Sun, IBM, HP) * - * also store integers in 2's complement format, but use the opposite (so * - * called big-endian) byte ordering. * - * * - * A VAX integer is converted to (big-endian) Unix format by reversing the * - * byte order. * - * * - * Most Unix machines implement the ANSI/IEEE 754-1985 floating-point arith- * - * metic standard. VAX and IEEE formats are similar (after byte-swapping). * - * The high-order bit is a sign bit (s). This is followed by a biased expo- * - * nent (e), and a (usually) hidden-bit normalized mantissa (m). They differ * - * in the number used to bias the exponent, the location of the implicit bi- * - * nary point for the mantissa, and the representation of exceptional numbers * - * (e.g., +/-infinity). * - * * - * VAX floating-point formats: (-1)^s * 2^(e-bias) * 0.1m * - * * - * 31 15 0 * - * | | | * - * F_floating mmmmmmmmmmmmmmmmseeeeeeeemmmmmmm bias = 128 * - * D_floating mmmmmmmmmmmmmmmmseeeeeeeemmmmmmm bias = 128 * - * mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm * - * G_floating mmmmmmmmmmmmmmmmseeeeeeeeeeemmmm bias = 1024 * - * mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm * - * H_floating mmmmmmmmmmmmmmmmseeeeeeeeeeeeeee bias = 16384 * - * mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm * - * mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm * - * mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm * - * * - * IEEE floating-point formats: (-1)^s * 2^(e-bias) * 1.m * - * * - * 31 15 0 * - * | | | * - * S_floating seeeeeeeemmmmmmmmmmmmmmmmmmmmmmm bias = 127 * - * T_floating seeeeeeeeeeemmmmmmmmmmmmmmmmmmmm bias = 1023 * - * mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm * - * X_floating seeeeeeeeeeeeeeemmmmmmmmmmmmmmmm bias = 16383 * - * mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm * - * mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm * - * mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm * - * * - * A VAX floating-point number is converted to IEEE floating-point format by * - * subtracting (1+VAX_bias-IEEE_bias) from the exponent field to (1) adjust * - * from VAX 0.1m hidden-bit normalization to IEEE 1.m hidden-bit normaliza- * - * tion and (2) adjust the bias from VAX format to IEEE format. True zero * - * [s=e=m=0] and dirty zero [s=e=0, m<>0] are special cases which must be * - * recognized and handled separately. * - * * - * Numbers whose absolute value is too small to represent in the normalized * - * IEEE format illustrated above are converted to subnormal form [e=0, m>0]: * - * (-1)^s * 2^(1-bias) * 0.m. Numbers whose absolute value is too small to * - * represent in subnormal form are set to 0.0 (silent underflow). * - * * - * Note: If the fractional part of the VAX floating-point number is too large * - * for the corresponding IEEE floating-point format, bits are simply * - * discarded from the right. Thus, the remaining fractional part is * - * chopped, not rounded to the lowest-order bit. This can only occur * - * when the conversion requires IEEE subnormal form. * - * * - * A VAX floating-point reserved operand [s=1, e=0, m=any] causes a SIGFPE * - * exception to be raised. The converted result is set to zero. * - * * - * Conversely, an IEEE floating-point number is converted to VAX floating- * - * point format by adding (1+VAX_bias-IEEE_bias) to the exponent field. * - * +zero [s=e=m=0], -zero [s=1, e=m=0], infinities [s=X, e=all-1's, m=0], and * - * NaNs [s=X, e=all-1's, m<>0] are special cases which must be recognized and * - * handled separately. Infinities and NaNs cause a SIGFPE exception to be * - * raised. The result returned has the largest VAX exponent [e=all-1's] and * - * zero mantissa [m=0] with the same sign as the original. * - * * - * Numbers whose absolute value is too small to represent in the normalized * - * VAX format illustrated above are set to 0.0 (silent underflow). (VAX * - * floating-point format does not support subnormal numbers.) Numbers whose * - * absolute value exceeds the largest representable VAX-format number cause a * - * SIGFPE exception to be raised (overflow). (VAX floating-point format does * - * not have reserved bit patterns for infinities and not-a-numbers [NaNs].) * - * The result returned has the largest VAX exponent and mantissa [e=m= * - * all-1's] with the same sign as the original. * - * * - * * - * Two variants of convert_vax_data.c are available using IS_LITTLE_ENDIAN * - * and APPEND_UNDERSCORE. If IS_LITTLE_ENDIAN is defined as 0 (false), then * - * the conversions are performed for a big-endian machine, i.e., byte reor- * - * dering is performed for all data types. If IS_LITTLE_ENDIAN is defined as * - * 1 (true), then no reordering is performed. (Integers are identical to VAX * - * format.) * - * * - * If IS_LITTLE_ENDIAN is not defined, then it is defined as 1 (true) if any * - * of the following macros are defined: * - * * - * vax __vax vms __vms __alpha DEC VAX C, GNU C on a DEC VAX or a DEC * - * Alpha, DEC C * - * M_I86 _M_IX86 __M_ALPHA Microsoft 80x86 C or Microsoft Visual C++ * - * on an Intel x86 or a DEC Alpha * - * i386 __i386 Sun C, GNU C, or Intel C on an Intel x86 * - * __x86_64 __x86_64__ GNU C or Portland Group C on an AMD * - * Opteron or an Intel EM64T * - * * - * If APPEND_UNDERSCORE is defined, the entry point names are compiled with * - * an underscore appended. This is required so that they can be called by * - * Fortran in cases where the Fortran compiler appends an underscore to * - * externally called routines (e.g., Sun Fortran). * - * * - * Normally, all routines are compiled into a single object module. To com- * - * pile a single routine into its own module, define MAKE_routine_name, sub- * - * stituting the upper-case name of the routine for routine_name. For exam- * - * ple, MAKE_TO_VAX_I2. (This is useful, for example, to insert the routines * - * into a library such that a linker may extract only the routines actually * - * needed by a particular program.) * - * * - * convert_vax_data.c assumes an ANSI C compiler, 8-bit chars, 16-bit shorts, * - * and 32-bit ints. * - * * - * * - * References: ANSI/IEEE Std 754-1985, IEEE Standard for Binary Floating- * - * Point Arithmetic, Institute of Electrical and Electronics * - * Engineers * - * Brunner, Richard A., Ed., 1991, VAX Architecture Reference * - * Manual, Second Edition, Digital Press * - * Sites, Richard L., and Witek, Richard T., 1995, Alpha AXP * - * Architecture Reference Manual, Second Edition, Digital * - * Press * - * * - * Author: Lawrence M. Baker * - * U.S. Geological Survey * - * 345 Middlefield Road MS977 * - * Menlo Park, CA 94025 * - * baker@usgs.gov * - * * - * Citation: Baker, L.M., 2005, libvaxdata: VAX Data Format Conversion * - * Routines: U.S. Geological Survey Open-File Report 2005- * - * 1424 (http://pubs.usgs.gov/of/2005/1424/). * - * * - * * - * Disclaimer * - * * - * Although this program has been used by the USGS, no warranty, expressed or * - * implied, is made by the USGS or the United States Government as to the * - * accuracy and functioning of the program and related program material, nor * - * shall the fact of distribution constitute any such warranty, and no * - * responsibility is assumed by the USGS in connection therewith. * - * * - * * - * Modification History: * - * * - * 8-Mar-2001 L. M. Baker Original version. * - * Define upcased and underscore-appended * - * variants. * - * 9-Mar-2001 L. M. Baker Add #ifndef _CONVERT_VAX_DATA guard. * - * 16-Sep-2005 L. M. Baker Correct the diagram of IEEE X_floating * - * (exponent is 15 bits, not 11 bits). * - * 19-Sep-2005 L. M. Baker Add fixups for IEEE-to-VAX conversion * - * faults (+-infinity, +-NaN, overflow). * - * 8-Nov-2005 L. M. Baker Move #define const if not __STDC__ from * - * convert_vax_data.c * - * * - ******************************************************************************/ - -#ifndef _CONVERT_VAX_DATA -#define _CONVERT_VAX_DATA - -#ifndef FORTRAN_LINKAGE -#define FORTRAN_LINKAGE -#endif - -#ifdef UPCASE - -#define from_vax_i2 FROM_VAX_I2 -#define from_vax_i4 FROM_VAX_I4 -#define from_vax_r4 FROM_VAX_R4 -#define from_vax_d8 FROM_VAX_D8 -#define from_vax_g8 FROM_VAX_G8 -#define from_vax_h16 FROM_VAX_H16 - -#define to_vax_i2 TO_VAX_I2 -#define to_vax_i4 TO_VAX_I4 -#define to_vax_r4 TO_VAX_R4 -#define to_vax_d8 TO_VAX_D8 -#define to_vax_g8 TO_VAX_G8 -#define to_vax_h16 TO_VAX_H16 - -#endif - -#ifdef APPEND_UNDERSCORE - -#define from_vax_i2 from_vax_i2##_ -#define from_vax_i4 from_vax_i4##_ -#define from_vax_r4 from_vax_r4##_ -#define from_vax_d8 from_vax_d8##_ -#define from_vax_g8 from_vax_g8##_ -#define from_vax_h16 from_vax_h16##_ - -#define to_vax_i2 to_vax_i2##_ -#define to_vax_i4 to_vax_i4##_ -#define to_vax_r4 to_vax_r4##_ -#define to_vax_d8 to_vax_d8##_ -#define to_vax_g8 to_vax_g8##_ -#define to_vax_h16 to_vax_h16##_ - -#endif - -/* const is ANSI C, C++ only */ -#if !defined( __STDC__ ) && !defined( __cplusplus ) -#define const -#endif - -void FORTRAN_LINKAGE from_vax_i2( const void *inbuf, void *outbuf, - const int *count ); -void FORTRAN_LINKAGE from_vax_i4( const void *inbuf, void *outbuf, - const int *count ); -void FORTRAN_LINKAGE from_vax_r4( const void *inbuf, void *outbuf, - const int *count ); -void FORTRAN_LINKAGE from_vax_d8( const void *inbuf, void *outbuf, - const int *count ); -void FORTRAN_LINKAGE from_vax_g8( const void *inbuf, void *outbuf, - const int *count ); -void FORTRAN_LINKAGE from_vax_h16( const void *inbuf, void *outbuf, - const int *count ); - -void FORTRAN_LINKAGE to_vax_i2( const void *inbuf, void *outbuf, - const int *count ); -void FORTRAN_LINKAGE to_vax_i4( const void *inbuf, void *outbuf, - const int *count ); -void FORTRAN_LINKAGE to_vax_r4( const void *inbuf, void *outbuf, - const int *count ); -void FORTRAN_LINKAGE to_vax_d8( const void *inbuf, void *outbuf, - const int *count ); -void FORTRAN_LINKAGE to_vax_g8( const void *inbuf, void *outbuf, - const int *count ); -void FORTRAN_LINKAGE to_vax_h16( const void *inbuf, void *outbuf, - const int *count ); - -#endif /* #ifndef _CONVERT_VAX_DATA */ diff --git a/modules/io/src/img/image_format_conversion.cc b/modules/io/src/img/image_format_conversion.cc deleted file mode 100644 index 8ce7122fc..000000000 --- a/modules/io/src/img/image_format_conversion.cc +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// This file is part of the OpenStructure project <www.openstructure.org> -// -// Copyright (C) 2008-2020 by the OpenStructure authors -// Copyright (C) 2003-2010 by the IPLT authors -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License as published by the Free -// Software Foundation; either version 3.0 of the License, or (at your option) -// any later version. -// This library is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -// details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this library; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -//------------------------------------------------------------------------------ - -/* - wrapper around Lawrence Baker's vax conversion routines - - Author: Ansgar Philippsen -*/ - -#ifndef IMG_IMAGE_FORMAT_H -#error "image_format_conversion.cc must be included from image_format.hh" -#endif - -#include <ost/message.hh> -#include <ost/io/io_exception.hh> - -extern "C" { -#include "convert_vax_data.h" -} - -namespace ost { namespace io { - -template<typename T> -inline -void VaxToIEEE(T* t,unsigned int n); - -template<> -inline -void VaxToIEEE(char* t,unsigned int n) -{ - // noop -} - -template<> -inline -void VaxToIEEE(unsigned char* t,unsigned int n) -{ - // noop -} - -template<> -inline -void VaxToIEEE(float* t,unsigned int n) -{ - static int count[]={0}; - count[0]=n; - from_vax_r4(t,t,count); -} - -template<> -inline -void VaxToIEEE(int* t,unsigned int n) -{ - static int count[]={0}; - count[0]=n; - from_vax_i4(t,t,count); -} - -template<> -inline -void VaxToIEEE(unsigned int* t,unsigned int n) -{ - static int count[]={0}; - count[0]=n; - from_vax_i4(t,t,count); -} - -template<> -inline -void VaxToIEEE(short* t,unsigned int n) -{ - static int count[]={0}; - count[0]=n; - from_vax_i2(t,t,count); -} - -template<> -inline -void VaxToIEEE(unsigned short* t,unsigned int n) -{ - static int count[]={0}; - count[0]=n; - from_vax_i2(t,t,count); -} - -template<typename T> -inline -void VaxToIEEE(T* t,unsigned int n) -{ - throw IOException("unsupported VaxToIEEE conversion"); -} - -}} // ns -- GitLab