-------------------------------------------------------------------------------
                Matrox Imaging Library (6.1) SSE.txt Readme File
                                  May 15, 2000
    Copyright  2000 by Matrox Electronic Systems Ltd. All rights reserved.
-------------------------------------------------------------------------------


The following file contains a list of all the functions that have been 
optimized with SSE code. A supplementary section also suggests the data
alignment required to obtain the best performance with SSE when a buffer is 
created with the MbufCreate2d()/MbufCreateColor() function. Another section 
indicates how to enable/disable the use of SSE optimization by MIL. 


Contents

1. Image processing commands.
2. Buffer management commands.
3. Measurements commands.
4. Pattern matching commands.
5. Blob analysis commands.
6. Graphics commands.
7. Data alignment.
8. Enable/Disable the use of SSE.
9. Known difference with FPU equivalent instruction.


-------------------------------------------------------------------------------
Symbols used in the file
-------------------------------------------------------------------------------

Buffers:    Dst   : Destination
            Src   : Source
            Cnd   : Condition

Data type   UChar : unsigned char
            Char  : signed char
            UShort: unsigned short
            Short : signed short
            ULong : unsigned long
            Long  : signed long
            Float : float
            Bin   : binary

All the buffer bit and sign means all but floating point buffers.


*******************************************************************************
1. Image processing commands.
*******************************************************************************

*******************************************************************************
2. Buffer management commands.
*******************************************************************************

2.1   MbufCopy()

      Only the following versions of the function are optimized with SSE:

      Dst      Src
      ------   ------
      UChar    Float
      Char     Float
      UShort   Float
      Short    Float
      ULong    Float
      Long     Float

      Float    UChar 
      Float    Char  
      Float    UShort
      Float    Short 
      Float    ULong 
      Float    Long
      
      Note that in the case of float to long or float to unsigned long, the 
      result can differ if the value to convert is outside the range of a long 
      or unsigned long, respectively. This is due to the fact that a casting in 
      C++ is done in a __int64 before it has been copied in the destination. In 
      the other cases, the result can differ if the value to convert is outside 
      the range of a long, even if you have an unsigned destination. This is 
      done to optimize the speed.

*******************************************************************************
3. Measurements commands.
*******************************************************************************

*******************************************************************************
4. Pattern matching commands.
*******************************************************************************

*******************************************************************************
5. Blob analysis commands.
*******************************************************************************

*******************************************************************************
6. Graphics commands.
*******************************************************************************

*******************************************************************************
7. Data alignment.
*******************************************************************************

   When a MIL buffer is created using MbufCreate2d()/MbufCreateColor(), its 
   image row data (scanline) should be aligned on 32-byte boundaries to give 
   the best performance in conjunction with the SSE-enabled functions. When it 
   is not possible to align on 32-byte boundaries, then the buffer should at 
   least be aligned on xmmword (128-bit) or doubleword (32-bit) boundaries. 
   Note that, by using the MbufAlloc2d()/MbufAllocColor() function, you don't 
   have to worry about data alignment since in this case, MIL automatically 
   allocates the buffer with the proper alignment.

   Moreover, 32 extra bytes should be available in reading at the beginning and 
   end of the buffer in order for the MMX-enabled algorithms to be able to 
   perform prefetching. The performance could decrease dramatically if those 
   extra pixels are not available. When they are available, then the define 
   M_SSE_ENABLED must be added to the attribute parameter at buffer creation 
   time (MbufCreate2d()/MbufCreateColor()) so that the SSE-enabled algorithms
   know that prefetching can be performed on them. It is also possible to set 
   this flag after buffer creation time using the MbufControl(...M_FORMAT...) 
   command. In which case, the following syntax should appear:

   MbufControl(MilImage,
               M_FORMAT,
               M_SSE_ENABLED|MbufInquire(MilImage, M_FORMAT, NULL));

   (Note that this control is usually reserved for internal use only and thus 
   does not appear in the official documentation.)


*******************************************************************************
8. Enable/Disable the use of SSE.
*******************************************************************************

   A system control type has been created to allow you to switch the
   SSE optimization off. This is useful when comparing the execution time of
   a specific processing operation on an SSE CPU versus a non SSE-CPU. The new 
   MsysControl() type and its control values are the following:

      M_USE_SSE                             Controls the use of SSE code when
                                            processing is done on the specified
                                            system.
                                            Valid states are: 
                                            M_ENABLE  - The SSE opcodes will be
                                                        used to accelerate
                                                        processing. An error
                                                        will be generated if
                                                        no SSE processor is
                                                        detected. (One should 
                                                        use M_DEFAULT instead).
                                            M_DISABLE - Never use SSE opcodes.
                                            M_DEFAULT - M_ENABLE when an SSE
                                                        processor detected, 
                                                        otherwise M_DISABLE.

   Note that an equivalent MsysInquire() has been created so that it can be 
   used to detect whether or not an SSE CPU is present.

   Example: if (MsysInquire(MilSystem, M_USE_SSE, M_NULL)==M_ENABLE)
               {
               // SSE CPU detected
               }
            else   
               {
               // SSE CPU NOT detected
               }


*******************************************************************************
9. Known difference with FPU equivalent instruction.
*******************************************************************************

   9.1 We have denoted some difference in the conversion instructions from 
       float to int. Those are due to the fact that the conversion function in 
       MSDEV makes the conversion in a __int64 before copying it in the long. 
       The SSE instructions, however, make the conversion on 32-bit directly. 
       This gives exactly the same value for values that fit the range of a 
       long, but not for values that overflow the range of a long.