Annotation of tme/ic/ieee754/ieee754-precision.sh, revision 1.1.1.2

1.1       root        1: #! /bin/sh
                      2: 
1.1.1.2 ! root        3: # $Id: ieee754-precision.sh,v 1.2 2007/08/26 14:02:04 fredette Exp $
1.1       root        4: 
                      5: # ic/ieee754/ieee754-precision.sh - emits information about IEEE 754 types
                      6: # in a form usable by scripts that automatically generate code:
                      7: 
                      8: #
                      9: # Copyright (c) 2004 Matt Fredette
                     10: # All rights reserved.
                     11: #
                     12: # Redistribution and use in source and binary forms, with or without
                     13: # modification, are permitted provided that the following conditions
                     14: # are met:
                     15: # 1. Redistributions of source code must retain the above copyright
                     16: #    notice, this list of conditions and the following disclaimer.
                     17: # 2. Redistributions in binary form must reproduce the above copyright
                     18: #    notice, this list of conditions and the following disclaimer in the
                     19: #    documentation and/or other materials provided with the distribution.
                     20: # 3. All advertising materials mentioning features or use of this software
                     21: #    must display the following acknowledgement:
                     22: #      This product includes software developed by Matt Fredette.
                     23: # 4. The name of the author may not be used to endorse or promote products
                     24: #    derived from this software without specific prior written permission.
                     25: #
                     26: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     27: # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
                     28: # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
                     29: # DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
                     30: # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
                     31: # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
                     32: # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     33: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
                     34: # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
                     35: # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     36: # POSSIBILITY OF SUCH DAMAGE.
                     37: #
                     38: 
                     39: # get the precision's SoftFloat name, its integral type, its size
                     40: # in bytes, any member name for its sign+exponent word, the
                     41: # exponent mask for the sign+exponent word, the number of fraction
                     42: # bits, and the member names and masks for its fraction chunks:
                     43: #
                     44: precision=$1
                     45: prefix=$2
                     46: case $1 in
                     47: single) 
                     48:     cat <<EOF
                     49: ${prefix}precision_sf=float32 ;
                     50: ${prefix}integral=tme_uint32_t ;
                     51: ${prefix}constant=tme_uint32_t ;
                     52: ${prefix}size=4 ;
                     53: ${prefix}sexp= ;
                     54: ${prefix}mask_exp=0x7f800000 ;
                     55: ${prefix}fracbits=23 ;
                     56: ${prefix}implicit=true ;
                     57: ${prefix}chunk_member_0= ; chunk_mask_0=0x007f0000 ;
                     58: ${prefix}chunk_member_1= ; chunk_mask_1=0x0000ffff ;
                     59: ${prefix}chunk_member_2=x ;
                     60: EOF
                     61:     ;;
                     62: double)
                     63:     cat <<EOF
                     64: ${prefix}precision_sf=float64 ;
                     65: ${prefix}integral='union tme_value64' ;
                     66: ${prefix}constant='struct tme_ieee754_double_constant' ;
                     67: ${prefix}size=8 ;
                     68: ${prefix}sexp=.tme_value64_uint32_hi ;
                     69: ${prefix}mask_exp=0x7ff00000 ;
                     70: ${prefix}fracbits=52 ;
                     71: ${prefix}implicit=true ;
                     72: ${prefix}chunk_member_0=.tme_value64_uint32_hi ; chunk_mask_0=0x000f0000 ;
                     73: ${prefix}chunk_member_1=.tme_value64_uint32_hi ; chunk_mask_1=0x0000ffff ;
                     74: ${prefix}chunk_member_2=.tme_value64_uint32_lo ; chunk_mask_2=0xffff0000 ;
                     75: ${prefix}chunk_member_3=.tme_value64_uint32_lo ; chunk_mask_3=0x0000ffff ;
                     76: ${prefix}chunk_member_4=x ;
                     77: EOF
                     78:     ;;
                     79: extended80)
                     80:     cat <<EOF
                     81: ${prefix}precision_sf=floatx80 ;
                     82: ${prefix}integral='struct tme_float_ieee754_extended80' ;
                     83: ${prefix}constant='struct tme_ieee754_extended80_constant' ;
                     84: ${prefix}size=12 ;
                     85: ${prefix}sexp=.tme_float_ieee754_extended80_sexp ;
                     86: ${prefix}mask_exp=0x7fff ;
                     87: ${prefix}fracbits=63 ;
                     88: ${prefix}implicit=false ;
                     89: ${prefix}chunk_member_0=.tme_float_ieee754_extended80_significand.tme_value64_uint32_hi ; chunk_mask_0=0xffff0000 ;
                     90: ${prefix}chunk_member_1=.tme_float_ieee754_extended80_significand.tme_value64_uint32_hi ; chunk_mask_1=0x0000ffff ;
                     91: ${prefix}chunk_member_2=.tme_float_ieee754_extended80_significand.tme_value64_uint32_lo ; chunk_mask_2=0xffff0000 ;
                     92: ${prefix}chunk_member_3=.tme_float_ieee754_extended80_significand.tme_value64_uint32_lo ; chunk_mask_3=0x0000ffff ;
                     93: ${prefix}chunk_member_4=x ;
                     94: EOF
                     95:     ;;
                     96: quad)
                     97:     cat <<EOF
                     98: ${prefix}precision_sf=float128 ;
                     99: ${prefix}integral='struct tme_float_ieee754_quad' ;
                    100: ${prefix}constant='struct tme_ieee754_quad_constant' ;
                    101: ${prefix}size=16 ;
                    102: ${prefix}sexp=.tme_float_ieee754_quad_hi.tme_value64_uint32_hi ;
                    103: ${prefix}mask_exp=0x7fff0000 ;
                    104: ${prefix}fracbits=112 ;
                    105: ${prefix}implicit=true ;
                    106: ${prefix}chunk_member_0=.tme_float_ieee754_quad_hi.tme_value64_uint32_hi ; chunk_mask_0=0x0000ffff ;
                    107: ${prefix}chunk_member_1=.tme_float_ieee754_quad_hi.tme_value64_uint32_lo ; chunk_mask_1=0xffff0000 ;
                    108: ${prefix}chunk_member_2=.tme_float_ieee754_quad_hi.tme_value64_uint32_lo ; chunk_mask_2=0x0000ffff ;
                    109: ${prefix}chunk_member_3=.tme_float_ieee754_quad_lo.tme_value64_uint32_hi ; chunk_mask_3=0xffff0000 ;
                    110: ${prefix}chunk_member_4=.tme_float_ieee754_quad_lo.tme_value64_uint32_hi ; chunk_mask_4=0x0000ffff ;
                    111: ${prefix}chunk_member_5=.tme_float_ieee754_quad_lo.tme_value64_uint32_lo ; chunk_mask_5=0xffff0000 ;
                    112: ${prefix}chunk_member_6=.tme_float_ieee754_quad_lo.tme_value64_uint32_lo ; chunk_mask_6=0x0000ffff ;
                    113: ${prefix}chunk_member_7=x ;
                    114: EOF
                    115:     ;;
                    116: esac
                    117: 
                    118: # to avoid integer overflow warnings, make sure that the exponent
                    119: # mask is always unsigned:
                    120: #
1.1.1.2 ! root      121: echo ${prefix}'mask_exp="((tme_uint32_t) ${'${prefix}'mask_exp})" ;'
1.1       root      122: 
                    123: # a mask for the sign bit can be derived from the exponent mask:
                    124: #
1.1.1.2 ! root      125: echo ${prefix}'mask_sign="(${'${prefix}'mask_exp} + _TME_FIELD_MASK_FACTOR(${'${prefix}'mask_exp}))" ; '
1.1       root      126: 
                    127: # the maximum biased exponent can be derived from the exponent mask:
                    128: #
1.1.1.2 ! root      129: echo ${prefix}'exp_biased_max="(${'${prefix}'mask_exp} / _TME_FIELD_MASK_FACTOR(${'${prefix}'mask_exp}))" ; '
1.1       root      130: 
                    131: # the exponent bias can be derived from the maximum biased exponent:
                    132: #
1.1.1.2 ! root      133: echo ${prefix}'exp_bias="(${'${prefix}'exp_biased_max} >> 1)" ; '
1.1       root      134: 
                    135: # make a capitalized version of the precision name:
                    136: #
                    137: echo ${prefix}'capprecision=`echo ${precision} | tr a-z A-Z` ; '
                    138: 
                    139: # done:
                    140: #
                    141: exit 0;

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.