pnggccrd.c
Upload User: kairuinn
Upload Date: 2009-02-07
Package Size: 2922k
Code Size: 234k
Category:

Graph program

Development Platform:

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