Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Set dependency control HW scoreboard kernel
  3.  * Copyright © <2010>, Intel Corporation.
  4.  *
  5.  * Permission is hereby granted, free of charge, to any person obtaining a
  6.  * copy of this software and associated documentation files (the
  7.  * "Software"), to deal in the Software without restriction, including
  8.  * without limitation the rights to use, copy, modify, merge, publish,
  9.  * distribute, sub license, and/or sell copies of the Software, and to
  10.  * permit persons to whom the Software is furnished to do so, subject to
  11.  * the following conditions:
  12.  *
  13.  * The above copyright notice and this permission notice (including the
  14.  * next paragraph) shall be included in all copies or substantial portions
  15.  * of the Software.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  20.  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
  21.  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  22.  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  23.  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24.  *
  25.  * This file was originally licensed under the following license
  26.  *
  27.  *  Licensed under the Apache License, Version 2.0 (the "License");
  28.  *  you may not use this file except in compliance with the License.
  29.  *  You may obtain a copy of the License at
  30.  *
  31.  *      http://www.apache.org/licenses/LICENSE-2.0
  32.  *
  33.  *  Unless required by applicable law or agreed to in writing, software
  34.  *  distributed under the License is distributed on an "AS IS" BASIS,
  35.  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  36.  *  See the License for the specific language governing permissions and
  37.  *  limitations under the License.
  38.  *
  39.  */
  40. // Kernel name: SetHWScoreboard.asm
  41. //
  42. // Set dependency control HW scoreboard kernel
  43. //
  44.  
  45. // ----------------------------------------------------
  46. //  Main: SetHWScoreboard
  47. // ----------------------------------------------------
  48.  
  49. .kernel SetHWScoreboard
  50.  
  51. SETHWSCOREBOARD:
  52.  
  53. #ifdef _DEBUG
  54. // WA for FULSIM so we'll know which kernel is being debugged
  55. mov (1) acc0:ud 0xf0aa55a5:ud
  56. #endif
  57.  
  58. #include "header.inc"
  59. #include "SetHWScoreboard_header.inc"
  60.  
  61. //
  62. //  Now, begin source code....
  63. //
  64.  
  65. .code
  66.  
  67. //      Separate the TotalMB so TotalMB will be multiple of 8
  68. //      and RemainderMB will hold the TotalMB%8
  69. //
  70.         and.z.f0.1 (1)  RemainderMB<1>:uw       TotalMB<0;1,0>:uw       0x0007:uw       // number of %8 commands
  71.         and.z.f0.0 (1)  TotalMB<1>:uw           TotalMB<0;1,0>:uw       0xfff8:uw       // Number of 8-command blocks
  72.  
  73.         mov (1) MB_SHIFT_MASK_W<1>:uw           0x100*16+12:w                                   // Set up shift values (12, 16)
  74.  
  75. //      Initialize common DAP read header
  76. //
  77.         mov (8) MRF_READ_HEADER_SRC<1>:ud       r0.0<8;8,1>:ud
  78.         shl (1) MRF_READ_HEADER_SRC.2<1>:ud     StartingMB<0;1,0>:uw    6:uw    // Byte-aligned offset being read
  79.  
  80. //      Initialize Inter DAP write header
  81.         mov (8) MRF_INTER_WRITE_HEADER<1>:ud    r0.0<8;8,1>:ud
  82.  
  83.         (f0.0) jmpi (1) SetHWScoreboard_Remainder                                                       // Jump if TotalMB < 8
  84.  
  85. //------------------------------------------------------------------------
  86. //      Command buffer parsing loop
  87. //      Each loop will handle 8 commands
  88. //------------------------------------------------------------------------
  89. //
  90. SetHWScoreboard_Loop:
  91. //      Load block 0 (Commands 0/1)
  92.         mov (8) MRF_READ_HEADER0.0<1>:ud        MRF_READ_HEADER_SRC.0<8;8,1>:ud
  93.         send (16)       CMD_BUFFER_W(0)<1>      MRF_READ_HEADER0        null:uw DAPREAD RESP_LEN(4)+OWBRMSGDSC_SC+OWORD_8+BI_CMD_BUFFER
  94.  
  95. //      Load block 1  (Commands 2/3)
  96.         mov (8) MRF_READ_HEADER1.0<1>:ud        MRF_READ_HEADER_SRC.0<8;8,1>:ud
  97.         add     (1)     MRF_READ_HEADER1.2<1>:ud        MRF_READ_HEADER_SRC.2<0;1,0>:ud         128:ud          // Point to next 2-command block
  98.         send (16)       CMD_BUFFER_W(4)<1>      MRF_READ_HEADER1        null:uw DAPREAD RESP_LEN(4)+OWBRMSGDSC_SC+OWORD_8+BI_CMD_BUFFER
  99.  
  100. //      Load block 2  (Commands 4/5)
  101.         mov (8) MRF_READ_HEADER2.0<1>:ud        MRF_READ_HEADER_SRC.0<8;8,1>:ud
  102.         add     (1)     MRF_READ_HEADER2.2<1>:ud        MRF_READ_HEADER_SRC.2<0;1,0>:ud         256:ud          // Point to next 2-command block
  103.         send (16)       CMD_BUFFER_W(8)<1>      MRF_READ_HEADER2        null:uw DAPREAD RESP_LEN(4)+OWBRMSGDSC_SC+OWORD_8+BI_CMD_BUFFER
  104.  
  105. //      Load block 3  (Commands 6/7)
  106.         mov (8) MRF_READ_HEADER3.0<1>:ud        MRF_READ_HEADER_SRC.0<8;8,1>:ud
  107.         add     (1)     MRF_READ_HEADER3.2<1>:ud        MRF_READ_HEADER_SRC.2<0;1,0>:ud         384:ud          // Point to next 2-command block
  108.         send (16)       CMD_BUFFER_W(12)<1>     MRF_READ_HEADER3        null:uw DAPREAD RESP_LEN(4)+OWBRMSGDSC_SC+OWORD_8+BI_CMD_BUFFER
  109.  
  110. //      Start parsing commands
  111.    $for(0; <16; 2) {
  112.         and.nz.f0.1 (8) NULLREG CMD_BUFFER_D(%1,4)<0;1,0>       IS_INTRA_MB:ud          // Is it an "Intra" MB?
  113.         or (1)  CMD_BUFFER_D(%1,2)<1>   CMD_BUFFER_D(%1,2)<0;1,0>       BIT21:ud        // Set "Use Scoreboard" for every MB
  114.         shl     (2)     CMD_BUFFER_W(%1,2)<1>   CMD_BUFFER_W(%1,14)<0;1,0>      MB_SHIFT_MASK_B<2;2,1>:b        // Set HW SB masks
  115.         mov (2) CMD_BUFFER_B(%1,4)<2>   CMD_BUFFER_B(%1,20)<2;2,1>                              // Set scoreboard (X,Y) for intra MB
  116.         (-f0.1) mov (2) CMD_BUFFER_W(%1,2)<1>   CMD_BUFFER_B(%1,20)<2;2,1>              // Set scoreboard (X,Y) for inter MB
  117.         (f0.1) jmpi (1) Parse_8_Loop_%1
  118.  
  119. //      Inter Macroblock
  120. //      Output MEDIA_OBJECT command in raster scan order
  121.         mul (16) acc0<1>:uw     CMD_BUFFER_B(%1,21)<0;1,0>      PicWidthMB<0;1,0>:uw    // MB offset = Y*W
  122.         add (16) acc0<1>:uw     acc0<8;8,1>:uw  CMD_BUFFER_B(%1,20)<0;1,0>                      // MB offset = Y*W+X
  123.         shl (1) MRF_INTER_WRITE_HEADER.2<1>:ud  acc0.2<0;1,0>:uw        6:uw            // Byte-aligned MB offset
  124.         mov (16)        MRF_INTER_WRITE_DATA0<1>:ud     CMD_BUFFER_D(%1)<8;8,1> {Compr} // Copy entire command to inter buffer
  125.         mov     (16)    CMD_BUFFER_D(%1)<1>             0:ud    {Compr}                                         // Clear original command
  126.         send (16)       NULLREGW        MRF_INTER_WRITE_HEADER  null:uw DAPWRITE        MSG_LEN(2)+OWBWMSGDSC+OWORD_4+BI_CMD_BUFFER
  127.  
  128. Parse_8_Loop_%1:
  129.         }
  130.  
  131.         add.z.f0.0 (1)  TotalMB<1>:w    TotalMB<0;1,0>:w        -8:w                            // Update remaining number of 8-command blocks
  132.  
  133. //      Output modified intra commands
  134. //      Write block 0
  135.         mov (8) MRF_INTRA_WRITE_HEADER.0<1>:ud  MRF_READ_HEADER_SRC.0<8;8,1>:ud
  136.    $for(0; <4; 2) {
  137.         mov (16)        MRF_CMD_BUF_D(%1)<1>    CMD_BUFFER_D(%1)<8;8,1> {Compr}
  138.         }
  139.         send (16)       NULLREGW        MRF_INTRA_WRITE_HEADER  null:uw DAPWRITE        MSG_LEN(4)+OWBWMSGDSC+OWORD_8+BI_CMD_BUFFER
  140.  
  141. //      Write block 1
  142.         mov (8) m1.0<1>:ud      MRF_READ_HEADER_SRC.0<8;8,1>:ud
  143.         add     (1)     m1.2<1>:ud      MRF_READ_HEADER_SRC.2<0;1,0>:ud         128:ud          // Point to next 2-command block
  144.         mov (16)        m2<1>:ud        CMD_BUFFER_D(4)<8;8,1>  {Compr}
  145.         mov (16)        m4<1>:ud        CMD_BUFFER_D(6)<8;8,1>  {Compr}
  146.         send (16)       NULLREGW        m1      null:uw DAPWRITE        MSG_LEN(4)+OWBWMSGDSC+OWORD_8+BI_CMD_BUFFER
  147.  
  148. //      Write block 2
  149.         add     (1)     MRF_INTRA_WRITE_HEADER.2<1>:ud  MRF_READ_HEADER_SRC.2<0;1,0>:ud         256:ud          // Point to next 2-command block
  150.    $for(0; <4; 2) {
  151.         mov (16)        MRF_CMD_BUF_D(%1)<1>    CMD_BUFFER_D(%1+8)<8;8,1>       {Compr}
  152.         }
  153.         send (16)       NULLREGW        MRF_INTRA_WRITE_HEADER  null:uw DAPWRITE        MSG_LEN(4)+OWBWMSGDSC+OWORD_8+BI_CMD_BUFFER
  154.  
  155. //      Write block 3
  156.         add     (1)     m1.2<1>:ud      MRF_READ_HEADER_SRC.2<0;1,0>:ud         384:ud          // Point to next 2-command block
  157.         mov (16)        m2<1>:ud        CMD_BUFFER_D(12)<8;8,1> {Compr}
  158.         mov (16)        m4<1>:ud        CMD_BUFFER_D(14)<8;8,1> {Compr}
  159.         send (16)       NULLREGW        m1      null:uw DAPWRITE        MSG_LEN(4)+OWBWMSGDSC+OWORD_8+BI_CMD_BUFFER
  160.  
  161. //      Update message header for next DAP read
  162.         add (1) MRF_READ_HEADER_SRC.2<1>:ud     MRF_READ_HEADER_SRC.2<0;1,0>:ud 512:ud  // Point to next block of 8-commands
  163.  
  164.         cmp.z.f0.1 (1)  NULLREG RemainderMB<0;1,0>:w    0:uw    // Check if remainder MB = 0
  165.         (-f0.0) jmpi (1)        SetHWScoreboard_Loop                    // Continue if more command blocks remain
  166.  
  167. SetHWScoreboard_Remainder:
  168. //      f0.1 should have been set to indicate if RemainderMB = 0
  169. //
  170.         (f0.1) jmpi (1) SetHWScoreboard_Done                            // Stop if all commands have been updated
  171.  
  172. //      Blindly load next 8 commands anyway
  173. //
  174. //      Load block 0 (Commands 0/1)
  175.         mov (8) MRF_READ_HEADER0.0<1>:ud        MRF_READ_HEADER_SRC.0<8;8,1>:ud
  176.         send (16)       CMD_BUFFER_W(0)<1>      MRF_READ_HEADER0        null:uw DAPREAD RESP_LEN(4)+OWBRMSGDSC_SC+OWORD_8+BI_CMD_BUFFER
  177.  
  178. //      Load block 1  (Commands 2/3)
  179.         mov (8) MRF_READ_HEADER1.0<1>:ud        MRF_READ_HEADER_SRC.0<8;8,1>:ud
  180.         add     (1)     MRF_READ_HEADER1.2<1>:ud        MRF_READ_HEADER_SRC.2<0;1,0>:ud         128:ud          // Point to next 2-command block
  181.         send (16)       CMD_BUFFER_W(4)<1>      MRF_READ_HEADER1        null:uw DAPREAD RESP_LEN(4)+OWBRMSGDSC_SC+OWORD_8+BI_CMD_BUFFER
  182.  
  183. //      Load block 2  (Commands 4/5)
  184.         mov (8) MRF_READ_HEADER2.0<1>:ud        MRF_READ_HEADER_SRC.0<8;8,1>:ud
  185.         add     (1)     MRF_READ_HEADER2.2<1>:ud        MRF_READ_HEADER_SRC.2<0;1,0>:ud         256:ud          // Point to next 2-command block
  186.         send (16)       CMD_BUFFER_W(8)<1>      MRF_READ_HEADER2        null:uw DAPREAD RESP_LEN(4)+OWBRMSGDSC_SC+OWORD_8+BI_CMD_BUFFER
  187.  
  188. //      Load block 3  (Commands 6/7)
  189.         mov (8) MRF_READ_HEADER3.0<1>:ud        MRF_READ_HEADER_SRC.0<8;8,1>:ud
  190.         add     (1)     MRF_READ_HEADER3.2<1>:ud        MRF_READ_HEADER_SRC.2<0;1,0>:ud         384:ud          // Point to next 2-command block
  191.         send (16)       CMD_BUFFER_W(12)<1>     MRF_READ_HEADER3        null:uw DAPREAD RESP_LEN(4)+OWBRMSGDSC_SC+OWORD_8+BI_CMD_BUFFER
  192.  
  193. //      Initialize necessary pointers
  194.         mov (1) a0.1<1>:ud      ((CMD_BUFFER_REG_OFF+1)*0x10000+CMD_BUFFER_REG_OFF)*32  // a0.2:w points to command buffer (first half)
  195.                                                                                                                                                         // a0.3:w points to command buffer (second half)
  196. //      Initialize Inter DAP write header
  197.         mov (8) MRF_INTER_WRITE_HEADER<1>:ud    r0.0<8;8,1>:ud
  198.  
  199. SetHWScoreboard_Remainder_Loop:
  200.         and.nz.f0.1 (8) NULLREG r[a0.2,4*4]<0;1,0>:ud   IS_INTRA_MB:ud          // Is it an "Intra" MB?
  201.         add.z.f0.0 (1)  RemainderMB<1>:w        RemainderMB<0;1,0>:w    -1:w    // Decrement MB #
  202.         or (1)  r[a0.2,2*4]<1>:ud       r[a0.2,2*4]<0;1,0>:ud   BIT21:ud                // Set "Use Scoreboard" for every MB
  203.         shl     (2)     r[a0.2,2*2]<1>:uw       r[a0.2,14*2]<0;1,0>:uw  MB_SHIFT_MASK_B<2;2,1>:b        // Set HW SB masks
  204.         mov (2) r[a0.2,4*1]<2>:ub       r[a0.2,5*4]<2;2,1>:ub                                   // Set scoreboard (X,Y) for intra MB
  205.  
  206.         (-f0.1) mov (2) r[a0.2,4*1]<1>:uw       r[a0.2,5*4]<2;2,1>:ub                   // Set scoreboard (X,Y) for inter MB
  207.         (f0.1) jmpi (1) Output_Remainder_Intra
  208.  
  209. //      Inter Macroblock
  210. //      Output MEDIA_OBJECT command in raster scan order
  211.         mul (16) acc0<1>:uw     r[a0.2,21]<0;1,0>:ub    PicWidthMB<0;1,0>:uw    // MB offset = Y*W
  212.         add (16) acc0<1>:uw     acc0<8;8,1>:uw  r[a0.2,20]<0;1,0>:ub                    // MB offset = Y*W+X
  213.         shl (1) MRF_INTER_WRITE_HEADER.2<1>:ud  acc0.2<0;1,0>:uw        6:uw    // Byte-aligned MB offset
  214.         mov (16)        MRF_INTER_WRITE_DATA0<1>:ud     r[a0.2]<8;8,1>:ud       {Compr} // Copy entire command to inter buffer
  215.         mov     (16)    r[a0.2]<1>:ud           0:ud    {Compr}                                         // Clear original command
  216.         send (16)       NULLREGW        MRF_INTER_WRITE_HEADER  null:uw DAPWRITE        MSG_LEN(2)+OWBWMSGDSC+OWORD_4+BI_CMD_BUFFER
  217.  
  218. Output_Remainder_Intra:
  219. //      Intra MB command always output
  220.         mov (8) MRF_INTRA_WRITE_HEADER.0<1>:ud  MRF_READ_HEADER_SRC.0<8;8,1>:ud
  221.         mov (16)        MRF_CMD_BUF_D(0)<1>             r[a0.2]<8;8,1>:ud       {Compr}         // Copy entire command to intra buffer
  222.         send (16)       NULLREGW        MRF_INTRA_WRITE_HEADER  null:uw DAPWRITE        MSG_LEN(2)+OWBWMSGDSC+OWORD_4+BI_CMD_BUFFER
  223.  
  224.         add     (1)     MRF_READ_HEADER_SRC.2<1>:ud             MRF_READ_HEADER_SRC.2<0;1,0>:ud         64:ud   // Point to next command
  225.         add (1) a0.1<1>:ud      a0.1<0;1,0>:ud  0x00400040:ud                                   // Update pointers
  226.         (-f0.0) jmpi (1)        SetHWScoreboard_Remainder_Loop
  227.  
  228. // All MBs have been decoded. Terminate the thread now
  229. //
  230. SetHWScoreboard_Done:
  231.    END_THREAD
  232.  
  233. #if !defined(COMBINED_KERNEL)           // For standalone kernel only
  234. .end_code
  235.  
  236. .end_kernel
  237. #endif
  238.  
  239. // End of SetHWScoreboard
  240.