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 // WORD32 log_WD, 93 // WORD32 wt, 94 // WORD32 ofst, 95 // WORD32 ht, 96 // WORD32 wd) 97 // 98 //**************Variables Vs Registers***************************************** 99 // x0 => puc_src 100 // x1 => puc_dst 101 // w2 => src_strd 102 // w3 => dst_strd 103 // w4 => log_WD 104 // w5 => wt 105 // w6 => ofst 106 // w7 => ht 107 // [sp] => wd (w8) 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 sxtw x2, w2 122 sxtw x3, w3 123 stp x19, x20, [sp, #-16]! 124 ldr w8, [sp, #80] //Load wd 125 sxtw x8, w8 126 127 dup v2.4h, w5 //D2 = wt (16-bit) 128 neg w9, w4 //w9 = -log_WD 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 137 loop_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.h[0] //weight mult. for rows 1,2 148 mul v6.8h, v6.8h , v2.h[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 169 loop_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.h[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.h[0] //weight mult. for row 2 182 mul v8.8h, v8.8h , v2.h[0] //weight mult. for row 3 183 mul v10.8h, v10.8h , v2.h[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 209 loop_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.h[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.h[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.h[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.h[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.h[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.h[0] //weight mult. for row 3H 229 mul v24.8h, v24.8h , v2.h[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.h[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 263 end_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 // WORD32 log_WD, 323 // WORD32 wt, 324 // WORD32 ofst, 325 // WORD32 ht, 326 // WORD32 wd) 327 // 328 //**************Variables Vs Registers***************************************** 329 // x0 => puc_src 330 // x1 => puc_dst 331 // w2 => src_strd 332 // w3 => dst_strd 333 // w4 => log_WD 334 // w5 => wt 335 // w6 => ofst 336 // w7 => ht 337 // [sp] => wd (w8) 338 // 339 340 341 342 343 .global ih264_weighted_pred_chroma_av8 344 345 ih264_weighted_pred_chroma_av8: 346 347 // STMFD sp!, {x4-x9,x14} //stack stores the values of the arguments 348 push_v_regs 349 sxtw x2, w2 350 sxtw x3, w3 351 stp x19, x20, [sp, #-16]! 352 353 ldr w8, [sp, #80] //Load wd 354 sxtw x8, w8 355 356 neg w9, w4 //w9 = -log_WD 357 dup v2.4s, w5 //Q1 = {wt_u (16-bit), wt_v (16-bit)} 358 359 360 dup v4.4h, w6 //D4 = {ofst_u (8-bit), ofst_v (8-bit)} 361 cmp w8, #8 //check if wd is 8 362 dup v0.8h, w9 //Q0 = -log_WD (16-bit) 363 beq loop_8_uv //branch if wd is 8 364 365 cmp w8, #4 //check if ws is 4 366 beq loop_4_uv //branch if wd is 4 367 368 loop_2_uv: //each iteration processes two rows 369 370 ld1 {v6.s}[0], [x0], x2 //load row 1 in source 371 ld1 {v6.s}[1], [x0], x2 //load row 2 in source 372 uxtl v6.8h, v6.8b //converting rows 1,2 to 16-bit 373 mul v6.8h, v6.8h , v2.8h //weight mult. for rows 1,2 374 srshl v6.8h, v6.8h , v0.8h //rounds off the weighted samples from rows 1,2 375 saddw v6.8h, v6.8h , v4.8b //adding offset for rows 1,2 376 sqxtun v6.8b, v6.8h //saturating rows 1,2 to unsigned 8-bit 377 subs w7, w7, #2 //decrement ht by 2 378 st1 {v6.s}[0], [x1], x3 //store row 1 in destination 379 st1 {v6.s}[1], [x1], x3 //store row 2 in destination 380 bgt loop_2_uv //if greater than 0 repeat the loop again 381 b end_loops_uv 382 383 loop_4_uv: //each iteration processes two rows 384 385 ld1 {v6.8b}, [x0], x2 //load row 1 in source 386 ld1 {v8.8b}, [x0], x2 //load row 2 in source 387 uxtl v6.8h, v6.8b //converting row 1 to 16-bit 388 uxtl v8.8h, v8.8b //converting row 2 to 16-bit 389 mul v6.8h, v6.8h , v2.8h //weight mult. for row 1 390 mul v8.8h, v8.8h , v2.8h //weight mult. for row 2 391 subs w7, w7, #2 //decrement ht by 2 392 srshl v6.8h, v6.8h , v0.8h //rounds off the weighted samples from row 1 393 srshl v8.8h, v8.8h , v0.8h //rounds off the weighted samples from row 2 394 saddw v6.8h, v6.8h , v4.8b //adding offset for row 1 395 saddw v8.8h, v8.8h , v4.8b //adding offset for row 2 396 sqxtun v6.8b, v6.8h //saturating row 1 to unsigned 8-bit 397 sqxtun v8.8b, v8.8h //saturating row 2 to unsigned 8-bit 398 st1 {v6.8b}, [x1], x3 //store row 1 in destination 399 st1 {v8.8b}, [x1], x3 //store row 2 in destination 400 401 bgt loop_4_uv //if greater than 0 repeat the loop again 402 403 b end_loops_uv 404 405 loop_8_uv: //each iteration processes two rows 406 407 ld1 {v6.8b, v7.8b}, [x0], x2 //load row 1 in source 408 ld1 {v8.8b, v9.8b}, [x0], x2 //load row 2 in source 409 uxtl v14.8h, v6.8b //converting row 1L to 16-bit 410 ld1 {v10.8b, v11.8b}, [x0], x2 //load row 3 in source 411 uxtl v16.8h, v7.8b //converting row 1H to 16-bit 412 ld1 {v12.8b, v13.8b}, [x0], x2 //load row 4 in source 413 414 mul v14.8h, v14.8h , v2.8h //weight mult. for row 1L 415 uxtl v18.8h, v8.8b //converting row 2L to 16-bit 416 mul v16.8h, v16.8h , v2.8h //weight mult. for row 1H 417 uxtl v20.8h, v9.8b //converting row 2H to 16-bit 418 mul v18.8h, v18.8h , v2.8h //weight mult. for row 2L 419 uxtl v22.8h, v10.8b //converting row 3L to 16-bit 420 mul v20.8h, v20.8h , v2.8h //weight mult. for row 2H 421 uxtl v24.8h, v11.8b //converting row 3H to 16-bit 422 mul v22.8h, v22.8h , v2.8h //weight mult. for row 3L 423 uxtl v26.8h, v12.8b //converting row 4L to 16-bit 424 mul v24.8h, v24.8h , v2.8h //weight mult. for row 3H 425 uxtl v28.8h, v13.8b //converting row 4H to 16-bit 426 427 mul v26.8h, v26.8h , v2.8h //weight mult. for row 4L 428 srshl v14.8h, v14.8h , v0.8h //rounds off the weighted samples from row 1L 429 mul v28.8h, v28.8h , v2.8h //weight mult. for row 4H 430 431 srshl v16.8h, v16.8h , v0.8h //rounds off the weighted samples from row 1H 432 srshl v18.8h, v18.8h , v0.8h //rounds off the weighted samples from row 2L 433 saddw v14.8h, v14.8h , v4.8b //adding offset for row 1L 434 srshl v20.8h, v20.8h , v0.8h //rounds off the weighted samples from row 2H 435 saddw v16.8h, v16.8h , v4.8b //adding offset for row 1H 436 sqxtun v6.8b, v14.8h //saturating row 1L to unsigned 8-bit 437 srshl v22.8h, v22.8h , v0.8h //rounds off the weighted samples from row 3L 438 saddw v18.8h, v18.8h , v4.8b //adding offset for row 2L 439 sqxtun v7.8b, v16.8h //saturating row 1H to unsigned 8-bit 440 srshl v24.8h, v24.8h , v0.8h //rounds off the weighted samples from row 3H 441 saddw v20.8h, v20.8h , v4.8b //adding offset for row 2H 442 sqxtun v8.8b, v18.8h //saturating row 2L to unsigned 8-bit 443 srshl v26.8h, v26.8h , v0.8h //rounds off the weighted samples from row 4L 444 saddw v22.8h, v22.8h , v4.8b //adding offset for row 3L 445 sqxtun v9.8b, v20.8h //saturating row 2H to unsigned 8-bit 446 srshl v28.8h, v28.8h , v0.8h //rounds off the weighted samples from row 4H 447 saddw v24.8h, v24.8h , v4.8b //adding offset for row 3H 448 449 sqxtun v10.8b, v22.8h //saturating row 3L to unsigned 8-bit 450 saddw v26.8h, v26.8h , v4.8b //adding offset for row 4L 451 sqxtun v11.8b, v24.8h //saturating row 3H to unsigned 8-bit 452 saddw v28.8h, v28.8h , v4.8b //adding offset for row 4H 453 454 sqxtun v12.8b, v26.8h //saturating row 4L to unsigned 8-bit 455 st1 {v6.8b, v7.8b}, [x1], x3 //store row 1 in destination 456 sqxtun v13.8b, v28.8h //saturating row 4H to unsigned 8-bit 457 st1 {v8.8b, v9.8b}, [x1], x3 //store row 2 in destination 458 subs w7, w7, #4 //decrement ht by 4 459 st1 {v10.8b, v11.8b}, [x1], x3 //store row 3 in destination 460 st1 {v12.8b, v13.8b}, [x1], x3 //store row 4 in destination 461 462 bgt loop_8_uv //if greater than 0 repeat the loop again 463 464 end_loops_uv: 465 466 // LDMFD sp!,{x4-x9,x15} //Reload the registers from sp 467 ldp x19, x20, [sp], #16 468 pop_v_regs 469 ret 470 471 472 473