ih264_weighted_pred_av8.s revision a2b49e5f0574dee76f81507f288143d83a4b7c1a
1//****************************************************************************** 2//* 3//* Copyright (C) 2015 The Android Open Source Project 4//* 5//* Licensed under the Apache License, Version 2.0 (the "License"); 6//* you may not use this file except in compliance with the License. 7//* You may obtain a copy of the License at: 8//* 9//* http://www.apache.org/licenses/LICENSE-2.0 10//* 11//* Unless required by applicable law or agreed to in writing, software 12//* distributed under the License is distributed on an "AS IS" BASIS, 13//* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14//* See the License for the specific language governing permissions and 15//* limitations under the License. 16//* 17//***************************************************************************** 18//* Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore 19//*/ 20///** 21//****************************************************************************** 22//* @file 23//* ih264_weighted_pred_av8.s 24//* 25//* @brief 26//* Contains function definitions for weighted prediction. 27//* Functions are coded using NEON intrinsics and can be compiled using ARM RVCT 28//* 29//* @author 30//* Kaushik Senthoor R 31//* 32//* @par List of Functions: 33//* 34//* - ih264_weighted_pred_luma_av8() 35//* - ih264_weighted_pred_chroma_av8() 36//* 37//* @remarks 38//* None 39//* 40//******************************************************************************* 41//*/ 42//******************************************************************************* 43//* @function 44//* ih264_weighted_pred_luma_av8() 45//* 46//* @brief 47//* This routine performs the default weighted prediction as described in sec 48//* 8.4.2.3.2 titled "Weighted sample prediction process" for luma. 49//* 50//* @par Description: 51//* This function gets a ht x wd block, calculates the weighted sample, rounds 52//* off, adds offset and stores it in the destination block. 53//* 54//* @param[in] puc_src: 55//* UWORD8 Pointer to the buffer containing the input block. 56//* 57//* @param[out] puc_dst 58//* UWORD8 pointer to the destination where the output block is stored. 59//* 60//* @param[in] src_strd 61//* Stride of the input buffer 62//* 63//* @param[in] dst_strd 64//* Stride of the destination buffer 65//* 66//* @param[in] log_WD 67//* number of bits to be rounded off 68//* 69//* @param[in] wt 70//* weight for the weighted prediction 71//* 72//* @param[in] ofst 73//* offset used after rounding off 74//* 75//* @param[in] ht 76//* integer height of the array 77//* 78//* @param[in] wd 79//* integer width of the array 80//* 81//* @returns 82//* None 83//* 84//* @remarks 85//* (ht,wd) can be (4,4), (4,8), (8,4), (8,8), (8,16), (16,8) or (16,16). 86//* 87//******************************************************************************* 88//*/ 89//void ih264_weighted_pred_luma_av8(UWORD8 *puc_src, 90// UWORD8 *puc_dst, 91// WORD32 src_strd, 92// WORD32 dst_strd, 93// UWORD8 log_WD, 94// UWORD32 wt, 95// UWORD16 ofst, 96// UWORD8 ht, 97// UWORD8 wd) 98// 99//**************Variables Vs Registers***************************************** 100// x0 => puc_src 101// x1 => puc_dst 102// x2 => src_strd 103// x3 => dst_strd 104// [sp] => log_WD (x4) 105// [sp+4] => wt (x5) 106// [sp+8] => ofst (x6) 107// [sp+12] => ht (x7) 108// [sp+16] => wd (x8) 109// 110.text 111.p2align 2 112.include "ih264_neon_macros.s" 113 114 115 116 .global ih264_weighted_pred_luma_av8 117 118ih264_weighted_pred_luma_av8: 119 120 // STMFD sp!, {x4-x9,x14} //stack stores the values of the arguments 121 push_v_regs 122 stp x19, x20, [sp, #-16]! 123 ldr w8, [sp, #80] //Load wd 124 sxtw x8, w8 125 126 dup v2.4h, w5 //D2 = wt (16-bit) 127 sub x20, x4, #0 //x9 = -log_WD 128 neg x9, x20 129 dup v3.8b, w6 //D3 = ofst (8-bit) 130 cmp w8, #16 //check if wd is 16 131 dup v0.8h, w9 //Q0 = -log_WD (16-bit) 132 beq loop_16 //branch if wd is 16 133 134 cmp w8, #8 //check if wd is 8 135 beq loop_8 //branch if wd is 8 136 137loop_4: //each iteration processes four rows 138 139 ld1 {v4.s}[0], [x0], x2 //load row 1 in source 140 ld1 {v4.s}[1], [x0], x2 //load row 2 in source 141 ld1 {v6.s}[0], [x0], x2 //load row 3 in source 142 ld1 {v6.s}[1], [x0], x2 //load row 4 in source 143 144 uxtl v4.8h, v4.8b //converting rows 1,2 to 16-bit 145 uxtl v6.8h, v6.8b //converting rows 3,4 to 16-bit 146 147 mul v4.8h, v4.8h , v2.4h[0] //weight mult. for rows 1,2 148 mul v6.8h, v6.8h , v2.4h[0] //weight mult. for rows 3,4 149 150 subs w7, w7, #4 //decrement ht by 4 151 srshl v4.8h, v4.8h , v0.8h //rounds off the weighted samples from rows 1,2 152 srshl v6.8h, v6.8h , v0.8h //rounds off the weighted samples from rows 3,4 153 154 saddw v4.8h, v4.8h , v3.8b //adding offset for rows 1,2 155 saddw v6.8h, v6.8h , v3.8b //adding offset for rows 3,4 156 157 sqxtun v4.8b, v4.8h //saturating rows 1,2 to unsigned 8-bit 158 sqxtun v6.8b, v6.8h //saturating rows 3,4 to unsigned 8-bit 159 160 st1 {v4.s}[0], [x1], x3 //store row 1 in destination 161 st1 {v4.s}[1], [x1], x3 //store row 2 in destination 162 st1 {v6.s}[0], [x1], x3 //store row 3 in destination 163 st1 {v6.s}[1], [x1], x3 //store row 4 in destination 164 165 bgt loop_4 //if greater than 0 repeat the loop again 166 167 b end_loops 168 169loop_8: //each iteration processes four rows 170 171 ld1 {v4.8b}, [x0], x2 //load row 1 in source 172 ld1 {v6.8b}, [x0], x2 //load row 2 in source 173 ld1 {v8.8b}, [x0], x2 //load row 3 in source 174 uxtl v4.8h, v4.8b //converting row 1 to 16-bit 175 ld1 {v10.8b}, [x0], x2 //load row 4 in source 176 uxtl v6.8h, v6.8b //converting row 2 to 16-bit 177 178 uxtl v8.8h, v8.8b //converting row 3 to 16-bit 179 mul v4.8h, v4.8h , v2.4h[0] //weight mult. for row 1 180 uxtl v10.8h, v10.8b //converting row 4 to 16-bit 181 mul v6.8h, v6.8h , v2.4h[0] //weight mult. for row 2 182 mul v8.8h, v8.8h , v2.4h[0] //weight mult. for row 3 183 mul v10.8h, v10.8h , v2.4h[0] //weight mult. for row 4 184 185 srshl v4.8h, v4.8h , v0.8h //rounds off the weighted samples from row 1 186 srshl v6.8h, v6.8h , v0.8h //rounds off the weighted samples from row 2 187 srshl v8.8h, v8.8h , v0.8h //rounds off the weighted samples from row 3 188 saddw v4.8h, v4.8h , v3.8b //adding offset for row 1 189 srshl v10.8h, v10.8h , v0.8h //rounds off the weighted samples from row 4 190 saddw v6.8h, v6.8h , v3.8b //adding offset for row 2 191 192 saddw v8.8h, v8.8h , v3.8b //adding offset for row 3 193 sqxtun v4.8b, v4.8h //saturating row 1 to unsigned 8-bit 194 saddw v10.8h, v10.8h , v3.8b //adding offset for row 4 195 sqxtun v6.8b, v6.8h //saturating row 2 to unsigned 8-bit 196 sqxtun v8.8b, v8.8h //saturating row 3 to unsigned 8-bit 197 sqxtun v10.8b, v10.8h //saturating row 4 to unsigned 8-bit 198 199 st1 {v4.8b}, [x1], x3 //store row 1 in destination 200 st1 {v6.8b}, [x1], x3 //store row 2 in destination 201 subs w7, w7, #4 //decrement ht by 4 202 st1 {v8.8b}, [x1], x3 //store row 3 in destination 203 st1 {v10.8b}, [x1], x3 //store row 4 in destination 204 205 bgt loop_8 //if greater than 0 repeat the loop again 206 207 b end_loops 208 209loop_16: //each iteration processes two rows 210 211 ld1 {v4.8b, v5.8b}, [x0], x2 //load row 1 in source 212 ld1 {v6.8b, v7.8b}, [x0], x2 //load row 2 in source 213 uxtl v12.8h, v4.8b //converting row 1L to 16-bit 214 ld1 {v8.8b, v9.8b}, [x0], x2 //load row 3 in source 215 uxtl v14.8h, v5.8b //converting row 1H to 16-bit 216 ld1 {v10.8b, v11.8b}, [x0], x2 //load row 4 in source 217 uxtl v16.8h, v6.8b //converting row 2L to 16-bit 218 mul v12.8h, v12.8h , v2.4h[0] //weight mult. for row 1L 219 uxtl v18.8h, v7.8b //converting row 2H to 16-bit 220 mul v14.8h, v14.8h , v2.4h[0] //weight mult. for row 1H 221 uxtl v20.8h, v8.8b //converting row 3L to 16-bit 222 mul v16.8h, v16.8h , v2.4h[0] //weight mult. for row 2L 223 uxtl v22.8h, v9.8b //converting row 3H to 16-bit 224 mul v18.8h, v18.8h , v2.4h[0] //weight mult. for row 2H 225 uxtl v24.8h, v10.8b //converting row 4L to 16-bit 226 mul v20.8h, v20.8h , v2.4h[0] //weight mult. for row 3L 227 uxtl v26.8h, v11.8b //converting row 4H to 16-bit 228 mul v22.8h, v22.8h , v2.4h[0] //weight mult. for row 3H 229 mul v24.8h, v24.8h , v2.4h[0] //weight mult. for row 4L 230 srshl v12.8h, v12.8h , v0.8h //rounds off the weighted samples from row 1L 231 mul v26.8h, v26.8h , v2.4h[0] //weight mult. for row 4H 232 srshl v14.8h, v14.8h , v0.8h //rounds off the weighted samples from row 1H 233 srshl v16.8h, v16.8h , v0.8h //rounds off the weighted samples from row 2L 234 saddw v12.8h, v12.8h , v3.8b //adding offset for row 1L 235 srshl v18.8h, v18.8h , v0.8h //rounds off the weighted samples from row 2H 236 saddw v14.8h, v14.8h , v3.8b //adding offset for row 1H 237 sqxtun v4.8b, v12.8h //saturating row 1L to unsigned 8-bit 238 srshl v20.8h, v20.8h , v0.8h //rounds off the weighted samples from row 3L 239 saddw v16.8h, v16.8h , v3.8b //adding offset for row 2L 240 sqxtun v5.8b, v14.8h //saturating row 1H to unsigned 8-bit 241 srshl v22.8h, v22.8h , v0.8h //rounds off the weighted samples from row 3H 242 saddw v18.8h, v18.8h , v3.8b //adding offset for row 2H 243 sqxtun v6.8b, v16.8h //saturating row 2L to unsigned 8-bit 244 srshl v24.8h, v24.8h , v0.8h //rounds off the weighted samples from row 4L 245 saddw v20.8h, v20.8h , v3.8b //adding offset for row 3L 246 sqxtun v7.8b, v18.8h //saturating row 2H to unsigned 8-bit 247 srshl v26.8h, v26.8h , v0.8h //rounds off the weighted samples from row 4H 248 saddw v22.8h, v22.8h , v3.8b //adding offset for row 3H 249 sqxtun v8.8b, v20.8h //saturating row 3L to unsigned 8-bit 250 saddw v24.8h, v24.8h , v3.8b //adding offset for row 4L 251 sqxtun v9.8b, v22.8h //saturating row 3H to unsigned 8-bit 252 saddw v26.8h, v26.8h , v3.8b //adding offset for row 4H 253 sqxtun v10.8b, v24.8h //saturating row 4L to unsigned 8-bit 254 st1 {v4.8b, v5.8b}, [x1], x3 //store row 1 in destination 255 sqxtun v11.8b, v26.8h //saturating row 4H to unsigned 8-bit 256 st1 {v6.8b, v7.8b}, [x1], x3 //store row 2 in destination 257 subs w7, w7, #4 //decrement ht by 4 258 st1 {v8.8b, v9.8b}, [x1], x3 //store row 3 in destination 259 st1 {v10.8b, v11.8b}, [x1], x3 //store row 4 in destination 260 261 bgt loop_16 //if greater than 0 repeat the loop again 262 263end_loops: 264 265 // LDMFD sp!,{x4-x9,x15} //Reload the registers from sp 266 ldp x19, x20, [sp], #16 267 pop_v_regs 268 ret 269 270 271//******************************************************************************* 272//* @function 273//* ih264_weighted_pred_chroma_av8() 274//* 275//* @brief 276//* This routine performs the default weighted prediction as described in sec 277//* 8.4.2.3.2 titled "Weighted sample prediction process" for chroma. 278//* 279//* @par Description: 280//* This function gets a ht x wd block, calculates the weighted sample, rounds 281//* off, adds offset and stores it in the destination block for U and V. 282//* 283//* @param[in] puc_src: 284//* UWORD8 Pointer to the buffer containing the input block. 285//* 286//* @param[out] puc_dst 287//* UWORD8 pointer to the destination where the output block is stored. 288//* 289//* @param[in] src_strd 290//* Stride of the input buffer 291//* 292//* @param[in] dst_strd 293//* Stride of the destination buffer 294//* 295//* @param[in] log_WD 296//* number of bits to be rounded off 297//* 298//* @param[in] wt 299//* weights for the weighted prediction for U and V 300//* 301//* @param[in] ofst 302//* offsets used after rounding off for U and V 303//* 304//* @param[in] ht 305//* integer height of the array 306//* 307//* @param[in] wd 308//* integer width of the array 309//* 310//* @returns 311//* None 312//* 313//* @remarks 314//* (ht,wd) can be (2,2), (2,4), (4,2), (4,4), (4,8), (8,4) or (8,8). 315//* 316//******************************************************************************* 317//*/ 318//void ih264_weighted_pred_chroma_av8(UWORD8 *puc_src, 319// UWORD8 *puc_dst, 320// WORD32 src_strd, 321// WORD32 dst_strd, 322// UWORD8 log_WD, 323// UWORD32 wt, 324// UWORD16 ofst, 325// UWORD8 ht, 326// UWORD8 wd) 327// 328//**************Variables Vs Registers***************************************** 329// x0 => puc_src 330// x1 => puc_dst 331// x2 => src_strd 332// x3 => dst_strd 333// [sp] => log_WD (x4) 334// [sp+4] => wt (x5) 335// [sp+8] => ofst (x6) 336// [sp+12] => ht (x7) 337// [sp+16] => wd (x8) 338// 339 340 341 342 343 .global ih264_weighted_pred_chroma_av8 344 345ih264_weighted_pred_chroma_av8: 346 347 // STMFD sp!, {x4-x9,x14} //stack stores the values of the arguments 348 push_v_regs 349 stp x19, x20, [sp, #-16]! 350 351 ldr w8, [sp, #80] //Load wd 352 sxtw x8, w8 353 354 sub x20, x4, #0 //x9 = -log_WD 355 neg x9, x20 356 dup v2.4s, w5 //Q1 = {wt_u (16-bit), wt_v (16-bit)} 357 358 359 dup v4.4h, w6 //D4 = {ofst_u (8-bit), ofst_v (8-bit)} 360 cmp w8, #8 //check if wd is 8 361 dup v0.8h, w9 //Q0 = -log_WD (16-bit) 362 beq loop_8_uv //branch if wd is 8 363 364 cmp w8, #4 //check if ws is 4 365 beq loop_4_uv //branch if wd is 4 366 367loop_2_uv: //each iteration processes two rows 368 369 ld1 {v6.s}[0], [x0], x2 //load row 1 in source 370 ld1 {v6.s}[1], [x0], x2 //load row 2 in source 371 uxtl v6.8h, v6.8b //converting rows 1,2 to 16-bit 372 mul v6.8h, v6.8h , v2.8h //weight mult. for rows 1,2 373 srshl v6.8h, v6.8h , v0.8h //rounds off the weighted samples from rows 1,2 374 saddw v6.8h, v6.8h , v4.8b //adding offset for rows 1,2 375 sqxtun v6.8b, v6.8h //saturating rows 1,2 to unsigned 8-bit 376 subs w7, w7, #2 //decrement ht by 2 377 st1 {v6.s}[0], [x1], x3 //store row 1 in destination 378 st1 {v6.s}[1], [x1], x3 //store row 2 in destination 379 bgt loop_2_uv //if greater than 0 repeat the loop again 380 b end_loops_uv 381 382loop_4_uv: //each iteration processes two rows 383 384 ld1 {v6.8b}, [x0], x2 //load row 1 in source 385 ld1 {v8.8b}, [x0], x2 //load row 2 in source 386 uxtl v6.8h, v6.8b //converting row 1 to 16-bit 387 uxtl v8.8h, v8.8b //converting row 2 to 16-bit 388 mul v6.8h, v6.8h , v2.8h //weight mult. for row 1 389 mul v8.8h, v8.8h , v2.8h //weight mult. for row 2 390 subs w7, w7, #2 //decrement ht by 2 391 srshl v6.8h, v6.8h , v0.8h //rounds off the weighted samples from row 1 392 srshl v8.8h, v8.8h , v0.8h //rounds off the weighted samples from row 2 393 saddw v6.8h, v6.8h , v4.8b //adding offset for row 1 394 saddw v8.8h, v8.8h , v4.8b //adding offset for row 2 395 sqxtun v6.8b, v6.8h //saturating row 1 to unsigned 8-bit 396 sqxtun v8.8b, v8.8h //saturating row 2 to unsigned 8-bit 397 st1 {v6.8b}, [x1], x3 //store row 1 in destination 398 st1 {v8.8b}, [x1], x3 //store row 2 in destination 399 400 bgt loop_4_uv //if greater than 0 repeat the loop again 401 402 b end_loops_uv 403 404loop_8_uv: //each iteration processes two rows 405 406 ld1 {v6.8b, v7.8b}, [x0], x2 //load row 1 in source 407 ld1 {v8.8b, v9.8b}, [x0], x2 //load row 2 in source 408 uxtl v14.8h, v6.8b //converting row 1L to 16-bit 409 ld1 {v10.8b, v11.8b}, [x0], x2 //load row 3 in source 410 uxtl v16.8h, v7.8b //converting row 1H to 16-bit 411 ld1 {v12.8b, v13.8b}, [x0], x2 //load row 4 in source 412 413 mul v14.8h, v14.8h , v2.8h //weight mult. for row 1L 414 uxtl v18.8h, v8.8b //converting row 2L to 16-bit 415 mul v16.8h, v16.8h , v2.8h //weight mult. for row 1H 416 uxtl v20.8h, v9.8b //converting row 2H to 16-bit 417 mul v18.8h, v18.8h , v2.8h //weight mult. for row 2L 418 uxtl v22.8h, v10.8b //converting row 3L to 16-bit 419 mul v20.8h, v20.8h , v2.8h //weight mult. for row 2H 420 uxtl v24.8h, v11.8b //converting row 3H to 16-bit 421 mul v22.8h, v22.8h , v2.8h //weight mult. for row 3L 422 uxtl v26.8h, v12.8b //converting row 4L to 16-bit 423 mul v24.8h, v24.8h , v2.8h //weight mult. for row 3H 424 uxtl v28.8h, v13.8b //converting row 4H to 16-bit 425 426 mul v26.8h, v26.8h , v2.8h //weight mult. for row 4L 427 srshl v14.8h, v14.8h , v0.8h //rounds off the weighted samples from row 1L 428 mul v28.8h, v28.8h , v2.8h //weight mult. for row 4H 429 430 srshl v16.8h, v16.8h , v0.8h //rounds off the weighted samples from row 1H 431 srshl v18.8h, v18.8h , v0.8h //rounds off the weighted samples from row 2L 432 saddw v14.8h, v14.8h , v4.8b //adding offset for row 1L 433 srshl v20.8h, v20.8h , v0.8h //rounds off the weighted samples from row 2H 434 saddw v16.8h, v16.8h , v4.8b //adding offset for row 1H 435 sqxtun v6.8b, v14.8h //saturating row 1L to unsigned 8-bit 436 srshl v22.8h, v22.8h , v0.8h //rounds off the weighted samples from row 3L 437 saddw v18.8h, v18.8h , v4.8b //adding offset for row 2L 438 sqxtun v7.8b, v16.8h //saturating row 1H to unsigned 8-bit 439 srshl v24.8h, v24.8h , v0.8h //rounds off the weighted samples from row 3H 440 saddw v20.8h, v20.8h , v4.8b //adding offset for row 2H 441 sqxtun v8.8b, v18.8h //saturating row 2L to unsigned 8-bit 442 srshl v26.8h, v26.8h , v0.8h //rounds off the weighted samples from row 4L 443 saddw v22.8h, v22.8h , v4.8b //adding offset for row 3L 444 sqxtun v9.8b, v20.8h //saturating row 2H to unsigned 8-bit 445 srshl v28.8h, v28.8h , v0.8h //rounds off the weighted samples from row 4H 446 saddw v24.8h, v24.8h , v4.8b //adding offset for row 3H 447 448 sqxtun v10.8b, v22.8h //saturating row 3L to unsigned 8-bit 449 saddw v26.8h, v26.8h , v4.8b //adding offset for row 4L 450 sqxtun v11.8b, v24.8h //saturating row 3H to unsigned 8-bit 451 saddw v28.8h, v28.8h , v4.8b //adding offset for row 4H 452 453 sqxtun v12.8b, v26.8h //saturating row 4L to unsigned 8-bit 454 st1 {v6.8b, v7.8b}, [x1], x3 //store row 1 in destination 455 sqxtun v13.8b, v28.8h //saturating row 4H to unsigned 8-bit 456 st1 {v8.8b, v9.8b}, [x1], x3 //store row 2 in destination 457 subs w7, w7, #4 //decrement ht by 4 458 st1 {v10.8b, v11.8b}, [x1], x3 //store row 3 in destination 459 st1 {v12.8b, v13.8b}, [x1], x3 //store row 4 in destination 460 461 bgt loop_8_uv //if greater than 0 repeat the loop again 462 463end_loops_uv: 464 465 // LDMFD sp!,{x4-x9,x15} //Reload the registers from sp 466 ldp x19, x20, [sp], #16 467 pop_v_regs 468 ret 469 470 471 472