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

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

unix.superglobalmegacorp.com

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