Annotation of tme/generic/fb-xlat-auto.sh, revision 1.1.1.4

1.1       root        1: #! /bin/sh
                      2: 
1.1.1.4 ! root        3: # $Id: fb-xlat-auto.sh,v 1.12 2009/08/30 21:51:53 fredette Exp $
1.1       root        4: 
                      5: # generic/fb-xlat-auto.sh - automatically generates C code 
                      6: # for many framebuffer translation functions:
                      7: 
                      8: #
1.1.1.2   root        9: # Copyright (c) 2003, 2005 Matt Fredette
1.1       root       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: # this script generates one or more C functions.  each function
                     40: # translates an image from a source image format into a destination
                     41: # image format, optionally halving or doubling the image size in the
                     42: # process.
                     43: #
                     44: # the source and destination image formats are represented by "keys",
                     45: # strings that describe the different attributes of a format.
                     46: #
1.1.1.2   root       47: # a source image format key has the form: WxHdDbBsSpPoO[cC][mMS][_rR_gG_bB][_X]
1.1       root       48: #
1.1.1.2   root       49: # a destination image format key has the form: dDbBsSpPoO[mM][_rR_gG_bB]
1.1       root       50: #
                     51: # all of the lowercase letters and underscores are literals, and all
                     52: # of the uppercase letters represent attribute values.  the different
                     53: # attributes are:
                     54: #
                     55: # W is the width of the source image.  if zero, the generated function
                     56: # will be able to translate source images of any width, but it will be
                     57: # suboptimal.  if nonzero, the generated function will only be able to
                     58: # translate source images of that width, but it will have some
                     59: # optimization.  this attribute is only used in source keys, since the
                     60: # destination width is always the scaled source width.
                     61: #
                     62: # H is the height of the source image.  if zero, the generated
                     63: # function will be able to translate source images of any height, but
                     64: # it will be suboptimal.  if nonzero, the generated function will only
                     65: # be able to translate source images of that height, but it will have
                     66: # some optimization.  this attribute is only used in source keys,
                     67: # since the destination height is always the scaled source height.
                     68: #
                     69: # D is the color (d)epth, in bits, of the source/destination image.
                     70: # if zero, the generated function will be able to handle
                     71: # source/destination images of any depth, but it will be suboptimal.
                     72: # if nonzero, the generated function will only be able to handle
                     73: # source/destination images of that depth, but it will have some
                     74: # optimization.
                     75: #
                     76: # B is the (b)its-per-pixel of the source/destination image.  this
                     77: # must be at least as large as the depth, and it may be larger.  if
                     78: # zero, the generated function will be able to handle
                     79: # source/destination images of any bits-per-pixel, but it will be
                     80: # suboptimal.  if nonzero, the generated function will only be able to
                     81: # handle source/destination images of that bits-per-pixel, but it will
                     82: # have some optimization.
                     83: #
                     84: # S is the (s)kip-x-bits of the source/destination image.  this is the
                     85: # number of bits at the beginning of each image scanline that are not
                     86: # displayed.  if an underscore, the generated function will be able to
                     87: # handle source/destination images with any skip-x-bits, but it will
                     88: # be suboptimal.  if not an underscore, the generated function will
                     89: # only be able to handle source/destination images with that many
                     90: # skip-x-bits, but it will have some optimization.
                     91: #
                     92: # P is the (p)adding of the source/destination image.  this is how
                     93: # many bits each image scanline is padded to.  if zero, the generated
                     94: # function will be able to handle source/destination images with any
                     95: # padding, but it will be suboptimal.  if nonzero, the generated
                     96: # function will only be able to handle source/destination images with
                     97: # that padding, but it will have some optimization.
                     98: #
                     99: # O is the byte and bit (o)rder of the source/destination image.  this
                    100: # is always m or l for most- or least-significant, respectively.
                    101: # there is no "any" wildcard value.  this script cannot handle image
                    102: # formats where a word-unit of pixels has one order for its bytes in
                    103: # memory, but the opposite order for its pixels within the word-unit.
                    104: #
1.1.1.2   root      105: # C is the optional class.  it is 'm' for a monochrome (grayscale) image,
                    106: # and 'c' for a color image.  if not given, an image with a depth of
                    107: # one is considered monochrome, and any other image is considered color.
                    108: #
                    109: # M is the optional mapping type.  it is 'l' for a monochrome image
                    110: # that linearly maps pixels into intensities and for a color image
                    111: # that linearly maps pixel subfields into intensities.  it is 'i' for
                    112: # images that index pixels or pixel subfields into intensities.  if
                    113: # not given, monochrome images and color images with subfields are
                    114: # assumed to be linear, and color images without subfields are assumed
                    115: # to be indexed.
                    116: #
                    117: # S is the optional mapping size. if the mapping type is given, this
                    118: # must be given, and it is the size of the mapping range - i.e., the
                    119: # number of bits per intensity.  if the mapping type is not given, and
                    120: # the image is linearly mapped monochrome, the mapping size is assumed
                    121: # to be the same as the image depth.
                    122: #
                    123: # R, G, and B are the optional subfield masks.  if an image's pixels
                    124: # can be decomposed into subfields for red, green, and blue, these are
                    125: # the masks for the subfields.
                    126: #
1.1       root      127: # X is the optional scaling.  it is `h' to halve the source image,
                    128: # or `d' to double it.  this attribute is only used in source keys.
                    129: 
                    130: # this script generates a set of functions for the product of all
                    131: # source image formats and all destination image formats.
                    132: #
                    133: # "all source image formats" includes all source image formats given
                    134: # on the command line, plus:
                    135: #
                    136: #   the "any" source image format, unscaled
                    137: #   the "any" source image format, halved
                    138: #   the "any" source image format, doubled
                    139: #
                    140: # "all destination image formats" includes all destination
                    141: # image formats given on the command line, plus:
                    142: #
                    143: #   the "any" destination image format
                    144: #
                    145: src_all=
                    146: dst_all=
                    147: for order in m l; do
1.1.1.2   root      148:   src_key="0x0d0b0s_p0o${order}_r0x0_g0x0_b0x0"
1.1       root      149:   src_all="${src_all} ${src_key} ${src_key}_h ${src_key}_d"
1.1.1.2   root      150:   dst_all="${dst_all} d0b0s_p0o${order}_r0x0_g0x0_b0x0"
1.1       root      151: done
                    152: 
                    153: which=
                    154: for arg
                    155: do
                    156:     case $arg in
                    157:     src|dst) which=$arg ;;
                    158:     *)
                    159:        if test "x${which}" != x; then
                    160:            eval "${which}_all=\"$arg \$${which}_all\""
                    161:        fi
                    162:        ;;
                    163:     esac
                    164: done
                    165: 
                    166: PROG=`basename $0`
                    167: cat <<EOF
                    168: /* automatically generated by $PROG, do not edit! */
                    169: 
                    170: /*
1.1.1.2   root      171:  * Copyright (c) 2003, 2005 Matt Fredette
1.1       root      172:  * All rights reserved.
                    173:  *
                    174:  * Redistribution and use in source and binary forms, with or without
                    175:  * modification, are permitted provided that the following conditions
                    176:  * are met:
                    177:  * 1. Redistributions of source code must retain the above copyright
                    178:  *    notice, this list of conditions and the following disclaimer.
                    179:  * 2. Redistributions in binary form must reproduce the above copyright
                    180:  *    notice, this list of conditions and the following disclaimer in the
                    181:  *    documentation and/or other materials provided with the distribution.
                    182:  * 3. All advertising materials mentioning features or use of this software
                    183:  *    must display the following acknowledgement:
                    184:  *      This product includes software developed by Matt Fredette.
                    185:  * 4. The name of the author may not be used to endorse or promote products
                    186:  *    derived from this software without specific prior written permission.
                    187:  *
                    188:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                    189:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
                    190:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
                    191:  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
                    192:  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
                    193:  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
                    194:  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                    195:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
                    196:  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
                    197:  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                    198:  * POSSIBILITY OF SUCH DAMAGE.
                    199:  */
                    200: 
1.1.1.4 ! root      201: _TME_RCSID("\$Id: fb-xlat-auto.sh,v 1.12 2009/08/30 21:51:53 fredette Exp $");
1.1       root      202: 
                    203: /* the central feature of these translation functions is the "bit
                    204:    FIFO", a first-in, first-out stream of bits.  source bit FIFOs are
                    205:    used to read pixel bits out of source images, and destination bit
                    206:    FIFOs are used to write pixel bits into destination images.
                    207: 
                    208:    a bit FIFO has a visible part and an invisible part.
                    209: 
                    210:    the visible part of a bit FIFO is 32 bits wide, meaning the
                    211:    translation code can read (for a source bit FIFO) or write (for a
                    212:    destination bit FIFO) up to 32 bits of pixel data before a bit
                    213:    FIFO shift.
                    214: 
                    215:    the invisible part of a source bit FIFO contains pixel bits that
                    216:    have already been read from the source image memory, but that have
                    217:    yet to be shifted in to the visible part.
                    218: 
                    219:    the invisible part of a destination bit FIFO contains the pixel
                    220:    bits that have been shifted out of the visible part, but that have
                    221:    yet to be written to the destination image memory.
                    222: 
                    223:    depending on various attributes of an image format, it may be
                    224:    possible for the translation code to always read or write the
                    225:    entire 32 visible bits of a bit FIFO at a time, and as a result
                    226:    always shift the bit FIFO 32 bits at a time.  this is desirable
                    227:    because it minimizes bit FIFO shifts.
                    228: 
                    229:    when this does happen, it may also be the case that the visible
                    230:    part of the bit FIFO always perfectly corresponds to an aligned
                    231:    32-bit word in the image buffer.
                    232: 
                    233:    this is the optimal situation, as it makes it unnecessary to track
                    234:    the invisible part in C local variables at all - each 32-bit FIFO
                    235:    shift of a source bit FIFO just reads the next 32-bit word directly
                    236:    into the visible part, and each 32-bit FIFO shift of a destination
                    237:    bit FIFO just writes the next 32-bit word directly out of the
                    238:    visible part.
                    239: 
                    240:    within the visible part of a bit FIFO, which bits belong to which
                    241:    pixels depends on the "order" of the image format.  most-significant
                    242:    (big-endian) images have earlier (more to the left on the screen)
                    243:    pixels in more-significant bit positions.  least-significant
                    244:    (little-endian) images have earlier pixels in less-significant bit
                    245:    bit positions.
                    246: 
                    247:    bit significance *within* a pixel never depends on image order.
                    248:    once the bits belonging to a pixel have been identified according
                    249:    to image order, the least significant bit in that pixel's value is
                    250:    always the bit with the least absolute value.
                    251: 
                    252:    some pictures may help explain this better.  each picture shows the
                    253:    32 bit visible part of a bit FIFO, with the bits marked from 0
                    254:    (least significant) to 31 (most significant).  all of these
                    255:    examples are for a two-bit-deep/two-bits-per-pixel image, and in
                    256:    the visible part sixteen pixels are numbered.  lesser numbered
                    257:    pixels are earlier (more to the left on the screen).  some of the
                    258:    invisible part is also shown, along with the direction that the bit
                    259:    FIFO shifts in:
                    260: 
                    261:    a source bit FIFO for a little-endian source image with two bits
                    262:    per pixel looks like:
                    263: 
                    264:                         |  
                    265:                         | 31 30 29 28     7  6  5  4  3  2  1  0
                    266:       --+--+--+--+--+--+|+--+--+--+--+-  --+--+--+--+--+--+--+--+
                    267:     .. p18 | p17 | p16 ||| p15 | p14 | .. p3  | p2  | p1  | p0  |  
                    268:       --+--+--+--+--+--+|+--+--+--+--+-  --+--+--+--+--+--+--+--+
                    269:                         |
                    270:    invisible part       |             visible part
                    271:    
                    272:           shift -> shift -> shift -> shift -> shift ->
                    273: 
                    274:    a source bit FIFO for a big-endian source image with two bits per
                    275:    pixel looks like:
                    276: 
                    277:                                             |
                    278:      31 30 29 28 27 26 25 26  4  3  2  1  0 |                
                    279:     +--+--+--+--+--+--+--+--  -+--+--+--+--+|+--+--+--+--+--+--
                    280:     | p0  | p1  | p2  | p3  .. | p14 | p15 ||| p16 | p17 | p18 ..
                    281:     +--+--+--+--+--+--+--+--  -+--+--+--+--+|+--+--+--+--+--+--
                    282:                                             |
                    283:                visible part                 |    invisible part
                    284: 
                    285:         <- shift <- shift <- shift <- shift <- shift
                    286: 
                    287:    a destination bit FIFO for a little-endian destination image with
                    288:    two bits per pixel looks like:
                    289: 
                    290:                                             |
                    291:      31 30 29 28 27 26 25 26  4  3  2  1  0 |                
                    292:     +--+--+--+--+--+--+--+--  -+--+--+--+--+|+--+--+--+--+--+--
                    293:     | p23 | p22 | p21 | p20 .. | p9  | p8  ||| p7  | p6  | p5  ..
                    294:     +--+--+--+--+--+--+--+--  -+--+--+--+--+|+--+--+--+--+--+--
                    295:                                             |
                    296:                visible part                 |    invisible part
                    297: 
                    298:           shift -> shift -> shift -> shift -> shift ->
                    299: 
                    300:    a destination bit FIFO for a big-endian destination image with
                    301:    two bits per pixel looks like:
                    302: 
                    303:                         |  
                    304:                         | 31 30 29 28     7  6  5  4  3  2  1  0
                    305:       --+--+--+--+--+--+|+--+--+--+--+-  --+--+--+--+--+--+--+--+
                    306:     .. p5  | p6  | p7  ||| p8  | p9  | .. p20 | p21 | p22 | p23 |  
                    307:       --+--+--+--+--+--+|+--+--+--+--+-  --+--+--+--+--+--+--+--+
                    308:                         |
                    309:    invisible part       |             visible part
                    310: 
                    311:         <- shift <- shift <- shift <- shift <- shift
                    312:    
                    313:   each translation function has at least one source bit FIFO and at
                    314:   least one destination bit FIFO.  the general idea is to read source
                    315:   pixel value(s) from the source image, map those source pixel
                    316:   value(s) somehow into destination pixel value(s), and write those
                    317:   destination pixel value(s) to the destination image.
                    318: 
                    319:   translation functions that do not scale the image have exactly one
                    320:   source bit FIFO and exactly one destination bit FIFO.  one pixel
                    321:   read from the source bit FIFO becomes one pixel written to the
                    322:   destination bit FIFO.
                    323: 
                    324:   translation functions that halve the image size have two source bit
                    325:   FIFOs and one destination bit FIFO.  one source bit FIFO sources
                    326:   bits from an even-numbered scanline, and the other sources bits from
                    327:   an odd-numbered scanline.  four pixels read from the source bit
                    328:   FIFOs - two from each source bit FIFO, making a 2x2 square - become
                    329:   one pixel written to the destination bit FIFO.
                    330: 
                    331:   translation functions that double the image size have one source
                    332:   bit FIFO and two destination bit FIFOs.  one destination bit FIFO
                    333:   sinks bits for an even-numbered scanline, and the other sinks bits
                    334:   for an odd-numbered scanline.  one pixel read from the source bit
                    335:   FIFO becomes four pixels written to the destination bit FIFOs -
                    336:   two to each destination bit FIFO, making a 2x2 square.   
                    337: 
                    338:   translation functions don't necessarily always translate the entire
                    339:   source image into the entire destination image.  instead, the buffer
                    340:   holding the current source image is expected to be twice as large as
                    341:   necessary (plus some overhead), with the second half of the buffer
                    342:   holding a copy of the last translated ("old") source image.
                    343: 
                    344:   before setting up and translating pixels using bit FIFOs, a
                    345:   translation function treats the the current and old source images as
                    346:   an array of aligned 32-bit words and compares them.  if it finds no
                    347:   32-bit word that has changed, no translation is done and the
                    348:   function returns.
                    349: 
                    350:   otherwise, initial source pixel x and y coordinates are derived from
                    351:   the offset of the 32-bit word that failed comparison, and the source
                    352:   primary bit FIFO is primed.  if this translation function halves the
                    353:   image size, the source secondary bit FIFO is primed from the same x
                    354:   coordinate on the "other" (think y ^ 1) scanline.
                    355: 
                    356:   then, initial destination pixel x and y coordinates are derived from
                    357:   the initial source x and y coordinates, and the destination primary
                    358:   bit FIFO is primed.  if this translation function doubles the image
                    359:   size, the destination secondary bit FIFO is primed from the same x
                    360:   coordinate on the "other" (think y ^ 1) scanline.
                    361: 
                    362:   as mentioned previously, the buffer holding the current source image
                    363:   is expected to be twice as large as necessary (plus some overhead),
                    364:   with the second half of the buffer holding a copy of the last
                    365:   translated ("old") source image.
                    366: 
                    367:   this "overhead" is approximately two extra scanlines worth of data,
                    368:   that is initialized to all-bits-zero and must always remain zero.
                    369:   this extra data is present at the end of both the current ("new")
                    370:   and last translated ("old") source images.
                    371: 
                    372:   these extra, always-blank scanlines guarantee that the pixel
                    373:   translation loop terminates.  the pixel translation loop *never*
                    374:   checks for the end of the image buffer.  instead, it terminates only
                    375:   after it has read in TME_FB_XLAT_RUN consecutive aligned 32-bit
                    376:   words that have *not* changed between the new and old source images.
                    377:   this small amount of extra memory overhead simplifies the pixel
                    378:   translation loop, because it doesn't have to worry about going past
                    379:   the end of the actual image.
                    380: */
                    381: 
                    382: 
                    383: /* macros: */
                    384: 
                    385: /* given a 32-bit aligned pointer into the current source image, this
                    386:    returns the corresponding 32-bit aligned pointer in the last
                    387:    translated ("old") source image.  since the old source image
                    388:    follows the current source image, this is simple pointer arithmetic
                    389:    using src_bypb: */
                    390: #define TME_FB_XLAT_SRC_OLD(raw)                               \\
                    391:   ((tme_uint32_t *) (((tme_uint8_t *) (raw)) + src_bypb))
                    392: 
                    393: /* when the fast, aligned 32-bit word comparison loop finds a word
                    394:    that has changed in the source image, pixels are translated until
                    395:    TME_FB_XLAT_RUN consecutive aligned 32-bit words are processed that
                    396:    have *not* changed in the source image, at which point the fast
                    397:    comparison loop resumes.
                    398: 
                    399:    the idea is that after you've started translating pixels, once the
                    400:    FIFO shift operation has read TME_FB_XLAT_RUN consecutive raw,
                    401:    unchanged 32-bit words, all of the pixels from previous, changed
                    402:    32-bit words have been translated and shifted out of the source bit
                    403:    FIFO(s), and all bits remaining in the source bit FIFO(s) are for
                    404:    pixels in those unchanged 32-bit words.  since the pixels are
                    405:    unchanged, pixel translation can stop, and the entire state of the
                    406:    source bit FIFO(s) can be discarded.
                    407: 
                    408:    so, each time a raw, changed 32-bit word is read, xlat_run is
                    409:    reloaded with TME_FB_XLAT_RUN, and each time 32 bits worth of
                    410:    source image pixels are processed, it is decremented.  when it
                    411:    reaches zero, the source bit FIFO(s) are discarded, the destination
                    412:    bit FIFO(s) are flushed, the pixel translation loop breaks and the
                    413:    fast comparison loop continues: */
                    414: #define TME_FB_XLAT_RUN (2)
                    415: 
                    416: /* this shifts a source FIFO: */
                    417: #define TME_FB_XLAT_SHIFT_SRC(unaligned, fifo, next, bits, shift, raw, order)\\
                    418: do {                                                           \\
                    419:                                                                \\
                    420:   /* if the source FIFO may not be 32-bit aligned: */           \\
                    421:   if (unaligned) {                                              \\
                    422:                                                                 \\
                    423:     /* we must be shifting between 1 and 32 bits: */           \\
                    424:     assert ((shift) >= 1 && (shift) <= 32);                    \\
                    425:                                                                \\
                    426:     /* the FIFO must have more than 32 bits in it already: */  \\
                    427:     assert (bits > 32);                                                \\
                    428:                                                                \\
                    429:     /* shift the FIFO: */                                      \\
                    430:     if ((shift) == 32) {                                       \\
                    431:       fifo = next;                                             \\
                    432:     }                                                          \\
                    433:     else if (order == TME_ENDIAN_BIG) {                                \\
                    434:       fifo = (fifo << ((shift) & 31)) | (next >> (32 - (shift)));\\
                    435:       next <<= ((shift) & 31);                                 \\
                    436:     }                                                          \\
                    437:     else {                                                     \\
                    438:       fifo = (fifo >> ((shift) & 31)) | (next << (32 - (shift)));\\
                    439:       next >>= ((shift) & 31);                                 \\
                    440:     }                                                          \\
                    441:     bits -= (shift);                                           \\
                    442:                                                                \\
                    443:     /* if we have a new 32-bit word to read: */                        \\
                    444:     if (bits <= 32) {                                          \\
                    445:       next = *raw;                                             \\
                    446:       if (*TME_FB_XLAT_SRC_OLD(raw) != next) {                 \\
                    447:         *TME_FB_XLAT_SRC_OLD(raw) = next;                      \\
                    448:         xlat_run = TME_FB_XLAT_RUN;                            \\
                    449:       }                                                                \\
                    450:       raw++;                                                   \\
                    451:       next = (order == TME_ENDIAN_BIG                          \\
                    452:               ? tme_betoh_u32(next)                            \\
                    453:               : tme_letoh_u32(next));                          \\
                    454:                                                                \\
                    455:       /* before the load, if there were fewer than 32 bits     \\
                    456:          remaining in the FIFO, shift bits from the word       \\
                    457:          we just loaded into their proper positions: */                \\
                    458:       if (bits < 32) {                                         \\
                    459:         if (order == TME_ENDIAN_BIG) {                         \\
                    460:           fifo |= (next >> bits);                              \\
                    461:           next <<= (32 - bits);                                        \\
                    462:         }                                                      \\
                    463:         else {                                                 \\
                    464:           fifo |= (next << bits);                              \\
                    465:           next >>= (32 - bits);                                        \\
                    466:         }                                                      \\
                    467:       }                                                                \\
                    468:                                                                \\
                    469:       /* there are now 32 more bits in the FIFO: */            \\
                    470:       bits += 32;                                              \\
                    471:     }                                                          \\
                    472:   }                                                            \\
                    473:                                                                \\
                    474:   /* otherwise, if the source FIFO is always 32-bit aligned: */ \\
                    475:   else {                                                        \\
                    476:                                                                 \\
                    477:     /* we must be shifting exactly 32 bits: */                  \\
                    478:     assert((shift) == 32);                                      \\
                    479:                                                                 \\
                    480:     /* load the next 32-bit word: */                            \\
                    481:     fifo = *raw;                                                \\
                    482:     if (*TME_FB_XLAT_SRC_OLD(raw) != fifo) {                    \\
                    483:       *TME_FB_XLAT_SRC_OLD(raw) = fifo;                         \\
                    484:       xlat_run = TME_FB_XLAT_RUN;                               \\
                    485:     }                                                           \\
                    486:     raw++;                                                      \\
                    487:     fifo = (order == TME_ENDIAN_BIG                             \\
                    488:             ? tme_betoh_u32(fifo)                               \\
                    489:             : tme_letoh_u32(fifo));                             \\
                    490:   }                                                             \\
                    491: } while (/* CONSTCOND */ 0)
                    492: 
                    493: /* this shifts a destination FIFO: */
                    494: #define TME_FB_XLAT_SHIFT_DST(unaligned, fifo, next, bits, shift, raw, order)\\
                    495: do {                                                           \\
                    496:                                                                \\
                    497:   /* if the destination FIFO may not be 32-bit aligned: */      \\
                    498:   if (unaligned) {                                             \\
                    499:                                                                \\
                    500:     /* we must be shifting between 1 and 32 bits: */           \\
                    501:     assert ((shift) >= 1 && (shift) <= 32);                    \\
                    502:                                                                \\
                    503:     /* the FIFO must have fewer than 32 bits in it: */         \\
                    504:     assert (bits < 32);                                                \\
                    505:                                                                \\
                    506:     /* shift the FIFO: */                                      \\
                    507:     if (order == TME_ENDIAN_BIG) {                             \\
                    508:       next |= (fifo >> bits);                                  \\
                    509:       fifo <<= (32 - bits);                                    \\
                    510:     }                                                          \\
                    511:     else {                                                     \\
                    512:       next |= (fifo << bits);                                  \\
                    513:       fifo >>= (32 - bits);                                    \\
                    514:     }                                                          \\
1.1.1.3   root      515:     if (SHIFTMAX_INT32_T < 32 && bits == 0) {                  \\
                    516:       fifo = 0;                                                        \\
                    517:     }                                                          \\
1.1       root      518:     bits += (shift);                                           \\
                    519:                                                                \\
                    520:     /* if we have a completed 32-bit word to write: */         \\
                    521:     if (bits >= 32) {                                          \\
                    522:       *(raw++) = (order == TME_ENDIAN_BIG                      \\
                    523:                   ? tme_htobe_u32(next)                                \\
                    524:                   : tme_htole_u32(next));                      \\
                    525:       bits -= 32;                                              \\
                    526:       assert(bits != 0 || fifo == 0);                          \\
                    527:       next = fifo;                                             \\
                    528:     }                                                          \\
                    529:   }                                                            \\
                    530:                                                                \\
                    531:   /* the destination FIFO is always 32-bit aligned: */         \\
                    532:   else {                                                       \\
                    533:                                                                \\
                    534:     /* we must be shifting exactly 32 bits: */                  \\
                    535:     assert((shift) == 32);                                      \\
                    536:                                                                 \\
                    537:     /* store the next 32-bit word: */                           \\
                    538:     *(raw++) = (order == TME_ENDIAN_BIG                         \\
                    539:                 ? tme_htobe_u32(fifo)                           \\
                    540:                 : tme_htole_u32(fifo));                         \\
                    541:                                                                 \\
                    542:   }                                                            \\
                    543:                                                                 \\
                    544:   /* clear the writable part of the FIFO: */                   \\
                    545:   fifo = 0;                                                    \\
                    546: } while (/* CONSTCOND */ 0)
1.1.1.2   root      547: 
                    548: /* _TME_FB_XLAT_MAP_LINEAR_SCALE gives the factor needed to scale a
                    549:    masked value up or down to a given size in bits.  for example, if a
                    550:    value's mask is 0xf800 (a five bit mask), and the value needs to be
                    551:    scaled up to seven bits, this gives an factor of four.  if a
                    552:    value's mask is 0x7e0 (a six bit mask), and the value needs to be
                    553:    scaled down to three bits, this gives a factor of eight: */
                    554: #define _TME_FB_XLAT_MAP_LINEAR_SCALE(mask_in, mask_out)       \\
                    555:   (TME_FB_XLAT_MAP_BASE_MASK(mask_in)                          \\
                    556:    ^ TME_FB_XLAT_MAP_BASE_MASK(mask_out))
                    557: #define TME_FB_XLAT_MAP_LINEAR_SCALE(mask_in, mask_out)        \\
                    558:   (_TME_FB_XLAT_MAP_LINEAR_SCALE(mask_in, mask_out)            \\
                    559:    ? (TME_FB_XLAT_MAP_BASE_MASK(_TME_FB_XLAT_MAP_LINEAR_SCALE(mask_in, mask_out))\\
                    560:       + 1)                                                     \\
                    561:    : 1)
                    562: 
                    563: /* this linearly maps a value from one mask to another: */
                    564: #define _TME_FB_XLAT_MAP_LINEAR(value, mask_in, mask_out)      \\
                    565:                                                                \\
                    566:   /* if the value does not need to be scaled up: */            \\
                    567:   (((TME_FB_XLAT_MAP_BASE_MASK(mask_out)                       \\
                    568:      <= TME_FB_XLAT_MAP_BASE_MASK(mask_in))                    \\
                    569:     ?                                                          \\
                    570:                                                                \\
                    571:     /* extract the value and scale it down: */                 \\
                    572:     (TME_FIELD_MASK_EXTRACTU(value, mask_in)                   \\
                    573:      / TME_FB_XLAT_MAP_LINEAR_SCALE(mask_in, mask_out))                \\
                    574:                                                                \\
                    575:     /* otherwise, the value needs to be scaled up: */          \\
                    576:     :                                                          \\
                    577:                                                                \\
                    578:     /* extract the value: */                                   \\
                    579:     ((TME_FIELD_MASK_EXTRACTU(value, mask_in)                  \\
                    580:                                                                \\
                    581:       /* scale it up: */                                       \\
                    582:       * TME_FB_XLAT_MAP_LINEAR_SCALE(mask_in, mask_out))       \\
                    583:                                                                \\
                    584:      /* if the least significant bit of the value is set, add  \\
                    585:        in the scale minus one.  this makes the linear mapping  \\
                    586:        at least cover the entire range: */                     \\
                    587:      + (((value /                                              \\
                    588:          _TME_FIELD_MASK_FACTOR(mask_in))                      \\
                    589:         & 1)                                                   \\
                    590:        * (TME_FB_XLAT_MAP_LINEAR_SCALE(mask_in, mask_out)      \\
                    591:           - 1))))                                              \\
                    592:                                                                \\
                    593:    /* finally, shift the value into position: */               \\
                    594:    * _TME_FIELD_MASK_FACTOR(mask_out))
                    595: 
                    596: /* this indexes a value: */
                    597: #define _TME_FB_XLAT_MAP_INDEX(value, mask_out, index)         \\
                    598:                                                                \\
                    599:   /* intensities are either stored as 8 or 16 bits: */         \\
                    600:   (((TME_FB_XLAT_MAP_BASE_MASK(mask_out) <= 0xff)              \\
                    601:     ? ((const tme_uint8_t *) (index))[(value)]                 \\
                    602:     : ((const tme_uint16_t *) (index))[(value)])               \\
                    603:                                                                \\
                    604:    /* shift the value into position: */                                \\
                    605:    * _TME_FIELD_MASK_FACTOR(mask_out))
                    606: 
                    607: /* this maps one subfield or intensity value into another subfield or
                    608:    intensity value: */
                    609: #define TME_FB_XLAT_MAP(value, mask_in, mask_out, indexed, index)\\
                    610:                                                                \\
                    611:   /* do the linear mapping or the index mapping: */            \\
                    612:   ((!(indexed))                                                        \\
                    613:    ? _TME_FB_XLAT_MAP_LINEAR(value, mask_in, mask_out)         \\
                    614:    : _TME_FB_XLAT_MAP_INDEX(TME_FIELD_MASK_EXTRACTU(value, mask_in), mask_out, index))
1.1       root      615: EOF
                    616: 
                    617: # the next function number:
                    618: xlat_next=0
                    619: xlat_array=
                    620: 
                    621: # permute over the source possibilities:
                    622: for src_key in ${src_all}; do
                    623: 
                    624:     # take apart the source possibility:
                    625:     src_parts=${src_key}
                    626: 
                    627:     # get the width:
                    628:         width=`echo ${src_parts} | sed -e 's/^\([0-9][0-9]*\)\(.*\)$/\1/'`
                    629:     src_parts=`echo ${src_parts} | sed -e 's/^\([0-9][0-9]*\)\(.*\)$/\2/'`
                    630:     
                    631:     # get the height:
                    632:        height=`echo ${src_parts} | sed -e 's/^x\([0-9][0-9]*\)\(.*\)$/\1/'`
                    633:     src_parts=`echo ${src_parts} | sed -e 's/^x\([0-9][0-9]*\)\(.*\)$/\2/'`
                    634: 
                    635:     # get the source depth:
                    636:     src_depth=`echo ${src_parts} | sed -e 's/^d\([0-9][0-9]*\)\(.*\)$/\1/'`
                    637:     src_parts=`echo ${src_parts} | sed -e 's/^d\([0-9][0-9]*\)\(.*\)$/\2/'`
                    638: 
                    639:     # get the source bits per pixel:
                    640:      src_bipp=`echo ${src_parts} | sed -e 's/^b\([0-9][0-9]*\)\(.*\)$/\1/'`
                    641:     src_parts=`echo ${src_parts} | sed -e 's/^b\([0-9][0-9]*\)\(.*\)$/\2/'`
                    642: 
                    643:     # get the source skip pixel count:
                    644:     src_skipx=`echo ${src_parts} | sed -e 's/^s\([_0-9][0-9]*\)\(.*\)$/\1/'`
                    645:     src_parts=`echo ${src_parts} | sed -e 's/^s\([_0-9][0-9]*\)\(.*\)$/\2/'`
                    646:     
                    647:     # get the source scanline pad:
                    648:       src_pad=`echo ${src_parts} | sed -e 's/^p\([0-9][0-9]*\)\(.*\)$/\1/'`
                    649:     src_parts=`echo ${src_parts} | sed -e 's/^p\([0-9][0-9]*\)\(.*\)$/\2/'`
                    650: 
                    651:     # get the source "order" - i.e., byte order and leftmost (first)
                    652:     # pixel significance:
                    653:     src_order=`echo ${src_parts} | sed -e 's/^o\([ml]\)\(.*\)$/\1/'`
                    654:     src_parts=`echo ${src_parts} | sed -e 's/^o\([ml]\)\(.*\)$/\2/'`
                    655: 
1.1.1.2   root      656:     # get the optional source "class" - monochrome or color:
                    657:     src_class=`echo ${src_parts} | sed -e 's/^c\([mc]\)\(.*\)$/\1/'`
                    658:     if test "x${src_class}" = "x${src_parts}"; then src_class= ; fi
                    659:     src_parts=`echo ${src_parts} | sed -e 's/^c\([mc]\)\(.*\)$/\2/'`
                    660: 
                    661:     # get the optional source pixel mapping - linear or indexed, and
                    662:     # the optional number of bits in the map range:
                    663:       src_map=`echo ${src_parts} | sed -e 's/^m\([li]\)\([0-9]*\)\(.*\)$/\1/'`
                    664:     src_map_bits=`echo ${src_parts} | sed -e 's/^m\([li]\)\([0-9]*\)\(.*\)$/\2/'`
                    665:     if test "x${src_map}" = "x${src_parts}"; then src_map= ; src_map_bits= ; fi
                    666:     src_parts=`echo ${src_parts} | sed -e 's/^m\([li]\)\([0-9]*\)\(.*\)$/\3/'`
                    667: 
                    668:     # get the optional source pixel subfield masks:
                    669:     src_mask_g= ; src_mask_r= ; src_mask_b=
                    670:     while true; do
                    671:        src_mask=`echo ${src_parts} | sed -e 's/^\(_[rgb]\)\(0x[0-9A-Fa-f][0-9A-Fa-f]*\)\(.*\)$/src_mask\1=\2/'`
                    672:        if test "x${src_mask}" = "x${src_parts}"; then break; fi
                    673:        eval ${src_mask}
                    674:        src_parts=`echo ${src_parts} | sed -e 's/^\(_[rgb]\)\(0x[0-9A-Fa-f][0-9A-Fa-f]*\)\(.*\)$/\3/'`
                    675:     done
                    676: 
1.1       root      677:     # get the source scaling:
                    678:     scale="${src_parts}_"
                    679: 
1.1.1.2   root      680:     # if the source class is not given, but the source depth is
                    681:     # known, assume monochrome if the source depth is one, else
                    682:     # assume color:
                    683:     #
                    684:     if test "x${src_class}" = x; then 
                    685:        case "${src_depth}" in
                    686:        0) src_class= ;;
                    687:        1) src_class=m ;;
                    688:        *) src_class=c ;;
                    689:        esac
                    690:     fi
                    691: 
                    692:     # if the source mapping type is not given:
                    693:     #
                    694:     if test "x${src_map}" = x; then
                    695:        
                    696:        # if the source class is known as color:
                    697:        #
                    698:        if test "x${src_class}" = "xc"; then
                    699: 
                    700:            # if it is known that there are not any subfield masks, assume an indexed
                    701:            # mapping, else if it is known that there are subfield masks, assume a
                    702:            # linear mapping:
                    703:            #
                    704:            case "x${src_mask_r}" in
                    705:            x0x0) ;;
                    706:            x) src_map=i ;;
                    707:            *) src_map=l ;;
                    708:            esac
                    709:        
                    710:        # if the source class is known as monochrome:
                    711:        #
                    712:        elif test "x${src_class}" = "xm"; then
                    713: 
                    714:            # assume a linear mapping:
                    715:            #
                    716:            src_map=l
                    717:        fi
                    718:     fi
                    719:     
                    720:     # if the size of the source mapping range in bits is not given:
                    721:     #
                    722:     if test "x${src_map_bits}" = x; then
                    723: 
                    724:        # if the source class is known as mono and the source mapping
                    725:        # type is known as linear, assume that the source depth is the
                    726:        # size of the mapping range in bits:
                    727:        #
                    728:        if test "x${src_class}" = xm && test "x${src_map}" = xl; then
                    729:            src_map_bits=${src_depth}
                    730: 
                    731:        # otherwise, set the size of the mapping range to zero to indicate
                    732:        # unknown:
                    733:        #
                    734:        else
                    735:            src_map_bits=0
                    736:        fi
                    737:     fi
                    738: 
1.1       root      739:     # permute over the destination possibilities:
                    740:     for dst_key in ${dst_all}; do
                    741: 
                    742:        # take apart the destination possibility:
                    743:        dst_parts=${dst_key}
                    744: 
                    745:        # get the destination depth:
                    746:        dst_depth=`echo ${dst_parts} | sed -e 's/^d\([0-9][0-9]*\)\(.*\)$/\1/'`
                    747:        dst_parts=`echo ${dst_parts} | sed -e 's/^d\([0-9][0-9]*\)\(.*\)$/\2/'`
                    748: 
                    749:        # get the destination bits per pixel:
                    750:         dst_bipp=`echo ${dst_parts} | sed -e 's/^b\([0-9][0-9]*\)\(.*\)$/\1/'`
                    751:        dst_parts=`echo ${dst_parts} | sed -e 's/^b\([0-9][0-9]*\)\(.*\)$/\2/'`
                    752:     
                    753:        # get the destination skip pixel count:
                    754:        dst_skipx=`echo ${dst_parts} | sed -e 's/^s\([_0-9][0-9]*\)\(.*\)$/\1/'`
                    755:        dst_parts=`echo ${dst_parts} | sed -e 's/^s\([_0-9][0-9]*\)\(.*\)$/\2/'`
                    756:     
                    757:        # get the destination scanline pad:
                    758:          dst_pad=`echo ${dst_parts} | sed -e 's/^p\([0-9][0-9]*\)\(.*\)$/\1/'`
                    759:        dst_parts=`echo ${dst_parts} | sed -e 's/^p\([0-9][0-9]*\)\(.*\)$/\2/'`
                    760: 
                    761:        # get the destination "order" - i.e., byte order and leftmost
                    762:        # (first) pixel significance:
                    763:        dst_order=`echo ${dst_parts} | sed -e 's/^o\([ml]\)\(.*\)$/\1/'`
                    764:        dst_parts=`echo ${dst_parts} | sed -e 's/^o\([ml]\)\(.*\)$/\2/'`
                    765: 
1.1.1.2   root      766:        # get the optional destination pixel mapping - linear or indexed:
                    767:          dst_map=`echo ${dst_parts} | sed -e 's/^m\([li]\)\(.*\)$/\1/'`
                    768:        if test "x${dst_map}" = "x${dst_parts}"; then dst_map= ; fi
                    769:        dst_parts=`echo ${dst_parts} | sed -e 's/^m\([li]\)\(.*\)$/\2/'`
                    770: 
                    771:        # get the optional destination pixel subfield masks:
                    772:        dst_mask_g= ; dst_mask_r= ; dst_mask_b=
                    773:        while true; do
                    774:            dst_mask=`echo ${dst_parts} | sed -e 's/^\(_[rgb]\)\(0x[0-9A-Fa-f][0-9A-Fa-f]*\)\(.*\)$/dst_mask\1=\2/'`
                    775:            if test "x${dst_mask}" = "x${dst_parts}"; then break; fi
                    776:            eval ${dst_mask}
                    777:            dst_parts=`echo ${dst_parts} | sed -e 's/^\(_[rgb]\)\(0x[0-9A-Fa-f][0-9A-Fa-f]*\)\(.*\)$/\3/'`
                    778:        done
1.1       root      779: 
                    780:        # allocate the xlat number:
                    781:        xlat=${xlat_next}
                    782:        xlat_next=`expr ${xlat_next} + 1`
                    783:        xlat_info="tme_fb_xlat${xlat}"
                    784: 
                    785:        # start the function:
                    786:        echo ""
                    787:        echo "/* this translates frame buffer contents from this source format:"
                    788:        case "${width}x${height}" in
                    789:        0x0) echo -n "     any dimensions" ;;
                    790:        *x0) echo -n "     width $width, any height" ;;
                    791:        0x*) echo -n "     any width, height ${height}" ;;
                    792:        *)   echo -n "     ${width}x${height}" ;;
                    793:        esac
                    794:        xlat_info="${xlat_info}, ${width}, ${height}"
                    795:        case ${scale} in
                    796:        _h_) echo " (image will be halved)" ; value="HALF" ;;
                    797:        _d_) echo " (image will be doubled)" ; value="DOUBLE" ;;
                    798:        *) echo "" ; value="NONE" ;;
                    799:        esac
                    800:        xlat_info="${xlat_info}, TME_FB_XLAT_SCALE_${value}"
                    801:        echo -n "     "
                    802:        case ${src_depth} in
                    803:        0)  echo -n "any depth" ;;
                    804:        1)  echo -n "1 bit deep" ;;
                    805:        *)  echo -n "${src_depth} bits deep" ;;
                    806:        esac
                    807:        xlat_info="${xlat_info}, ${src_depth}"
                    808:        case ${src_bipp} in
                    809:        0)  echo -n ", any bits per pixel" ;;
                    810:        1)  echo -n ", 1 bit per pixel" ;;
                    811:        *)  echo -n ", ${src_bipp} bits per pixel" ;;
                    812:        esac
                    813:        xlat_info="${xlat_info}, ${src_bipp}"
                    814:        case ${src_skipx} in
                    815:        _) echo -n ", any number of pixels skipped" ; value="-1";;
                    816:        *) echo -n ", ${src_skipx} pixels skipped" ; value=${src_skipx} ;;
                    817:        esac
                    818:        xlat_info="${xlat_info}, ${value}"
                    819:        case ${src_pad} in
                    820:        0)  echo -n ", any scanline padding" ;;
                    821:        *)  echo -n ", ${src_pad}-bit scanline padding" ;;
                    822:        esac
                    823:        xlat_info="${xlat_info}, ${src_pad}"
                    824:        case ${src_order} in
                    825:        m)  echo -n ", MSB-first" ; value="BIG" ;;
                    826:        l)  echo -n ", LSB-first" ; value="LITTLE" ;;
                    827:        esac
                    828:        xlat_info="${xlat_info}, TME_ENDIAN_${value}"
1.1.1.2   root      829:        case "x${src_class}" in
                    830:        xm)  echo -n ", monochrome" ; value="MONOCHROME" ;;
                    831:        xc)  echo -n ", color" ; value="COLOR" ;;
                    832:        *)   echo -n ", either color or monochrome" ; value="ANY" ;;
                    833:        esac
                    834:        xlat_info="${xlat_info}, TME_FB_XLAT_CLASS_${value}"
                    835:        case "x${src_map}" in
                    836:        xl)  echo -n ", linearly mapped pixels" ; value="LINEAR" ;;
                    837:        xi)  echo -n ", index mapped pixels" ; value="INDEX" ;;
                    838:        *)   echo -n ", any pixel mapping" ; value="ANY" ;;
                    839:        esac
                    840:        xlat_info="${xlat_info}, TME_FB_XLAT_MAP_${value}"
                    841:        value=${src_map_bits}
                    842:        case "${src_map_bits}" in
                    843:        0)   echo -n ", any bits per mapped intensity" ;;
                    844:        1)   echo -n ", 1 bit per mapped intensity" ;;
                    845:        *)   echo -n ", ${src_map_bits} bits per mapped intensity" ;;
                    846:        esac
                    847:        xlat_info="${xlat_info}, ${value}"
                    848:        for primary in g r b; do
                    849:            eval "src_mask=\$src_mask_${primary}"
                    850:            case "x${src_mask}" in
                    851:            x)  echo -n ", no ${primary} mask" ; value=0 ;;
                    852:            x0x0) echo -n ", any ${primary} mask" ; value=TME_FB_XLAT_MASK_ANY ;;
                    853:            *)  echo -n ", a ${primary} mask of ${src_mask}" ; value=${src_mask} ;;
                    854:            esac
                    855:            xlat_info="${xlat_info}, ${value}"
                    856:        done
1.1       root      857:        echo ""
                    858:        echo "   to this destination format:"
                    859:        echo -n "     "
                    860:        case ${dst_depth} in
                    861:        0)  echo -n "any depth" ;;
                    862:        1)  echo -n "1 bit deep" ;;
                    863:        *)  echo -n "${dst_depth} bits deep" ;;
                    864:        esac
                    865:        xlat_info="${xlat_info}, ${dst_depth}"
                    866:        case ${dst_bipp} in
                    867:        0)  echo -n ", any bits per pixel" ;;
                    868:        1)  echo -n ", 1 bit per pixel" ;;
                    869:        *)  echo -n ", ${dst_bipp} bits per pixel" ;;
                    870:        esac
                    871:        xlat_info="${xlat_info}, ${dst_bipp}"
                    872:        case ${dst_skipx} in
                    873:        _) echo -n ", any number of pixels skipped" ; value="-1";;
                    874:        *) echo -n ", ${dst_skipx} pixels skipped" ; value=${dst_skipx} ;;
                    875:        esac
                    876:        xlat_info="${xlat_info}, ${value}"
                    877:        case ${dst_pad} in
                    878:        0)  echo -n ", any scanline padding" ;;
                    879:        *)  echo -n ", ${dst_pad}-bit scanline padding" ;;
                    880:        esac
                    881:        xlat_info="${xlat_info}, ${dst_pad}"
                    882:        case ${dst_order} in
                    883:        m)  echo -n ", MSB-first" ; value="BIG" ;;
                    884:        l)  echo -n ", LSB-first" ; value="LITTLE" ;;
                    885:        esac
                    886:        xlat_info="${xlat_info}, TME_ENDIAN_${value}"
1.1.1.2   root      887:        case "x${dst_map}" in
                    888:        xl)  echo -n ", linearly mapped pixels" ; value="LINEAR" ;;
                    889:        xi)  echo -n ", index mapped pixels" ; value="INDEX" ;;
                    890:        *)   echo -n ", any pixel mapping" ; value="ANY" ;;
                    891:        esac
                    892:        xlat_info="${xlat_info}, TME_FB_XLAT_MAP_${value}"
                    893:        for primary in g r b; do
                    894:            eval "dst_mask=\$dst_mask_${primary}"
                    895:            case "x${dst_mask}" in
                    896:            x)  echo -n ", no ${primary} mask" ; value=0 ;;
                    897:            x0x0) echo -n ", any ${primary} mask" ; value=TME_FB_XLAT_MASK_ANY ;;
                    898:            *)  echo -n ", a ${primary} mask of ${dst_mask}" ; value=${dst_mask} ;;
                    899:            esac
                    900:            xlat_info="${xlat_info}, ${value}"
                    901:        done
1.1       root      902:        save_IFS=$IFS
                    903:        IFS=
                    904:        xlat_array="${xlat_array}
                    905:   { $xlat_info }, "
                    906:        IFS=$save_IFS
                    907:        echo ""
                    908:        echo "*/"
                    909:        echo "static int"
                    910:        echo "tme_fb_xlat${xlat}(struct tme_fb_connection *src,"
                    911:        echo "             struct tme_fb_connection *dst)"
                    912:        echo "{"
                    913:        undef_macros=
                    914: 
                    915:        echo ""
                    916:        echo "  /* whenever possible we define macros instead of declaring"
                    917:        echo "     variables, for optimization: */"
                    918: 
                    919:        echo ""
                    920:        echo "  /* declare src_x and src_y.  these are the current translation"
                    921:        echo "     coordinates in the source image: */"
                    922:        echo "  unsigned int src_x, src_y;"
                    923: 
                    924:        echo ""
                    925:        echo "  /* declare dst_x and dst_y.  these are the current translation"
                    926:        echo "     coordinates in the destination image.  since this function"
                    927:        if test $scale = _; then
                    928:            echo "     does not scale the image, these coordinates are always"
                    929:            echo "     the same as the coordinates in the source image: */"
                    930:            echo "#define dst_x (src_x)"
                    931:            echo "#define dst_y (src_y)"
                    932:            undef_macros="${undef_macros} dst_x dst_y"
                    933:            scale_op=
                    934:            scale_math=
                    935:        else
                    936:            if test $scale = _h_; then
                    937:                scale_op='/'
                    938:                scale_name='halves'
                    939:            else
                    940:                scale_op='*'
                    941:                scale_name='doubles'
                    942:            fi
                    943:            scale_math=" ${scale_op} 2"
                    944:            echo "     ${scale_name} the image, the coordinates in the destination image"
                    945:            echo "     are always the coordinates in the source image${scale_math}: */"
                    946:            echo "  unsigned int dst_x, dst_y;"
                    947:        fi
                    948: 
                    949:        echo ""
                    950:        echo "  /* declare pixel.  this holds a single pixel value being translated"
                    951:        echo "     for the destination image: */"
                    952:        echo "  tme_uint32_t pixel;"
                    953: 
                    954:        echo ""
                    955:        echo "  /* declare src_width and dst_width.  these are in terms of pixels: */"
                    956:        value="(src_width${scale_math})"        
                    957:        if test ${width} = 0; then
                    958:            echo "  const unsigned int src_width = src->tme_fb_connection_width;"
                    959:            if test $scale != _; then
                    960:                echo "  const unsigned int dst_width = ${value};"
                    961:            else
                    962:                echo "#define dst_width ${value}"
                    963:                undef_macros="${undef_macros} dst_width"
                    964:            fi
                    965:        else
                    966:            echo "#define src_width (${width})"
                    967:            echo "#define dst_width ${value}"
                    968:            undef_macros="${undef_macros} src_width dst_width"
                    969:        fi
                    970: 
                    971:        echo ""
                    972:        echo "  /* declare src_depth, the source pixel depth, which is in"
                    973:        echo "     terms of bits.  declare src_mask, which is the corresponding"
                    974:        echo "     mask of one bits: */"
                    975:        value="(0xffffffff >> (32 - src_depth))"
                    976:        if test ${src_depth} = 0; then
                    977:            echo "  const unsigned int src_depth = src->tme_fb_connection_depth;"
                    978:            echo "  const tme_uint32_t src_mask = ${value};"
                    979:        else
                    980:            echo "#define src_depth (${src_depth})"
                    981:            echo "#define src_mask ${value}"
                    982:            undef_macros="${undef_macros} src_depth src_mask"
                    983:        fi
                    984: 
1.1.1.2   root      985:        # if we are halving, or if source pixels may have subfields,
                    986:        # we may need to deal with intensities:
                    987:        #
                    988:        if test ${scale} = _h_ || test "x${src_mask_g}" != x; then
                    989: 
                    990:            echo ""
                    991:            echo "  /* declare src_indexed.  this is nonzero if source pixel subfields"
                    992:            echo "     are index-mapped into intensities: */"
                    993:            if test "x${src_map}" = x; then
                    994:                echo "  const unsigned int src_indexed = (src->tme_fb_connection_map_g != NULL);"
                    995:            else
                    996:                if test "x${src_map}" = xi; then value=TRUE; else value=FALSE; fi
                    997:                echo "#define src_indexed (${value})"
                    998:                undef_macros="${undef_macros} src_indexed"
                    999:            fi
                   1000: 
                   1001:            echo ""
                   1002:            echo "  /* declare src_mask_i, which is the mask for a source intensity: */"
                   1003:            if test "${src_map_bits}" = 0; then
                   1004:                echo "  const tme_uint32_t src_mask_i = (0xffffffff >> (32 - src->tme_fb_connection_map_bits));"
                   1005:            else
                   1006:                echo "#define src_mask_i (0xffffffff >> (32 - ${src_map_bits}))"
                   1007:                undef_macros="${undef_macros} src_mask_i"
                   1008:            fi
                   1009: 
                   1010:            if test "x${src_class}" != xm; then
                   1011:                echo ""
                   1012:                echo "  /* declare dst_indexed.  this is nonzero if intensities are index-mapped"
                   1013:                echo "     into destination pixel subfields: */"
                   1014:                if test "x${dst_map}" = x; then
                   1015:                    echo "  const unsigned int dst_indexed = (dst->tme_fb_connection_map_g != NULL);"
                   1016:                else
                   1017:                    if test "x${dst_map}" = xi; then value=TRUE; else value=FALSE; fi
                   1018:                    echo "#define dst_indexed (${value})"
                   1019:                    undef_macros="${undef_macros} dst_indexed"
                   1020:                fi
                   1021: 
                   1022:                echo ""
                   1023:                echo "  /* declare dst_masks_default.  this is nonzero if the destination"
                   1024:                echo "     subfield masks are the default: */"
                   1025:                if test "x${dst_mask_g}" = "x0x0"; then
                   1026:                    echo "  const unsigned int dst_masks_default = (dst->tme_fb_connection_mask_g == 0);"
                   1027:                else
                   1028:                    if test "x${dst_mask_g}" = x; then value=TRUE; else value=FALSE; fi
                   1029:                    echo "#define dst_masks_default (${value})"
                   1030:                    undef_macros="${undef_macros} dst_masks_default"
                   1031:                fi
                   1032:            fi
                   1033: 
                   1034:            for primary in g r b; do
                   1035:                primary_cap=`echo ${primary} | tr a-z A-Z`
                   1036:                echo ""
                   1037:                echo "  /* declare src_mask_${primary}, the mask for the ${primary} subfield in a source pixel: */"
                   1038:                eval "src_mask=\$src_mask_${primary}"
                   1039:                if test "x${src_mask}" = x0x0; then
                   1040:                    echo "  const tme_uint32_t src_mask_${primary}"
                   1041:                    echo "    = (src->tme_fb_connection_mask_${primary} != 0"
                   1042:                    echo "       ? src->tme_fb_connection_mask_${primary}"
                   1043:                    echo "       : src_mask);"
                   1044:                else
                   1045:                    if test "x${src_mask}" = x; then src_mask="src_mask"; fi
                   1046:                    echo "#define src_mask_${primary} (${src_mask})"
                   1047:                    undef_macros="${undef_macros} src_mask_${primary}"
                   1048:                fi
                   1049:                echo ""
                   1050:                echo "  /* declare value_${primary}, the intensity value for the ${primary} subfield in a pixel: */"
                   1051:                echo "  tme_uint32_t value_${primary};"
                   1052:                if test "x${src_class}" = xm; then break; fi
                   1053:                echo ""
                   1054:                echo "  /* declare dst_mask_${primary}, the mask for the ${primary} subfield in a destination pixel: */"
                   1055:                eval "dst_mask=\$dst_mask_${primary}"
                   1056:                if test "x${dst_mask}" = x0x0; then
                   1057:                    echo "  const tme_uint32_t dst_mask_${primary}"
                   1058:                    echo "    = (dst->tme_fb_connection_mask_${primary} != 0"
                   1059:                    echo "       ? dst->tme_fb_connection_mask_${primary}"
                   1060:                    echo "       : TME_FB_XLAT_MASK_DEFAULT_${primary_cap});"
                   1061:                else
                   1062:                    if test "x${dst_mask}" = x; then dst_mask="TME_FB_XLAT_MASK_DEFAULT_${primary_cap}"; fi
                   1063:                    echo "#define dst_mask_${primary} (${dst_mask})"
                   1064:                    undef_macros="${undef_macros} dst_mask_${primary}"
                   1065:                fi
                   1066:            done
                   1067:        fi
                   1068: 
1.1       root     1069:        echo ""
                   1070:        echo "  /* declare src_bipp and dst_bipp.  these are the bits-per-pixel"
                   1071:        echo "     values for the source and destination images: */"
                   1072:        if test ${src_bipp} = 0; then
                   1073:            echo "  const unsigned int src_bipp = src->tme_fb_connection_bits_per_pixel;"
                   1074:        else
                   1075:            echo "#define src_bipp (${src_bipp})"
                   1076:            undef_macros="${undef_macros} src_bipp"
                   1077:        fi
                   1078:        if test ${dst_bipp} = 0; then
                   1079:            echo "  const unsigned int dst_bipp = dst->tme_fb_connection_bits_per_pixel;"
                   1080:        else
                   1081:            echo "#define dst_bipp (${dst_bipp})"
                   1082:            undef_macros="${undef_macros} dst_bipp"
                   1083:        fi
                   1084: 
                   1085:        echo ""
                   1086:        echo "  /* declare src_skipx and dst_skipx.  these are the counts of"
                   1087:        echo "     undisplayed pixels at the beginning of each scanline in the"
                   1088:        echo "     source and destination images: */"
                   1089:        if test ${src_skipx} = _; then
                   1090:            echo "  const unsigned int src_skipx = src->tme_fb_connection_skipx;"
                   1091:        else
                   1092:            echo "#define src_skipx (${src_skipx})"
                   1093:            undef_macros="${undef_macros} src_skipx"
                   1094:        fi
                   1095:        if test ${dst_skipx} = _; then
                   1096:            echo "  const unsigned int dst_skipx = dst->tme_fb_connection_skipx;"
                   1097:        else
                   1098:            echo "#define dst_skipx (${dst_skipx})"
                   1099:            undef_macros="${undef_macros} dst_skipx"
                   1100:        fi
                   1101: 
                   1102:        echo ""
                   1103:        echo "  /* declare src_pad and dst_pad.  these are the paddings, in bits,"
                   1104:        echo "     of each scanline in the source and destination images: */"
                   1105:        if test ${src_pad} = 0; then
                   1106:            echo "  const unsigned int src_pad = src->tme_fb_connection_scanline_pad;"
                   1107:        else
                   1108:            echo "#define src_pad (${src_pad})"
                   1109:            undef_macros="${undef_macros} src_pad"
                   1110:        fi
                   1111:        if test ${dst_pad} = 0; then
                   1112:            echo "  const unsigned int dst_pad = dst->tme_fb_connection_scanline_pad;"
                   1113:        else
                   1114:            echo "#define dst_pad (${dst_pad})"
                   1115:            undef_macros="${undef_macros} dst_pad"
                   1116:        fi
                   1117: 
                   1118:        echo ""
                   1119:        echo "  /* declare src_order and dst_order.  these are the bit and byte"
                   1120:        echo "     orders (either TME_ENDIAN_BIG or TME_ENDIAN_LITTLE) of the"
                   1121:        echo "     source and destination images.  since these values profoundly"
                   1122:        echo "     affect optimization, they are always constant: */"
                   1123:        if test ${src_order} = m; then value=BIG; else value=LITTLE; fi
                   1124:        echo "#define src_order (TME_ENDIAN_${value})"
                   1125:        undef_macros="${undef_macros} src_order"
                   1126:        if test ${dst_order} = m; then value=BIG; else value=LITTLE; fi
                   1127:        echo "#define dst_order (TME_ENDIAN_${value})"
                   1128:        undef_macros="${undef_macros} dst_order"
                   1129: 
                   1130:        echo ""
                   1131:        echo "  /* declare src_bypl and dst_bypl.  these are the bytes per scanline"
                   1132:        echo "     in the source and destination images.  these values are calculated"
                   1133:        echo "     from the count of undisplayed and displayed pixels per scanline,"
                   1134:        echo "     the number of bits per pixel, and the scanline padding: */"
                   1135:        value="(((((src_skipx + src_width) * src_bipp) + (src_pad - 1)) & -src_pad) / 8)"
                   1136:        if test ${src_skipx} = _ || test ${width} = 0 || test ${src_bipp} = 0 || test ${src_pad} = 0; then
                   1137:            echo "  const unsigned int src_bypl = ${value};"
                   1138:            src_bypl_var=true
                   1139:        else
                   1140:            echo "#define src_bypl ${value}"
                   1141:            undef_macros="${undef_macros} src_bypl"
                   1142:            src_bypl_var=false
                   1143:        fi
                   1144:        value="(((((dst_skipx + dst_width) * dst_bipp) + (dst_pad - 1)) & -dst_pad) / 8)"
                   1145:        if test ${dst_skipx} = _ || test ${width} = 0 || test ${dst_bipp} = 0 || test ${dst_pad} = 0; then
                   1146:            echo "  const unsigned int dst_bypl = ${value};"
                   1147:            dst_bypl_var=true
                   1148:        else
                   1149:            echo "#define dst_bypl ${value}"
                   1150:            undef_macros="${undef_macros} dst_bypl"
                   1151:            dst_bypl_var=false
                   1152:        fi
                   1153: 
                   1154:        echo ""
                   1155:        echo "  /* declare src_packed and dst_packed.  these are nonzero iff"
                   1156:        echo "     every last bit in a scanline belongs to a displayed pixel."
                   1157:        echo "     put another way, this is zero iff a scanline has undisplayed"
                   1158:        echo "     pixels at its beginning or padding bits at its end.  when"
                   1159:        echo "     a source image or destination image is packed, translation"
                   1160:        echo "     doesn't have to worry about skipping FIFO bits to get to"
                   1161:        echo "     bits belonging to displayed pixels: */"
                   1162:        value="((src_width * src_bipp) == (src_bypl * 8))"
                   1163:        if $src_bypl_var; then
                   1164:            echo "  const unsigned int src_packed = ${value};"
                   1165:        else
                   1166:            echo "#define src_packed ${value}"
                   1167:            undef_macros="${undef_macros} src_packed"
                   1168:        fi
                   1169:        value="((dst_width * dst_bipp) == (dst_bypl * 8))"
                   1170:        if $dst_bypl_var; then
                   1171:            echo "  const unsigned int dst_packed = ${value};"
                   1172:        else
                   1173:            echo "#define dst_packed ${value}"
                   1174:            undef_macros="${undef_macros} dst_packed"
                   1175:        fi
                   1176: 
                   1177:        echo ""
                   1178:        echo "  /* declare src_bypb and src_bypb_real.  src_bypb is the bytes"
                   1179:        echo "     per source image buffer with the \"translation termination"
                   1180:        echo "     overhead\" of approximately two extra scanlines.  src_bypb_real"
                   1181:        echo "     is the real bytes per source image buffer with no overhead."
                   1182:        echo "     both values are padded to a multiple of 4 bytes (32 bits): */"
                   1183:        if test ${height} = 0; then
                   1184:            value="src->tme_fb_connection_height"
                   1185:        else
                   1186:            value="${height}"
                   1187:        fi
                   1188:        value_real="(((${value} * src_bypl) + 3) & -4)"
                   1189:        value="((src_bypb_real + (src_bypl * 2)) & -4)"
                   1190:        if test ${height} = 0 || $src_bypl_var; then
                   1191:            echo "  const unsigned int src_bypb_real = ${value_real};"
                   1192:            echo "  const unsigned int src_bypb = ${value};"
                   1193:        else
                   1194:            echo "#define src_bypb_real ${value_real}"
                   1195:            echo "#define src_bypb ${value}"
                   1196:            undef_macros="${undef_macros} src_bypb_real src_bypb"
                   1197:        fi
                   1198:        
                   1199:        echo ""
                   1200:        echo "  /* declare the source primary bit FIFO:"
                   1201:        echo ""
                   1202:        echo "     src_raw0 points to the next aligned 32-bit word to be"
                   1203:        echo "     read from the image buffer."
                   1204:        echo ""
                   1205:        echo "     src_fifo0 is the visible part of the bit FIFO."
                   1206:        echo ""
                   1207:        echo "     src_fifo0_next and src_fifo0_bits are only used when the"
                   1208:        echo "     visible part of the bit FIFO is not guaranteed to always"
                   1209:        echo "     correspond to an aligned 32-bit word in the image buffer."
                   1210:        echo "     src_fifo0_next is the invisible part of the bit FIFO,"
                   1211:        echo "     and src_fifo0_bits tracks the total number of bits in the"
                   1212:        echo "     visible and invisible parts of the FIFO. */"
                   1213:        echo "  const tme_uint32_t *src_raw0;"
                   1214:        echo "  tme_uint32_t src_fifo0, src_fifo0_next;"
                   1215:        echo "  unsigned int src_fifo0_bits;"
                   1216: 
                   1217:        if test ${scale} = _h_; then
                   1218:            echo ""
                   1219:            echo "  /* since this function ${scale_name} the image, declare the"
                   1220:            echo "     source secondary bit FIFO.  these variables work in "
                   1221:            echo "     exactly the same way that their primary counterparts do: */"
                   1222:            echo "  const tme_uint32_t *src_raw1;"
                   1223:            echo "  tme_uint32_t src_fifo1, src_fifo1_next;"
                   1224:            echo "  unsigned int src_fifo1_bits;"
                   1225:        fi
                   1226: 
                   1227:        echo ""
                   1228:        echo "  /* declare the destination primary bit FIFO:"
                   1229:        echo ""
                   1230:        echo "     dst_raw0 points to the next aligned 32-bit word to be"
                   1231:        echo "     written into the image buffer."
                   1232:        echo ""
                   1233:        echo "     dst_fifo0 is the visible part of the bit FIFO."
                   1234:        echo ""
                   1235:        echo "     dst_fifo0_next and dst_fifo0_bits are only used when the"
                   1236:        echo "     visible part of the bit FIFO is not guaranteed to always"
                   1237:        echo "     correspond to an aligned 32-bit word in the image buffer."
                   1238:        echo "     dst_fifo0_next is the invisible part of the bit FIFO,"
                   1239:        echo "     and dst_fifo0_bits tracks the total number of bits in the"
                   1240:        echo "     invisible part of the FIFO. */"
                   1241:        echo "  tme_uint32_t *dst_raw0;"
                   1242:        echo "  tme_uint32_t dst_fifo0, dst_fifo0_next;"
                   1243:        echo "  unsigned int dst_fifo0_bits;"
                   1244: 
                   1245:        if test ${scale} = _d_; then
                   1246:            echo ""
                   1247:            echo "  /* since this function ${scale_name} the image, declare"
                   1248:            echo "     the destination secondary bit FIFO.  these variables work"
                   1249:            echo "     in exactly the same way that their primary counterparts"
                   1250:            echo "     do: */"
                   1251:            echo "  tme_uint32_t *dst_raw1;"
                   1252:            echo "  tme_uint32_t dst_fifo1, dst_fifo1_next;"
                   1253:            echo "  unsigned int dst_fifo1_bits;"
                   1254:        fi
                   1255: 
                   1256:        echo ""
                   1257:        echo "  /* declare src_off and dst_off.  these are used when priming a"
                   1258:        echo "     source or destination bit FIFO, to identify an initial aligned"
                   1259:        echo "     32-bit word in the source or destination image buffer, and an"
                   1260:        echo "     initial bit offset within that word: */"
                   1261:        echo "  unsigned int src_off, dst_off;"
                   1262: 
                   1263:        echo ""
                   1264:        echo "  /* declare src_fifo0_may_be_unaligned.  this is zero iff all"
                   1265:        echo "     aligned 32-bit words in the source buffer contain a whole"
1.1.1.2   root     1266:        echo "     number of displayed pixels, and at *all times during the"
                   1267:        echo "     translation* the visible part of the bit FIFO is guaranteed"
                   1268:        echo "     to correspond to an aligned 32-bit word in the image buffer."
                   1269:        echo ""
                   1270:        echo "     this is *not* so if any of the following are true:"
                   1271:        echo ""
                   1272:        echo "     - the source bits-per-pixel value is not known at compile"
                   1273:        echo "       time.  in this case, we can't unroll the translation loop"
                   1274:        echo "       for source pixels, and are forced to shift the FIFO after"
                   1275:        echo "       each one."
                   1276:        echo ""
                   1277:        echo "     - if the source image is not packed.  in this case, there may"
                   1278:        echo "       be undisplayed pixels in the FIFO, which we will need to"
                   1279:        echo "       shift out."
                   1280:        echo ""
                   1281:        echo "     - if there are 24 bits per source pixel.  in this case, a"
                   1282:        echo "       source pixel may cross a 32-bit boundary: */"
                   1283:        src_fifo0_may_be_unaligned_var=false
                   1284:        if test ${src_bipp} = 0; then
                   1285:            value=TRUE
                   1286:        else
                   1287:            value="(!src_packed || (src_bipp == 24))"
                   1288:            src_fifo0_may_be_unaligned_var=${src_bypl_var}
                   1289:        fi
                   1290:        if $src_fifo0_may_be_unaligned_var; then
1.1       root     1291:            echo "  const unsigned int src_fifo0_may_be_unaligned = ${value};"
                   1292:        else
                   1293:            echo "#define src_fifo0_may_be_unaligned ${value}"
                   1294:            undef_macros="${undef_macros} src_fifo0_may_be_unaligned"
                   1295:        fi
                   1296: 
                   1297:        if test $scale = _h_; then
                   1298:            echo ""
                   1299:            echo "  /* declare src_fifo1_may_be_unaligned.  this is zero iff all"
                   1300:            echo "     aligned 32-bit words in the source buffer contain a"
                   1301:            echo "     whole number of displayed pixels, *and* for every aligned"
                   1302:            echo "     32-bit word on one scanline all other scanlines have an"
                   1303:            echo "     aligned 32-bit word corresponding to the same x coordinate: */"
                   1304:            value="(src_fifo0_may_be_unaligned || (src_bypl & 3))"
                   1305:            if $src_bypl_var; then
                   1306:                echo "  const unsigned int src_fifo1_may_be_unaligned = ${value};"
                   1307:            else
                   1308:                echo "#define src_fifo1_may_be_unaligned ${value}"
                   1309:                undef_macros="${undef_macros} src_fifo1_may_be_unaligned"
                   1310:            fi
                   1311:        fi
                   1312: 
                   1313:        echo ""
1.1.1.2   root     1314:        echo "  /* declare dst_fifo0_may_be_unaligned.  this is zero iff all"
                   1315:        echo "     aligned 32-bit words in the destination buffer contain a whole"
                   1316:        echo "     number of displayed pixels, and at *all times during the"
                   1317:        echo "     translation* the visible part of the bit FIFO is guaranteed"
                   1318:        echo "     to correspond to an aligned 32-bit word in the image buffer."
                   1319:        echo ""
                   1320:        echo "     this is *not* so if any of the following are true:"
                   1321:        echo ""
                   1322:        echo "     - the destination bits-per-pixel value is not known at compile"
                   1323:        echo "       time.  in this case, we can't unroll the translation loop"
                   1324:        echo "       for destination pixels, and are forced to shift the FIFO"
                   1325:        echo "       after each one."
                   1326:        echo ""
                   1327:        echo "     - if src_fifo0_may_be_unaligned is true.  in this case, we"
                   1328:        echo "       definitely can't guarantee that any initial dst_x will"
                   1329:        echo "       correspond to an aligned 32-bit word in the destination buffer."
                   1330:        echo ""
                   1331:        echo "     - if the destination image is not packed.  in this case, there may"
                   1332:        echo "       be undisplayed pixels in the FIFO, which we will need to"
                   1333:        echo "       shift out."
                   1334:        echo ""
                   1335:        echo "     - if there are 24 bits per destination pixel.  in this case,"
                   1336:        echo "       a destination pixel may cross a 32-bit boundary."
                   1337:        echo ""
                   1338:        echo "     - if a possible initial dst_x doesn't correspond to an aligned"
                   1339:        echo "       32-bit word in the destination buffer.  for this last one:"
1.1       root     1340:        echo ""
                   1341:        echo "     since we require that src_fifo0_may_be_unaligned is zero, we"
                   1342:        echo "     know that the initial src_x = (Z * 32) / src_bipp for "
                   1343:        echo "     some Z.  we also have the initial dst_x = src_x${scale_math}."
                   1344:        echo "     the initial destination bit offset will then be:"
                   1345:        echo ""
                   1346:        echo "     (dst_skipx + dst_x) * dst_bipp"
                   1347:        echo "     = (dst_skipx * dst_bipp) + (dst_x * dst_bipp)"
                   1348:        echo ""
                   1349:        echo "     if we additionally require that (dst_skipx * dst_bipp)"
                   1350:        echo "     be 32-bit aligned, this reduces things to:"
                   1351:        echo ""
                   1352:        echo "     dst_x * dst_bipp"
                   1353:        echo "     = (src_x${scale_math}) * dst_bipp"
                   1354:        echo "     = (((Z * 32) / src_bipp)${scale_math}) * dst_bipp"
                   1355:        echo ""
                   1356:        echo "     which will be a multiple of 32 iff:"
                   1357:        echo ""
                   1358:        echo "      ((1 / src_bipp)${scale_math}) * dst_bipp >= 1 and integral"
1.1.1.2   root     1359:        echo ""
                   1360:        echo "     or, equivalently:"
                   1361:        echo ""
1.1       root     1362:        denom="src_bipp"
                   1363:        numer="dst_bipp"
                   1364:        case $scale in
                   1365:        _) ;;
                   1366:        _h_) denom="(${denom} * 2)" ;;
                   1367:        _d_) numer="(${numer} * 2)" ;;
                   1368:        esac
1.1.1.2   root     1369:        echo "       (${numer} % ${denom}) == 0"
                   1370:        echo "  */"
                   1371:        dst_fifo0_may_be_unaligned_var=false
                   1372:        if test ${dst_bipp} = 0; then
                   1373:            value=TRUE
                   1374:        else
                   1375:          value="(src_fifo0_may_be_unaligned || !dst_packed || (dst_bipp == 24) || (dst_bypl % 4) || ((dst_skipx * dst_bipp) % 32) || (${numer} % ${denom}))"
                   1376:          if $src_bypl_var || $dst_bypl_var; then
                   1377:            dst_fifo0_may_be_unaligned_var=true
                   1378:          fi
                   1379:        fi
                   1380:        if $dst_fifo0_may_be_unaligned_var; then
1.1       root     1381:            echo "  const unsigned int dst_fifo0_may_be_unaligned = ${value};"
                   1382:        else
                   1383:            echo "#define dst_fifo0_may_be_unaligned ${value}"
                   1384:            undef_macros="${undef_macros} dst_fifo0_may_be_unaligned"
                   1385:        fi
                   1386: 
                   1387:        if test $scale = _d_; then
                   1388:            echo ""
                   1389:            echo "  /* declare dst_fifo1_may_be_unaligned.  this is zero iff all"
                   1390:            echo "     32-bit aligned values in the destination buffer contain a"
                   1391:            echo "     whole number of displayed pixels, and for every 32-bit"
                   1392:            echo "     aligned value on one scanline all other scanlines have a"
                   1393:            echo "     32-bit aligned value corresponding to the same x coordinate: */"
                   1394:            value="(dst_fifo0_may_be_unaligned || (dst_bypl & 3))"
                   1395:            if $src_bypl_var || $dst_bypl_var; then
                   1396:                echo "  const unsigned int dst_fifo1_may_be_unaligned = ${value};"
                   1397:            else
                   1398:                echo "#define dst_fifo1_may_be_unaligned ${value}"
                   1399:                undef_macros="${undef_macros} dst_fifo1_may_be_unaligned"
                   1400:            fi
                   1401:        fi
1.1.1.4 ! root     1402: 
        !          1403:        echo ""
        !          1404:        echo "  /* declare src_offset_updated_first and src_offset_updated_last,"
        !          1405:        echo "     which hold the offsets of the first and last updated bytes in"
        !          1406:        echo "     the source image: */"
        !          1407:        echo "  tme_uint32_t src_offset_updated_first;"
        !          1408:        echo "  tme_uint32_t src_offset_updated_last;"
1.1       root     1409:        
                   1410:        echo ""
                   1411:        echo "  /* declare src_raw0_end.  when treating the source image as"
                   1412:        echo "     an array of aligned 32-bit words, this variable holds the"
                   1413:        echo "     address of the first word after the real source image."
                   1414:        echo "     if the fast, aligned 32-bit word comparison loop passes"
                   1415:        echo "     this point, the entire source image has been processed and"
                   1416:        echo "     the function terminates: */"
                   1417:        echo "  const tme_uint32_t *src_raw0_end;"
                   1418: 
                   1419:        echo ""
                   1420:        echo "  /* declare xlat_run.  see the comment for the TME_FB_XLAT_RUN"
                   1421:        echo "     macro for an explanation of what this variable does: */"
                   1422:        echo "  int xlat_run;"
                   1423: 
                   1424:        echo ""
                   1425:        echo "  /* this silences gcc -Wuninitialized: */"
                   1426:        echo "  src_fifo0_next = 0;"
                   1427:        echo "  src_fifo0_bits = 0;"
                   1428:        if test ${scale} = _h_; then
                   1429:            echo "  src_fifo1_next = 0;"
                   1430:            echo "  src_fifo1_bits = 0;"
                   1431:        fi
                   1432:        echo "  dst_fifo0_next = 0;"
                   1433:        echo "  dst_fifo0_bits = 0;"
                   1434:        if test ${scale} = _d_; then
                   1435:            echo "  dst_fifo1_next = 0;"
                   1436:            echo "  dst_fifo1_bits = 0;"
                   1437:        fi
                   1438: 
                   1439:        echo ""
                   1440:        echo "  /* initialize src_raw0 and src_raw0_end for the fast aligned 32-bit"
                   1441:        echo "     word comparison loop.  on entry to (and when continuing) that loop,"
                   1442:        echo "     src_raw0 always points to the aligned 32-bit word *before* the"
                   1443:        echo "     next word to check.  src_raw0_end always points after the last"
                   1444:        echo "     word to check."
                   1445:        echo ""
                   1446:        echo "     src_raw0 is actually part of the source primary bit FIFO, which"
                   1447:        echo "     is good, because when the fast comparison fails on a word, src_raw0"
                   1448:        echo "     is already primed and ready to work for that bit FIFO: */"
1.1.1.4 ! root     1449:        echo "  src_offset_updated_first = src->tme_fb_connection_offset_updated_first;"
        !          1450:        echo "  src_offset_updated_last = TME_MIN(src->tme_fb_connection_offset_updated_last, src_bypb_real - 1);"
        !          1451:        echo "  src->tme_fb_connection_offset_updated_first = 0;"
        !          1452:        echo "  src->tme_fb_connection_offset_updated_last = src_bypb_real - 1;"
        !          1453:        echo "  if (src_offset_updated_first > src_offset_updated_last) {"
        !          1454:        echo "    return (FALSE);"
        !          1455:        echo "  }"
        !          1456:        echo "  src_raw0"
        !          1457:        echo "    = (((const tme_uint32_t *)"
        !          1458:        echo "        (src->tme_fb_connection_buffer"
        !          1459:        echo "         + (src_offset_updated_first"
        !          1460:        echo "            & (0 - (tme_uint32_t) sizeof(tme_uint32_t)))))"
        !          1461:        echo "       -1);"
        !          1462:        echo "  src_raw0_end"
        !          1463:        echo "    = ((const tme_uint32_t *)"
        !          1464:        echo "       (src->tme_fb_connection_buffer"
        !          1465:        echo "        + src_offset_updated_last"
        !          1466:        echo "        + 1));"
1.1       root     1467: 
                   1468:        echo ""
                   1469:        echo "  /* initialize xlat_run to -1.  it can never go negative inside the"
                   1470:        echo "     pixel translation loop, so if xlat_run stays negative for the"
                   1471:        echo "     entire translation, it means that the source image hasn't changed"
                   1472:        echo "     since the last translation.  this information is returned to the"
                   1473:        echo "     caller to hopefully save more work in updating the display: */"
                   1474:        echo "  xlat_run = -1;"
                   1475:                
                   1476:        echo ""
                   1477:        echo "  /* this is the main translation loop, which contains the fast aligned"
                   1478:        echo "     32-bit word comparison loop, and the pixel translation loop: */"
                   1479:        echo "  for (;;) {"
                   1480: 
                   1481:        echo ""
                   1482:        echo "    /* this is the fast aligned 32-bit word comparison loop.  it"
                   1483:        echo "       terminates either when a word fails comparison, or when the"
                   1484:        echo "       entire source image has been compared.  the if test that"
                   1485:        echo "       follows checks for the latter case and breaks the main"
                   1486:        echo "       translation loop: */"
                   1487:        echo "    for (; (++src_raw0 < src_raw0_end"
                   1488:        echo "            && *src_raw0 == *TME_FB_XLAT_SRC_OLD(src_raw0)); );"
                   1489:        echo "    if (src_raw0 >= src_raw0_end) {"
                   1490:        echo "      break;"
                   1491:        echo "    }"
                   1492: 
                   1493:        echo ""
                   1494:        echo "    /* calculate the byte offset into the source buffer of the"
                   1495:        echo "       32-bit word that failed comparison: */"
                   1496:        echo "    src_off = ((tme_uint8_t *) src_raw0) - src->tme_fb_connection_buffer;"
                   1497: 
                   1498:        echo ""
                   1499:        echo "    /* calculate the source y pixel coordinate, and reduce"
                   1500:        echo "       src_off from the byte offset into the buffer to the"
                   1501:        echo "       byte offset into that scanline: */"
                   1502:        echo "    src_y = src_off / src_bypl;"
                   1503:        echo "    src_off = src_off % src_bypl;"
                   1504: 
                   1505:        echo ""
                   1506:        echo "    /* while translating pixels, we use one or more \"bit FIFOs\","
                   1507:        echo "       each composed of one or more 32-bit integers.  we load these"
                   1508:        echo "       FIFOs 32 bits at a time. */"
                   1509:        echo ""
                   1510:        echo "    /* prime the visible part of the source primary bit FIFO: */"
                   1511:        echo "    src_fifo0 = *src_raw0;"
                   1512:        echo "    *TME_FB_XLAT_SRC_OLD(src_raw0) = src_fifo0;"
                   1513:        echo "    src_raw0++;"
                   1514:        echo "    src_fifo0 = ((src_order == TME_ENDIAN_BIG)"
                   1515:        echo "                 ? tme_betoh_u32(src_fifo0)"
                   1516:        echo "                 : tme_letoh_u32(src_fifo0));"
                   1517:        echo ""
                   1518:        echo "    /* if the source primary bit FIFO may be unaligned: */"
                   1519:        echo "    if (src_fifo0_may_be_unaligned) {"
                   1520:        echo ""
                   1521:        echo "      /* prime the invisible part of the source primary bit FIFO and"
                   1522:        echo "         assume that we will not have to shift it to finish: */"
                   1523:        echo "      src_fifo0_next = *src_raw0;"
                   1524:        echo "      *TME_FB_XLAT_SRC_OLD(src_raw0) = src_fifo0_next;"
                   1525:        echo "      src_raw0++;"
                   1526:        echo "      src_fifo0_next = ((src_order == TME_ENDIAN_BIG)"
                   1527:        echo "                        ? tme_betoh_u32(src_fifo0_next)"
                   1528:        echo "                        : tme_letoh_u32(src_fifo0_next));"
                   1529:        echo "      src_fifo0_bits = 0;"
                   1530:        echo ""
                   1531:        echo "      /* if there are pixels that need to be skipped, the first 32 bits"
                   1532:        echo "         we loaded into the FIFO may have first bits that belong to"
                   1533:        echo "         those undisplayed (skipped) pixels.  it is *not* possible for"
                   1534:        echo "         it to have first bits that belong to the scanline pad; there"
                   1535:        echo "         might be pad bits in the *middle* of the first 32 bits, but any"
                   1536:        echo "         first bits *must* belong to pixels, displayed or not: */"
                   1537:        echo "      if (src_skipx > 0"
                   1538:        echo "          && (src_off * 8) < (src_skipx * src_bipp)) {"
                   1539:        echo ""
                   1540:        echo "        /* see how many bits we will need to skip: */"
                   1541:        echo "        src_fifo0_bits = (src_skipx * src_bipp) - (src_off * 8);"
                   1542:        echo ""
                   1543:        echo "        /* if it is more than 31 bits, this is an entire 32 bits of"
                   1544:        echo "           undisplayed pixels.  just advance: */"
                   1545:        echo "        if (src_fifo0_bits > 31) {"
                   1546:        echo "          src_raw0--;"
                   1547:        echo "          continue;"
                   1548:        echo "        }"
                   1549:        echo ""
                   1550:        echo "        /* set the source x coordinate to zero: */"
                   1551:        echo "        src_x = 0;"
                   1552:        echo "      }"
                   1553:        echo ""
                   1554:        echo "      /* otherwise, the first 32 bits we load will have first bits for"
                   1555:        echo "         a displayable pixel: */"
                   1556:        echo "      else {"
                   1557:        echo ""
                   1558:        echo "        /* if the source bits per pixel is 24,  calculate the number of"
                   1559:        echo "           bytes *before* the original src_raw0 of any split pixel, and"
                   1560:        echo "           subtract this from src_off, to leave src_off as the byte offset"
                   1561:        echo "           into the scanline of the beginning of a pixel: */"
                   1562:        echo "        if (src_bipp == 24) {"
                   1563:        echo "          src_fifo0_bits = (src_off % 3);"
                   1564:        echo "          src_off -= src_fifo0_bits;"
                   1565:        echo ""
                   1566:        echo "          /* if this is a split pixel, we need to prime the source primary"
                   1567:        echo "              bit FIFO starting with the part *before* the original src_raw0."
                   1568:        echo "              we do not have to copy to the old; it passed comparison: */"
                   1569:        echo "          if (src_fifo0_bits) {"
                   1570:        echo "            src_raw0--;"
                   1571:        echo "            src_fifo0_next = src_fifo0;"
                   1572:        echo "            src_fifo0 = ((src_order == TME_ENDIAN_BIG)"
                   1573:        echo "                         ? tme_betoh_u32(*(src_raw0 - 2))"
                   1574:        echo "                         : tme_letoh_u32(*(src_raw0 - 2)));"
                   1575:        echo "          }"
                   1576:        echo "        }"
                   1577:        echo ""
                   1578:        echo "        /* calculate the source x coordinate: */"
                   1579:        echo "        src_x = ((src_off * 8) / src_bipp) - src_skipx;"
                   1580:        echo "      }"
                   1581:        echo ""
                   1582:        echo "      /* do any shifting to finish priming the source primary FIFO: */"
                   1583:        echo "      if (src_fifo0_bits) {"
                   1584:        echo "        if (src_order == TME_ENDIAN_BIG) {"
                   1585:        echo "          src_fifo0 = (src_fifo0 << src_fifo0_bits) | (src_fifo0_next >> (32 - src_fifo0_bits));"
                   1586:        echo "          src_fifo0_next <<= src_fifo0_bits;"
                   1587:        echo "        }"
                   1588:        echo "        else {"
                   1589:        echo "          src_fifo0 = (src_fifo0 >> src_fifo0_bits) | (src_fifo0_next << (32 - src_fifo0_bits));"
                   1590:        echo "          src_fifo0_next >>= src_fifo0_bits;"
                   1591:        echo "        }"
                   1592:        echo "      }"
                   1593:        echo "      src_fifo0_bits = 64 - src_fifo0_bits;"
                   1594:        echo "    }"
                   1595:        echo ""
                   1596:        echo "    /* otherwise, the source primary FIFO is aligned: */"
                   1597:        echo "    else {"
                   1598:        echo "      src_x = ((src_off * 8) / src_bipp) - src_skipx;"
                   1599:        echo "    }"
                   1600: 
                   1601:        if test $scale = _h_; then
                   1602:            echo ""
                   1603:            echo "    /* when halving the image, we have a source secondary bit "
                   1604:            echo "       FIFO, providing pixel values at the same source x coordinate"
                   1605:            echo "       but on the \"other\" line.  prime the source secondary"
                   1606:            echo "       bit FIFO: */"
                   1607:            echo "    if (src_fifo1_may_be_unaligned) {"
                   1608:            echo ""
                   1609:            echo "      /* calculate the bit offset into the source buffer of"
                   1610:            echo "         this exact same pixel on the other line: */"
                   1611:            echo "      src_off = ((src_y ^ 1) * src_bypl * 8) + ((src_skipx + src_x) * src_bipp);"
                   1612:            echo ""
                   1613:            echo "      /* calculate how many bits offset from a 32-bit boundary the pixel is: */"
                   1614:            echo "      src_fifo1_bits = src_off % 32;"
                   1615:            echo ""
                   1616:            echo "      /* set src_raw1: */"
                   1617:            echo "      src_raw1 = (const tme_uint32_t *)"
                   1618:            echo "        (src->tme_fb_connection_buffer"
                   1619:            echo "         + ((src_off - src_fifo1_bits) / 8));"
                   1620:            echo ""
                   1621:            echo "      /* actually prime the FIFO by loading the first two words and"
                   1622:            echo "         shifting off any offset bits: */"
                   1623:            echo "      src_fifo1 = *src_raw1;"
                   1624:            echo "      *TME_FB_XLAT_SRC_OLD(src_raw1) = src_fifo1;"
                   1625:            echo "      src_raw1++;"
                   1626:            echo "      src_fifo1_next = *src_raw1;"
                   1627:            echo "      *TME_FB_XLAT_SRC_OLD(src_raw1) = src_fifo1_next;"
                   1628:            echo "      src_raw1++;"
                   1629:            echo "      if (src_order == TME_ENDIAN_BIG) {"
                   1630:            echo "        src_fifo1 = tme_betoh_u32(src_fifo1);"
                   1631:            echo "        src_fifo1_next = tme_betoh_u32(src_fifo1_next);"
                   1632:            echo "        if (src_fifo1_bits) {"
                   1633:            echo "          src_fifo1 = (src_fifo1 << src_fifo1_bits) | (src_fifo1_next >> (32 - src_fifo1_bits));"
                   1634:            echo "          src_fifo1_next <<= src_fifo1_bits;"
                   1635:            echo "        }"
                   1636:            echo "      }"
                   1637:            echo "      else {"
                   1638:            echo "        src_fifo1 = tme_letoh_u32(src_fifo1);"
                   1639:            echo "        src_fifo1_next = tme_letoh_u32(src_fifo1_next);"
                   1640:            echo "        if (src_fifo1_bits) {"
                   1641:            echo "          src_fifo1 = (src_fifo1 >> src_fifo1_bits) | (src_fifo1_next << (32 - src_fifo1_bits));"
                   1642:            echo "          src_fifo1_next >>= src_fifo1_bits;"
                   1643:            echo "        }"
                   1644:            echo "      }"
                   1645:            echo "      src_fifo1_bits = 64 - src_fifo1_bits;"
                   1646:            echo "    }"
                   1647:            echo ""
                   1648:            echo "    /* otherwise the source secondary FIFO is aligned: */"
                   1649:            echo "    else {"
                   1650:            echo "      src_raw1 = (const tme_uint32_t *)"
                   1651:            echo "        (((tme_uint8_t *) src_raw0)"
                   1652:            echo "         + (("
                   1653:            echo "             /* if src_y is even, this addend is now src_bypl * 4,"
                   1654:            echo "                else if src_y is odd, this addend is now src_bypl * 2: */"
                   1655:            echo "             ((src_bypl * 4) >> (src_y & 1))"
                   1656:            echo "             /* if src_y is even, this addend is now src_bypl,"
                   1657:            echo "                else if src_y is odd, this addend is now -src_bypl: */"
                   1658:            echo "             - (src_bypl * 3))"
                   1659:            echo "            /* this -4 compensates for src_raw0 already having"
                   1660:            echo "               been advanced by one: */"
                   1661:            echo "            - 4));"
                   1662:            echo "      src_fifo1 = *src_raw1;"
                   1663:            echo "      *TME_FB_XLAT_SRC_OLD(src_raw1) = src_fifo1;"
                   1664:            echo "      src_raw1++;"
                   1665:            echo "      src_fifo1 = ((src_order == TME_ENDIAN_BIG)"
                   1666:            echo "                   ? tme_betoh_u32(src_fifo1)"
                   1667:            echo "                   : tme_letoh_u32(src_fifo1));"
                   1668:            echo "    }"
                   1669:        fi
                   1670: 
                   1671:        if test $scale != _; then
                   1672:            echo ""
                   1673:            echo "    /* calculate the destination coordinates: */"
                   1674:            echo "    dst_y = src_y${scale_math};"
                   1675:            echo "    dst_x = src_x${scale_math};"
                   1676:        fi
                   1677: 
                   1678:        echo ""
                   1679:        echo "    /* prime the destination primary bit FIFO: */"
                   1680:        echo "    dst_fifo0 = 0;"
                   1681:        echo "    if (dst_fifo0_may_be_unaligned) {"
                   1682:        echo ""
                   1683:        echo "      /* calculate the bit offset into the destination buffer of"
                   1684:        echo "         the destination pixel: */"
                   1685:        echo "      dst_off = (dst_y * dst_bypl * 8) + ((dst_skipx + dst_x) * dst_bipp);"
                   1686:        echo ""
                   1687:        echo "      /* calculate the number of bits that will be in the primed FIFO: */"
                   1688:        echo "      dst_fifo0_bits = dst_off % 32;"
                   1689:        echo ""
                   1690:        echo "      /* set dst_raw0: */"
                   1691:        echo "      dst_raw0 = (tme_uint32_t *)"
                   1692:        echo "        (dst->tme_fb_connection_buffer"
                   1693:        echo "         + ((dst_off - dst_fifo0_bits) / 8));"
                   1694:        echo ""
                   1695:        echo "      /* prime the primary destination FIFO: */"
                   1696:        echo "      dst_fifo0_next = 0;"
                   1697:        echo "      if (dst_fifo0_bits) {"
                   1698:        echo "        dst_fifo0_next = (src_order == TME_ENDIAN_BIG"
                   1699:        echo "                          ? (tme_betoh_u32(*dst_raw0) & (0xffffffffUL << (32 - dst_fifo0_bits)))"
                   1700:        echo "                          : (tme_letoh_u32(*dst_raw0) & (0xffffffffUL >> (32 - dst_fifo0_bits))));"
                   1701:        echo "      }"
                   1702:        echo "    }"
                   1703:        echo ""
                   1704:        echo "    /* otherwise the destination primary FIFO is aligned: */"
                   1705:        echo "    else {"
                   1706:        echo "      dst_off = (dst_y * dst_bypl) + (((dst_skipx + dst_x) * dst_bipp) / 8);"
                   1707:        echo "      dst_raw0 = (tme_uint32_t *) (dst->tme_fb_connection_buffer + dst_off);"
                   1708:        echo "    }"
                   1709: 
                   1710:        if test $scale = _d_; then
                   1711:            echo ""
                   1712:            echo "    /* when doubling the image, we have a destination secondary bit "
                   1713:            echo "       FIFO, for pixel values at the same source x coordinate"
                   1714:            echo "       but on the \"other\" line.  prime the destination secondary"
                   1715:            echo "       bit FIFO: */"
                   1716:            echo "    dst_fifo1 = 0;"
                   1717:            echo "    if (dst_fifo1_may_be_unaligned) {"
                   1718:            echo ""
                   1719:            echo "      /* calculate the bit offset into the destination buffer of"
                   1720:            echo "         the destination pixel: */"
                   1721:            echo "      dst_off = ((dst_y + 1) * dst_bypl * 8) + ((dst_skipx + dst_x) * dst_bipp);"
                   1722:            echo ""
                   1723:            echo "      /* calculate the number of bits that will be in the primed FIFO: */"
                   1724:            echo "      dst_fifo1_bits = dst_off % 32;"
                   1725:            echo ""
                   1726:            echo "      /* set dst_raw1: */"
                   1727:            echo "      dst_raw1 = (tme_uint32_t *)"
                   1728:            echo "        (dst->tme_fb_connection_buffer"
                   1729:            echo "         + ((dst_off - dst_fifo1_bits) / 8));"
                   1730:            echo ""
                   1731:            echo "      /* prime the primary destination FIFO: */"
                   1732:            echo "      dst_fifo1_next = 0;"
                   1733:            echo "      if (dst_fifo1_bits) {"
                   1734:            echo "        dst_fifo1_next = (src_order == TME_ENDIAN_BIG"
                   1735:            echo "                          ? (tme_betoh_u32(*dst_raw1) & (0xffffffffUL << (32 - dst_fifo1_bits)))"
                   1736:            echo "                          : (tme_letoh_u32(*dst_raw1) & (0xffffffffUL >> (32 - dst_fifo1_bits))));"
                   1737:            echo "      }"
                   1738:            echo "    }"
                   1739:            echo ""
                   1740:            echo "    /* otherwise, the destination secondary FIFO is aligned: */"
                   1741:            echo "    else {"
                   1742:            echo "      dst_raw1 = (tme_uint32_t *)"
                   1743:            echo "        (((tme_uint8_t *) dst_raw0)"
                   1744:            echo "         + dst_bypl);"
                   1745:            echo "    }"
                   1746:        fi
                   1747: 
                   1748:        # we want to unroll the pixel translation loop to read as many
                   1749:        # source pixels as possible out of the source bit FIFOs and
                   1750:        # write as many destination pixels as possible into the
                   1751:        # destination bit FIFOs before shifting them.
                   1752:        #
                   1753:        # it is very common to want to unroll the translation loop a
                   1754:        # different number of times on source and destination pixels,
                   1755:        # so we always unroll the maximum possible, tracking within
                   1756:        # each unrolled iteration the relative unrolled iteration for
                   1757:        # the source and destination bit FIFOs.
                   1758:        # 
                   1759: 
                   1760:        # src_unroll and dst_unroll are the number of times we will
                   1761:        # unroll the translation loop on source and destination
                   1762:        # pixels, respectively.  assume no unrolling:
                   1763:        #
                   1764:        src_unroll=1
                   1765:        dst_unroll=1
                   1766: 
                   1767:        # src_iter_scale is the number of source pixels read out of a
                   1768:        # source bit FIFO in one unrolled iteration of the translation
                   1769:        # loop.  if this function halves the source image, this is
                   1770:        # two, otherwise this is one.
                   1771:        #
                   1772:        # dst_iter_scale is the number of destination pixels written
                   1773:        # to a destination bit FIFO in one unrolled iteration of the
                   1774:        # translation loop.  if this function doubles the source
                   1775:        # image, this is two, otherwise this is one.
                   1776:        #
                   1777:        # src_fifo_shift is the number of bits that the source bit
                   1778:        # FIFO(s) must be shifted after all unrolled iterations on
                   1779:        # source pixels.  assume no unrolling, so if this function
                   1780:        # halves the source image and src_bipp is less than 24, two
                   1781:        # pixels' bits must be shifted, otherwise one pixel's bits
                   1782:        # must be shifted.
                   1783:        #
                   1784:        # dst_fifo_shift is the number of bits that the destination bit
                   1785:        # FIFO(s) must be shifted after all unrolled iterations on
                   1786:        # destination pixels.  we are assuming no unrolling, so if this
                   1787:        # function doubles the source image and dst_bipp is less than
                   1788:        # 24, two pixels' bits must be shifted, otherwise one pixel's
                   1789:        # bits must be shifted:
                   1790:        #
                   1791:        if test $scale = _h_; then
                   1792:            src_iter_scale=2
                   1793:            src_fifo_shift="(src_bipp < 24 ? (src_bipp * 2) : src_bipp)"
                   1794:        else
                   1795:            src_iter_scale=1
                   1796:            src_fifo_shift="src_bipp"
                   1797:        fi
                   1798:        if test $scale = _d_; then
                   1799:            dst_iter_scale=2
                   1800:            dst_fifo_shift="(dst_bipp < 24 ? (dst_bipp * 2) : dst_bipp)"
                   1801:        else
                   1802:            dst_iter_scale=1
                   1803:            dst_fifo_shift="dst_bipp"
                   1804:        fi
                   1805: 
                   1806:        # if src_bipp is known now, see how many times we can unroll the
                   1807:        # translation loop on source pixels:
                   1808:        #
                   1809:        if test ${src_bipp} != 0; then
                   1810: 
                   1811:            # in general, we can unroll once for each pixel in the
                   1812:            # visible part of a source bit FIFO:
                   1813:            #
                   1814:            src_unroll=`expr 32 / ${src_bipp}`
                   1815: 
                   1816:            # if this function halves the source image, we can unroll
                   1817:            # half as many times:
                   1818:            #
                   1819:            src_unroll=`expr ${src_unroll} / ${src_iter_scale}`
                   1820: 
                   1821:            # if we think we can unroll zero times, this means that
                   1822:            # src_bipp is greater than 16 and this function halves the
                   1823:            # source image - the zero is telling us that two whole
                   1824:            # pixels cannot fit in the visible part of a source bit
                   1825:            # FIFO.  so we unroll once on source pixels, and shift
                   1826:            # only one pixel's bits after the unrolling (the halving
                   1827:            # code will be shifting one pixel's worth of bits to get
                   1828:            # to the next pixel it has to read):
                   1829:            #
                   1830:            if test ${src_unroll} = 0; then
                   1831:                src_unroll=1
                   1832:                src_fifo_shift=${src_bipp}
                   1833: 
                   1834:            # otherwise, we will be shifting the entire visible part
                   1835:            # of the source bit FIFO(s) after all unrolled iterations:
                   1836:            #
                   1837:            else
                   1838:                src_fifo_shift=32
                   1839:            fi
                   1840: 
                   1841:            echo ""
                   1842:            echo "    /* since src_bipp is known at code-generation time, the"
                   1843:            echo "       pixel translation loop is unrolled to translate all"
                   1844:            echo "       source pixels in the 32-bit visible part of the source"
                   1845:            echo "       bit FIFO(s) before shifting."
                   1846:            echo ""
                   1847:            echo "       in this case, src_bipp is known to be ${src_bipp}, so "`expr ${src_unroll} \* ${src_iter_scale}`" pixels will"
                   1848:            echo "       be read out of the source bit FIFO(s) before shifting, and"
                   1849:            echo "       when the source bit FIFO(s) are shifted, they are shifted"
                   1850:            echo "       ${src_fifo_shift} bits at a time: */"
                   1851:        fi
                   1852:        
                   1853:        # if dst_bipp is known now, see how many times we can unroll the
                   1854:        # translation loop on destination pixels:
                   1855:        #
                   1856:        if test ${dst_bipp} != 0; then
                   1857: 
                   1858:            # in general, we can unroll once for each pixel in the
                   1859:            # visible part of a destination bit FIFO:
                   1860:            #
                   1861:            dst_unroll=`expr 32 / ${dst_bipp}`
                   1862: 
                   1863:            # if this function doubles the source image, we can unroll
                   1864:            # half as many times:
                   1865:            #
                   1866:            dst_unroll=`expr ${dst_unroll} / ${dst_iter_scale}`
                   1867: 
                   1868:            # if we think we can unroll zero times, this means that
                   1869:            # dst_bipp is greater than 16 and this function doubles the
                   1870:            # source image - the zero is telling us that two whole
                   1871:            # pixels cannot fit in the visible part of a destination bit
                   1872:            # FIFO.  so we unroll once on destination pixels, and shift
                   1873:            # only one pixel's bits after the unrolling (the doubling
                   1874:            # code will be shifting one pixel's worth of bits to get
                   1875:            # out the first pixel it has to write):
                   1876:            #
                   1877:            if test ${dst_unroll} = 0; then
                   1878:                dst_unroll=1
                   1879:                dst_fifo_shift=${dst_bipp}
                   1880: 
                   1881:            # otherwise, we will be shifting the entire visible part
                   1882:            # of the source bit FIFO(s) after all unrolled iterations:
                   1883:            #
                   1884:            else
                   1885:                dst_fifo_shift=32
                   1886:            fi
                   1887: 
                   1888:            echo ""
                   1889:            echo "    /* since dst_bipp is known at code-generation time, the pixel"
                   1890:            echo "       translation loop is unrolled to translate all destination"
                   1891:            echo "       pixels in the 32-bit visible part of the destination bit"
                   1892:            echo "       FIFO(s) before shifting."
                   1893:            echo ""
                   1894:            echo "       in this case, dst_bipp is known to be ${dst_bipp}, so "`expr ${dst_unroll} \* ${dst_iter_scale}`" pixels will"
                   1895:            echo "       be written into the destination bit FIFO(s) before shifting,"
                   1896:            echo "       and when the destination bit FIFO(s) are shifted, they are"
                   1897:            echo "       shifted ${dst_fifo_shift} bits at a time: */"
                   1898:        fi
                   1899: 
                   1900:        # unroll the translation loop the maximum number amount of times:
                   1901:        #
                   1902:        if test `expr ${src_unroll} \> ${dst_unroll}` = 1; then
                   1903:            unroll=${src_unroll}
                   1904:        else
                   1905:            unroll=${dst_unroll}
                   1906:        fi
                   1907:        
                   1908:        echo ""
                   1909:        echo "    /* src_unroll = ${src_unroll}, src_iter_scale = ${src_iter_scale}"
                   1910:        echo "       dst_unroll = ${dst_unroll}, dst_iter_scale = ${dst_iter_scale} */"
                   1911:        echo "    for (xlat_run = TME_FB_XLAT_RUN;"
                   1912:        echo "         xlat_run > 0; ) {"
                   1913:        iter=0
                   1914: 
                   1915:        while test `expr ${iter} \< ${unroll}` = 1; do
                   1916:            echo ""
                   1917:            echo "      /* iter #${iter} */"
                   1918:            echo ""
                   1919:            iter_next=`expr ${iter} + 1`
                   1920: 
                   1921:            # the number of bits to skip in a source FIFO to get to
                   1922:            # this iteration's pixel:
                   1923:            src_shift=`expr ${iter} % ${src_unroll}`
                   1924:            src_shift='('`expr ${src_shift} \* ${src_iter_scale}`' * src_bipp)'
                   1925: 
                   1926:            echo "      /* get a pixel from the source primary FIFO: */"
                   1927:            echo "      pixel ="
                   1928:            echo "        ((src_fifo0"
                   1929:            echo "          >> (src_order == TME_ENDIAN_BIG"
                   1930:            echo "              ? (32 - (src_bipp + ${src_shift}))"
1.1.1.2   root     1931:            echo "              : ${src_shift})));"
                   1932:            indent0=X
1.1       root     1933: 
1.1.1.2   root     1934:            if test $scale != _h_; then
1.1       root     1935: 
1.1.1.2   root     1936:                if test "x${src_mask_g}" = x; then
                   1937:                    echo ""
                   1938:                    echo "      /* since source pixels are known at compile time to"
                   1939:                    echo "         not have subfields, map the source pixel into the"
                   1940:                    echo "         destination pixel: */"
                   1941:                    echo "      pixel = dst->tme_fb_connection_map_pixel[pixel & src_mask];"
                   1942:                else
                   1943:                    echo ""
                   1944:                    echo "      /* if the source depth is within the threshold for pixel"
                   1945:                    echo "         mapping, or if source pixels don't have subfields,"
                   1946:                    echo "         map the source pixel into the destination pixel: */"
                   1947:                    echo "      if (src_mask <= TME_FB_XLAT_MAP_INDEX_MASK_MAX"
                   1948:                    echo "          || src_mask_g == src_mask) {"
                   1949:                    echo "        pixel = dst->tme_fb_connection_map_pixel[pixel & src_mask];"
                   1950:                    echo "      }"
                   1951:                    echo ""
                   1952:                    echo "      /* otherwise, we will decompose this source pixel"
                   1953:                    echo "         and then compose the destination pixel: */"
                   1954:                    echo "      else {"
                   1955:                    echo ""
                   1956:                    echo "        /* map the pixel subfields into intensities: */"
                   1957:                    echo "        value_g = TME_FB_XLAT_MAP(pixel, src_mask_g, src_mask_i, src_indexed, src->tme_fb_connection_map_g);"
                   1958:                    if test "x${src_class}" != xm; then
                   1959:                        echo "        value_r = TME_FB_XLAT_MAP(pixel, src_mask_r, src_mask_i, src_indexed, src->tme_fb_connection_map_r);"
                   1960:                        echo "        value_b = TME_FB_XLAT_MAP(pixel, src_mask_b, src_mask_i, src_indexed, src->tme_fb_connection_map_b);"
                   1961:                    fi
                   1962:                    indent0="  "
                   1963:                    src_mask_i=src_mask_i
                   1964:                    src_mask_i_max=TME_FB_XLAT_MAP_INDEX_MASK_MAX
                   1965:                fi
                   1966: 
                   1967:            else
1.1       root     1968: 
                   1969:                echo ""
1.1.1.2   root     1970:                echo "      /* map the pixel subfields into intensities: */"
                   1971:                echo "      value_g = TME_FB_XLAT_MAP(pixel, src_mask_g, src_mask_i, src_indexed, src->tme_fb_connection_map_g);"
                   1972:                if test "x${src_class}" != xm; then
                   1973:                    echo "      value_r = TME_FB_XLAT_MAP(pixel, src_mask_r, src_mask_i, src_indexed, src->tme_fb_connection_map_r);"
                   1974:                    echo "      value_b = TME_FB_XLAT_MAP(pixel, src_mask_b, src_mask_i, src_indexed, src->tme_fb_connection_map_b);"
1.1       root     1975:                fi
1.1.1.2   root     1976: 
                   1977:                echo ""
                   1978:                echo "      /* get a second pixel, from the source secondary FIFO: */"
                   1979:                echo "      pixel ="
1.1       root     1980:                echo "        ((src_fifo1"
                   1981:                echo "          >> (src_order == TME_ENDIAN_BIG"
                   1982:                echo "              ? (32 - (src_bipp + ${src_shift}))"
1.1.1.2   root     1983:                echo "              : ${src_shift})));"
                   1984: 
                   1985:                echo ""
                   1986:                echo "      /* map the pixel subfields into intensities and accumulate them: */"
                   1987:                echo "      value_g += TME_FB_XLAT_MAP(pixel, src_mask_g, src_mask_i, src_indexed, src->tme_fb_connection_map_g);"
                   1988:                if test "x${src_class}" != xm; then
                   1989:                    echo "      value_r += TME_FB_XLAT_MAP(pixel, src_mask_r, src_mask_i, src_indexed, src->tme_fb_connection_map_r);"
                   1990:                    echo "      value_b += TME_FB_XLAT_MAP(pixel, src_mask_b, src_mask_i, src_indexed, src->tme_fb_connection_map_b);"
                   1991:                fi
1.1       root     1992: 
                   1993:                echo ""
                   1994:                echo "      /* get third and fourth pixels, from the source primary"
                   1995:                echo "         FIFO and source secondary FIFO, respectively.  if"
                   1996:                echo "         src_bipp is 24 or greater, these pixels are not yet"
                   1997:                echo "         entirely in the first parts of the FIFOs, so we need"
                   1998:                echo "         to shift: */"
                   1999:                echo "      if (src_bipp >= 24) {"
                   2000:                echo "        TME_FB_XLAT_SHIFT_SRC(src_fifo0_may_be_unaligned,"
                   2001:                echo "                              src_fifo0,"
                   2002:                echo "                              src_fifo0_next,"
                   2003:                echo "                              src_fifo0_bits,"
                   2004:                echo "                              src_bipp,"
                   2005:                echo "                              src_raw0,"
                   2006:                echo "                              src_order);"
                   2007:                echo "        TME_FB_XLAT_SHIFT_SRC(src_fifo1_may_be_unaligned,"
                   2008:                echo "                              src_fifo1,"
                   2009:                echo "                              src_fifo1_next,"
                   2010:                echo "                              src_fifo1_bits,"
                   2011:                echo "                              src_bipp,"
                   2012:                echo "                              src_raw1,"
                   2013:                echo "                              src_order);"
1.1.1.2   root     2014:                echo "        pixel ="
1.1       root     2015:                echo "          ((src_fifo0"
                   2016:                echo "            >> (src_order == TME_ENDIAN_BIG"
                   2017:                echo "                ? (32 - (src_bipp + ${src_shift}))"
1.1.1.2   root     2018:                echo "                : ${src_shift})));"
                   2019: 
                   2020:                echo ""
                   2021:                echo "        /* map the pixel subfields into intensities and accumulate them: */"
                   2022:                echo "        value_g += TME_FB_XLAT_MAP(pixel, src_mask_g, src_mask_i, src_indexed, src->tme_fb_connection_map_g);"
                   2023:                if test "x${src_class}" != xm; then
                   2024:                    echo "        value_r += TME_FB_XLAT_MAP(pixel, src_mask_r, src_mask_i, src_indexed, src->tme_fb_connection_map_r);"
                   2025:                    echo "        value_b += TME_FB_XLAT_MAP(pixel, src_mask_b, src_mask_i, src_indexed, src->tme_fb_connection_map_b);"
1.1       root     2026:                fi
1.1.1.2   root     2027:                echo ""
                   2028:                
                   2029:                echo "        pixel ="
1.1       root     2030:                echo "          ((src_fifo1"
                   2031:                echo "            >> (src_order == TME_ENDIAN_BIG"
                   2032:                echo "                ? (32 - (src_bipp + ${src_shift}))"
1.1.1.2   root     2033:                echo "                : ${src_shift})));"
                   2034: 
                   2035:                echo ""
                   2036:                echo "        /* map the pixel subfields into intensities and accumulate them: */"
                   2037:                echo "        value_g += TME_FB_XLAT_MAP(pixel, src_mask_g, src_mask_i, src_indexed, src->tme_fb_connection_map_g);"
                   2038:                if test "x${src_class}" != xm; then
                   2039:                    echo "        value_r += TME_FB_XLAT_MAP(pixel, src_mask_r, src_mask_i, src_indexed, src->tme_fb_connection_map_r);"
                   2040:                    echo "        value_b += TME_FB_XLAT_MAP(pixel, src_mask_b, src_mask_i, src_indexed, src->tme_fb_connection_map_b);"
                   2041:                fi
1.1       root     2042:                echo "      }"
                   2043:                echo ""
1.1.1.2   root     2044:                echo "      /* otherwise, the third and fourth pixels are already in the"
1.1       root     2045:                echo "         visible parts of the source bit FIFOs; we just have to"
                   2046:                echo "         reach over the pixels we already read to get at them: */"
                   2047:                echo "      else {"
1.1.1.2   root     2048:                echo "        pixel ="
1.1       root     2049:                echo "          ((src_fifo0"
                   2050:                echo "            >> (src_order == TME_ENDIAN_BIG"
                   2051:                echo "                ? (32 - (src_bipp + (${src_shift} + src_bipp)))"
1.1.1.2   root     2052:                echo "                : (${src_shift} + src_bipp))));"
                   2053:                echo ""
                   2054:                echo "        /* map the pixel subfields into intensities and accumulate them: */"
                   2055:                echo "        value_g += TME_FB_XLAT_MAP(pixel, src_mask_g, src_mask_i, src_indexed, src->tme_fb_connection_map_g);"
                   2056:                if test "x${src_class}" != xm; then
                   2057:                    echo "        value_r += TME_FB_XLAT_MAP(pixel, src_mask_r, src_mask_i, src_indexed, src->tme_fb_connection_map_r);"
                   2058:                    echo "        value_b += TME_FB_XLAT_MAP(pixel, src_mask_b, src_mask_i, src_indexed, src->tme_fb_connection_map_b);"
1.1       root     2059:                fi
1.1.1.2   root     2060:                echo ""
                   2061:                echo "        pixel ="
1.1       root     2062:                echo "          ((src_fifo1"
                   2063:                echo "            >> (src_order == TME_ENDIAN_BIG"
                   2064:                echo "                ? (32 - (src_bipp + (${src_shift} + src_bipp)))"
1.1.1.2   root     2065:                echo "                : (${src_shift} + src_bipp))));"
                   2066:                echo ""
                   2067:                echo "        /* map the pixel subfields into intensities and accumulate them: */"
                   2068:                echo "        value_g += TME_FB_XLAT_MAP(pixel, src_mask_g, src_mask_i, src_indexed, src->tme_fb_connection_map_g);"
                   2069:                if test "x${src_class}" != xm; then
                   2070:                    echo "        value_r += TME_FB_XLAT_MAP(pixel, src_mask_r, src_mask_i, src_indexed, src->tme_fb_connection_map_r);"
                   2071:                    echo "        value_b += TME_FB_XLAT_MAP(pixel, src_mask_b, src_mask_i, src_indexed, src->tme_fb_connection_map_b);"
                   2072:                fi
1.1       root     2073:                echo "      }"
1.1.1.2   root     2074:                indent0=
                   2075:                src_mask_i='((src_mask_i * 4) + 3)'
                   2076:                src_mask_i_max='(TME_FB_XLAT_MAP_INDEX_MASK_MAX / 4)'
                   2077:            fi
1.1       root     2078: 
1.1.1.2   root     2079:            # if we may have intensities:
                   2080:            #
                   2081:            if test "X${indent0}" != XX; then
1.1       root     2082:                echo ""
1.1.1.2   root     2083:                indent1=X
                   2084:                case "x${src_class}" in
                   2085:                xm)
                   2086:                    echo "${indent0}      /* since the source_class is known as monochrome at code-generation"
                   2087:                    echo "${indent0}         time, we map the green intensity directly into a pixel.  we may have"
                   2088:                    echo "${indent0}         to scale the intensity to be in the lookup range: */"
                   2089:                    echo "${indent0}      if (src_mask_i > ${src_mask_i_max}) {"
1.1.1.3   root     2090:                    echo "${indent0}        value_g /= TME_FB_XLAT_MAP_LINEAR_SCALE(${src_mask_i}, TME_FB_XLAT_MAP_INDEX_MASK_MAX);"
1.1.1.2   root     2091:                    echo "${indent0}      }"
                   2092:                    echo "${indent0}      pixel = dst->tme_fb_connection_map_pixel[value_g];"
                   2093:                    ;;
                   2094:                x)
                   2095:                    echo "${indent0}      /* if the source class is monochrome, we map the green intensity"
                   2096:                    echo "${indent0}         directly into a pixel.  we may have to scale the intensity"
                   2097:                    echo "${indent0}         to be in the lookup range: */"
                   2098:                    echo "${indent0}      if (src->tme_fb_connection_class == TME_FB_XLAT_CLASS_MONOCHROME) {"
                   2099:                    echo "${indent0}        if (src_mask_i > ${src_mask_i_max}) {"
1.1.1.3   root     2100:                    echo "${indent0}          value_g /= TME_FB_XLAT_MAP_LINEAR_SCALE(${src_mask_i}, TME_FB_XLAT_MAP_INDEX_MASK_MAX);"
1.1.1.2   root     2101:                    echo "${indent0}        }"
                   2102:                    echo "${indent0}        pixel = dst->tme_fb_connection_map_pixel[value_g];"
                   2103:                    echo "${indent0}      }"
1.1       root     2104:                    echo ""
1.1.1.2   root     2105:                    echo "${indent0}      /* otherwise, we have to consider all three intensities: */"
                   2106:                    echo "${indent0}      else {"
                   2107:                    indent1="${indent0}  "
                   2108:                    ;;
                   2109:                *)
                   2110:                    echo "${indent0}      /* we have to consider all three intensities: */"
                   2111:                    indent1="${indent0}"
                   2112:                esac
                   2113: 
                   2114:                if test "X${indent1}" != "XX"; then
                   2115:                    echo ""
                   2116:                    echo "${indent1}      /* if destination intensities are indexed: */"
                   2117:                    echo "${indent1}      if (dst_indexed) {"
                   2118:                    echo ""
                   2119:                    echo "${indent1}        /* we may have to scale the intensities to be in the lookup range: */"
                   2120:                    echo "${indent1}        if (src_mask_i > ${src_mask_i_max}) {"
1.1.1.3   root     2121:                    echo "${indent1}          value_g /= TME_FB_XLAT_MAP_LINEAR_SCALE(${src_mask_i}, TME_FB_XLAT_MAP_INDEX_MASK_MAX);"
                   2122:                    echo "${indent1}          value_r /= TME_FB_XLAT_MAP_LINEAR_SCALE(${src_mask_i}, TME_FB_XLAT_MAP_INDEX_MASK_MAX);"
                   2123:                    echo "${indent1}          value_b /= TME_FB_XLAT_MAP_LINEAR_SCALE(${src_mask_i}, TME_FB_XLAT_MAP_INDEX_MASK_MAX);"
1.1.1.2   root     2124:                    echo "${indent1}        }"
                   2125:                    echo ""
                   2126:                    echo "${indent1}        /* form the pixel: */"
                   2127:                    echo "${indent1}        pixel  = _TME_FB_XLAT_MAP_INDEX(value_g, dst_mask_g, dst->tme_fb_connection_map_g);"
                   2128:                    echo "${indent1}        pixel |= _TME_FB_XLAT_MAP_INDEX(value_r, dst_mask_r, dst->tme_fb_connection_map_r);"
                   2129:                    echo "${indent1}        pixel |= _TME_FB_XLAT_MAP_INDEX(value_b, dst_mask_b, dst->tme_fb_connection_map_b);"
                   2130:                    echo "${indent1}      }"
                   2131:                    echo ""
                   2132:                    echo "${indent1}      /* otherwise, destination intensities are linear: */"
                   2133:                    echo "${indent1}      else {"
                   2134:                    echo ""
                   2135:                    echo "${indent1}        /* form the pixel: */"
                   2136:                    echo "${indent1}        pixel  = _TME_FB_XLAT_MAP_LINEAR(value_g, ${src_mask_i}, dst_mask_g);"
                   2137:                    echo "${indent1}        pixel |= _TME_FB_XLAT_MAP_LINEAR(value_r, ${src_mask_i}, dst_mask_r);"
                   2138:                    echo "${indent1}        pixel |= _TME_FB_XLAT_MAP_LINEAR(value_b, ${src_mask_i}, dst_mask_b);"
                   2139:                    echo ""
                   2140:                    echo "${indent1}        /* if destination pixels are indexed: */"
                   2141:                    echo "${indent1}        if (dst_masks_default) {"
                   2142:                    echo "${indent1}          pixel = dst->tme_fb_connection_map_pixel[pixel];"
                   2143:                    echo "${indent1}        }"
                   2144:                    echo "${indent1}      }"
                   2145: 
                   2146:                    if test "X${indent1}" != "X${indent0}"; then
                   2147:                        echo "${indent0}      }"
                   2148:                    fi
                   2149:                    if test "X${indent0}" != X; then
                   2150:                        echo "${indent0}    }"
                   2151:                    fi
1.1       root     2152:                fi
                   2153:            fi
                   2154: 
                   2155:            echo ""
                   2156:            if test $scale = _h_; then
                   2157: 
                   2158:                echo "      /* if we just read the last pixels on these"
                   2159:                echo "         source scanlines: */"
                   2160:                if test `expr ${iter_next} % ${src_unroll}` = 0; then
                   2161:                    echo "      if ((src_x +="
                   2162:                    echo "           (src_packed"
                   2163:                    echo "            ? `expr ${src_unroll} \* 2`"
                   2164:                    echo "            : 2))"
                   2165:                    echo "           == src_width) {"
                   2166:                else
                   2167:                    echo "      if (!src_packed"
                   2168:                    echo "          && (src_x += 2) == src_width) {"
                   2169:                fi
                   2170:                echo ""
                   2171:                echo "        /* we need to rapidly shift the source FIFOs"
                   2172:                echo "           to skip not only pad bits and undisplayed"
                   2173:                echo "           pixels on the next line, but actually the"
                   2174:                echo "           *entire* next line."
                   2175:                echo ""
                   2176:                echo "           note that this sounds like when we're done,"
                   2177:                echo "           the bits at the fronts of the FIFOs will be"
                   2178:                echo "           the *first* pixels on the next scanlines."
                   2179:                echo ""
                   2180:                echo "           but the bits at the fronts of the FIFOs now"
                   2181:                echo "           are the *last* pixels on the current scanlines -"
                   2182:                echo "           they haven't been shifted off yet.  so when"
                   2183:                echo "           we're done, we want one pixel's worth of bits"
                   2184:                echo "           in the FIFOs before the first pixel on the"
                   2185:                echo "           next scanlines: */"
                   2186:                echo ""
                   2187:                echo "        /* calculate the number of bits that we need"
                   2188:                echo "           to shift the source primary FIFO, after"
                   2189:                echo "           discarding any bits in it now: */"
                   2190:                echo "        src_off = ((src_bypl * 8) - (src_width * src_bipp)) + (src_bypl * 8);"
                   2191:                echo "        src_off -= (src_fifo0_may_be_unaligned"
                   2192:                echo "                    ? src_fifo0_bits"
                   2193:                echo "                    : 32);"
                   2194:                echo ""
                   2195:                echo "        /* rapidly advance src_raw0 by the number of"
                   2196:                echo "           whole 32-bit words.  this will leave it pointing"
                   2197:                echo "           to the 32-bit word that has the first bit that"
                   2198:                echo "           we want to end up as the first bit in the source"
                   2199:                echo "           primary FIFO: */"
                   2200:                echo "        src_raw0 += (src_off / 32);"
                   2201:                echo ""
                   2202:                echo "        /* reprime the source primary FIFO: */"
                   2203:                echo "        src_fifo0 = *src_raw0;"
                   2204:                echo "        *TME_FB_XLAT_SRC_OLD(src_raw0) = src_fifo0;"
                   2205:                echo "        src_raw0++;"
                   2206:                echo "        src_fifo0 = ((src_order == TME_ENDIAN_BIG)"
                   2207:                echo "                     ? tme_betoh_u32(src_fifo0)"
                   2208:                echo "                     : tme_letoh_u32(src_fifo0));"
                   2209:                echo ""
                   2210:                echo "        /* if the source primary FIFO may be unaligned: */"
                   2211:                echo "        if (src_fifo0_may_be_unaligned) {"
                   2212:                echo ""
                   2213:                echo "          /* reprime the top half of the FIFO, leaving a"
                   2214:                echo "             total of 64 bits in it: */"
                   2215:                echo "          src_fifo0_next = *src_raw0;"
                   2216:                echo "          *TME_FB_XLAT_SRC_OLD(src_raw0) = src_fifo0_next;"
                   2217:                echo "          src_raw0++;"
                   2218:                echo "          src_fifo0_next = ((src_order == TME_ENDIAN_BIG)"
                   2219:                echo "                            ? tme_betoh_u32(src_fifo0_next)"
                   2220:                echo "                            : tme_letoh_u32(src_fifo0_next));"
                   2221:                echo "          src_fifo0_bits = 64;"
                   2222:                echo ""
                   2223:                echo "          /* if we have to shift off bits left over"
                   2224:                echo "             from rapidly advancing whole 32-bit words: */"
                   2225:                echo "          src_off %= 32;"
                   2226:                echo "          if (src_off > 0) {"
1.1.1.2   root     2227:                echo "            TME_FB_XLAT_SHIFT_SRC(TRUE,"
1.1       root     2228:                echo "                                  src_fifo0,"
                   2229:                echo "                                  src_fifo0_next,"
                   2230:                echo "                                  src_fifo0_bits,"
                   2231:                echo "                                  src_off,"
                   2232:                echo "                                  src_raw0,"
                   2233:                echo "                                  src_order);"
                   2234:                echo "          }"
                   2235:                echo "        }"
                   2236:                echo ""
                   2237:                echo "        /* otherwise, the source primary FIFO is always aligned: */"
                   2238:                echo "        else {"
                   2239:                echo "          assert ((src_off % 32) == 0);"
                   2240:                echo "        }"
                   2241:                echo ""
                   2242:                echo "        /* calculate the number of bits that we need"
                   2243:                echo "           to shift the source secondary FIFO, after"
                   2244:                echo "           discarding any bits in it now: */"
                   2245:                echo "        src_off = ((src_bypl * 8) - (src_width * src_bipp)) + (src_bypl * 8);"
                   2246:                echo "        src_off -= (src_fifo1_may_be_unaligned"
                   2247:                echo "                    ? src_fifo1_bits"
                   2248:                echo "                    : 32);"
                   2249:                echo ""
                   2250:                echo "        /* rapidly advance src_raw1 by the number of"
                   2251:                echo "           whole 32-bit words.  this will leave it pointing"
                   2252:                echo "           to the 32-bit word that has the first bit that"
                   2253:                echo "           we want to end up as the first bit in the source"
                   2254:                echo "           secondary FIFO: */"
                   2255:                echo "        src_raw1 += (src_off / 32);"
                   2256:                echo ""
                   2257:                echo "        /* reprime the source secondary FIFO: */"
                   2258:                echo "        src_fifo1 = *src_raw1;"
                   2259:                echo "        *TME_FB_XLAT_SRC_OLD(src_raw1) = src_fifo1;"
                   2260:                echo "        src_raw1++;"
                   2261:                echo "        src_fifo1 = ((src_order == TME_ENDIAN_BIG)"
                   2262:                echo "                     ? tme_betoh_u32(src_fifo1)"
                   2263:                echo "                     : tme_letoh_u32(src_fifo1));"
                   2264:                echo ""
                   2265:                echo "        /* if the source secondary FIFO may be unaligned: */"
                   2266:                echo "        if (src_fifo1_may_be_unaligned) {"
                   2267:                echo ""
                   2268:                echo "          /* reprime the top half of the FIFO, leaving a"
                   2269:                echo "             total of 64 bits in it: */"
                   2270:                echo "          src_fifo1_next = *src_raw1;"
                   2271:                echo "          *TME_FB_XLAT_SRC_OLD(src_raw1) = src_fifo1_next;"
                   2272:                echo "          src_raw1++;"
                   2273:                echo "          src_fifo1_next = ((src_order == TME_ENDIAN_BIG)"
                   2274:                echo "                            ? tme_betoh_u32(src_fifo1_next)"
                   2275:                echo "                            : tme_letoh_u32(src_fifo1_next));"
                   2276:                echo "          src_fifo1_bits = 64;"
                   2277:                echo ""
                   2278:                echo "          /* if we have to shift off bits left over"
                   2279:                echo "             from rapidly advancing whole 32-bit words: */"
                   2280:                echo "          src_off %= 32;"
                   2281:                echo "          if (src_off > 0) {"
1.1.1.2   root     2282:                echo "            TME_FB_XLAT_SHIFT_SRC(TRUE,"
1.1       root     2283:                echo "                                  src_fifo1,"
                   2284:                echo "                                  src_fifo1_next,"
                   2285:                echo "                                  src_fifo1_bits,"
                   2286:                echo "                                  src_off,"
                   2287:                echo "                                  src_raw1,"
                   2288:                echo "                                  src_order);"
                   2289:                echo "          }"
                   2290:                echo "        }"
                   2291:                echo ""
                   2292:                echo "        /* otherwise, the source secondary FIFO is always aligned: */"
                   2293:                echo "        else {"
                   2294:                echo "          assert ((src_off % 32) == 0);"
                   2295:                echo "        }"
                   2296:                echo ""
                   2297:                echo "        /* we are now on the first pixel of the next scanline: */"
                   2298:                echo "        src_x = 0;"
                   2299:                echo "      }"
                   2300:            else
                   2301:                echo "      /* if the source buffer is not packed, and we just"
                   2302:                echo "         read the last pixel on this source scanline: */"
                   2303:                echo "      if (!src_packed"
                   2304:                echo "          && ++src_x == src_width) {"
                   2305:                echo ""
                   2306:                echo "        /* calculate the number of bits between the"
                   2307:                echo "           last bit of the last pixel and the first bit"
                   2308:                echo "           of the first displayed pixel on the next"
                   2309:                echo "           scanline.  this is equal to the number of"
                   2310:                echo "           pad bits plus bits for undisplayed pixels: */"
                   2311:                echo "        src_off = ((src_bypl * 8) - (src_width * src_bipp));"
                   2312:                echo ""
                   2313:                echo "        /* while there are bits to shift: */"
                   2314:                echo "        for (; src_off > 0; src_off -= TME_MIN(src_off, 32)) {"
                   2315:                echo ""
                   2316:                echo "          /* shift the source primary FIFO: */"
                   2317:                echo "          TME_FB_XLAT_SHIFT_SRC(src_fifo0_may_be_unaligned,"
                   2318:                echo "                                src_fifo0,"
                   2319:                echo "                                src_fifo0_next,"
                   2320:                echo "                                src_fifo0_bits,"
                   2321:                echo "                                TME_MIN(src_off, 32),"
                   2322:                echo "                                src_raw0,"
                   2323:                echo "                                src_order);"
                   2324:                echo "        }"
                   2325:                echo ""
                   2326:                echo "        /* we are now on the first pixel of the next scanline: */"
                   2327:                echo "        src_x = 0;"
                   2328:                echo "      }"
                   2329:            fi
                   2330: 
                   2331:            if test `expr ${iter_next} % ${src_unroll}` = 0; then
1.1.1.2   root     2332: 
                   2333:                echo ""
                   2334:                if test "${src_fifo_shift}" = 32; then
                   2335:                    echo "      /* we've just translated another 32-bit word of the"
                   2336:                    echo "         source image, so decrement xlat_run: */"
                   2337:                    echo "      xlat_run--;"
                   2338:                else
                   2339:                    echo "      /* if we've just finished translating another 32-bit"
                   2340:                    echo "         word of the source image, decrement xlat_run: */"
                   2341:                    echo "      if (src_fifo0_bits <= 32 + ${src_fifo_shift}) {"
                   2342:                    echo "        xlat_run--;"
                   2343:                    echo "      }"
                   2344:                fi    
1.1       root     2345:                echo ""
                   2346:                echo "      /* shift the source primary FIFO: */"
                   2347:                echo "      TME_FB_XLAT_SHIFT_SRC(src_fifo0_may_be_unaligned,"
                   2348:                echo "                            src_fifo0,"
                   2349:                echo "                            src_fifo0_next,"
                   2350:                echo "                            src_fifo0_bits,"
                   2351:                echo "                            ${src_fifo_shift},"
                   2352:                echo "                            src_raw0,"
                   2353:                echo "                            src_order);"
                   2354:                if test $scale = _h_; then
                   2355:                    echo ""
                   2356:                    echo "      /* shift the source secondary FIFO: */"
                   2357:                    echo "      TME_FB_XLAT_SHIFT_SRC(src_fifo1_may_be_unaligned,"
                   2358:                    echo "                            src_fifo1,"
                   2359:                    echo "                            src_fifo1_next,"
                   2360:                    echo "                            src_fifo1_bits,"
                   2361:                    echo "                            ${src_fifo_shift},"
                   2362:                    echo "                            src_raw1,"
                   2363:                    echo "                            src_order);"
                   2364:                fi
                   2365:            fi
                   2366:            
                   2367:            # the number of bits to skip in a destination FIFO to get to
                   2368:            # this iteration's pixel:
                   2369:            dst_shift=`expr ${iter} % ${dst_unroll}`
                   2370:            dst_shift='('`expr ${dst_shift} \* ${dst_iter_scale}`' * dst_bipp)'
                   2371: 
                   2372:            echo ""
                   2373:            echo "      /* put the pixel into the destination primary FIFO: */"
                   2374:            echo "      dst_fifo0 |="
                   2375:            echo "        (pixel"
                   2376:            echo "         << (dst_order == TME_ENDIAN_BIG"
                   2377:            echo "             ? ((32 - dst_bipp) - ${dst_shift})"
                   2378:            echo "             : ${dst_shift}));"
                   2379: 
                   2380:            if test $scale = _d_; then
                   2381: 
                   2382:                echo ""
                   2383:                echo "      /* put the pixel into the destination secondary FIFO: */"
                   2384:                echo "      dst_fifo1 |="
                   2385:                echo "        (pixel"
                   2386:                echo "         << (dst_order == TME_ENDIAN_BIG"
                   2387:                echo "             ? ((32 - dst_bipp) - ${dst_shift})"
                   2388:                echo "             : ${dst_shift}));"
                   2389: 
                   2390:                echo ""
1.1.1.2   root     2391:                if test `expr ${dst_bipp} \>= 24` = 1; then
                   2392:                    echo "      /* put the pixel into both FIFOs again.  in"
                   2393:                    echo "         this case, dst_bipp is known to be ${dst_bipp},"
                   2394:                    echo "         meaning the FIFOs cannot entirely take these"
                   2395:                    echo "         further pixels, so we need to shift the FIFOs: */"
                   2396:                    indent0=""
                   2397:                    indent1=X
                   2398:                elif test ${dst_bipp} = 0; then
                   2399:                    echo "      /* put the pixel into both FIFOs again.  if"
                   2400:                    echo "         dst_bipp is 24 or greater, the FIFOs can"
                   2401:                    echo "         not entirely take these further pixels,"
                   2402:                    echo "         so we need to shift the FIFOs: */"
                   2403:                    echo "      if (dst_bipp >= 24) {"
                   2404:                    indent0="  "
                   2405:                    indent1="  "
                   2406:                else
                   2407:                    echo "      /* put the pixel into both FIFOs again.  in"
                   2408:                    echo "         this case, dst_bipp is known to be ${dst_bipp},"
                   2409:                    echo "         meaning the FIFOs can take these further pixels"
                   2410:                    echo "         without shifting the FIFOs, as long as we shift"
                   2411:                    echo "         the pixels one pixel further: */"
                   2412:                    indent0=X
                   2413:                    indent1=""
                   2414:                fi
                   2415:                if test "X${indent0}" != "XX"; then
                   2416:                    echo "${indent0}      TME_FB_XLAT_SHIFT_DST(dst_fifo0_may_be_unaligned,"
                   2417:                    echo "${indent0}                            dst_fifo0,"
                   2418:                    echo "${indent0}                            dst_fifo0_next,"
                   2419:                    echo "${indent0}                            dst_fifo0_bits,"
                   2420:                    echo "${indent0}                            dst_bipp,"
                   2421:                    echo "${indent0}                            dst_raw0,"
                   2422:                    echo "${indent0}                            dst_order);"
                   2423:                    echo "${indent0}      TME_FB_XLAT_SHIFT_DST(dst_fifo1_may_be_unaligned,"
                   2424:                    echo "${indent0}                            dst_fifo1,"
                   2425:                    echo "${indent0}                            dst_fifo1_next,"
                   2426:                    echo "${indent0}                            dst_fifo1_bits,"
                   2427:                    echo "${indent0}                            dst_bipp,"
                   2428:                    echo "${indent0}                            dst_raw1,"
                   2429:                    echo "${indent0}                            dst_order);"
                   2430:                    echo ""
                   2431:                    echo "${indent0}      /* now that we've shifted by dst_bipp, we can"
                   2432:                    echo "${indent0}         put the further pixels exactly where the"
                   2433:                    echo "${indent0}         first pixels went in the FIFOs: */"
                   2434:                    echo "${indent0}      dst_fifo0 |="
                   2435:                    echo "${indent0}        (pixel"
                   2436:                    echo "${indent0}         << (dst_order == TME_ENDIAN_BIG"
                   2437:                    echo "${indent0}             ? ((32 - dst_bipp) - ${dst_shift})"
                   2438:                    echo "${indent0}             : ${dst_shift}));"
                   2439:                    echo "${indent0}      dst_fifo1 |="
                   2440:                    echo "${indent0}        (pixel"
                   2441:                    echo "${indent0}         << (dst_order == TME_ENDIAN_BIG"
                   2442:                    echo "${indent0}             ? ((32 - dst_bipp) - ${dst_shift})"
                   2443:                    echo "${indent0}             : ${dst_shift}));"
                   2444:                fi
                   2445:                if test ${dst_bipp} = 0; then
                   2446:                    echo "      }"
                   2447:                    echo ""
                   2448:                    echo "      /* otherwise, the FIFOs can take these further pixels,"
                   2449:                    echo "         as long as we shift the pixels one pixel further: */"
                   2450:                    echo "      else {"
                   2451:                fi
                   2452:                if test "X${indent1}" != "XX"; then
                   2453:                    echo "${indent1}      dst_fifo0 |="
                   2454:                    echo "${indent1}        (pixel"
                   2455:                    echo "${indent1}         << (dst_order == TME_ENDIAN_BIG"
                   2456:                    echo "${indent1}             ? ((32 - dst_bipp) - (${dst_shift} + dst_bipp))"
                   2457:                    echo "${indent1}             : (${dst_shift} + dst_bipp)));"
                   2458:                    echo "${indent1}      dst_fifo1 |="
                   2459:                    echo "${indent1}        (pixel"
                   2460:                    echo "${indent1}         << (dst_order == TME_ENDIAN_BIG"
                   2461:                    echo "${indent1}             ? ((32 - dst_bipp) - (${dst_shift} + dst_bipp))"
                   2462:                    echo "${indent1}             : (${dst_shift} + dst_bipp)));"
                   2463:                fi
                   2464:                if test ${dst_bipp} = 0; then
                   2465:                    echo "      }"
                   2466:                fi
1.1       root     2467:            fi
                   2468: 
                   2469:            echo ""
                   2470:            echo "      /* if the destination buffer is not packed, and we just"
                   2471:            echo "         wrote the last pixel on this destination scanline: */"
                   2472:            if test $scale = _d_; then value=2; else value=1; fi
                   2473:            echo "      if (!dst_packed"
                   2474:            echo "          && (dst_x += ${value}) == dst_width) {"
                   2475:            echo ""
                   2476:            echo "        /* calculate the number of bits between the"
                   2477:            echo "           last bit of the last pixel and the first bit"
                   2478:            echo "           of the first displayed pixel on the next"
                   2479:            echo "           scanline.  this is equal to the number of"
                   2480:            echo "           pad bits plus bits for undisplayed pixels: */"
                   2481:            echo "        dst_off = ((dst_bypl * 8) - (dst_width * dst_bipp));"
                   2482:            echo ""
                   2483:            echo "        /* while there are bits to shift: */"
                   2484:            echo "        for (; dst_off > 0; dst_off -= TME_MIN(dst_off, 32)) {"
                   2485:            echo ""
                   2486:            echo "          /* shift the destination primary FIFO: */"
                   2487:            echo "          TME_FB_XLAT_SHIFT_DST(dst_fifo0_may_be_unaligned,"
                   2488:            echo "                                dst_fifo0,"
                   2489:            echo "                                dst_fifo0_next,"
                   2490:            echo "                                dst_fifo0_bits,"
                   2491:            echo "                                TME_MIN(dst_off, 32),"
                   2492:            echo "                                dst_raw0,"
                   2493:            echo "                                dst_order);"
                   2494:            if test $scale = _d_; then
                   2495:                echo ""
                   2496:                echo "          /* shift the destination secondary FIFO: */"
                   2497:                echo "          TME_FB_XLAT_SHIFT_DST(dst_fifo1_may_be_unaligned,"
                   2498:                echo "                                dst_fifo1,"
                   2499:                echo "                                dst_fifo1_next,"
                   2500:                echo "                                dst_fifo1_bits,"
                   2501:                echo "                                TME_MIN(dst_off, 32),"
                   2502:                echo "                                dst_raw1,"
                   2503:                echo "                                dst_order);"
                   2504:            fi
                   2505:            echo "        }"
                   2506:            echo ""
                   2507:            echo "        /* we are now on the first pixel of the next scanline: */"
                   2508:            echo "        dst_x = 0;"
                   2509:            echo "      }"
                   2510: 
                   2511:            if test `expr ${iter_next} % ${dst_unroll}` = 0; then
                   2512:                echo ""
                   2513:                echo "      /* shift the destination primary FIFO: */"
                   2514:                echo "      TME_FB_XLAT_SHIFT_DST(dst_fifo0_may_be_unaligned,"
                   2515:                echo "                            dst_fifo0,"
                   2516:                echo "                            dst_fifo0_next,"
                   2517:                echo "                            dst_fifo0_bits,"
                   2518:                echo "                            ${dst_fifo_shift},"
                   2519:                echo "                            dst_raw0,"
                   2520:                echo "                            dst_order);"
                   2521:                if test $scale = _d_; then
                   2522:                    echo ""
                   2523:                    echo "      /* shift the destination secondary FIFO: */"
                   2524:                    echo "      TME_FB_XLAT_SHIFT_DST(dst_fifo1_may_be_unaligned,"
                   2525:                    echo "                            dst_fifo1,"
                   2526:                    echo "                            dst_fifo1_next,"
                   2527:                    echo "                            dst_fifo1_bits,"
                   2528:                    echo "                            ${dst_fifo_shift},"
                   2529:                    echo "                            dst_raw1,"
                   2530:                    echo "                            dst_order);"
                   2531:                fi
                   2532:            fi
                   2533: 
                   2534:            iter=${iter_next}
                   2535:        done
                   2536:        echo ""
                   2537:        echo "    }"
                   2538: 
                   2539:        if test `expr ${iter} % ${dst_unroll}` != 0; then
                   2540:            echo "$PROG internal error - the last iter did not shift the destination FIFOs ($iter and $dst_unroll)" 1>&2
                   2541:            exit 1
                   2542:        fi
                   2543:        
                   2544:        echo ""
                   2545:        echo "    /* if the destination FIFOs may be unaligned, there"
                   2546:        echo "       may be bits left in the FIFO that we need to flush: */"
                   2547:        echo "    if (dst_fifo0_may_be_unaligned"
                   2548:        echo "        && dst_fifo0_bits > 0) {"
                   2549:        echo "      dst_fifo0 = *dst_raw0;"
                   2550:        echo "      if (dst_order == TME_ENDIAN_BIG) {"
                   2551:        echo "        dst_fifo0_next |= (tme_betoh_u32(dst_fifo0) & (0xffffffff >> dst_fifo0_bits));"
                   2552:        echo "        dst_fifo0_next = tme_htobe_u32(dst_fifo0_next);"
                   2553:        echo "      }"
                   2554:        echo "      else {"
                   2555:        echo "        dst_fifo0_next |= (tme_letoh_u32(dst_fifo0) & (0xffffffff << dst_fifo0_bits));"
                   2556:        echo "        dst_fifo0_next = tme_htole_u32(dst_fifo0_next);"
                   2557:        echo "      }"
                   2558:        echo "      *dst_raw0 = dst_fifo0;"
                   2559:        echo "    }"
                   2560:        if test $scale = _d_; then
                   2561:            echo "    if (dst_fifo1_may_be_unaligned"
                   2562:            echo "        && dst_fifo1_bits > 0) {"
                   2563:            echo "      dst_fifo1 = *dst_raw1;"
                   2564:            echo "      if (dst_order == TME_ENDIAN_BIG) {"
                   2565:            echo "        dst_fifo1_next |= (tme_betoh_u32(dst_fifo1) & (0xffffffff >> dst_fifo1_bits));"
                   2566:            echo "        dst_fifo1_next = tme_htobe_u32(dst_fifo1_next);"
                   2567:            echo "      }"
                   2568:            echo "      else {"
                   2569:            echo "        dst_fifo1_next |= (tme_letoh_u32(dst_fifo1) & (0xffffffff << dst_fifo1_bits));"
                   2570:            echo "        dst_fifo1_next = tme_htole_u32(dst_fifo1_next);"
                   2571:            echo "      }"
                   2572:            echo "      *dst_raw1 = dst_fifo1;"
                   2573:            echo "    }"
                   2574:        fi
                   2575: 
                   2576:        echo ""
                   2577:        echo "    /* loop back to compare more 32-bit words: */"
                   2578:        echo "    src_raw0--;"
                   2579:        echo "  }"
                   2580: 
                   2581:        echo ""
                   2582:        echo "  /* return nonzero iff we did some translating: */"
                   2583:        echo "  return (xlat_run >= 0);"
                   2584:        
                   2585:        echo ""
                   2586:        for macro in ${undef_macros}; do
                   2587:            echo "#undef ${macro}"
                   2588:        done
                   2589:        echo "}"
                   2590: 
                   2591:     done
                   2592: done
                   2593: 
                   2594: echo ""
                   2595: echo "/* the xlat function array: */"
                   2596: echo "static const struct tme_fb_xlat tme_fb_xlats[] = {$xlat_array
                   2597: };"
                   2598: 
                   2599: # done:
                   2600: exit 0

unix.superglobalmegacorp.com

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