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