Annotation of tme/ic/ieee754/ieee754-ops-auto.sh, revision 1.1.1.3

1.1       root        1: #! /bin/sh
                      2: 
1.1.1.3 ! root        3: # $Id: ieee754-ops-auto.sh,v 1.5 2009/08/28 01:34:01 fredette Exp $
1.1       root        4: 
                      5: # ic/ieee754/ieee754-misc-auto.sh - automatically generates C code 
                      6: # for IEEE 754 emulation operations:
                      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: header=false
                     40: 
                     41: for option
                     42: do
                     43:     case $option in
                     44:     --header) header=true ;;
                     45:     esac
                     46: done
                     47: 
                     48: PROG=`basename $0`
                     49: cat <<EOF
                     50: /* automatically generated by $PROG, do not edit! */
                     51: #include <tme/common.h>
1.1.1.3 ! root       52: _TME_RCSID("\$Id: ieee754-ops-auto.sh,v 1.5 2009/08/28 01:34:01 fredette Exp $");
1.1       root       53: 
                     54: EOF
                     55: if $header; then 
                     56: :
                     57: else
                     58:     cat <<EOF
                     59: #include "softfloat-tme.h"
                     60: #include <math.h>
                     61: EOF
                     62: fi
                     63: 
                     64: # the precision information helper script:
                     65: #
                     66: ieee754_precision_sh=`echo $0 | sed -e "s/$PROG/ieee754-precision.sh/"`
                     67: 
                     68: # the different compliance levels:
                     69: #
                     70: levels="strict partial unknown"
                     71: 
                     72: # permute for the different compliance levels:
                     73: #
                     74: for level in ${levels}; do
                     75: 
                     76:     # permute for functions or for a set:
                     77:     #
                     78:     for what in funcs set; do
                     79: 
                     80:        # if we're generating headers:
                     81:        #
                     82:        if $header; then
                     83: 
                     84:            # if we're doing the strict-level functions, start the
                     85:            # operations struct type:
                     86:            #
                     87:            if test "${level}-${what}" = strict-funcs; then
                     88:                echo "/* the IEEE 754 operations: */"
                     89:                echo "struct tme_ieee754_ops {"
                     90:                echo ""
                     91:                echo "  /* the version of this structure: */"
                     92:                echo "  tme_uint32_t tme_ieee754_ops_version;"
                     93:              
                     94: 
                     95:            # otherwise, if we're doing a set, just declare the set
                     96:            # and continue:
                     97:            #
                     98:            elif test ${what} = set; then
                     99:                echo ""
                    100:                echo "/* the ${level} compliance operations: */"
                    101:                echo "extern _tme_const struct tme_ieee754_ops tme_ieee754_ops_${level};"
                    102:                continue
                    103:            fi
                    104: 
                    105:        # otherwise, if we're doing a set:
                    106:        #
                    107:        elif test ${what} = set; then
                    108: 
                    109:            # start the operations set for this level:
                    110:            #
                    111:            echo ""
                    112:            echo "/* the ${level} compliance operations: */"
                    113:            echo "_tme_const struct tme_ieee754_ops tme_ieee754_ops_${level} = {"
                    114:            echo ""
                    115:            echo "  /* the version of this structure: */"
                    116:            echo "  TME_X_VERSION(0, 0),"
                    117:        fi
                    118: 
                    119:        # permute for the different precisions:
                    120:        #
                    121:        for precision in single double extended80 quad; do
                    122: 
                    123:            # get information about this precision:
                    124:            #
                    125:            eval `sh ${ieee754_precision_sh} ${precision}`
                    126: 
                    127:            # generate the operations:
                    128:            #
                    129:            for name in add sub mul div \
                    130:                        rem sqrt abs neg move \
                    131:                        rint \
                    132:                        cos acos cosh \
                    133:                        sin asin sinh \
                    134:                        tan atan tanh atanh \
                    135:                        exp expm1 log10 log log1p \
                    136:                        getexp getman scale \
                    137:                        pow \
                    138:                        from_single from_double from_extended80 from_quad \
1.1.1.2   root      139:                        from_int32 from_int64 \
1.1       root      140:                        to_int32 to_int64 \
                    141:                        ; do
                    142: 
                    143:                # get the characteristics of this operation that are the
                    144:                # same at all compliance levels:
                    145:                #
                    146:                monadic=true
                    147:                case "${name}" in
                    148:                add | sub | mul | div | rem | pow | scale)
                    149:                    monadic=false
                    150:                    ;;
                    151:                esac
1.1.1.2   root      152:                src_type="struct tme_float *"
1.1       root      153:                dst_type="struct tme_float"
                    154:                case "${name}" in
1.1.1.2   root      155:                from_int32) src_type="tme_int32_t " ;;
                    156:                from_int64) src_type="tme_int64_t " ;;
1.1       root      157:                to_int32) dst_type="tme_int32_t" ;;
1.1.1.3 ! root      158:                to_int64) dst_type="tme_int64_t" ;;
1.1       root      159:                esac
                    160: 
                    161:                # we don't need a function to convert from the same
                    162:                # precision to this precision:
                    163:                #
                    164:                from_precision=
                    165:                case "${name}" in 
                    166:                from_*)
                    167:                    from_precision=`echo ${name} | sed -e 's/^from_//'`
                    168:                    if test ${from_precision} = ${precision}; then
                    169:                        continue
                    170:                    fi
                    171:                    ;;
                    172:                esac
                    173: 
                    174:                # if we're generating headers:
                    175:                #
                    176:                if $header; then
                    177: 
                    178:                    # only emit this header information if we're
                    179:                    # doing the strict level functions:
                    180:                    #
                    181:                    if test "${level}-${what}" = strict-funcs; then
                    182:                        echo ""
                    183:                        echo "  /* this does a ${precision}-precision "`echo ${name} | tr _ -`": */"
                    184:                        echo -n "  void (*tme_ieee754_ops_${precision}_${name}) _TME_P((struct tme_ieee754_ctl *, "
                    185:                        if $monadic; then :; else
                    186:                            echo -n "_tme_const struct tme_float *, "
                    187:                        fi
1.1.1.2   root      188:                        echo "_tme_const ${src_type}, ${dst_type} *));"
1.1       root      189:                    fi
                    190:                        
                    191:                    continue
                    192:                fi
                    193: 
                    194:                # start with no function for this set:
                    195:                #
                    196:                func_set='  NULL,'
                    197: 
                    198:                # permute for the stricter compliance levels:
                    199:                #
                    200:                for level_stricter in ${levels}; do
                    201: 
                    202:                    # form this function name:
                    203:                    #
                    204:                    func="_tme_ieee754_${level_stricter}_${precision}_${name}"
                    205: 
                    206:                    # the function type is normally determined by
                    207:                    # whether or not a softfloat function, libm
                    208:                    # function, or C operator is given.  it can be
                    209:                    # overridden:
                    210:                    # 
                    211:                    type=
                    212:                    func_softfloat=
                    213:                    func_libm=
                    214:                    func_libm_has_f=true
                    215:                    op_builtin=
                    216: 
                    217:                    # any preprocessor condition controlling whether or not
                    218:                    # the function can be emitted is normally determined by
                    219:                    # the function type.  it can be overridden:
                    220:                    #
                    221:                    cond=
1.1.1.2   root      222:                    cond_int64=
                    223:                    cond_builtin_match=
1.1       root      224: 
                    225:                    # assume that we will use the operands as passed
                    226:                    # in.  the precisions will later default to the
                    227:                    # precision of the result, if they are not
                    228:                    # overridden:
                    229:                    #
                    230:                    op0=src0
                    231:                    op0_precision=
                    232:                    if $monadic; then op1= ; else op1=src1 ; fi
                    233:                    op1_precision=
                    234: 
                    235:                    # miscellaneous attributes:
                    236:                    #
                    237:                    src0_buffer=
                    238:                    src0_precision=
                    239:                    src1_buffer=
                    240:                    src1_precision=
                    241:                    check_nan=
                    242:                    check_inf_src0=
                    243:                    enter_softfloat=
                    244:                    enter_native=
                    245: 
                    246:                    # characterize this operation at this compliance level:
                    247:                    #
                    248:                    case "${level_stricter}-${name}" in
                    249:                    strict-add | strict-sub | strict-mul | strict-div | strict-rem | strict-sqrt) 
                    250:                        func_softfloat="${name}"
                    251:                        ;;
                    252:                    *-add) op_builtin='+' ;;
                    253:                    *-sub) op_builtin='-' ;;
                    254:                    *-mul) op_builtin='*' ;;
                    255:                    *-div) op_builtin='/' ;;
                    256:                    *-sqrt) func_libm=sqrt ;;
                    257:                    partial-abs | unknown-abs) func_libm=fabs ;;
1.1.1.2   root      258:                    strict-neg) op0=-1 ; func_softfloat=mul ; op1=src0 ;;
                    259:                    partial-neg | unknown-neg) op0=-1 ; op_builtin='*'; op1=src0 ;;
1.1       root      260:                    strict-move) func_softfloat=add ; op1=0 ;;
                    261:                    *-move) type="${level_stricter}-move" ; src0_buffer=false ;;
                    262:                    strict-rint) func_softfloat=round_to_int ;;
                    263:                    partial-pow | unknown-pow) func_libm="${name}" ;;
                    264:                    partial-log | unknown-log) func_libm="${name}" ;;
                    265:                    partial-exp | unknown-exp) func_libm="${name}" ;;
                    266:                    partial-log10 | unknown-log10) func_libm="${name}" ;;
                    267:                    partial-scale | unknown-scale) func_libm=scalbn ;;
                    268:                    strict-getexp | strict-getman) type="${level_stricter}-${name}" ; check_nan=true ; check_inf_src0=return-nan ;;
                    269:                    strict-from_*) func_softfloat="OP0_PRECISION_SF_to_${precision_sf}" ; op0_precision="${from_precision}" ;;
                    270:                    strict-to_int32) type="${level_stricter}-${name}" ; func_softfloat="${precision_sf}_${name}" ;;
1.1.1.3 ! root      271:                    strict-to_int64) type="${level_stricter}-${name}" ; func_softfloat="${precision_sf}_${name}" ;;
1.1       root      272:                    esac
                    273: 
                    274:                    # finish typing this function:
                    275:                    #
                    276:                    if test "x${type}" = x; then
                    277:                        if test "x${func_softfloat}" != x; then
                    278:                            type=softfloat
                    279:                        elif test "x${func_libm}" != x; then
                    280:                            type=libm
                    281:                        elif test "x${op_builtin}" != x; then
                    282:                            type=builtin
                    283:                        else
                    284:                            type=none
                    285:                        fi
                    286:                    fi
                    287: 
                    288:                    # finish the preprocessor condition controlling
                    289:                    # whether or not the function can be emitted:
                    290:                    #
                    291:                    if test "x${cond}" = x; then
1.1.1.2   root      292: 
                    293:                        # assume that this function can be unconditionally emitted:
                    294:                        #
                    295:                        cond=1
                    296: 
1.1       root      297:                        case "${precision}-${level_stricter}-${type}" in
                    298: 
                    299:                        # a function with a none type can't be emitted:
                    300:                        #
                    301:                        *-*-none) cond=0 ;;
                    302: 
                    303:                        # extended80 or quad precision softfloat
                    304:                        # functions are conditional on a 64-bit
                    305:                        # integral type:
                    306:                        #
1.1.1.2   root      307:                        extended80-*-softfloat | quad-*-softfloat) cond_int64=true ;;
1.1       root      308: 
                    309:                        # partial compliance functions are conditional
                    310:                        # on the builtin type being an exact match for
                    311:                        # the IEEE 754 type:
                    312:                        #
1.1.1.2   root      313:                        *-partial-*) cond_builtin_match=true ;;
1.1       root      314:                        esac
                    315:                    fi
1.1.1.2   root      316:                    case "${src_type}" in tme_int64_t*) cond_int64=true ;; esac
                    317:                    case "${dst_type}" in tme_int64_t*) cond_int64=true ;; esac
                    318:                    if test "x${cond_int64}" != x; then
                    319:                        cond="${cond} && defined(TME_HAVE_INT64_T)"
                    320:                    fi
                    321:                    if test "x${cond_builtin_match}" != x; then
                    322:                        cond="${cond} && (TME_FLOAT_FORMAT_IEEE754_${capprecision}_BUILTIN == TME_FLOAT_FORMAT_IEEE754_${capprecision})"
                    323:                    fi
                    324:                    eval "cond=\`echo '${cond}' | sed -e 's%^1 && %%'\`"
                    325:                    case "${cond}" in 0*) cond=0 ;; esac
1.1       root      326: 
                    327:                    # finish the operands:
                    328:                    #
                    329:                    for _opn in 0 1; do
                    330:                        eval "opn=\$op${_opn}"
                    331:                        if test "x${opn}" = x; then
                    332:                            continue
                    333:                        fi
                    334:                        eval "opn_precision=\$op${_opn}_precision"
                    335:                        if test "x${opn_precision}" = x; then
                    336:                            opn_precision="${precision}"
                    337:                        fi
1.1.1.2   root      338:                        case "${opn_precision}" in
                    339:                        int32 | int64)
                    340:                            check_nan=false
                    341:                            eval "op${_opn}_precision_sf=\$opn_precision"
                    342:                            continue
                    343:                            ;;
                    344:                        esac
1.1       root      345:                        eval `sh ${ieee754_precision_sh} ${opn_precision} opn_`
                    346:                        case "${opn}" in
                    347:                        src[01])
                    348:                            eval "${opn}_precision=\$opn_precision"
                    349:                            if test "x${func_softfloat}" != x || test "x${func_libm}${op_builtin}" = x; then
                    350:                                eval "srcn_buffer=\$${opn}_buffer"
                    351:                                if test "x${srcn_buffer}" = x; then
                    352:                                    eval "${opn}_buffer=true"
                    353:                                fi
                    354:                                opn="tme_ieee754_${opn_precision}_value_get(${opn}, &${opn}_buffer)"
                    355:                                if test "x${func_softfloat}" != x; then
                    356:                                    opn="((const ${opn_precision_sf} *) ${opn})"
                    357:                                fi
                    358:                                opn="(*${opn})"
                    359:                            else
                    360:                                opn="tme_ieee754_${opn_precision}_value_builtin_get(${opn})"
                    361:                            fi
                    362:                            ;;
1.1.1.2   root      363:                        [0-9] | -[0-9])
1.1       root      364:                            if test "x${func_softfloat}" != x; then
                    365:                                opn="int32_to_${opn_precision_sf}(${opn})"
                    366:                            fi
                    367:                            ;;
                    368:                        esac
                    369:                        eval "op${_opn}=\$opn"
                    370:                        eval "op${_opn}_precision=\$opn_precision"
                    371:                        eval "op${_opn}_precision_sf=\$opn_precision_sf"
                    372:                        eval "op${_opn}_integral=\$opn_integral"
                    373:                    done
                    374: 
                    375:                    # finish the miscellaneous attributes:
                    376:                    #
                    377:                    if test "x${src0_buffer}" = x; then
                    378:                        src0_buffer=false
                    379:                    fi
                    380:                    if test "x${src1_buffer}" = x; then
                    381:                        src1_buffer=false
                    382:                    fi
                    383:                    if test "x${check_nan}" = x; then
                    384:                        if test "${level_stricter}" = partial; then
                    385:                            check_nan=true
                    386:                        else
                    387:                            check_nan=false
                    388:                        fi
                    389:                    fi
                    390:                    if test "x${enter_softfloat}" = x; then
                    391:                        if test "x${func_softfloat}" != x; then
                    392:                            enter_softfloat=true
                    393:                        else
                    394:                            enter_softfloat=false
                    395:                        fi
                    396:                    fi
                    397:                    if test "x${enter_native}" = x; then
                    398:                        if test "${level_stricter}" = partial; then
                    399:                            enter_native=true
                    400:                        else
                    401:                            enter_native=false
                    402:                        fi
                    403:                    fi
                    404: 
                    405:                    # if we're making functions, and we're at the
                    406:                    # right level to emit this function, and this
                    407:                    # function can be emitted:
                    408:                    #
                    409:                    if test ${what} = funcs && test ${level_stricter} = ${level} && test "${cond}" != 0; then
                    410: 
                    411:                        # start any conditional:
                    412:                        #
                    413:                        if test "${cond}" != 1; then
                    414:                            echo ""
                    415:                            echo "#if ${cond}"
                    416:                        fi
                    417:                            
                    418:                        # start the function:
                    419:                        #
                    420:                        echo ""
                    421:                        echo "/* this does a ${level} compliance ${precision}-precision "`echo ${name} | tr _ -`": */"
                    422:                        echo "static void"
1.1.1.2   root      423:                        echo -n "${func}(struct tme_ieee754_ctl *ieee754_ctl, const ${src_type}src0, "
1.1       root      424:                        if $monadic; then :; else
                    425:                            echo -n "const struct tme_float *src1, "
                    426:                        fi
                    427:                        echo "${dst_type} *dst)"
                    428:                        echo "{"
                    429: 
                    430:                        # emit locals:
                    431:                        #
                    432:                        if ${src0_buffer}; then
                    433:                            echo "  ${op0_integral} src0_buffer;"
                    434:                        fi
                    435:                        if ${src1_buffer}; then
                    436:                            echo "  ${op1_integral} src1_buffer;"
                    437:                        fi
                    438:                        echo "  int exceptions;"
                    439: 
                    440:                        # check the operand(s):
                    441:                        #
                    442:                        if ${check_nan}; then
                    443:                            echo ""
                    444:                            echo "  /* check for a NaN operand: */"
                    445:                            if $monadic; then nanf=monadic; src1= ; else nanf=dyadic; src1=", src1"; fi
                    446:                            echo "  if (__tme_predict_false(tme_ieee754_${src0_precision}_check_nan_${nanf}(ieee754_ctl, src0${src1}, dst))) {"
                    447:                            echo "    return;"
                    448:                            echo "  }"
                    449:                        fi
                    450:                        if test "x${check_inf_src0}" != x; then
                    451:                            echo ""
                    452:                            echo "  /* if the operand is an infinity: */"
                    453:                            echo "  if (tme_ieee754_${precision}_is_inf(src0)) {"
                    454:                            echo ""
                    455:                            case "${check_inf_src0}" in
                    456:                            return-nan)
                    457:                                echo "    /* return a NaN: */"
                    458:                                echo "    dst->tme_float_format = TME_FLOAT_FORMAT_IEEE754_${capprecision};"
                    459:                                echo "    dst->tme_float_value_ieee754_${precision} = ieee754_ctl->tme_ieee754_ctl_default_nan_${precision};"
                    460:                                echo "    return;"
                    461:                                ;;
                    462:                            esac
                    463:                            echo "  }"
                    464:                        fi
                    465: 
                    466:                        # enter the operation mode:
                    467:                        #
                    468:                        if ${enter_softfloat}; then
                    469:                            echo ""
                    470:                            echo "  /* enter softfloat operation: */"
                    471:                            echo "  tme_mutex_lock(&tme_ieee754_global_mutex);"
                    472:                            echo "  tme_ieee754_global_ctl = ieee754_ctl;"
                    473:                            echo "  tme_ieee754_global_exceptions = 0;"
                    474:                            echo "  ieee754_ctl->tme_ieee754_ctl_lock_unlock = tme_ieee754_unlock_softfloat;"
                    475:                        fi
                    476:                        if ${enter_native}; then
                    477:                            echo ""
                    478:                            echo "  /* enter native floating-point operation: */"
                    479:                            echo "  tme_float_enter(ieee754_ctl->tme_ieee754_ctl_rounding_mode, tme_ieee754_exception_float, ieee754_ctl);"
                    480:                            echo "  ieee754_ctl->tme_ieee754_ctl_lock_unlock = tme_float_leave;"
                    481:                        fi
                    482: 
                    483:                        # assume that this operation raises no exceptions:
                    484:                        #
                    485:                        echo ""
                    486:                        echo "  /* assume that this operation raises no exceptions: */"
                    487:                        echo "  exceptions = 0;"
                    488: 
                    489:                        # the operation:
                    490:                        #
                    491:                        echo ""
                    492:                        echo "  /* the operation: */"
                    493:                        case "${type}" in
                    494: 
                    495:                        # a move operation:
                    496:                        #
                    497:                        *-move)
                    498:                            echo "  *dst = *src0;"
                    499:                            ;;
                    500: 
                    501:                        # a getexp operation:
                    502:                        #
                    503:                        strict-getexp)
                    504:                            echo ""
                    505:                            echo "  /* if the operand is a zero, return a zero: */"
                    506:                            echo "  if (tme_ieee754_${precision}_is_zero(src0)) {"
                    507:                            echo "    tme_ieee754_${precision}_value_builtin_set(dst, TME_FLOAT_FORMAT_IEEE754_${capprecision}_BUILTIN, 0);"
                    508:                            echo "  }"
                    509:                            echo ""
                    510:                            echo "  /* otherwise, return the unbiased exponent: */"
                    511:                            echo "  else {"
                    512:                            echo "    tme_ieee754_${precision}_value_builtin_set(dst, TME_FLOAT_FORMAT_IEEE754_${capprecision}_BUILTIN, TME_FIELD_MASK_EXTRACTU(${op0}${sexp}, ${mask_exp}) - ${exp_bias});"
                    513:                            echo "  }"
                    514:                            ;;
                    515: 
                    516:                        # a getman operation:
                    517:                        #
                    518:                        strict-getman)
                    519:                            echo ""
                    520:                            echo "  /* if the operand is a zero, return it: */"
                    521:                            echo "  if (tme_ieee754_${precision}_is_zero(src0)) {"
                    522:                            echo "    *dst = *src0;"
                    523:                            echo "  }"
                    524:                            echo ""
                    525:                            echo "  /* otherwise, return the operand, with its exponent set to biased zero: */"
                    526:                            echo "  else {"
                    527:                            echo "    tme_ieee754_${precision}_value_set(dst, ${op0});"
                    528:                            echo "    TME_FIELD_MASK_DEPOSITU(dst->tme_float_value_ieee754_${precision}${sexp}, ${mask_exp}, ${exp_bias});"
                    529:                            echo "  }"
                    530:                            ;;
                    531: 
                    532:                        # a strict to-integer conversion operation:
                    533:                        #
                    534:                        strict-to_int32 | strict-to_int64)
                    535:                            echo "  *dst = ${precision_sf}_${name}(${op0});"
                    536:                            ;;
                    537: 
                    538:                        # a softfloat operation:
                    539:                        #
                    540:                        softfloat)
                    541:                            echo "  _tme_ieee754_${precision}_value_set(dst, ${precision_sf},"
                    542:                            func_softfloat_raw="${func_softfloat}"
                    543:                            func_softfloat=`echo ${func_softfloat} | sed -e "s/OP0_PRECISION_SF/${op0_precision_sf}/g"`
1.1.1.2   root      544:                            func_softfloat=`echo ${func_softfloat} | sed -e "s/OP1_PRECISION_SF/${op1_precision_sf}/g"`
1.1       root      545:                            if test "${func_softfloat}" = "${func_softfloat_raw}"; then
                    546:                                func_softfloat="${precision_sf}_${func_softfloat}"
                    547:                            fi
                    548:                            echo -n "    ${func_softfloat}(${op0}"
                    549:                            if test "x${op1}" != x; then
                    550:                                echo ","
                    551:                                echo -n "                ${op1}"
                    552:                            fi
                    553:                            echo "));"
                    554:                            ;;
                    555: 
                    556:                        # a libm operation:
                    557:                        #
                    558:                        libm)
                    559:                            if test "x${op1}" = x; then ops="${op0}"; else ops="${op0}, ${op1}"; fi
                    560:                            # if there is a float variant of this libm function:
                    561:                            #
                    562:                            if ${func_libm_has_f}; then
                    563:                                echo "#if (TME_FLOAT_FORMAT_IEEE754_${capprecision}_BUILTIN == TME_FLOAT_FORMAT_FLOAT)"
                    564:                                echo "  tme_ieee754_${precision}_value_builtin_set(dst, TME_FLOAT_FORMAT_FLOAT, ${func_libm}f(${ops}));"
                    565:                                echo "#else  /* (TME_FLOAT_FORMAT_IEEE754_${capprecision}_BUILTIN != TME_FLOAT_FORMAT_FLOAT) */"
                    566:                            fi
                    567:                            echo "  tme_ieee754_${precision}_value_builtin_set(dst, TME_FLOAT_FORMAT_DOUBLE, ${func_libm}(${ops}));"
                    568:                            if ${func_libm_has_f}; then
                    569:                                echo "#endif /* (TME_FLOAT_FORMAT_IEEE754_${capprecision}_BUILTIN != TME_FLOAT_FORMAT_FLOAT) */"
                    570:                            fi
                    571:                            ;;
                    572: 
                    573:                        # a builtin operation:
                    574:                        #
                    575:                        builtin)
                    576:                            echo "  tme_ieee754_${precision}_value_builtin_set(dst, TME_FLOAT_FORMAT_IEEE754_${capprecision}_BUILTIN, ${op0} ${op_builtin} ${op1});"
                    577:                            ;;
                    578: 
                    579:                        *)
                    580:                            echo "$PROG internal error: don't know how to generate a ${type} type operation" 1>&2
                    581:                            exit 1
                    582:                            ;;
                    583:                        esac
                    584: 
                    585:                        # leave the operation mode:
                    586:                        #
                    587:                        if ${enter_native}; then
                    588:                            echo ""
                    589:                            echo "  /* leave native floating-point operation: */"
                    590:                            echo "  exceptions |= tme_float_leave();"
                    591:                        fi
                    592:                        if ${enter_softfloat}; then
                    593:                            echo ""
                    594:                            echo "  /* leave softfloat operation: */"
                    595:                            echo "  tme_ieee754_global_ctl = NULL;"
                    596:                            echo "  exceptions |= tme_ieee754_global_exceptions;"
                    597:                            echo "  tme_mutex_unlock(&tme_ieee754_global_mutex);"
                    598:                        fi
                    599:                        echo "  ieee754_ctl->tme_ieee754_ctl_lock_unlock = NULL;"
                    600: 
                    601:                        # signal any exceptions:
                    602:                        #
                    603:                        echo ""
                    604:                        echo "  /* signal any exceptions: */"
                    605:                        echo "  if (exceptions != 0) {"
                    606:                        echo "    (*ieee754_ctl->tme_ieee754_ctl_exception)(ieee754_ctl, exceptions);"
                    607:                        echo "  }"
                    608: 
                    609:                        # end the function:
                    610:                        #
                    611:                        echo "}"
                    612: 
                    613:                        # close any conditional:
                    614:                        #
                    615:                        if test "${cond}" != 1; then
                    616:                            echo ""
                    617:                            echo "#endif /* ${cond} */"
                    618:                        fi
                    619:                    fi
                    620: 
                    621:                    # update the function for this set:
                    622:                    #
                    623:                    case "${cond}" in
                    624:                    0) ;;
                    625:                    1) func_set="  ${func}," ;;
                    626:                    *) func_set="#if (${cond})@  ${func},@#else  /* !(${cond}) */@${func_set}@#endif /* !(${cond}) */" ;;
                    627:                    esac
                    628: 
                    629:                    # stop now if we just did this level:
                    630:                    #
                    631:                    if test ${level_stricter} = ${level}; then
                    632:                        break
                    633:                    fi
                    634:                done
                    635:                    
                    636:                # if we're making a set:
                    637:                #
                    638:                if test ${what} = set; then
                    639:                    echo ""
                    640:                    echo "  /* this does a ${level} compliance ${precision}-precision ${name}: */"
                    641:                    echo "${func_set}" | tr '@' '\n'
                    642:                fi
                    643:                        
                    644:            done
                    645:        done
                    646: 
                    647:        # if we're generating headers:
                    648:        #
                    649:        if $header; then
                    650: 
                    651:            # if we're doing the strict-level functions, close the
                    652:            # operations struct type:
                    653:            #
                    654:            if test "${level}-${what}" = strict-funcs; then
                    655:                echo "};"
                    656:            fi
                    657: 
                    658:        # otherwise, if we're doing a set:
                    659:        #
                    660:        elif test ${what} = set; then
                    661: 
                    662:            # close the operations set for this level:
                    663:            #
                    664:            echo "};"
                    665:        fi
                    666: 
                    667:     done
                    668: 
                    669: done
                    670: 
                    671: # if we're not generating headers:
                    672: #
                    673: if $header; then :; else
                    674: 
                    675:     echo ""
                    676:     echo "/* this looks up an operations structure: */"
                    677:     echo "const struct tme_ieee754_ops *"
                    678:     echo "tme_ieee754_ops_lookup(const char *compliance)"
                    679:     echo "{"
                    680:     echo ""
                    681:     for level in ${levels}; do
                    682:        echo "  if (TME_ARG_IS(compliance, \"${level}\")) { "
                    683:        echo "    return (&tme_ieee754_ops_${level});"
                    684:        echo "  }"
                    685:     done
                    686:     echo "  return (NULL);"
                    687:     echo "}"
                    688: 
                    689:     echo ""
                    690:     echo "/* this is a compliance options string: */"
                    691:     echo -n "const char * const tme_ieee754_compliance_options = \"{ ";
                    692:     sep=
                    693:     for level in ${levels}; do
                    694:        echo -n "${sep}${level}"
                    695:        sep=' | '
                    696:     done
                    697:     echo " }\";"
                    698: fi
                    699: 
                    700: # done:
                    701: #
                    702: exit 0;

unix.superglobalmegacorp.com

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