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