pnggccrd.c
上传用户:jnfxsk
上传日期:2022-06-16
资源大小:3675k
文件大小:235k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. /* pnggccrd.c - mixed C/assembler version of utilities to read a PNG file
  2.  *
  3.  * For Intel x86 CPU (Pentium-MMX or later) and GNU C compiler.
  4.  *
  5.  *     See http://www.intel.com/drg/pentiumII/appnotes/916/916.htm
  6.  *     and http://www.intel.com/drg/pentiumII/appnotes/923/923.htm
  7.  *     for Intel's performance analysis of the MMX vs. non-MMX code.
  8.  *
  9.  * libpng version 1.2.8 - December 3, 2004
  10.  * For conditions of distribution and use, see copyright notice in png.h
  11.  * Copyright (c) 1998-2004 Glenn Randers-Pehrson
  12.  * Copyright (c) 1998, Intel Corporation
  13.  *
  14.  * Based on MSVC code contributed by Nirav Chhatrapati, Intel Corp., 1998.
  15.  * Interface to libpng contributed by Gilles Vollant, 1999.
  16.  * GNU C port by Greg Roelofs, 1999-2001.
  17.  *
  18.  * Lines 2350-4300 converted in place with intel2gas 1.3.1:
  19.  *
  20.  *   intel2gas -mdI pnggccrd.c.partially-msvc -o pnggccrd.c
  21.  *
  22.  * and then cleaned up by hand.  See http://hermes.terminal.at/intel2gas/ .
  23.  *
  24.  * NOTE:  A sufficiently recent version of GNU as (or as.exe under DOS/Windows)
  25.  *        is required to assemble the newer MMX instructions such as movq.
  26.  *        For djgpp, see
  27.  *
  28.  *           ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/bnu281b.zip
  29.  *
  30.  *        (or a later version in the same directory).  For Linux, check your
  31.  *        distribution's web site(s) or try these links:
  32.  *
  33.  *           http://rufus.w3.org/linux/RPM/binutils.html
  34.  *           http://www.debian.org/Packages/stable/devel/binutils.html
  35.  *           ftp://ftp.slackware.com/pub/linux/slackware/slackware/slakware/d1/
  36.  *             binutils.tgz
  37.  *
  38.  *        For other platforms, see the main GNU site:
  39.  *
  40.  *           ftp://ftp.gnu.org/pub/gnu/binutils/
  41.  *
  42.  *        Version 2.5.2l.15 is definitely too old...
  43.  */
  44. /*
  45.  * TEMPORARY PORTING NOTES AND CHANGELOG (mostly by Greg Roelofs)
  46.  * =====================================
  47.  *
  48.  * 19991006:
  49.  *  - fixed sign error in post-MMX cleanup code (16- & 32-bit cases)
  50.  *
  51.  * 19991007:
  52.  *  - additional optimizations (possible or definite):
  53.  *     x [DONE] write MMX code for 64-bit case (pixel_bytes == 8) [not tested]
  54.  *     - write MMX code for 48-bit case (pixel_bytes == 6)
  55.  *     - figure out what's up with 24-bit case (pixel_bytes == 3):
  56.  *        why subtract 8 from width_mmx in the pass 4/5 case?
  57.  *        (only width_mmx case) (near line 1606)
  58.  *     x [DONE] replace pixel_bytes within each block with the true
  59.  *        constant value (or are compilers smart enough to do that?)
  60.  *     - rewrite all MMX interlacing code so it's aligned with
  61.  *        the *beginning* of the row buffer, not the end.  This
  62.  *        would not only allow one to eliminate half of the memory
  63.  *        writes for odd passes (that is, pass == odd), it may also
  64.  *        eliminate some unaligned-data-access exceptions (assuming
  65.  *        there's a penalty for not aligning 64-bit accesses on
  66.  *        64-bit boundaries).  The only catch is that the "leftover"
  67.  *        pixel(s) at the end of the row would have to be saved,
  68.  *        but there are enough unused MMX registers in every case,
  69.  *        so this is not a problem.  A further benefit is that the
  70.  *        post-MMX cleanup code (C code) in at least some of the
  71.  *        cases could be done within the assembler block.
  72.  *  x [DONE] the "v3 v2 v1 v0 v7 v6 v5 v4" comments are confusing,
  73.  *     inconsistent, and don't match the MMX Programmer's Reference
  74.  *     Manual conventions anyway.  They should be changed to
  75.  *     "b7 b6 b5 b4 b3 b2 b1 b0," where b0 indicates the byte that
  76.  *     was lowest in memory (e.g., corresponding to a left pixel)
  77.  *     and b7 is the byte that was highest (e.g., a right pixel).
  78.  *
  79.  * 19991016:
  80.  *  - Brennan's Guide notwithstanding, gcc under Linux does *not*
  81.  *     want globals prefixed by underscores when referencing them--
  82.  *     i.e., if the variable is const4, then refer to it as const4,
  83.  *     not _const4.  This seems to be a djgpp-specific requirement.
  84.  *     Also, such variables apparently *must* be declared outside
  85.  *     of functions; neither static nor automatic variables work if
  86.  *     defined within the scope of a single function, but both
  87.  *     static and truly global (multi-module) variables work fine.
  88.  *
  89.  * 19991023:
  90.  *  - fixed png_combine_row() non-MMX replication bug (odd passes only?)
  91.  *  - switched from string-concatenation-with-macros to cleaner method of
  92.  *     renaming global variables for djgpp--i.e., always use prefixes in
  93.  *     inlined assembler code (== strings) and conditionally rename the
  94.  *     variables, not the other way around.  Hence _const4, _mask8_0, etc.
  95.  *
  96.  * 19991024:
  97.  *  - fixed mmxsupport()/png_do_read_interlace() first-row bug
  98.  *     This one was severely weird:  even though mmxsupport() doesn't touch
  99.  *     ebx (where "row" pointer was stored), it nevertheless managed to zero
  100.  *     the register (even in static/non-fPIC code--see below), which in turn
  101.  *     caused png_do_read_interlace() to return prematurely on the first row of
  102.  *     interlaced images (i.e., without expanding the interlaced pixels).
  103.  *     Inspection of the generated assembly code didn't turn up any clues,
  104.  *     although it did point at a minor optimization (i.e., get rid of
  105.  *     mmx_supported_local variable and just use eax).  Possibly the CPUID
  106.  *     instruction is more destructive than it looks?  (Not yet checked.)
  107.  *  - "info gcc" was next to useless, so compared fPIC and non-fPIC assembly
  108.  *     listings...  Apparently register spillage has to do with ebx, since
  109.  *     it's used to index the global offset table.  Commenting it out of the
  110.  *     input-reg lists in png_combine_row() eliminated compiler barfage, so
  111.  *     ifdef'd with __PIC__ macro:  if defined, use a global for unmask
  112.  *
  113.  * 19991107:
  114.  *  - verified CPUID clobberage:  12-char string constant ("GenuineIntel",
  115.  *     "AuthenticAMD", etc.) placed in ebx:ecx:edx.  Still need to polish.
  116.  *
  117.  * 19991120:
  118.  *  - made "diff" variable (now "_dif") global to simplify conversion of
  119.  *     filtering routines (running out of regs, sigh).  "diff" is still used
  120.  *     in interlacing routines, however.
  121.  *  - fixed up both versions of mmxsupport() (ORIG_THAT_USED_TO_CLOBBER_EBX
  122.  *     macro determines which is used); original not yet tested.
  123.  *
  124.  * 20000213:
  125.  *  - when compiling with gcc, be sure to use  -fomit-frame-pointer
  126.  *
  127.  * 20000319:
  128.  *  - fixed a register-name typo in png_do_read_interlace(), default (MMX) case,
  129.  *     pass == 4 or 5, that caused visible corruption of interlaced images
  130.  *
  131.  * 20000623:
  132.  *  - Various problems were reported with gcc 2.95.2 in the Cygwin environment,
  133.  *     many of the form "forbidden register 0 (ax) was spilled for class AREG."
  134.  *     This is explained at http://gcc.gnu.org/fom_serv/cache/23.html, and
  135.  *     Chuck Wilson supplied a patch involving dummy output registers.  See
  136.  *     http://sourceforge.net/bugs/?func=detailbug&bug_id=108741&group_id=5624
  137.  *     for the original (anonymous) SourceForge bug report.
  138.  *
  139.  * 20000706:
  140.  *  - Chuck Wilson passed along these remaining gcc 2.95.2 errors:
  141.  *       pnggccrd.c: In function `png_combine_row':
  142.  *       pnggccrd.c:525: more than 10 operands in `asm'
  143.  *       pnggccrd.c:669: more than 10 operands in `asm'
  144.  *       pnggccrd.c:828: more than 10 operands in `asm'
  145.  *       pnggccrd.c:994: more than 10 operands in `asm'
  146.  *       pnggccrd.c:1177: more than 10 operands in `asm'
  147.  *     They are all the same problem and can be worked around by using the
  148.  *     global _unmask variable unconditionally, not just in the -fPIC case.
  149.  *     Reportedly earlier versions of gcc also have the problem with more than
  150.  *     10 operands; they just don't report it.  Much strangeness ensues, etc.
  151.  *
  152.  * 20000729:
  153.  *  - enabled png_read_filter_row_mmx_up() (shortest remaining unconverted
  154.  *     MMX routine); began converting png_read_filter_row_mmx_sub()
  155.  *  - to finish remaining sections:
  156.  *     - clean up indentation and comments
  157.  *     - preload local variables
  158.  *     - add output and input regs (order of former determines numerical
  159.  *        mapping of latter)
  160.  *     - avoid all usage of ebx (including bx, bh, bl) register [20000823]
  161.  *     - remove "$" from addressing of Shift and Mask variables [20000823]
  162.  *
  163.  * 20000731:
  164.  *  - global union vars causing segfaults in png_read_filter_row_mmx_sub()?
  165.  *
  166.  * 20000822:
  167.  *  - ARGH, stupid png_read_filter_row_mmx_sub() segfault only happens with
  168.  *     shared-library (-fPIC) version!  Code works just fine as part of static
  169.  *     library.  Damn damn damn damn damn, should have tested that sooner.
  170.  *     ebx is getting clobbered again (explicitly this time); need to save it
  171.  *     on stack or rewrite asm code to avoid using it altogether.  Blargh!
  172.  *
  173.  * 20000823:
  174.  *  - first section was trickiest; all remaining sections have ebx -> edx now.
  175.  *     (-fPIC works again.)  Also added missing underscores to various Shift*
  176.  *     and *Mask* globals and got rid of leading "$" signs.
  177.  *
  178.  * 20000826:
  179.  *  - added visual separators to help navigate microscopic printed copies
  180.  *     (http://pobox.com/~newt/code/gpr-latest.zip, mode 10); started working
  181.  *     on png_read_filter_row_mmx_avg()
  182.  *
  183.  * 20000828:
  184.  *  - finished png_read_filter_row_mmx_avg():  only Paeth left! (930 lines...)
  185.  *     What the hell, did png_read_filter_row_mmx_paeth(), too.  Comments not
  186.  *     cleaned up/shortened in either routine, but functionality is complete
  187.  *     and seems to be working fine.
  188.  *
  189.  * 20000829:
  190.  *  - ahhh, figured out last(?) bit of gcc/gas asm-fu:  if register is listed
  191.  *     as an input reg (with dummy output variables, etc.), then it *cannot*
  192.  *     also appear in the clobber list or gcc 2.95.2 will barf.  The solution
  193.  *     is simple enough...
  194.  *
  195.  * 20000914:
  196.  *  - bug in png_read_filter_row_mmx_avg():  16-bit grayscale not handled
  197.  *     correctly (but 48-bit RGB just fine)
  198.  *
  199.  * 20000916:
  200.  *  - fixed bug in png_read_filter_row_mmx_avg(), bpp == 2 case; three errors:
  201.  *     - "_ShiftBpp.use = 24;"      should have been   "_ShiftBpp.use = 16;"
  202.  *     - "_ShiftRem.use = 40;"      should have been   "_ShiftRem.use = 48;"
  203.  *     - "psllq _ShiftRem, %%mm2"   should have been   "psrlq _ShiftRem, %%mm2"
  204.  *
  205.  * 20010101:
  206.  *  - added new png_init_mmx_flags() function (here only because it needs to
  207.  *     call mmxsupport(), which should probably become global png_mmxsupport());
  208.  *     modified other MMX routines to run conditionally (png_ptr->asm_flags)
  209.  *
  210.  * 20010103:
  211.  *  - renamed mmxsupport() to png_mmx_support(), with auto-set of mmx_supported,
  212.  *     and made it public; moved png_init_mmx_flags() to png.c as internal func
  213.  *
  214.  * 20010104:
  215.  *  - removed dependency on png_read_filter_row_c() (C code already duplicated
  216.  *     within MMX version of png_read_filter_row()) so no longer necessary to
  217.  *     compile it into pngrutil.o
  218.  *
  219.  * 20010310:
  220.  *  - fixed buffer-overrun bug in png_combine_row() C code (non-MMX)
  221.  *
  222.  * 20020304:
  223.  *  - eliminated incorrect use of width_mmx in pixel_bytes == 8 case
  224.  *
  225.  * 20040724:
  226.  *   - more tinkering with clobber list at lines 4529 and 5033, to get
  227.  *     it to compile on gcc-3.4.
  228.  *
  229.  * STILL TO DO:
  230.  *     - test png_do_read_interlace() 64-bit case (pixel_bytes == 8)
  231.  *     - write MMX code for 48-bit case (pixel_bytes == 6)
  232.  *     - figure out what's up with 24-bit case (pixel_bytes == 3):
  233.  *        why subtract 8 from width_mmx in the pass 4/5 case?
  234.  *        (only width_mmx case) (near line 1606)
  235.  *     - rewrite all MMX interlacing code so it's aligned with beginning
  236.  *        of the row buffer, not the end (see 19991007 for details)
  237.  *     x pick one version of mmxsupport() and get rid of the other
  238.  *     - add error messages to any remaining bogus default cases
  239.  *     - enable pixel_depth == 8 cases in png_read_filter_row()? (test speed)
  240.  *     x add support for runtime enable/disable/query of various MMX routines
  241.  */
  242. #define PNG_INTERNAL
  243. #include "png.h"
  244. #if defined(PNG_USE_PNGGCCRD)
  245. int PNGAPI png_mmx_support(void);
  246. #ifdef PNG_USE_LOCAL_ARRAYS
  247. static const int FARDATA png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  248. static const int FARDATA png_pass_inc[7]   = {8, 8, 4, 4, 2, 2, 1};
  249. static const int FARDATA png_pass_width[7] = {8, 4, 4, 2, 2, 1, 1};
  250. #endif
  251. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  252. /* djgpp, Win32, and Cygwin add their own underscores to global variables,
  253.  * so define them without: */
  254. #if defined(__DJGPP__) || defined(WIN32) || defined(__CYGWIN__)
  255. #  define _mmx_supported  mmx_supported
  256. #  define _const4         const4
  257. #  define _const6         const6
  258. #  define _mask8_0        mask8_0
  259. #  define _mask16_1       mask16_1
  260. #  define _mask16_0       mask16_0
  261. #  define _mask24_2       mask24_2
  262. #  define _mask24_1       mask24_1
  263. #  define _mask24_0       mask24_0
  264. #  define _mask32_3       mask32_3
  265. #  define _mask32_2       mask32_2
  266. #  define _mask32_1       mask32_1
  267. #  define _mask32_0       mask32_0
  268. #  define _mask48_5       mask48_5
  269. #  define _mask48_4       mask48_4
  270. #  define _mask48_3       mask48_3
  271. #  define _mask48_2       mask48_2
  272. #  define _mask48_1       mask48_1
  273. #  define _mask48_0       mask48_0
  274. #  define _LBCarryMask    LBCarryMask
  275. #  define _HBClearMask    HBClearMask
  276. #  define _ActiveMask     ActiveMask
  277. #  define _ActiveMask2    ActiveMask2
  278. #  define _ActiveMaskEnd  ActiveMaskEnd
  279. #  define _ShiftBpp       ShiftBpp
  280. #  define _ShiftRem       ShiftRem
  281. #ifdef PNG_THREAD_UNSAFE_OK
  282. #  define _unmask         unmask
  283. #  define _FullLength     FullLength
  284. #  define _MMXLength      MMXLength
  285. #  define _dif            dif
  286. #  define _patemp         patemp
  287. #  define _pbtemp         pbtemp
  288. #  define _pctemp         pctemp
  289. #endif
  290. #endif
  291. /* These constants are used in the inlined MMX assembly code.
  292.    Ignore gcc's "At top level: defined but not used" warnings. */
  293. /* GRR 20000706:  originally _unmask was needed only when compiling with -fPIC,
  294.  *  since that case uses the %ebx register for indexing the Global Offset Table
  295.  *  and there were no other registers available.  But gcc 2.95 and later emit
  296.  *  "more than 10 operands in `asm'" errors when %ebx is used to preload unmask
  297.  *  in the non-PIC case, so we'll just use the global unconditionally now.
  298.  */
  299. #ifdef PNG_THREAD_UNSAFE_OK
  300. static int _unmask;
  301. #endif
  302. static unsigned long long _mask8_0  = 0x0102040810204080LL;
  303. static unsigned long long _mask16_1 = 0x0101020204040808LL;
  304. static unsigned long long _mask16_0 = 0x1010202040408080LL;
  305. static unsigned long long _mask24_2 = 0x0101010202020404LL;
  306. static unsigned long long _mask24_1 = 0x0408080810101020LL;
  307. static unsigned long long _mask24_0 = 0x2020404040808080LL;
  308. static unsigned long long _mask32_3 = 0x0101010102020202LL;
  309. static unsigned long long _mask32_2 = 0x0404040408080808LL;
  310. static unsigned long long _mask32_1 = 0x1010101020202020LL;
  311. static unsigned long long _mask32_0 = 0x4040404080808080LL;
  312. static unsigned long long _mask48_5 = 0x0101010101010202LL;
  313. static unsigned long long _mask48_4 = 0x0202020204040404LL;
  314. static unsigned long long _mask48_3 = 0x0404080808080808LL;
  315. static unsigned long long _mask48_2 = 0x1010101010102020LL;
  316. static unsigned long long _mask48_1 = 0x2020202040404040LL;
  317. static unsigned long long _mask48_0 = 0x4040808080808080LL;
  318. static unsigned long long _const4   = 0x0000000000FFFFFFLL;
  319. //static unsigned long long _const5 = 0x000000FFFFFF0000LL;     // NOT USED
  320. static unsigned long long _const6   = 0x00000000000000FFLL;
  321. // These are used in the row-filter routines and should/would be local
  322. //  variables if not for gcc addressing limitations.
  323. // WARNING: Their presence probably defeats the thread safety of libpng.
  324. #ifdef PNG_THREAD_UNSAFE_OK
  325. static png_uint_32  _FullLength;
  326. static png_uint_32  _MMXLength;
  327. static int          _dif;
  328. static int          _patemp; // temp variables for Paeth routine
  329. static int          _pbtemp;
  330. static int          _pctemp;
  331. #endif
  332. void /* PRIVATE */
  333. png_squelch_warnings(void)
  334. {
  335. #ifdef PNG_THREAD_UNSAFE_OK
  336.    _dif = _dif;
  337.    _patemp = _patemp;
  338.    _pbtemp = _pbtemp;
  339.    _pctemp = _pctemp;
  340.    _MMXLength = _MMXLength;
  341. #endif
  342.    _const4  = _const4;
  343.    _const6  = _const6;
  344.    _mask8_0  = _mask8_0;
  345.    _mask16_1 = _mask16_1;
  346.    _mask16_0 = _mask16_0;
  347.    _mask24_2 = _mask24_2;
  348.    _mask24_1 = _mask24_1;
  349.    _mask24_0 = _mask24_0;
  350.    _mask32_3 = _mask32_3;
  351.    _mask32_2 = _mask32_2;
  352.    _mask32_1 = _mask32_1;
  353.    _mask32_0 = _mask32_0;
  354.    _mask48_5 = _mask48_5;
  355.    _mask48_4 = _mask48_4;
  356.    _mask48_3 = _mask48_3;
  357.    _mask48_2 = _mask48_2;
  358.    _mask48_1 = _mask48_1;
  359.    _mask48_0 = _mask48_0;
  360. }
  361. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  362. static int _mmx_supported = 2;
  363. /*===========================================================================*/
  364. /*                                                                           */
  365. /*                       P N G _ C O M B I N E _ R O W                       */
  366. /*                                                                           */
  367. /*===========================================================================*/
  368. #if defined(PNG_HAVE_ASSEMBLER_COMBINE_ROW)
  369. #define BPP2  2
  370. #define BPP3  3 /* bytes per pixel (a.k.a. pixel_bytes) */
  371. #define BPP4  4
  372. #define BPP6  6 /* (defined only to help avoid cut-and-paste errors) */
  373. #define BPP8  8
  374. /* Combines the row recently read in with the previous row.
  375.    This routine takes care of alpha and transparency if requested.
  376.    This routine also handles the two methods of progressive display
  377.    of interlaced images, depending on the mask value.
  378.    The mask value describes which pixels are to be combined with
  379.    the row.  The pattern always repeats every 8 pixels, so just 8
  380.    bits are needed.  A one indicates the pixel is to be combined; a
  381.    zero indicates the pixel is to be skipped.  This is in addition
  382.    to any alpha or transparency value associated with the pixel.
  383.    If you want all pixels to be combined, pass 0xff (255) in mask. */
  384. /* Use this routine for the x86 platform - it uses a faster MMX routine
  385.    if the machine supports MMX. */
  386. void /* PRIVATE */
  387. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  388. {
  389.    png_debug(1, "in png_combine_row (pnggccrd.c)n");
  390. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  391.    if (_mmx_supported == 2) {
  392. #if !defined(PNG_1_0_X)
  393.        /* this should have happened in png_init_mmx_flags() already */
  394.        png_warning(png_ptr, "asm_flags may not have been initialized");
  395. #endif
  396.        png_mmx_support();
  397.    }
  398. #endif
  399.    if (mask == 0xff)
  400.    {
  401.       png_debug(2,"mask == 0xff:  doing single png_memcpy()n");
  402.       png_memcpy(row, png_ptr->row_buf + 1,
  403.        (png_size_t)PNG_ROWBYTES(png_ptr->row_info.pixel_depth,png_ptr->width));
  404.    }
  405.    else   /* (png_combine_row() is never called with mask == 0) */
  406.    {
  407.       switch (png_ptr->row_info.pixel_depth)
  408.       {
  409.          case 1:        /* png_ptr->row_info.pixel_depth */
  410.          {
  411.             png_bytep sp;
  412.             png_bytep dp;
  413.             int s_inc, s_start, s_end;
  414.             int m;
  415.             int shift;
  416.             png_uint_32 i;
  417.             sp = png_ptr->row_buf + 1;
  418.             dp = row;
  419.             m = 0x80;
  420. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  421.             if (png_ptr->transformations & PNG_PACKSWAP)
  422.             {
  423.                 s_start = 0;
  424.                 s_end = 7;
  425.                 s_inc = 1;
  426.             }
  427.             else
  428. #endif
  429.             {
  430.                 s_start = 7;
  431.                 s_end = 0;
  432.                 s_inc = -1;
  433.             }
  434.             shift = s_start;
  435.             for (i = 0; i < png_ptr->width; i++)
  436.             {
  437.                if (m & mask)
  438.                {
  439.                   int value;
  440.                   value = (*sp >> shift) & 0x1;
  441.                   *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  442.                   *dp |= (png_byte)(value << shift);
  443.                }
  444.                if (shift == s_end)
  445.                {
  446.                   shift = s_start;
  447.                   sp++;
  448.                   dp++;
  449.                }
  450.                else
  451.                   shift += s_inc;
  452.                if (m == 1)
  453.                   m = 0x80;
  454.                else
  455.                   m >>= 1;
  456.             }
  457.             break;
  458.          }
  459.          case 2:        /* png_ptr->row_info.pixel_depth */
  460.          {
  461.             png_bytep sp;
  462.             png_bytep dp;
  463.             int s_start, s_end, s_inc;
  464.             int m;
  465.             int shift;
  466.             png_uint_32 i;
  467.             int value;
  468.             sp = png_ptr->row_buf + 1;
  469.             dp = row;
  470.             m = 0x80;
  471. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  472.             if (png_ptr->transformations & PNG_PACKSWAP)
  473.             {
  474.                s_start = 0;
  475.                s_end = 6;
  476.                s_inc = 2;
  477.             }
  478.             else
  479. #endif
  480.             {
  481.                s_start = 6;
  482.                s_end = 0;
  483.                s_inc = -2;
  484.             }
  485.             shift = s_start;
  486.             for (i = 0; i < png_ptr->width; i++)
  487.             {
  488.                if (m & mask)
  489.                {
  490.                   value = (*sp >> shift) & 0x3;
  491.                   *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  492.                   *dp |= (png_byte)(value << shift);
  493.                }
  494.                if (shift == s_end)
  495.                {
  496.                   shift = s_start;
  497.                   sp++;
  498.                   dp++;
  499.                }
  500.                else
  501.                   shift += s_inc;
  502.                if (m == 1)
  503.                   m = 0x80;
  504.                else
  505.                   m >>= 1;
  506.             }
  507.             break;
  508.          }
  509.          case 4:        /* png_ptr->row_info.pixel_depth */
  510.          {
  511.             png_bytep sp;
  512.             png_bytep dp;
  513.             int s_start, s_end, s_inc;
  514.             int m;
  515.             int shift;
  516.             png_uint_32 i;
  517.             int value;
  518.             sp = png_ptr->row_buf + 1;
  519.             dp = row;
  520.             m = 0x80;
  521. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  522.             if (png_ptr->transformations & PNG_PACKSWAP)
  523.             {
  524.                s_start = 0;
  525.                s_end = 4;
  526.                s_inc = 4;
  527.             }
  528.             else
  529. #endif
  530.             {
  531.                s_start = 4;
  532.                s_end = 0;
  533.                s_inc = -4;
  534.             }
  535.             shift = s_start;
  536.             for (i = 0; i < png_ptr->width; i++)
  537.             {
  538.                if (m & mask)
  539.                {
  540.                   value = (*sp >> shift) & 0xf;
  541.                   *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  542.                   *dp |= (png_byte)(value << shift);
  543.                }
  544.                if (shift == s_end)
  545.                {
  546.                   shift = s_start;
  547.                   sp++;
  548.                   dp++;
  549.                }
  550.                else
  551.                   shift += s_inc;
  552.                if (m == 1)
  553.                   m = 0x80;
  554.                else
  555.                   m >>= 1;
  556.             }
  557.             break;
  558.          }
  559.          case 8:        /* png_ptr->row_info.pixel_depth */
  560.          {
  561.             png_bytep srcptr;
  562.             png_bytep dstptr;
  563. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
  564. #if !defined(PNG_1_0_X)
  565.             if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
  566.                 /* && _mmx_supported */ )
  567. #else
  568.             if (_mmx_supported)
  569. #endif
  570.             {
  571.                png_uint_32 len;
  572.                int diff;
  573.                int dummy_value_a;   // fix 'forbidden register spilled' error
  574.                int dummy_value_d;
  575.                int dummy_value_c;
  576.                int dummy_value_S;
  577.                int dummy_value_D;
  578.                _unmask = ~mask;            // global variable for -fPIC version
  579.                srcptr = png_ptr->row_buf + 1;
  580.                dstptr = row;
  581.                len  = png_ptr->width &~7;  // reduce to multiple of 8
  582.                diff = (int) (png_ptr->width & 7);  // amount lost
  583.                __asm__ __volatile__ (
  584.                   "movd      _unmask, %%mm7  nt" // load bit pattern
  585.                   "psubb     %%mm6, %%mm6    nt" // zero mm6
  586.                   "punpcklbw %%mm7, %%mm7    nt"
  587.                   "punpcklwd %%mm7, %%mm7    nt"
  588.                   "punpckldq %%mm7, %%mm7    nt" // fill reg with 8 masks
  589.                   "movq      _mask8_0, %%mm0 nt"
  590.                   "pand      %%mm7, %%mm0    nt" // nonzero if keep byte
  591.                   "pcmpeqb   %%mm6, %%mm0    nt" // zeros->1s, v versa
  592. // preload        "movl      len, %%ecx      nt" // load length of line
  593. // preload        "movl      srcptr, %%esi   nt" // load source
  594. // preload        "movl      dstptr, %%edi   nt" // load dest
  595.                   "cmpl      $0, %%ecx       nt" // len == 0 ?
  596.                   "je        mainloop8end    nt"
  597.                 "mainloop8:                  nt"
  598.                   "movq      (%%esi), %%mm4  nt" // *srcptr
  599.                   "pand      %%mm0, %%mm4    nt"
  600.                   "movq      %%mm0, %%mm6    nt"
  601.                   "pandn     (%%edi), %%mm6  nt" // *dstptr
  602.                   "por       %%mm6, %%mm4    nt"
  603.                   "movq      %%mm4, (%%edi)  nt"
  604.                   "addl      $8, %%esi       nt" // inc by 8 bytes processed
  605.                   "addl      $8, %%edi       nt"
  606.                   "subl      $8, %%ecx       nt" // dec by 8 pixels processed
  607.                   "ja        mainloop8       nt"
  608.                 "mainloop8end:               nt"
  609. // preload        "movl      diff, %%ecx     nt" // (diff is in eax)
  610.                   "movl      %%eax, %%ecx    nt"
  611.                   "cmpl      $0, %%ecx       nt"
  612.                   "jz        end8            nt"
  613. // preload        "movl      mask, %%edx     nt"
  614.                   "sall      $24, %%edx      nt" // make low byte, high byte
  615.                 "secondloop8:                nt"
  616.                   "sall      %%edx           nt" // move high bit to CF
  617.                   "jnc       skip8           nt" // if CF = 0
  618.                   "movb      (%%esi), %%al   nt"
  619.                   "movb      %%al, (%%edi)   nt"
  620.                 "skip8:                      nt"
  621.                   "incl      %%esi           nt"
  622.                   "incl      %%edi           nt"
  623.                   "decl      %%ecx           nt"
  624.                   "jnz       secondloop8     nt"
  625.                 "end8:                       nt"
  626.                   "EMMS                      nt"  // DONE
  627.                   : "=a" (dummy_value_a),           // output regs (dummy)
  628.                     "=d" (dummy_value_d),
  629.                     "=c" (dummy_value_c),
  630.                     "=S" (dummy_value_S),
  631.                     "=D" (dummy_value_D)
  632.                   : "3" (srcptr),      // esi       // input regs
  633.                     "4" (dstptr),      // edi
  634.                     "0" (diff),        // eax
  635. // was (unmask)     "b"    RESERVED    // ebx       // Global Offset Table idx
  636.                     "2" (len),         // ecx
  637.                     "1" (mask)         // edx
  638. #if 0  /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
  639.                   : "%mm0", "%mm4", "%mm6", "%mm7"  // clobber list
  640. #endif
  641.                );
  642.             }
  643.             else /* mmx _not supported - Use modified C routine */
  644. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  645.             {
  646.                register png_uint_32 i;
  647.                png_uint_32 initial_val = png_pass_start[png_ptr->pass];
  648.                  /* png.c:  png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
  649.                register int stride = png_pass_inc[png_ptr->pass];
  650.                  /* png.c:  png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
  651.                register int rep_bytes = png_pass_width[png_ptr->pass];
  652.                  /* png.c:  png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
  653.                png_uint_32 len = png_ptr->width &~7;  /* reduce to mult. of 8 */
  654.                int diff = (int) (png_ptr->width & 7); /* amount lost */
  655.                register png_uint_32 final_val = len;  /* GRR bugfix */
  656.                srcptr = png_ptr->row_buf + 1 + initial_val;
  657.                dstptr = row + initial_val;
  658.                for (i = initial_val; i < final_val; i += stride)
  659.                {
  660.                   png_memcpy(dstptr, srcptr, rep_bytes);
  661.                   srcptr += stride;
  662.                   dstptr += stride;
  663.                }
  664.                if (diff)  /* number of leftover pixels:  3 for pngtest */
  665.                {
  666.                   final_val+=diff /* *BPP1 */ ;
  667.                   for (; i < final_val; i += stride)
  668.                   {
  669.                      if (rep_bytes > (int)(final_val-i))
  670.                         rep_bytes = (int)(final_val-i);
  671.                      png_memcpy(dstptr, srcptr, rep_bytes);
  672.                      srcptr += stride;
  673.                      dstptr += stride;
  674.                   }
  675.                }
  676.             } /* end of else (_mmx_supported) */
  677.             break;
  678.          }       /* end 8 bpp */
  679.          case 16:       /* png_ptr->row_info.pixel_depth */
  680.          {
  681.             png_bytep srcptr;
  682.             png_bytep dstptr;
  683. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
  684. #if !defined(PNG_1_0_X)
  685.             if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
  686.                 /* && _mmx_supported */ )
  687. #else
  688.             if (_mmx_supported)
  689. #endif
  690.             {
  691.                png_uint_32 len;
  692.                int diff;
  693.                int dummy_value_a;   // fix 'forbidden register spilled' error
  694.                int dummy_value_d;
  695.                int dummy_value_c;
  696.                int dummy_value_S;
  697.                int dummy_value_D;
  698.                _unmask = ~mask;            // global variable for -fPIC version
  699.                srcptr = png_ptr->row_buf + 1;
  700.                dstptr = row;
  701.                len  = png_ptr->width &~7;  // reduce to multiple of 8
  702.                diff = (int) (png_ptr->width & 7); // amount lost //
  703.                __asm__ __volatile__ (
  704.                   "movd      _unmask, %%mm7   nt" // load bit pattern
  705.                   "psubb     %%mm6, %%mm6     nt" // zero mm6
  706.                   "punpcklbw %%mm7, %%mm7     nt"
  707.                   "punpcklwd %%mm7, %%mm7     nt"
  708.                   "punpckldq %%mm7, %%mm7     nt" // fill reg with 8 masks
  709.                   "movq      _mask16_0, %%mm0 nt"
  710.                   "movq      _mask16_1, %%mm1 nt"
  711.                   "pand      %%mm7, %%mm0     nt"
  712.                   "pand      %%mm7, %%mm1     nt"
  713.                   "pcmpeqb   %%mm6, %%mm0     nt"
  714.                   "pcmpeqb   %%mm6, %%mm1     nt"
  715. // preload        "movl      len, %%ecx       nt" // load length of line
  716. // preload        "movl      srcptr, %%esi    nt" // load source
  717. // preload        "movl      dstptr, %%edi    nt" // load dest
  718.                   "cmpl      $0, %%ecx        nt"
  719.                   "jz        mainloop16end    nt"
  720.                 "mainloop16:                  nt"
  721.                   "movq      (%%esi), %%mm4   nt"
  722.                   "pand      %%mm0, %%mm4     nt"
  723.                   "movq      %%mm0, %%mm6     nt"
  724.                   "movq      (%%edi), %%mm7   nt"
  725.                   "pandn     %%mm7, %%mm6     nt"
  726.                   "por       %%mm6, %%mm4     nt"
  727.                   "movq      %%mm4, (%%edi)   nt"
  728.                   "movq      8(%%esi), %%mm5  nt"
  729.                   "pand      %%mm1, %%mm5     nt"
  730.                   "movq      %%mm1, %%mm7     nt"
  731.                   "movq      8(%%edi), %%mm6  nt"
  732.                   "pandn     %%mm6, %%mm7     nt"
  733.                   "por       %%mm7, %%mm5     nt"
  734.                   "movq      %%mm5, 8(%%edi)  nt"
  735.                   "addl      $16, %%esi       nt" // inc by 16 bytes processed
  736.                   "addl      $16, %%edi       nt"
  737.                   "subl      $8, %%ecx        nt" // dec by 8 pixels processed
  738.                   "ja        mainloop16       nt"
  739.                 "mainloop16end:               nt"
  740. // preload        "movl      diff, %%ecx      nt" // (diff is in eax)
  741.                   "movl      %%eax, %%ecx     nt"
  742.                   "cmpl      $0, %%ecx        nt"
  743.                   "jz        end16            nt"
  744. // preload        "movl      mask, %%edx      nt"
  745.                   "sall      $24, %%edx       nt" // make low byte, high byte
  746.                 "secondloop16:                nt"
  747.                   "sall      %%edx            nt" // move high bit to CF
  748.                   "jnc       skip16           nt" // if CF = 0
  749.                   "movw      (%%esi), %%ax    nt"
  750.                   "movw      %%ax, (%%edi)    nt"
  751.                 "skip16:                      nt"
  752.                   "addl      $2, %%esi        nt"
  753.                   "addl      $2, %%edi        nt"
  754.                   "decl      %%ecx            nt"
  755.                   "jnz       secondloop16     nt"
  756.                 "end16:                       nt"
  757.                   "EMMS                       nt" // DONE
  758.                   : "=a" (dummy_value_a),           // output regs (dummy)
  759.                     "=c" (dummy_value_c),
  760.                     "=d" (dummy_value_d),
  761.                     "=S" (dummy_value_S),
  762.                     "=D" (dummy_value_D)
  763.                   : "0" (diff),        // eax       // input regs
  764. // was (unmask)     " "    RESERVED    // ebx       // Global Offset Table idx
  765.                     "1" (len),         // ecx
  766.                     "2" (mask),        // edx
  767.                     "3" (srcptr),      // esi
  768.                     "4" (dstptr)       // edi
  769. #if 0  /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
  770.                   : "%mm0", "%mm1", "%mm4"          // clobber list
  771.                   , "%mm5", "%mm6", "%mm7"
  772. #endif
  773.                );
  774.             }
  775.             else /* mmx _not supported - Use modified C routine */
  776. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  777.             {
  778.                register png_uint_32 i;
  779.                png_uint_32 initial_val = BPP2 * png_pass_start[png_ptr->pass];
  780.                  /* png.c:  png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
  781.                register int stride = BPP2 * png_pass_inc[png_ptr->pass];
  782.                  /* png.c:  png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
  783.                register int rep_bytes = BPP2 * png_pass_width[png_ptr->pass];
  784.                  /* png.c:  png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
  785.                png_uint_32 len = png_ptr->width &~7;  /* reduce to mult. of 8 */
  786.                int diff = (int) (png_ptr->width & 7); /* amount lost */
  787.                register png_uint_32 final_val = BPP2 * len;   /* GRR bugfix */
  788.                srcptr = png_ptr->row_buf + 1 + initial_val;
  789.                dstptr = row + initial_val;
  790.                for (i = initial_val; i < final_val; i += stride)
  791.                {
  792.                   png_memcpy(dstptr, srcptr, rep_bytes);
  793.                   srcptr += stride;
  794.                   dstptr += stride;
  795.                }
  796.                if (diff)  /* number of leftover pixels:  3 for pngtest */
  797.                {
  798.                   final_val+=diff*BPP2;
  799.                   for (; i < final_val; i += stride)
  800.                   {
  801.                      if (rep_bytes > (int)(final_val-i))
  802.                         rep_bytes = (int)(final_val-i);
  803.                      png_memcpy(dstptr, srcptr, rep_bytes);
  804.                      srcptr += stride;
  805.                      dstptr += stride;
  806.                   }
  807.                }
  808.             } /* end of else (_mmx_supported) */
  809.             break;
  810.          }       /* end 16 bpp */
  811.          case 24:       /* png_ptr->row_info.pixel_depth */
  812.          {
  813.             png_bytep srcptr;
  814.             png_bytep dstptr;
  815. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
  816. #if !defined(PNG_1_0_X)
  817.             if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
  818.                 /* && _mmx_supported */ )
  819. #else
  820.             if (_mmx_supported)
  821. #endif
  822.             {
  823.                png_uint_32 len;
  824.                int diff;
  825.                int dummy_value_a;   // fix 'forbidden register spilled' error
  826.                int dummy_value_d;
  827.                int dummy_value_c;
  828.                int dummy_value_S;
  829.                int dummy_value_D;
  830.                _unmask = ~mask;            // global variable for -fPIC version
  831.                srcptr = png_ptr->row_buf + 1;
  832.                dstptr = row;
  833.                len  = png_ptr->width &~7;  // reduce to multiple of 8
  834.                diff = (int) (png_ptr->width & 7); // amount lost //
  835.                __asm__ __volatile__ (
  836.                   "movd      _unmask, %%mm7   nt" // load bit pattern
  837.                   "psubb     %%mm6, %%mm6     nt" // zero mm6
  838.                   "punpcklbw %%mm7, %%mm7     nt"
  839.                   "punpcklwd %%mm7, %%mm7     nt"
  840.                   "punpckldq %%mm7, %%mm7     nt" // fill reg with 8 masks
  841.                   "movq      _mask24_0, %%mm0 nt"
  842.                   "movq      _mask24_1, %%mm1 nt"
  843.                   "movq      _mask24_2, %%mm2 nt"
  844.                   "pand      %%mm7, %%mm0     nt"
  845.                   "pand      %%mm7, %%mm1     nt"
  846.                   "pand      %%mm7, %%mm2     nt"
  847.                   "pcmpeqb   %%mm6, %%mm0     nt"
  848.                   "pcmpeqb   %%mm6, %%mm1     nt"
  849.                   "pcmpeqb   %%mm6, %%mm2     nt"
  850. // preload        "movl      len, %%ecx       nt" // load length of line
  851. // preload        "movl      srcptr, %%esi    nt" // load source
  852. // preload        "movl      dstptr, %%edi    nt" // load dest
  853.                   "cmpl      $0, %%ecx        nt"
  854.                   "jz        mainloop24end    nt"
  855.                 "mainloop24:                  nt"
  856.                   "movq      (%%esi), %%mm4   nt"
  857.                   "pand      %%mm0, %%mm4     nt"
  858.                   "movq      %%mm0, %%mm6     nt"
  859.                   "movq      (%%edi), %%mm7   nt"
  860.                   "pandn     %%mm7, %%mm6     nt"
  861.                   "por       %%mm6, %%mm4     nt"
  862.                   "movq      %%mm4, (%%edi)   nt"
  863.                   "movq      8(%%esi), %%mm5  nt"
  864.                   "pand      %%mm1, %%mm5     nt"
  865.                   "movq      %%mm1, %%mm7     nt"
  866.                   "movq      8(%%edi), %%mm6  nt"
  867.                   "pandn     %%mm6, %%mm7     nt"
  868.                   "por       %%mm7, %%mm5     nt"
  869.                   "movq      %%mm5, 8(%%edi)  nt"
  870.                   "movq      16(%%esi), %%mm6 nt"
  871.                   "pand      %%mm2, %%mm6     nt"
  872.                   "movq      %%mm2, %%mm4     nt"
  873.                   "movq      16(%%edi), %%mm7 nt"
  874.                   "pandn     %%mm7, %%mm4     nt"
  875.                   "por       %%mm4, %%mm6     nt"
  876.                   "movq      %%mm6, 16(%%edi) nt"
  877.                   "addl      $24, %%esi       nt" // inc by 24 bytes processed
  878.                   "addl      $24, %%edi       nt"
  879.                   "subl      $8, %%ecx        nt" // dec by 8 pixels processed
  880.                   "ja        mainloop24       nt"
  881.                 "mainloop24end:               nt"
  882. // preload        "movl      diff, %%ecx      nt" // (diff is in eax)
  883.                   "movl      %%eax, %%ecx     nt"
  884.                   "cmpl      $0, %%ecx        nt"
  885.                   "jz        end24            nt"
  886. // preload        "movl      mask, %%edx      nt"
  887.                   "sall      $24, %%edx       nt" // make low byte, high byte
  888.                 "secondloop24:                nt"
  889.                   "sall      %%edx            nt" // move high bit to CF
  890.                   "jnc       skip24           nt" // if CF = 0
  891.                   "movw      (%%esi), %%ax    nt"
  892.                   "movw      %%ax, (%%edi)    nt"
  893.                   "xorl      %%eax, %%eax     nt"
  894.                   "movb      2(%%esi), %%al   nt"
  895.                   "movb      %%al, 2(%%edi)   nt"
  896.                 "skip24:                      nt"
  897.                   "addl      $3, %%esi        nt"
  898.                   "addl      $3, %%edi        nt"
  899.                   "decl      %%ecx            nt"
  900.                   "jnz       secondloop24     nt"
  901.                 "end24:                       nt"
  902.                   "EMMS                       nt" // DONE
  903.                   : "=a" (dummy_value_a),           // output regs (dummy)
  904.                     "=d" (dummy_value_d),
  905.                     "=c" (dummy_value_c),
  906.                     "=S" (dummy_value_S),
  907.                     "=D" (dummy_value_D)
  908.                   : "3" (srcptr),      // esi       // input regs
  909.                     "4" (dstptr),      // edi
  910.                     "0" (diff),        // eax
  911. // was (unmask)     "b"    RESERVED    // ebx       // Global Offset Table idx
  912.                     "2" (len),         // ecx
  913.                     "1" (mask)         // edx
  914. #if 0  /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
  915.                   : "%mm0", "%mm1", "%mm2"          // clobber list
  916.                   , "%mm4", "%mm5", "%mm6", "%mm7"
  917. #endif
  918.                );
  919.             }
  920.             else /* mmx _not supported - Use modified C routine */
  921. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  922.             {
  923.                register png_uint_32 i;
  924.                png_uint_32 initial_val = BPP3 * png_pass_start[png_ptr->pass];
  925.                  /* png.c:  png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
  926.                register int stride = BPP3 * png_pass_inc[png_ptr->pass];
  927.                  /* png.c:  png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
  928.                register int rep_bytes = BPP3 * png_pass_width[png_ptr->pass];
  929.                  /* png.c:  png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
  930.                png_uint_32 len = png_ptr->width &~7;  /* reduce to mult. of 8 */
  931.                int diff = (int) (png_ptr->width & 7); /* amount lost */
  932.                register png_uint_32 final_val = BPP3 * len;   /* GRR bugfix */
  933.                srcptr = png_ptr->row_buf + 1 + initial_val;
  934.                dstptr = row + initial_val;
  935.                for (i = initial_val; i < final_val; i += stride)
  936.                {
  937.                   png_memcpy(dstptr, srcptr, rep_bytes);
  938.                   srcptr += stride;
  939.                   dstptr += stride;
  940.                }
  941.                if (diff)  /* number of leftover pixels:  3 for pngtest */
  942.                {
  943.                   final_val+=diff*BPP3;
  944.                   for (; i < final_val; i += stride)
  945.                   {
  946.                      if (rep_bytes > (int)(final_val-i))
  947.                         rep_bytes = (int)(final_val-i);
  948.                      png_memcpy(dstptr, srcptr, rep_bytes);
  949.                      srcptr += stride;
  950.                      dstptr += stride;
  951.                   }
  952.                }
  953.             } /* end of else (_mmx_supported) */
  954.             break;
  955.          }       /* end 24 bpp */
  956.          case 32:       /* png_ptr->row_info.pixel_depth */
  957.          {
  958.             png_bytep srcptr;
  959.             png_bytep dstptr;
  960. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
  961. #if !defined(PNG_1_0_X)
  962.             if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
  963.                 /* && _mmx_supported */ )
  964. #else
  965.             if (_mmx_supported)
  966. #endif
  967.             {
  968.                png_uint_32 len;
  969.                int diff;
  970.                int dummy_value_a;   // fix 'forbidden register spilled' error
  971.                int dummy_value_d;
  972.                int dummy_value_c;
  973.                int dummy_value_S;
  974.                int dummy_value_D;
  975.                _unmask = ~mask;            // global variable for -fPIC version
  976.                srcptr = png_ptr->row_buf + 1;
  977.                dstptr = row;
  978.                len  = png_ptr->width &~7;  // reduce to multiple of 8
  979.                diff = (int) (png_ptr->width & 7); // amount lost //
  980.                __asm__ __volatile__ (
  981.                   "movd      _unmask, %%mm7   nt" // load bit pattern
  982.                   "psubb     %%mm6, %%mm6     nt" // zero mm6
  983.                   "punpcklbw %%mm7, %%mm7     nt"
  984.                   "punpcklwd %%mm7, %%mm7     nt"
  985.                   "punpckldq %%mm7, %%mm7     nt" // fill reg with 8 masks
  986.                   "movq      _mask32_0, %%mm0 nt"
  987.                   "movq      _mask32_1, %%mm1 nt"
  988.                   "movq      _mask32_2, %%mm2 nt"
  989.                   "movq      _mask32_3, %%mm3 nt"
  990.                   "pand      %%mm7, %%mm0     nt"
  991.                   "pand      %%mm7, %%mm1     nt"
  992.                   "pand      %%mm7, %%mm2     nt"
  993.                   "pand      %%mm7, %%mm3     nt"
  994.                   "pcmpeqb   %%mm6, %%mm0     nt"
  995.                   "pcmpeqb   %%mm6, %%mm1     nt"
  996.                   "pcmpeqb   %%mm6, %%mm2     nt"
  997.                   "pcmpeqb   %%mm6, %%mm3     nt"
  998. // preload        "movl      len, %%ecx       nt" // load length of line
  999. // preload        "movl      srcptr, %%esi    nt" // load source
  1000. // preload        "movl      dstptr, %%edi    nt" // load dest
  1001.                   "cmpl      $0, %%ecx        nt" // lcr
  1002.                   "jz        mainloop32end    nt"
  1003.                 "mainloop32:                  nt"
  1004.                   "movq      (%%esi), %%mm4   nt"
  1005.                   "pand      %%mm0, %%mm4     nt"
  1006.                   "movq      %%mm0, %%mm6     nt"
  1007.                   "movq      (%%edi), %%mm7   nt"
  1008.                   "pandn     %%mm7, %%mm6     nt"
  1009.                   "por       %%mm6, %%mm4     nt"
  1010.                   "movq      %%mm4, (%%edi)   nt"
  1011.                   "movq      8(%%esi), %%mm5  nt"
  1012.                   "pand      %%mm1, %%mm5     nt"
  1013.                   "movq      %%mm1, %%mm7     nt"
  1014.                   "movq      8(%%edi), %%mm6  nt"
  1015.                   "pandn     %%mm6, %%mm7     nt"
  1016.                   "por       %%mm7, %%mm5     nt"
  1017.                   "movq      %%mm5, 8(%%edi)  nt"
  1018.                   "movq      16(%%esi), %%mm6 nt"
  1019.                   "pand      %%mm2, %%mm6     nt"
  1020.                   "movq      %%mm2, %%mm4     nt"
  1021.                   "movq      16(%%edi), %%mm7 nt"
  1022.                   "pandn     %%mm7, %%mm4     nt"
  1023.                   "por       %%mm4, %%mm6     nt"
  1024.                   "movq      %%mm6, 16(%%edi) nt"
  1025.                   "movq      24(%%esi), %%mm7 nt"
  1026.                   "pand      %%mm3, %%mm7     nt"
  1027.                   "movq      %%mm3, %%mm5     nt"
  1028.                   "movq      24(%%edi), %%mm4 nt"
  1029.                   "pandn     %%mm4, %%mm5     nt"
  1030.                   "por       %%mm5, %%mm7     nt"
  1031.                   "movq      %%mm7, 24(%%edi) nt"
  1032.                   "addl      $32, %%esi       nt" // inc by 32 bytes processed
  1033.                   "addl      $32, %%edi       nt"
  1034.                   "subl      $8, %%ecx        nt" // dec by 8 pixels processed
  1035.                   "ja        mainloop32       nt"
  1036.                 "mainloop32end:               nt"
  1037. // preload        "movl      diff, %%ecx      nt" // (diff is in eax)
  1038.                   "movl      %%eax, %%ecx     nt"
  1039.                   "cmpl      $0, %%ecx        nt"
  1040.                   "jz        end32            nt"
  1041. // preload        "movl      mask, %%edx      nt"
  1042.                   "sall      $24, %%edx       nt" // low byte => high byte
  1043.                 "secondloop32:                nt"
  1044.                   "sall      %%edx            nt" // move high bit to CF
  1045.                   "jnc       skip32           nt" // if CF = 0
  1046.                   "movl      (%%esi), %%eax   nt"
  1047.                   "movl      %%eax, (%%edi)   nt"
  1048.                 "skip32:                      nt"
  1049.                   "addl      $4, %%esi        nt"
  1050.                   "addl      $4, %%edi        nt"
  1051.                   "decl      %%ecx            nt"
  1052.                   "jnz       secondloop32     nt"
  1053.                 "end32:                       nt"
  1054.                   "EMMS                       nt" // DONE
  1055.                   : "=a" (dummy_value_a),           // output regs (dummy)
  1056.                     "=d" (dummy_value_d),
  1057.                     "=c" (dummy_value_c),
  1058.                     "=S" (dummy_value_S),
  1059.                     "=D" (dummy_value_D)
  1060.                   : "3" (srcptr),      // esi       // input regs
  1061.                     "4" (dstptr),      // edi
  1062.                     "0" (diff),        // eax
  1063. // was (unmask)     "b"    RESERVED    // ebx       // Global Offset Table idx
  1064.                     "2" (len),         // ecx
  1065.                     "1" (mask)         // edx
  1066. #if 0  /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
  1067.                   : "%mm0", "%mm1", "%mm2", "%mm3"  // clobber list
  1068.                   , "%mm4", "%mm5", "%mm6", "%mm7"
  1069. #endif
  1070.                );
  1071.             }
  1072.             else /* mmx _not supported - Use modified C routine */
  1073. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  1074.             {
  1075.                register png_uint_32 i;
  1076.                png_uint_32 initial_val = BPP4 * png_pass_start[png_ptr->pass];
  1077.                  /* png.c:  png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
  1078.                register int stride = BPP4 * png_pass_inc[png_ptr->pass];
  1079.                  /* png.c:  png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
  1080.                register int rep_bytes = BPP4 * png_pass_width[png_ptr->pass];
  1081.                  /* png.c:  png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
  1082.                png_uint_32 len = png_ptr->width &~7;  /* reduce to mult. of 8 */
  1083.                int diff = (int) (png_ptr->width & 7); /* amount lost */
  1084.                register png_uint_32 final_val = BPP4 * len;   /* GRR bugfix */
  1085.                srcptr = png_ptr->row_buf + 1 + initial_val;
  1086.                dstptr = row + initial_val;
  1087.                for (i = initial_val; i < final_val; i += stride)
  1088.                {
  1089.                   png_memcpy(dstptr, srcptr, rep_bytes);
  1090.                   srcptr += stride;
  1091.                   dstptr += stride;
  1092.                }
  1093.                if (diff)  /* number of leftover pixels:  3 for pngtest */
  1094.                {
  1095.                   final_val+=diff*BPP4;
  1096.                   for (; i < final_val; i += stride)
  1097.                   {
  1098.                      if (rep_bytes > (int)(final_val-i))
  1099.                         rep_bytes = (int)(final_val-i);
  1100.                      png_memcpy(dstptr, srcptr, rep_bytes);
  1101.                      srcptr += stride;
  1102.                      dstptr += stride;
  1103.                   }
  1104.                }
  1105.             } /* end of else (_mmx_supported) */
  1106.             break;
  1107.          }       /* end 32 bpp */
  1108.          case 48:       /* png_ptr->row_info.pixel_depth */
  1109.          {
  1110.             png_bytep srcptr;
  1111.             png_bytep dstptr;
  1112. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
  1113. #if !defined(PNG_1_0_X)
  1114.             if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
  1115.                 /* && _mmx_supported */ )
  1116. #else
  1117.             if (_mmx_supported)
  1118. #endif
  1119.             {
  1120.                png_uint_32 len;
  1121.                int diff;
  1122.                int dummy_value_a;   // fix 'forbidden register spilled' error
  1123.                int dummy_value_d;
  1124.                int dummy_value_c;
  1125.                int dummy_value_S;
  1126.                int dummy_value_D;
  1127.                _unmask = ~mask;            // global variable for -fPIC version
  1128.                srcptr = png_ptr->row_buf + 1;
  1129.                dstptr = row;
  1130.                len  = png_ptr->width &~7;  // reduce to multiple of 8
  1131.                diff = (int) (png_ptr->width & 7); // amount lost //
  1132.                __asm__ __volatile__ (
  1133.                   "movd      _unmask, %%mm7   nt" // load bit pattern
  1134.                   "psubb     %%mm6, %%mm6     nt" // zero mm6
  1135.                   "punpcklbw %%mm7, %%mm7     nt"
  1136.                   "punpcklwd %%mm7, %%mm7     nt"
  1137.                   "punpckldq %%mm7, %%mm7     nt" // fill reg with 8 masks
  1138.                   "movq      _mask48_0, %%mm0 nt"
  1139.                   "movq      _mask48_1, %%mm1 nt"
  1140.                   "movq      _mask48_2, %%mm2 nt"
  1141.                   "movq      _mask48_3, %%mm3 nt"
  1142.                   "movq      _mask48_4, %%mm4 nt"
  1143.                   "movq      _mask48_5, %%mm5 nt"
  1144.                   "pand      %%mm7, %%mm0     nt"
  1145.                   "pand      %%mm7, %%mm1     nt"
  1146.                   "pand      %%mm7, %%mm2     nt"
  1147.                   "pand      %%mm7, %%mm3     nt"
  1148.                   "pand      %%mm7, %%mm4     nt"
  1149.                   "pand      %%mm7, %%mm5     nt"
  1150.                   "pcmpeqb   %%mm6, %%mm0     nt"
  1151.                   "pcmpeqb   %%mm6, %%mm1     nt"
  1152.                   "pcmpeqb   %%mm6, %%mm2     nt"
  1153.                   "pcmpeqb   %%mm6, %%mm3     nt"
  1154.                   "pcmpeqb   %%mm6, %%mm4     nt"
  1155.                   "pcmpeqb   %%mm6, %%mm5     nt"
  1156. // preload        "movl      len, %%ecx       nt" // load length of line
  1157. // preload        "movl      srcptr, %%esi    nt" // load source
  1158. // preload        "movl      dstptr, %%edi    nt" // load dest
  1159.                   "cmpl      $0, %%ecx        nt"
  1160.                   "jz        mainloop48end    nt"
  1161.                 "mainloop48:                  nt"
  1162.                   "movq      (%%esi), %%mm7   nt"
  1163.                   "pand      %%mm0, %%mm7     nt"
  1164.                   "movq      %%mm0, %%mm6     nt"
  1165.                   "pandn     (%%edi), %%mm6   nt"
  1166.                   "por       %%mm6, %%mm7     nt"
  1167.                   "movq      %%mm7, (%%edi)   nt"
  1168.                   "movq      8(%%esi), %%mm6  nt"
  1169.                   "pand      %%mm1, %%mm6     nt"
  1170.                   "movq      %%mm1, %%mm7     nt"
  1171.                   "pandn     8(%%edi), %%mm7  nt"
  1172.                   "por       %%mm7, %%mm6     nt"
  1173.                   "movq      %%mm6, 8(%%edi)  nt"
  1174.                   "movq      16(%%esi), %%mm6 nt"
  1175.                   "pand      %%mm2, %%mm6     nt"
  1176.                   "movq      %%mm2, %%mm7     nt"
  1177.                   "pandn     16(%%edi), %%mm7 nt"
  1178.                   "por       %%mm7, %%mm6     nt"
  1179.                   "movq      %%mm6, 16(%%edi) nt"
  1180.                   "movq      24(%%esi), %%mm7 nt"
  1181.                   "pand      %%mm3, %%mm7     nt"
  1182.                   "movq      %%mm3, %%mm6     nt"
  1183.                   "pandn     24(%%edi), %%mm6 nt"
  1184.                   "por       %%mm6, %%mm7     nt"
  1185.                   "movq      %%mm7, 24(%%edi) nt"
  1186.                   "movq      32(%%esi), %%mm6 nt"
  1187.                   "pand      %%mm4, %%mm6     nt"
  1188.                   "movq      %%mm4, %%mm7     nt"
  1189.                   "pandn     32(%%edi), %%mm7 nt"
  1190.                   "por       %%mm7, %%mm6     nt"
  1191.                   "movq      %%mm6, 32(%%edi) nt"
  1192.                   "movq      40(%%esi), %%mm7 nt"
  1193.                   "pand      %%mm5, %%mm7     nt"
  1194.                   "movq      %%mm5, %%mm6     nt"
  1195.                   "pandn     40(%%edi), %%mm6 nt"
  1196.                   "por       %%mm6, %%mm7     nt"
  1197.                   "movq      %%mm7, 40(%%edi) nt"
  1198.                   "addl      $48, %%esi       nt" // inc by 48 bytes processed
  1199.                   "addl      $48, %%edi       nt"
  1200.                   "subl      $8, %%ecx        nt" // dec by 8 pixels processed
  1201.                   "ja        mainloop48       nt"
  1202.                 "mainloop48end:               nt"
  1203. // preload        "movl      diff, %%ecx      nt" // (diff is in eax)
  1204.                   "movl      %%eax, %%ecx     nt"
  1205.                   "cmpl      $0, %%ecx        nt"
  1206.                   "jz        end48            nt"
  1207. // preload        "movl      mask, %%edx      nt"
  1208.                   "sall      $24, %%edx       nt" // make low byte, high byte
  1209.                 "secondloop48:                nt"
  1210.                   "sall      %%edx            nt" // move high bit to CF
  1211.                   "jnc       skip48           nt" // if CF = 0
  1212.                   "movl      (%%esi), %%eax   nt"
  1213.                   "movl      %%eax, (%%edi)   nt"
  1214.                 "skip48:                      nt"
  1215.                   "addl      $4, %%esi        nt"
  1216.                   "addl      $4, %%edi        nt"
  1217.                   "decl      %%ecx            nt"
  1218.                   "jnz       secondloop48     nt"
  1219.                 "end48:                       nt"
  1220.                   "EMMS                       nt" // DONE
  1221.                   : "=a" (dummy_value_a),           // output regs (dummy)
  1222.                     "=d" (dummy_value_d),
  1223.                     "=c" (dummy_value_c),
  1224.                     "=S" (dummy_value_S),
  1225.                     "=D" (dummy_value_D)
  1226.                   : "3" (srcptr),      // esi       // input regs
  1227.                     "4" (dstptr),      // edi
  1228.                     "0" (diff),        // eax
  1229. // was (unmask)     "b"    RESERVED    // ebx       // Global Offset Table idx
  1230.                     "2" (len),         // ecx
  1231.                     "1" (mask)         // edx
  1232. #if 0  /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
  1233.                   : "%mm0", "%mm1", "%mm2", "%mm3"  // clobber list
  1234.                   , "%mm4", "%mm5", "%mm6", "%mm7"
  1235. #endif
  1236.                );
  1237.             }
  1238.             else /* mmx _not supported - Use modified C routine */
  1239. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  1240.             {
  1241.                register png_uint_32 i;
  1242.                png_uint_32 initial_val = BPP6 * png_pass_start[png_ptr->pass];
  1243.                  /* png.c:  png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
  1244.                register int stride = BPP6 * png_pass_inc[png_ptr->pass];
  1245.                  /* png.c:  png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
  1246.                register int rep_bytes = BPP6 * png_pass_width[png_ptr->pass];
  1247.                  /* png.c:  png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
  1248.                png_uint_32 len = png_ptr->width &~7;  /* reduce to mult. of 8 */
  1249.                int diff = (int) (png_ptr->width & 7); /* amount lost */
  1250.                register png_uint_32 final_val = BPP6 * len;   /* GRR bugfix */
  1251.                srcptr = png_ptr->row_buf + 1 + initial_val;
  1252.                dstptr = row + initial_val;
  1253.                for (i = initial_val; i < final_val; i += stride)
  1254.                {
  1255.                   png_memcpy(dstptr, srcptr, rep_bytes);
  1256.                   srcptr += stride;
  1257.                   dstptr += stride;
  1258.                }
  1259.                if (diff)  /* number of leftover pixels:  3 for pngtest */
  1260.                {
  1261.                   final_val+=diff*BPP6;
  1262.                   for (; i < final_val; i += stride)
  1263.                   {
  1264.                      if (rep_bytes > (int)(final_val-i))
  1265.                         rep_bytes = (int)(final_val-i);
  1266.                      png_memcpy(dstptr, srcptr, rep_bytes);
  1267.                      srcptr += stride;
  1268.                      dstptr += stride;
  1269.                   }
  1270.                }
  1271.             } /* end of else (_mmx_supported) */
  1272.             break;
  1273.          }       /* end 48 bpp */
  1274.          case 64:       /* png_ptr->row_info.pixel_depth */
  1275.          {
  1276.             png_bytep srcptr;
  1277.             png_bytep dstptr;
  1278.             register png_uint_32 i;
  1279.             png_uint_32 initial_val = BPP8 * png_pass_start[png_ptr->pass];
  1280.               /* png.c:  png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
  1281.             register int stride = BPP8 * png_pass_inc[png_ptr->pass];
  1282.               /* png.c:  png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
  1283.             register int rep_bytes = BPP8 * png_pass_width[png_ptr->pass];
  1284.               /* png.c:  png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
  1285.             png_uint_32 len = png_ptr->width &~7;  /* reduce to mult. of 8 */
  1286.             int diff = (int) (png_ptr->width & 7); /* amount lost */
  1287.             register png_uint_32 final_val = BPP8 * len;   /* GRR bugfix */
  1288.             srcptr = png_ptr->row_buf + 1 + initial_val;
  1289.             dstptr = row + initial_val;
  1290.             for (i = initial_val; i < final_val; i += stride)
  1291.             {
  1292.                png_memcpy(dstptr, srcptr, rep_bytes);
  1293.                srcptr += stride;
  1294.                dstptr += stride;
  1295.             }
  1296.             if (diff)  /* number of leftover pixels:  3 for pngtest */
  1297.             {
  1298.                final_val+=diff*BPP8;
  1299.                for (; i < final_val; i += stride)
  1300.                {
  1301.                   if (rep_bytes > (int)(final_val-i))
  1302.                      rep_bytes = (int)(final_val-i);
  1303.                   png_memcpy(dstptr, srcptr, rep_bytes);
  1304.                   srcptr += stride;
  1305.                   dstptr += stride;
  1306.                }
  1307.             }
  1308.             break;
  1309.          }       /* end 64 bpp */
  1310.          default: /* png_ptr->row_info.pixel_depth != 1,2,4,8,16,24,32,48,64 */
  1311.          {
  1312.             /* this should never happen */
  1313.             png_warning(png_ptr, "Invalid row_info.pixel_depth in pnggccrd");
  1314.             break;
  1315.          }
  1316.       } /* end switch (png_ptr->row_info.pixel_depth) */
  1317.    } /* end if (non-trivial mask) */
  1318. } /* end png_combine_row() */
  1319. #endif /* PNG_HAVE_ASSEMBLER_COMBINE_ROW */
  1320. /*===========================================================================*/
  1321. /*                                                                           */
  1322. /*                 P N G _ D O _ R E A D _ I N T E R L A C E                 */
  1323. /*                                                                           */
  1324. /*===========================================================================*/
  1325. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  1326. #if defined(PNG_HAVE_ASSEMBLER_READ_INTERLACE)
  1327. /* png_do_read_interlace() is called after any 16-bit to 8-bit conversion
  1328.  * has taken place.  [GRR: what other steps come before and/or after?]
  1329.  */
  1330. void /* PRIVATE */
  1331. png_do_read_interlace(png_structp png_ptr)
  1332. {
  1333.    png_row_infop row_info = &(png_ptr->row_info);
  1334.    png_bytep row = png_ptr->row_buf + 1;
  1335.    int pass = png_ptr->pass;
  1336. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  1337.    png_uint_32 transformations = png_ptr->transformations;
  1338. #endif
  1339.    png_debug(1, "in png_do_read_interlace (pnggccrd.c)n");
  1340. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  1341.    if (_mmx_supported == 2) {
  1342. #if !defined(PNG_1_0_X)
  1343.        /* this should have happened in png_init_mmx_flags() already */
  1344.        png_warning(png_ptr, "asm_flags may not have been initialized");
  1345. #endif
  1346.        png_mmx_support();
  1347.    }
  1348. #endif
  1349.    if (row != NULL && row_info != NULL)
  1350.    {
  1351.       png_uint_32 final_width;
  1352.       final_width = row_info->width * png_pass_inc[pass];
  1353.       switch (row_info->pixel_depth)
  1354.       {
  1355.          case 1:
  1356.          {
  1357.             png_bytep sp, dp;
  1358.             int sshift, dshift;
  1359.             int s_start, s_end, s_inc;
  1360.             png_byte v;
  1361.             png_uint_32 i;
  1362.             int j;
  1363.             sp = row + (png_size_t)((row_info->width - 1) >> 3);
  1364.             dp = row + (png_size_t)((final_width - 1) >> 3);
  1365. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  1366.             if (transformations & PNG_PACKSWAP)
  1367.             {
  1368.                sshift = (int)((row_info->width + 7) & 7);
  1369.                dshift = (int)((final_width + 7) & 7);
  1370.                s_start = 7;
  1371.                s_end = 0;
  1372.                s_inc = -1;
  1373.             }
  1374.             else
  1375. #endif
  1376.             {
  1377.                sshift = 7 - (int)((row_info->width + 7) & 7);
  1378.                dshift = 7 - (int)((final_width + 7) & 7);
  1379.                s_start = 0;
  1380.                s_end = 7;
  1381.                s_inc = 1;
  1382.             }
  1383.             for (i = row_info->width; i; i--)
  1384.             {
  1385.                v = (png_byte)((*sp >> sshift) & 0x1);
  1386.                for (j = 0; j < png_pass_inc[pass]; j++)
  1387.                {
  1388.                   *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  1389.                   *dp |= (png_byte)(v << dshift);
  1390.                   if (dshift == s_end)
  1391.                   {
  1392.                      dshift = s_start;
  1393.                      dp--;
  1394.                   }
  1395.                   else
  1396.                      dshift += s_inc;
  1397.                }
  1398.                if (sshift == s_end)
  1399.                {
  1400.                   sshift = s_start;
  1401.                   sp--;
  1402.                }
  1403.                else
  1404.                   sshift += s_inc;
  1405.             }
  1406.             break;
  1407.          }
  1408.          case 2:
  1409.          {
  1410.             png_bytep sp, dp;
  1411.             int sshift, dshift;
  1412.             int s_start, s_end, s_inc;
  1413.             png_uint_32 i;
  1414.             sp = row + (png_size_t)((row_info->width - 1) >> 2);
  1415.             dp = row + (png_size_t)((final_width - 1) >> 2);
  1416. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  1417.             if (transformations & PNG_PACKSWAP)
  1418.             {
  1419.                sshift = (png_size_t)(((row_info->width + 3) & 3) << 1);
  1420.                dshift = (png_size_t)(((final_width + 3) & 3) << 1);
  1421.                s_start = 6;
  1422.                s_end = 0;
  1423.                s_inc = -2;
  1424.             }
  1425.             else
  1426. #endif
  1427.             {
  1428.                sshift = (png_size_t)((3 - ((row_info->width + 3) & 3)) << 1);
  1429.                dshift = (png_size_t)((3 - ((final_width + 3) & 3)) << 1);
  1430.                s_start = 0;
  1431.                s_end = 6;
  1432.                s_inc = 2;
  1433.             }
  1434.             for (i = row_info->width; i; i--)
  1435.             {
  1436.                png_byte v;
  1437.                int j;
  1438.                v = (png_byte)((*sp >> sshift) & 0x3);
  1439.                for (j = 0; j < png_pass_inc[pass]; j++)
  1440.                {
  1441.                   *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  1442.                   *dp |= (png_byte)(v << dshift);
  1443.                   if (dshift == s_end)
  1444.                   {
  1445.                      dshift = s_start;
  1446.                      dp--;
  1447.                   }
  1448.                   else
  1449.                      dshift += s_inc;
  1450.                }
  1451.                if (sshift == s_end)
  1452.                {
  1453.                   sshift = s_start;
  1454.                   sp--;
  1455.                }
  1456.                else
  1457.                   sshift += s_inc;
  1458.             }
  1459.             break;
  1460.          }
  1461.          case 4:
  1462.          {
  1463.             png_bytep sp, dp;
  1464.             int sshift, dshift;
  1465.             int s_start, s_end, s_inc;
  1466.             png_uint_32 i;
  1467.             sp = row + (png_size_t)((row_info->width - 1) >> 1);
  1468.             dp = row + (png_size_t)((final_width - 1) >> 1);
  1469. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  1470.             if (transformations & PNG_PACKSWAP)
  1471.             {
  1472.                sshift = (png_size_t)(((row_info->width + 1) & 1) << 2);
  1473.                dshift = (png_size_t)(((final_width + 1) & 1) << 2);
  1474.                s_start = 4;
  1475.                s_end = 0;
  1476.                s_inc = -4;
  1477.             }
  1478.             else
  1479. #endif
  1480.             {
  1481.                sshift = (png_size_t)((1 - ((row_info->width + 1) & 1)) << 2);
  1482.                dshift = (png_size_t)((1 - ((final_width + 1) & 1)) << 2);
  1483.                s_start = 0;
  1484.                s_end = 4;
  1485.                s_inc = 4;
  1486.             }
  1487.             for (i = row_info->width; i; i--)
  1488.             {
  1489.                png_byte v;
  1490.                int j;
  1491.                v = (png_byte)((*sp >> sshift) & 0xf);
  1492.                for (j = 0; j < png_pass_inc[pass]; j++)
  1493.                {
  1494.                   *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  1495.                   *dp |= (png_byte)(v << dshift);
  1496.                   if (dshift == s_end)
  1497.                   {
  1498.                      dshift = s_start;
  1499.                      dp--;
  1500.                   }
  1501.                   else
  1502.                      dshift += s_inc;
  1503.                }
  1504.                if (sshift == s_end)
  1505.                {
  1506.                   sshift = s_start;
  1507.                   sp--;
  1508.                }
  1509.                else
  1510.                   sshift += s_inc;
  1511.             }
  1512.             break;
  1513.          }
  1514.        /*====================================================================*/
  1515.          default: /* 8-bit or larger (this is where the routine is modified) */
  1516.          {
  1517. #if 0
  1518. //          static unsigned long long _const4 = 0x0000000000FFFFFFLL;  no good
  1519. //          static unsigned long long const4 = 0x0000000000FFFFFFLL;   no good
  1520. //          unsigned long long _const4 = 0x0000000000FFFFFFLL;         no good
  1521. //          unsigned long long const4 = 0x0000000000FFFFFFLL;          no good
  1522. #endif
  1523.             png_bytep sptr, dp;
  1524.             png_uint_32 i;
  1525.             png_size_t pixel_bytes;
  1526.             int width = (int)row_info->width;
  1527.             pixel_bytes = (row_info->pixel_depth >> 3);
  1528.             /* point sptr at the last pixel in the pre-expanded row: */
  1529.             sptr = row + (width - 1) * pixel_bytes;
  1530.             /* point dp at the last pixel position in the expanded row: */
  1531.             dp = row + (final_width - 1) * pixel_bytes;
  1532.             /* New code by Nirav Chhatrapati - Intel Corporation */
  1533. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  1534. #if !defined(PNG_1_0_X)
  1535.             if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_INTERLACE)
  1536.                 /* && _mmx_supported */ )
  1537. #else
  1538.             if (_mmx_supported)
  1539. #endif
  1540.             {
  1541.                //--------------------------------------------------------------
  1542.                if (pixel_bytes == 3)
  1543.                {
  1544.                   if (((pass == 0) || (pass == 1)) && width)
  1545.                   {
  1546.                      int dummy_value_c;   // fix 'forbidden register spilled'
  1547.                      int dummy_value_S;
  1548.                      int dummy_value_D;
  1549.                      __asm__ __volatile__ (
  1550.                         "subl $21, %%edi         nt"
  1551.                                      // (png_pass_inc[pass] - 1)*pixel_bytes
  1552.                      ".loop3_pass0:              nt"
  1553.                         "movd (%%esi), %%mm0     nt" // x x x x x 2 1 0
  1554.                         "pand _const4, %%mm0     nt" // z z z z z 2 1 0
  1555.                         "movq %%mm0, %%mm1       nt" // z z z z z 2 1 0
  1556.                         "psllq $16, %%mm0        nt" // z z z 2 1 0 z z
  1557.                         "movq %%mm0, %%mm2       nt" // z z z 2 1 0 z z
  1558.                         "psllq $24, %%mm0        nt" // 2 1 0 z z z z z
  1559.                         "psrlq $8, %%mm1         nt" // z z z z z z 2 1
  1560.                         "por %%mm2, %%mm0        nt" // 2 1 0 2 1 0 z z
  1561.                         "por %%mm1, %%mm0        nt" // 2 1 0 2 1 0 2 1
  1562.                         "movq %%mm0, %%mm3       nt" // 2 1 0 2 1 0 2 1
  1563.                         "psllq $16, %%mm0        nt" // 0 2 1 0 2 1 z z
  1564.                         "movq %%mm3, %%mm4       nt" // 2 1 0 2 1 0 2 1
  1565.                         "punpckhdq %%mm0, %%mm3  nt" // 0 2 1 0 2 1 0 2
  1566.                         "movq %%mm4, 16(%%edi)   nt"
  1567.                         "psrlq $32, %%mm0        nt" // z z z z 0 2 1 0
  1568.                         "movq %%mm3, 8(%%edi)    nt"
  1569.                         "punpckldq %%mm4, %%mm0  nt" // 1 0 2 1 0 2 1 0
  1570.                         "subl $3, %%esi          nt"
  1571.                         "movq %%mm0, (%%edi)     nt"
  1572.                         "subl $24, %%edi         nt"
  1573.                         "decl %%ecx              nt"
  1574.                         "jnz .loop3_pass0        nt"
  1575.                         "EMMS                    nt" // DONE
  1576.                         : "=c" (dummy_value_c),        // output regs (dummy)
  1577.                           "=S" (dummy_value_S),
  1578.                           "=D" (dummy_value_D)
  1579.                         : "1" (sptr),      // esi      // input regs
  1580.                           "2" (dp),        // edi
  1581.                           "0" (width),     // ecx
  1582.                           "rim" (_const4)  // %1(?)  (0x0000000000FFFFFFLL)
  1583. #if 0  /* %mm0, ..., %mm4 not supported by gcc 2.7.2.3 or egcs 1.1 */
  1584.                         : "%mm0", "%mm1", "%mm2"       // clobber list
  1585.                         , "%mm3", "%mm4"
  1586. #endif
  1587.                      );
  1588.                   }
  1589.                   else if (((pass == 2) || (pass == 3)) && width)
  1590.                   {
  1591.                      int dummy_value_c;   // fix 'forbidden register spilled'
  1592.                      int dummy_value_S;
  1593.                      int dummy_value_D;
  1594.                      __asm__ __volatile__ (
  1595.                         "subl $9, %%edi          nt"
  1596.                                      // (png_pass_inc[pass] - 1)*pixel_bytes
  1597.                      ".loop3_pass2:              nt"
  1598.                         "movd (%%esi), %%mm0     nt" // x x x x x 2 1 0
  1599.                         "pand _const4, %%mm0     nt" // z z z z z 2 1 0
  1600.                         "movq %%mm0, %%mm1       nt" // z z z z z 2 1 0
  1601.                         "psllq $16, %%mm0        nt" // z z z 2 1 0 z z
  1602.                         "movq %%mm0, %%mm2       nt" // z z z 2 1 0 z z
  1603.                         "psllq $24, %%mm0        nt" // 2 1 0 z z z z z
  1604.                         "psrlq $8, %%mm1         nt" // z z z z z z 2 1
  1605.                         "por %%mm2, %%mm0        nt" // 2 1 0 2 1 0 z z
  1606.                         "por %%mm1, %%mm0        nt" // 2 1 0 2 1 0 2 1
  1607.                         "movq %%mm0, 4(%%edi)    nt"
  1608.                         "psrlq $16, %%mm0        nt" // z z 2 1 0 2 1 0
  1609.                         "subl $3, %%esi          nt"
  1610.                         "movd %%mm0, (%%edi)     nt"
  1611.                         "subl $12, %%edi         nt"
  1612.                         "decl %%ecx              nt"
  1613.                         "jnz .loop3_pass2        nt"
  1614.                         "EMMS                    nt" // DONE
  1615.                         : "=c" (dummy_value_c),        // output regs (dummy)
  1616.                           "=S" (dummy_value_S),
  1617.                           "=D" (dummy_value_D)
  1618.                         : "1" (sptr),      // esi      // input regs
  1619.                           "2" (dp),        // edi
  1620.                           "0" (width),     // ecx
  1621.                           "rim" (_const4)  // (0x0000000000FFFFFFLL)
  1622. #if 0  /* %mm0, ..., %mm2 not supported by gcc 2.7.2.3 or egcs 1.1 */
  1623.                         : "%mm0", "%mm1", "%mm2"       // clobber list
  1624. #endif
  1625.                      );
  1626.                   }
  1627.                   else if (width) /* && ((pass == 4) || (pass == 5)) */
  1628.                   {
  1629.                      int width_mmx = ((width >> 1) << 1) - 8;   // GRR:  huh?
  1630.                      if (width_mmx < 0)
  1631.                          width_mmx = 0;
  1632.                      width -= width_mmx;        // 8 or 9 pix, 24 or 27 bytes
  1633.                      if (width_mmx)
  1634.                      {
  1635.                         // png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  1636.                         // sptr points at last pixel in pre-expanded row
  1637.                         // dp points at last pixel position in expanded row
  1638.                         int dummy_value_c;  // fix 'forbidden register spilled'
  1639.                         int dummy_value_S;
  1640.                         int dummy_value_D;
  1641.                         __asm__ __volatile__ (
  1642.                            "subl $3, %%esi          nt"
  1643.                            "subl $9, %%edi          nt"
  1644.                                         // (png_pass_inc[pass] + 1)*pixel_bytes
  1645.                         ".loop3_pass4:              nt"
  1646.                            "movq (%%esi), %%mm0     nt" // x x 5 4 3 2 1 0
  1647.                            "movq %%mm0, %%mm1       nt" // x x 5 4 3 2 1 0
  1648.                            "movq %%mm0, %%mm2       nt" // x x 5 4 3 2 1 0
  1649.                            "psllq $24, %%mm0        nt" // 4 3 2 1 0 z z z
  1650.                            "pand _const4, %%mm1     nt" // z z z z z 2 1 0
  1651.                            "psrlq $24, %%mm2        nt" // z z z x x 5 4 3
  1652.                            "por %%mm1, %%mm0        nt" // 4 3 2 1 0 2 1 0
  1653.                            "movq %%mm2, %%mm3       nt" // z z z x x 5 4 3
  1654.                            "psllq $8, %%mm2         nt" // z z x x 5 4 3 z
  1655.                            "movq %%mm0, (%%edi)     nt"
  1656.                            "psrlq $16, %%mm3        nt" // z z z z z x x 5
  1657.                            "pand _const6, %%mm3     nt" // z z z z z z z 5
  1658.                            "por %%mm3, %%mm2        nt" // z z x x 5 4 3 5
  1659.                            "subl $6, %%esi          nt"
  1660.                            "movd %%mm2, 8(%%edi)    nt"
  1661.                            "subl $12, %%edi         nt"
  1662.                            "subl $2, %%ecx          nt"
  1663.                            "jnz .loop3_pass4        nt"
  1664.                            "EMMS                    nt" // DONE
  1665.                            : "=c" (dummy_value_c),        // output regs (dummy)
  1666.                              "=S" (dummy_value_S),
  1667.                              "=D" (dummy_value_D)
  1668.                            : "1" (sptr),      // esi      // input regs
  1669.                              "2" (dp),        // edi
  1670.                              "0" (width_mmx), // ecx
  1671.                              "rim" (_const4), // 0x0000000000FFFFFFLL
  1672.                              "rim" (_const6)  // 0x00000000000000FFLL
  1673. #if 0  /* %mm0, ..., %mm3 not supported by gcc 2.7.2.3 or egcs 1.1 */
  1674.                            : "%mm0", "%mm1"               // clobber list
  1675.                            , "%mm2", "%mm3"
  1676. #endif
  1677.                         );
  1678.                      }
  1679.                      sptr -= width_mmx*3;
  1680.                      dp -= width_mmx*6;
  1681.                      for (i = width; i; i--)
  1682.                      {
  1683.                         png_byte v[8];
  1684.                         int j;
  1685.                         png_memcpy(v, sptr, 3);
  1686.                         for (j = 0; j < png_pass_inc[pass]; j++)
  1687.                         {
  1688.                            png_memcpy(dp, v, 3);
  1689.                            dp -= 3;
  1690.                         }
  1691.                         sptr -= 3;
  1692.                      }
  1693.                   }
  1694.                } /* end of pixel_bytes == 3 */
  1695.                //--------------------------------------------------------------
  1696.                else if (pixel_bytes == 1)
  1697.                {
  1698.                   if (((pass == 0) || (pass == 1)) && width)
  1699.                   {
  1700.                      int width_mmx = ((width >> 2) << 2);
  1701.                      width -= width_mmx;        // 0-3 pixels => 0-3 bytes
  1702.                      if (width_mmx)
  1703.                      {
  1704.                         int dummy_value_c;  // fix 'forbidden register spilled'
  1705.                         int dummy_value_S;
  1706.                         int dummy_value_D;
  1707.                         __asm__ __volatile__ (
  1708.                            "subl $3, %%esi          nt"
  1709.                            "subl $31, %%edi         nt"
  1710.                         ".loop1_pass0:              nt"
  1711.                            "movd (%%esi), %%mm0     nt" // x x x x 3 2 1 0
  1712.                            "movq %%mm0, %%mm1       nt" // x x x x 3 2 1 0
  1713.                            "punpcklbw %%mm0, %%mm0  nt" // 3 3 2 2 1 1 0 0
  1714.                            "movq %%mm0, %%mm2       nt" // 3 3 2 2 1 1 0 0
  1715.                            "punpcklwd %%mm0, %%mm0  nt" // 1 1 1 1 0 0 0 0
  1716.                            "movq %%mm0, %%mm3       nt" // 1 1 1 1 0 0 0 0
  1717.                            "punpckldq %%mm0, %%mm0  nt" // 0 0 0 0 0 0 0 0
  1718.                            "punpckhdq %%mm3, %%mm3  nt" // 1 1 1 1 1 1 1 1
  1719.                            "movq %%mm0, (%%edi)     nt"
  1720.                            "punpckhwd %%mm2, %%mm2  nt" // 3 3 3 3 2 2 2 2
  1721.                            "movq %%mm3, 8(%%edi)    nt"
  1722.                            "movq %%mm2, %%mm4       nt" // 3 3 3 3 2 2 2 2
  1723.                            "punpckldq %%mm2, %%mm2  nt" // 2 2 2 2 2 2 2 2
  1724.                            "punpckhdq %%mm4, %%mm4  nt" // 3 3 3 3 3 3 3 3
  1725.                            "movq %%mm2, 16(%%edi)   nt"
  1726.                            "subl $4, %%esi          nt"
  1727.                            "movq %%mm4, 24(%%edi)   nt"
  1728.                            "subl $32, %%edi         nt"
  1729.                            "subl $4, %%ecx          nt"
  1730.                            "jnz .loop1_pass0        nt"
  1731.                            "EMMS                    nt" // DONE
  1732.                            : "=c" (dummy_value_c),        // output regs (dummy)
  1733.                              "=S" (dummy_value_S),
  1734.                              "=D" (dummy_value_D)
  1735.                            : "1" (sptr),      // esi      // input regs
  1736.                              "2" (dp),        // edi
  1737.                              "0" (width_mmx)  // ecx
  1738. #if 0  /* %mm0, ..., %mm4 not supported by gcc 2.7.2.3 or egcs 1.1 */
  1739.                            : "%mm0", "%mm1", "%mm2"       // clobber list
  1740.                            , "%mm3", "%mm4"
  1741. #endif
  1742.                         );
  1743.                      }
  1744.                      sptr -= width_mmx;
  1745.                      dp -= width_mmx*8;
  1746.                      for (i = width; i; i--)
  1747.                      {
  1748.                         int j;
  1749.                        /* I simplified this part in version 1.0.4e
  1750.                         * here and in several other instances where
  1751.                         * pixel_bytes == 1  -- GR-P
  1752.                         *
  1753.                         * Original code:
  1754.                         *
  1755.                         * png_byte v[8];
  1756.                         * png_memcpy(v, sptr, pixel_bytes);
  1757.                         * for (j = 0; j < png_pass_inc[pass]; j++)
  1758.                         * {
  1759.                         *    png_memcpy(dp, v, pixel_bytes);
  1760.                         *    dp -= pixel_bytes;
  1761.                         * }
  1762.                         * sptr -= pixel_bytes;
  1763.                         *
  1764.                         * Replacement code is in the next three lines:
  1765.                         */
  1766.                         for (j = 0; j < png_pass_inc[pass]; j++)
  1767.                         {
  1768.                            *dp-- = *sptr;
  1769.                         }
  1770.                         --sptr;
  1771.                      }
  1772.                   }
  1773.                   else if (((pass == 2) || (pass == 3)) && width)
  1774.                   {
  1775.                      int width_mmx = ((width >> 2) << 2);
  1776.                      width -= width_mmx;        // 0-3 pixels => 0-3 bytes
  1777.                      if (width_mmx)
  1778.                      {
  1779.                         int dummy_value_c;  // fix 'forbidden register spilled'
  1780.                         int dummy_value_S;
  1781.                         int dummy_value_D;
  1782.                         __asm__ __volatile__ (
  1783.                            "subl $3, %%esi          nt"
  1784.                            "subl $15, %%edi         nt"
  1785.                         ".loop1_pass2:              nt"
  1786.                            "movd (%%esi), %%mm0     nt" // x x x x 3 2 1 0
  1787.                            "punpcklbw %%mm0, %%mm0  nt" // 3 3 2 2 1 1 0 0
  1788.                            "movq %%mm0, %%mm1       nt" // 3 3 2 2 1 1 0 0
  1789.                            "punpcklwd %%mm0, %%mm0  nt" // 1 1 1 1 0 0 0 0
  1790.                            "punpckhwd %%mm1, %%mm1  nt" // 3 3 3 3 2 2 2 2
  1791.                            "movq %%mm0, (%%edi)     nt"
  1792.                            "subl $4, %%esi          nt"
  1793.                            "movq %%mm1, 8(%%edi)    nt"
  1794.                            "subl $16, %%edi         nt"
  1795.                            "subl $4, %%ecx          nt"
  1796.                            "jnz .loop1_pass2        nt"
  1797.                            "EMMS                    nt" // DONE
  1798.                            : "=c" (dummy_value_c),        // output regs (dummy)
  1799.                              "=S" (dummy_value_S),
  1800.                              "=D" (dummy_value_D)
  1801.                            : "1" (sptr),      // esi      // input regs
  1802.                              "2" (dp),        // edi
  1803.                              "0" (width_mmx)  // ecx
  1804. #if 0  /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
  1805.                            : "%mm0", "%mm1"               // clobber list
  1806. #endif
  1807.                         );
  1808.                      }
  1809.                      sptr -= width_mmx;
  1810.                      dp -= width_mmx*4;
  1811.                      for (i = width; i; i--)
  1812.                      {
  1813.                         int j;
  1814.                         for (j = 0; j < png_pass_inc[pass]; j++)
  1815.                         {
  1816.                            *dp-- = *sptr;
  1817.                         }
  1818.                         --sptr;
  1819.                      }
  1820.                   }
  1821.                   else if (width)  /* && ((pass == 4) || (pass == 5)) */
  1822.                   {
  1823.                      int width_mmx = ((width >> 3) << 3);
  1824.                      width -= width_mmx;        // 0-3 pixels => 0-3 bytes
  1825.                      if (width_mmx)
  1826.                      {
  1827.                         int dummy_value_c;  // fix 'forbidden register spilled'
  1828.                         int dummy_value_S;
  1829.                         int dummy_value_D;
  1830.                         __asm__ __volatile__ (
  1831.                            "subl $7, %%esi          nt"
  1832.                            "subl $15, %%edi         nt"
  1833.                         ".loop1_pass4:              nt"
  1834.                            "movq (%%esi), %%mm0     nt" // 7 6 5 4 3 2 1 0
  1835.                            "movq %%mm0, %%mm1       nt" // 7 6 5 4 3 2 1 0
  1836.                            "punpcklbw %%mm0, %%mm0  nt" // 3 3 2 2 1 1 0 0
  1837.                            "punpckhbw %%mm1, %%mm1  nt" // 7 7 6 6 5 5 4 4
  1838.                            "movq %%mm1, 8(%%edi)    nt"
  1839.                            "subl $8, %%esi          nt"
  1840.                            "movq %%mm0, (%%edi)     nt"
  1841.                            "subl $16, %%edi         nt"
  1842.                            "subl $8, %%ecx          nt"
  1843.                            "jnz .loop1_pass4        nt"
  1844.                            "EMMS                    nt" // DONE
  1845.                            : "=c" (dummy_value_c),        // output regs (none)
  1846.                              "=S" (dummy_value_S),
  1847.                              "=D" (dummy_value_D)
  1848.                            : "1" (sptr),      // esi      // input regs
  1849.                              "2" (dp),        // edi
  1850.                              "0" (width_mmx)  // ecx
  1851. #if 0  /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
  1852.                            : "%mm0", "%mm1"               // clobber list
  1853. #endif
  1854.                         );
  1855.                      }
  1856.                      sptr -= width_mmx;
  1857.                      dp -= width_mmx*2;
  1858.                      for (i = width; i; i--)
  1859.                      {
  1860.                         int j;
  1861.                         for (j = 0; j < png_pass_inc[pass]; j++)
  1862.                         {
  1863.                            *dp-- = *sptr;
  1864.                         }
  1865.                         --sptr;
  1866.                      }
  1867.                   }
  1868.                } /* end of pixel_bytes == 1 */
  1869.                //--------------------------------------------------------------
  1870.                else if (pixel_bytes == 2)
  1871.                {
  1872.                   if (((pass == 0) || (pass == 1)) && width)
  1873.                   {
  1874.                      int width_mmx = ((width >> 1) << 1);
  1875.                      width -= width_mmx;        // 0,1 pixels => 0,2 bytes
  1876.                      if (width_mmx)
  1877.                      {
  1878.                         int dummy_value_c;  // fix 'forbidden register spilled'
  1879.                         int dummy_value_S;
  1880.                         int dummy_value_D;
  1881.                         __asm__ __volatile__ (
  1882.                            "subl $2, %%esi          nt"
  1883.                            "subl $30, %%edi         nt"
  1884.                         ".loop2_pass0:              nt"
  1885.                            "movd (%%esi), %%mm0     nt" // x x x x 3 2 1 0
  1886.                            "punpcklwd %%mm0, %%mm0  nt" // 3 2 3 2 1 0 1 0
  1887.                            "movq %%mm0, %%mm1       nt" // 3 2 3 2 1 0 1 0
  1888.                            "punpckldq %%mm0, %%mm0  nt" // 1 0 1 0 1 0 1 0
  1889.                            "punpckhdq %%mm1, %%mm1  nt" // 3 2 3 2 3 2 3 2
  1890.                            "movq %%mm0, (%%edi)     nt"
  1891.                            "movq %%mm0, 8(%%edi)    nt"
  1892.                            "movq %%mm1, 16(%%edi)   nt"
  1893.                            "subl $4, %%esi          nt"
  1894.                            "movq %%mm1, 24(%%edi)   nt"
  1895.                            "subl $32, %%edi         nt"
  1896.                            "subl $2, %%ecx          nt"
  1897.                            "jnz .loop2_pass0        nt"
  1898.                            "EMMS                    nt" // DONE
  1899.                            : "=c" (dummy_value_c),        // output regs (dummy)
  1900.                              "=S" (dummy_value_S),
  1901.                              "=D" (dummy_value_D)
  1902.                            : "1" (sptr),      // esi      // input regs
  1903.                              "2" (dp),        // edi
  1904.                              "0" (width_mmx)  // ecx
  1905. #if 0  /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
  1906.                            : "%mm0", "%mm1"               // clobber list
  1907. #endif
  1908.                         );
  1909.                      }
  1910.                      sptr -= (width_mmx*2 - 2); // sign fixed
  1911.                      dp -= (width_mmx*16 - 2);  // sign fixed
  1912.                      for (i = width; i; i--)
  1913.                      {
  1914.                         png_byte v[8];
  1915.                         int j;
  1916.                         sptr -= 2;
  1917.                         png_memcpy(v, sptr, 2);
  1918.                         for (j = 0; j < png_pass_inc[pass]; j++)
  1919.                         {
  1920.                            dp -= 2;
  1921.                            png_memcpy(dp, v, 2);
  1922.                         }
  1923.                      }
  1924.                   }
  1925.                   else if (((pass == 2) || (pass == 3)) && width)
  1926.                   {
  1927.                      int width_mmx = ((width >> 1) << 1) ;
  1928.                      width -= width_mmx;        // 0,1 pixels => 0,2 bytes
  1929.                      if (width_mmx)
  1930.                      {
  1931.                         int dummy_value_c;  // fix 'forbidden register spilled'
  1932.                         int dummy_value_S;
  1933.                         int dummy_value_D;
  1934.                         __asm__ __volatile__ (
  1935.                            "subl $2, %%esi          nt"
  1936.                            "subl $14, %%edi         nt"
  1937.                         ".loop2_pass2:              nt"
  1938.                            "movd (%%esi), %%mm0     nt" // x x x x 3 2 1 0
  1939.                            "punpcklwd %%mm0, %%mm0  nt" // 3 2 3 2 1 0 1 0
  1940.                            "movq %%mm0, %%mm1       nt" // 3 2 3 2 1 0 1 0
  1941.                            "punpckldq %%mm0, %%mm0  nt" // 1 0 1 0 1 0 1 0
  1942.                            "punpckhdq %%mm1, %%mm1  nt" // 3 2 3 2 3 2 3 2
  1943.                            "movq %%mm0, (%%edi)     nt"
  1944.                            "subl $4, %%esi          nt"
  1945.                            "movq %%mm1, 8(%%edi)    nt"
  1946.                            "subl $16, %%edi         nt"
  1947.                            "subl $2, %%ecx          nt"
  1948.                            "jnz .loop2_pass2        nt"
  1949.                            "EMMS                    nt" // DONE
  1950.                            : "=c" (dummy_value_c),        // output regs (dummy)
  1951.                              "=S" (dummy_value_S),
  1952.                              "=D" (dummy_value_D)
  1953.                            : "1" (sptr),      // esi      // input regs
  1954.                              "2" (dp),        // edi
  1955.                              "0" (width_mmx)  // ecx
  1956. #if 0  /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
  1957.                            : "%mm0", "%mm1"               // clobber list
  1958. #endif
  1959.                         );
  1960.                      }
  1961.                      sptr -= (width_mmx*2 - 2); // sign fixed
  1962.                      dp -= (width_mmx*8 - 2);   // sign fixed
  1963.                      for (i = width; i; i--)
  1964.                      {
  1965.                         png_byte v[8];
  1966.                         int j;
  1967.                         sptr -= 2;
  1968.                         png_memcpy(v, sptr, 2);
  1969.                         for (j = 0; j < png_pass_inc[pass]; j++)
  1970.                         {
  1971.                            dp -= 2;
  1972.                            png_memcpy(dp, v, 2);
  1973.                         }
  1974.                      }
  1975.                   }
  1976.                   else if (width)  // pass == 4 or 5
  1977.                   {
  1978.                      int width_mmx = ((width >> 1) << 1) ;
  1979.                      width -= width_mmx;        // 0,1 pixels => 0,2 bytes
  1980.                      if (width_mmx)
  1981.                      {
  1982.                         int dummy_value_c;  // fix 'forbidden register spilled'
  1983.                         int dummy_value_S;
  1984.                         int dummy_value_D;
  1985.                         __asm__ __volatile__ (
  1986.                            "subl $2, %%esi          nt"
  1987.                            "subl $6, %%edi          nt"
  1988.                         ".loop2_pass4:              nt"
  1989.                            "movd (%%esi), %%mm0     nt" // x x x x 3 2 1 0
  1990.                            "punpcklwd %%mm0, %%mm0  nt" // 3 2 3 2 1 0 1 0
  1991.                            "subl $4, %%esi          nt"
  1992.                            "movq %%mm0, (%%edi)     nt"
  1993.                            "subl $8, %%edi          nt"
  1994.                            "subl $2, %%ecx          nt"
  1995.                            "jnz .loop2_pass4        nt"
  1996.                            "EMMS                    nt" // DONE
  1997.                            : "=c" (dummy_value_c),        // output regs (dummy)
  1998.                              "=S" (dummy_value_S),
  1999.                              "=D" (dummy_value_D)
  2000.                            : "1" (sptr),      // esi      // input regs
  2001.                              "2" (dp),        // edi
  2002.                              "0" (width_mmx)  // ecx
  2003. #if 0  /* %mm0 not supported by gcc 2.7.2.3 or egcs 1.1 */
  2004.                            : "%mm0"                       // clobber list
  2005. #endif
  2006.                         );
  2007.                      }
  2008.                      sptr -= (width_mmx*2 - 2); // sign fixed
  2009.                      dp -= (width_mmx*4 - 2);   // sign fixed
  2010.                      for (i = width; i; i--)
  2011.                      {
  2012.                         png_byte v[8];
  2013.                         int j;
  2014.                         sptr -= 2;
  2015.                         png_memcpy(v, sptr, 2);
  2016.                         for (j = 0; j < png_pass_inc[pass]; j++)
  2017.                         {
  2018.                            dp -= 2;
  2019.                            png_memcpy(dp, v, 2);
  2020.                         }
  2021.                      }
  2022.                   }
  2023.                } /* end of pixel_bytes == 2 */
  2024.                //--------------------------------------------------------------
  2025.                else if (pixel_bytes == 4)
  2026.                {
  2027.                   if (((pass == 0) || (pass == 1)) && width)
  2028.                   {
  2029.                      int width_mmx = ((width >> 1) << 1);
  2030.                      width -= width_mmx;        // 0,1 pixels => 0,4 bytes
  2031.                      if (width_mmx)
  2032.                      {
  2033.                         int dummy_value_c;  // fix 'forbidden register spilled'
  2034.                         int dummy_value_S;
  2035.                         int dummy_value_D;
  2036.                         __asm__ __volatile__ (
  2037.                            "subl $4, %%esi          nt"
  2038.                            "subl $60, %%edi         nt"
  2039.                         ".loop4_pass0:              nt"
  2040.                            "movq (%%esi), %%mm0     nt" // 7 6 5 4 3 2 1 0
  2041.                            "movq %%mm0, %%mm1       nt" // 7 6 5 4 3 2 1 0
  2042.                            "punpckldq %%mm0, %%mm0  nt" // 3 2 1 0 3 2 1 0
  2043.                            "punpckhdq %%mm1, %%mm1  nt" // 7 6 5 4 7 6 5 4
  2044.                            "movq %%mm0, (%%edi)     nt"
  2045.                            "movq %%mm0, 8(%%edi)    nt"
  2046.                            "movq %%mm0, 16(%%edi)   nt"
  2047.                            "movq %%mm0, 24(%%edi)   nt"
  2048.                            "movq %%mm1, 32(%%edi)   nt"
  2049.                            "movq %%mm1, 40(%%edi)   nt"
  2050.                            "movq %%mm1, 48(%%edi)   nt"
  2051.                            "subl $8, %%esi          nt"
  2052.                            "movq %%mm1, 56(%%edi)   nt"
  2053.                            "subl $64, %%edi         nt"
  2054.                            "subl $2, %%ecx          nt"
  2055.                            "jnz .loop4_pass0        nt"
  2056.                            "EMMS                    nt" // DONE
  2057.                            : "=c" (dummy_value_c),        // output regs (dummy)
  2058.                              "=S" (dummy_value_S),
  2059.                              "=D" (dummy_value_D)
  2060.                            : "1" (sptr),      // esi      // input regs
  2061.                              "2" (dp),        // edi
  2062.                              "0" (width_mmx)  // ecx
  2063. #if 0  /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
  2064.                            : "%mm0", "%mm1"               // clobber list
  2065. #endif
  2066.                         );
  2067.                      }
  2068.                      sptr -= (width_mmx*4 - 4); // sign fixed
  2069.                      dp -= (width_mmx*32 - 4);  // sign fixed
  2070.                      for (i = width; i; i--)
  2071.                      {
  2072.                         png_byte v[8];
  2073.                         int j;
  2074.                         sptr -= 4;
  2075.                         png_memcpy(v, sptr, 4);
  2076.                         for (j = 0; j < png_pass_inc[pass]; j++)
  2077.                         {
  2078.                            dp -= 4;
  2079.                            png_memcpy(dp, v, 4);
  2080.                         }
  2081.                      }
  2082.                   }
  2083.                   else if (((pass == 2) || (pass == 3)) && width)
  2084.                   {
  2085.                      int width_mmx = ((width >> 1) << 1);
  2086.                      width -= width_mmx;        // 0,1 pixels => 0,4 bytes
  2087.                      if (width_mmx)
  2088.                      {
  2089.                         int dummy_value_c;  // fix 'forbidden register spilled'
  2090.                         int dummy_value_S;
  2091.                         int dummy_value_D;
  2092.                         __asm__ __volatile__ (
  2093.                            "subl $4, %%esi          nt"
  2094.                            "subl $28, %%edi         nt"
  2095.                         ".loop4_pass2:              nt"
  2096.                            "movq (%%esi), %%mm0     nt" // 7 6 5 4 3 2 1 0
  2097.                            "movq %%mm0, %%mm1       nt" // 7 6 5 4 3 2 1 0
  2098.                            "punpckldq %%mm0, %%mm0  nt" // 3 2 1 0 3 2 1 0
  2099.                            "punpckhdq %%mm1, %%mm1  nt" // 7 6 5 4 7 6 5 4
  2100.                            "movq %%mm0, (%%edi)     nt"
  2101.                            "movq %%mm0, 8(%%edi)    nt"
  2102.                            "movq %%mm1, 16(%%edi)   nt"
  2103.                            "movq %%mm1, 24(%%edi)   nt"
  2104.                            "subl $8, %%esi          nt"
  2105.                            "subl $32, %%edi         nt"
  2106.                            "subl $2, %%ecx          nt"
  2107.                            "jnz .loop4_pass2        nt"
  2108.                            "EMMS                    nt" // DONE
  2109.                            : "=c" (dummy_value_c),        // output regs (dummy)
  2110.                              "=S" (dummy_value_S),
  2111.                              "=D" (dummy_value_D)
  2112.                            : "1" (sptr),      // esi      // input regs
  2113.                              "2" (dp),        // edi
  2114.                              "0" (width_mmx)  // ecx
  2115. #if 0  /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
  2116.                            : "%mm0", "%mm1"               // clobber list
  2117. #endif
  2118.                         );
  2119.                      }
  2120.                      sptr -= (width_mmx*4 - 4); // sign fixed
  2121.                      dp -= (width_mmx*16 - 4);  // sign fixed
  2122.                      for (i = width; i; i--)
  2123.                      {
  2124.                         png_byte v[8];
  2125.                         int j;
  2126.                         sptr -= 4;
  2127.                         png_memcpy(v, sptr, 4);
  2128.                         for (j = 0; j < png_pass_inc[pass]; j++)
  2129.                         {
  2130.                            dp -= 4;
  2131.                            png_memcpy(dp, v, 4);
  2132.                         }
  2133.                      }
  2134.                   }
  2135.                   else if (width)  // pass == 4 or 5
  2136.                   {
  2137.                      int width_mmx = ((width >> 1) << 1) ;
  2138.                      width -= width_mmx;        // 0,1 pixels => 0,4 bytes
  2139.                      if (width_mmx)
  2140.                      {
  2141.                         int dummy_value_c;  // fix 'forbidden register spilled'
  2142.                         int dummy_value_S;
  2143.                         int dummy_value_D;
  2144.                         __asm__ __volatile__ (
  2145.                            "subl $4, %%esi          nt"
  2146.                            "subl $12, %%edi         nt"
  2147.                         ".loop4_pass4:              nt"
  2148.                            "movq (%%esi), %%mm0     nt" // 7 6 5 4 3 2 1 0
  2149.                            "movq %%mm0, %%mm1       nt" // 7 6 5 4 3 2 1 0
  2150.                            "punpckldq %%mm0, %%mm0  nt" // 3 2 1 0 3 2 1 0
  2151.                            "punpckhdq %%mm1, %%mm1  nt" // 7 6 5 4 7 6 5 4
  2152.                            "movq %%mm0, (%%edi)     nt"
  2153.                            "subl $8, %%esi          nt"
  2154.                            "movq %%mm1, 8(%%edi)    nt"
  2155.                            "subl $16, %%edi         nt"
  2156.                            "subl $2, %%ecx          nt"
  2157.                            "jnz .loop4_pass4        nt"
  2158.                            "EMMS                    nt" // DONE
  2159.                            : "=c" (dummy_value_c),        // output regs (dummy)
  2160.                              "=S" (dummy_value_S),
  2161.                              "=D" (dummy_value_D)
  2162.                            : "1" (sptr),      // esi      // input regs
  2163.                              "2" (dp),        // edi
  2164.                              "0" (width_mmx)  // ecx
  2165. #if 0  /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
  2166.                            : "%mm0", "%mm1"               // clobber list
  2167. #endif
  2168.                         );
  2169.                      }
  2170.                      sptr -= (width_mmx*4 - 4); // sign fixed
  2171.                      dp -= (width_mmx*8 - 4);   // sign fixed
  2172.                      for (i = width; i; i--)
  2173.                      {
  2174.                         png_byte v[8];
  2175.                         int j;
  2176.                         sptr -= 4;
  2177.                         png_memcpy(v, sptr, 4);
  2178.                         for (j = 0; j < png_pass_inc[pass]; j++)
  2179.                         {
  2180.                            dp -= 4;
  2181.                            png_memcpy(dp, v, 4);
  2182.                         }
  2183.                      }
  2184.                   }
  2185.                } /* end of pixel_bytes == 4 */
  2186.                //--------------------------------------------------------------
  2187.                else if (pixel_bytes == 8)
  2188.                {
  2189. // GRR TEST:  should work, but needs testing (special 64-bit version of rpng2?)
  2190.                   // GRR NOTE:  no need to combine passes here!
  2191.                   if (((pass == 0) || (pass == 1)) && width)
  2192.                   {
  2193.                      int dummy_value_c;  // fix 'forbidden register spilled'
  2194.                      int dummy_value_S;
  2195.                      int dummy_value_D;
  2196.                      // source is 8-byte RRGGBBAA
  2197.                      // dest is 64-byte RRGGBBAA RRGGBBAA RRGGBBAA RRGGBBAA ...
  2198.                      __asm__ __volatile__ (
  2199.                         "subl $56, %%edi         nt" // start of last block
  2200.                      ".loop8_pass0:              nt"
  2201.                         "movq (%%esi), %%mm0     nt" // 7 6 5 4 3 2 1 0
  2202.                         "movq %%mm0, (%%edi)     nt"
  2203.                         "movq %%mm0, 8(%%edi)    nt"
  2204.                         "movq %%mm0, 16(%%edi)   nt"
  2205.                         "movq %%mm0, 24(%%edi)   nt"
  2206.                         "movq %%mm0, 32(%%edi)   nt"
  2207.                         "movq %%mm0, 40(%%edi)   nt"
  2208.                         "movq %%mm0, 48(%%edi)   nt"
  2209.                         "subl $8, %%esi          nt"
  2210.                         "movq %%mm0, 56(%%edi)   nt"
  2211.                         "subl $64, %%edi         nt"
  2212.                         "decl %%ecx              nt"
  2213.                         "jnz .loop8_pass0        nt"
  2214.                         "EMMS                    nt" // DONE
  2215.                         : "=c" (dummy_value_c),        // output regs (dummy)
  2216.                           "=S" (dummy_value_S),
  2217.                           "=D" (dummy_value_D)
  2218.                         : "1" (sptr),      // esi      // input regs
  2219.                           "2" (dp),        // edi
  2220.                           "0" (width)      // ecx
  2221. #if 0  /* %mm0 not supported by gcc 2.7.2.3 or egcs 1.1 */
  2222.                         : "%mm0"                       // clobber list
  2223. #endif
  2224.                      );
  2225.                   }
  2226.                   else if (((pass == 2) || (pass == 3)) && width)
  2227.                   {
  2228.                      // source is 8-byte RRGGBBAA
  2229.                      // dest is 32-byte RRGGBBAA RRGGBBAA RRGGBBAA RRGGBBAA
  2230.                      // (recall that expansion is _in place_:  sptr and dp
  2231.                      //  both point at locations within same row buffer)
  2232.                      {
  2233.                         int dummy_value_c;  // fix 'forbidden register spilled'
  2234.                         int dummy_value_S;
  2235.                         int dummy_value_D;
  2236.                         __asm__ __volatile__ (
  2237.                            "subl $24, %%edi         nt" // start of last block
  2238.                         ".loop8_pass2:              nt"
  2239.                            "movq (%%esi), %%mm0     nt" // 7 6 5 4 3 2 1 0
  2240.                            "movq %%mm0, (%%edi)     nt"
  2241.                            "movq %%mm0, 8(%%edi)    nt"
  2242.                            "movq %%mm0, 16(%%edi)   nt"
  2243.                            "subl $8, %%esi          nt"
  2244.                            "movq %%mm0, 24(%%edi)   nt"
  2245.                            "subl $32, %%edi         nt"
  2246.                            "decl %%ecx              nt"
  2247.                            "jnz .loop8_pass2        nt"
  2248.                            "EMMS                    nt" // DONE
  2249.                            : "=c" (dummy_value_c),        // output regs (dummy)
  2250.                              "=S" (dummy_value_S),
  2251.                              "=D" (dummy_value_D)
  2252.                            : "1" (sptr),      // esi      // input regs
  2253.                              "2" (dp),        // edi
  2254.                              "0" (width)      // ecx
  2255. #if 0  /* %mm0 not supported by gcc 2.7.2.3 or egcs 1.1 */
  2256.                            : "%mm0"                       // clobber list
  2257. #endif
  2258.                         );
  2259.                      }
  2260.                   }
  2261.                   else if (width)  // pass == 4 or 5
  2262.                   {
  2263.                      // source is 8-byte RRGGBBAA
  2264.                      // dest is 16-byte RRGGBBAA RRGGBBAA
  2265.                      {
  2266.                         int dummy_value_c;  // fix 'forbidden register spilled'
  2267.                         int dummy_value_S;
  2268.                         int dummy_value_D;
  2269.                         __asm__ __volatile__ (
  2270.                            "subl $8, %%edi          nt" // start of last block
  2271.                         ".loop8_pass4:              nt"
  2272.                            "movq (%%esi), %%mm0     nt" // 7 6 5 4 3 2 1 0
  2273.                            "movq %%mm0, (%%edi)     nt"
  2274.                            "subl $8, %%esi          nt"
  2275.                            "movq %%mm0, 8(%%edi)    nt"
  2276.                            "subl $16, %%edi         nt"
  2277.                            "decl %%ecx              nt"
  2278.                            "jnz .loop8_pass4        nt"
  2279.                            "EMMS                    nt" // DONE
  2280.                            : "=c" (dummy_value_c),        // output regs (dummy)
  2281.                              "=S" (dummy_value_S),
  2282.                              "=D" (dummy_value_D)
  2283.                            : "1" (sptr),      // esi      // input regs
  2284.                              "2" (dp),        // edi
  2285.                              "0" (width)      // ecx
  2286. #if 0  /* %mm0 not supported by gcc 2.7.2.3 or egcs 1.1 */
  2287.                            : "%mm0"                       // clobber list
  2288. #endif
  2289.                         );
  2290.                      }
  2291.                   }
  2292.                } /* end of pixel_bytes == 8 */
  2293.                //--------------------------------------------------------------
  2294.                else if (pixel_bytes == 6)
  2295.                {
  2296.                   for (i = width; i; i--)
  2297.                   {
  2298.                      png_byte v[8];
  2299.                      int j;
  2300.                      png_memcpy(v, sptr, 6);
  2301.                      for (j = 0; j < png_pass_inc[pass]; j++)
  2302.                      {
  2303.                         png_memcpy(dp, v, 6);
  2304.                         dp -= 6;
  2305.                      }
  2306.                      sptr -= 6;
  2307.                   }
  2308.                } /* end of pixel_bytes == 6 */
  2309.                //--------------------------------------------------------------
  2310.                else
  2311.                {
  2312.                   for (i = width; i; i--)
  2313.                   {
  2314.                      png_byte v[8];
  2315.                      int j;
  2316.                      png_memcpy(v, sptr, pixel_bytes);
  2317.                      for (j = 0; j < png_pass_inc[pass]; j++)
  2318.                      {
  2319.                         png_memcpy(dp, v, pixel_bytes);
  2320.                         dp -= pixel_bytes;
  2321.                      }
  2322.                      sptr-= pixel_bytes;
  2323.                   }
  2324.                }
  2325.             } // end of _mmx_supported ========================================
  2326.             else /* MMX not supported:  use modified C code - takes advantage
  2327.                   *   of inlining of png_memcpy for a constant */
  2328.                  /* GRR 19991007:  does it?  or should pixel_bytes in each
  2329.                   *   block be replaced with immediate value (e.g., 1)? */
  2330.                  /* GRR 19991017:  replaced with constants in each case */
  2331. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  2332.             {
  2333.                if (pixel_bytes == 1)
  2334.                {
  2335.                   for (i = width; i; i--)
  2336.                   {
  2337.                      int j;
  2338.                      for (j = 0; j < png_pass_inc[pass]; j++)
  2339.                      {
  2340.                         *dp-- = *sptr;
  2341.                      }
  2342.                      --sptr;
  2343.                   }
  2344.                }
  2345.                else if (pixel_bytes == 3)
  2346.                {
  2347.                   for (i = width; i; i--)
  2348.                   {
  2349.                      png_byte v[8];
  2350.                      int j;
  2351.                      png_memcpy(v, sptr, 3);
  2352.                      for (j = 0; j < png_pass_inc[pass]; j++)
  2353.                      {
  2354.                         png_memcpy(dp, v, 3);
  2355.                         dp -= 3;
  2356.                      }
  2357.                      sptr -= 3;
  2358.                   }
  2359.                }
  2360.                else if (pixel_bytes == 2)
  2361.                {
  2362.                   for (i = width; i; i--)
  2363.                   {
  2364.                      png_byte v[8];
  2365.                      int j;
  2366.                      png_memcpy(v, sptr, 2);
  2367.                      for (j = 0; j < png_pass_inc[pass]; j++)
  2368.                      {
  2369.                         png_memcpy(dp, v, 2);
  2370.                         dp -= 2;
  2371.                      }
  2372.                      sptr -= 2;
  2373.                   }
  2374.                }
  2375.                else if (pixel_bytes == 4)
  2376.                {
  2377.                   for (i = width; i; i--)
  2378.                   {
  2379.                      png_byte v[8];
  2380.                      int j;
  2381.                      png_memcpy(v, sptr, 4);
  2382.                      for (j = 0; j < png_pass_inc[pass]; j++)
  2383.                      {
  2384. #ifdef PNG_DEBUG
  2385.                         if (dp < row || dp+3 > row+png_ptr->row_buf_size)
  2386.                         {
  2387.                            printf("dp out of bounds: row=%d, dp=%d, rp=%dn",
  2388.                              row, dp, row+png_ptr->row_buf_size);
  2389.                            printf("row_buf=%dn",png_ptr->row_buf_size);
  2390.                         }
  2391. #endif
  2392.                         png_memcpy(dp, v, 4);
  2393.                         dp -= 4;
  2394.                      }
  2395.                      sptr -= 4;
  2396.                   }
  2397.                }
  2398.                else if (pixel_bytes == 6)
  2399.                {
  2400.                   for (i = width; i; i--)
  2401.                   {
  2402.                      png_byte v[8];
  2403.                      int j;
  2404.                      png_memcpy(v, sptr, 6);
  2405.                      for (j = 0; j < png_pass_inc[pass]; j++)
  2406.                      {
  2407.                         png_memcpy(dp, v, 6);
  2408.                         dp -= 6;
  2409.                      }
  2410.                      sptr -= 6;
  2411.                   }
  2412.                }
  2413.                else if (pixel_bytes == 8)
  2414.                {
  2415.                   for (i = width; i; i--)
  2416.                   {