dct-a.S 32.4 KB
Newer Older
1
/****************************************************************************
2
 * dct-a.S: aarch64 transform and zigzag
3
 *****************************************************************************
Henrik Gramner's avatar
Henrik Gramner committed
4
 * Copyright (C) 2009-2019 x264 project
5 6
 *
 * Authors: David Conrad <lessen42@gmail.com>
7
 *          Janne Grunau <janne-x264@jannau.net>
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
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
 *
 * This program is also available under a commercial proprietary license.
 * For more information, contact us at licensing@x264.com.
 *****************************************************************************/

#include "asm.S"

const scan4x4_frame, align=4
.byte    0,1,   8,9,   2,3,   4,5
.byte   10,11, 16,17, 24,25, 18,19
.byte   12,13,  6,7,  14,15, 20,21
.byte   26,27, 28,29, 22,23, 30,31
endconst

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
const scan4x4_field, align=4
.byte    0,1,   2,3,   8,9,   4,5
.byte    6,7,  10,11, 12,13, 14,15
endconst

const sub4x4_frame, align=4
.byte    0,  1,  4,  8
.byte    5,  2,  3,  6
.byte    9, 12, 13, 10
.byte    7, 11, 14, 15
endconst

const sub4x4_field, align=4
.byte    0,  4,  1,  8
.byte   12,  5,  9, 13
.byte    2,  6, 10, 14
.byte    3,  7, 11, 15
endconst

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
// sum = a + (b>>shift)   sub = (a>>shift) - b
.macro SUMSUB_SHR shift sum sub a b t0 t1
    sshr        \t0,  \b, #\shift
    sshr        \t1,  \a, #\shift
    add         \sum, \a, \t0
    sub         \sub, \t1, \b
.endm

// sum = (a>>shift) + b   sub = a - (b>>shift)
.macro SUMSUB_SHR2 shift sum sub a b t0 t1
    sshr        \t0,  \a, #\shift
    sshr        \t1,  \b, #\shift
    add         \sum, \t0, \b
    sub         \sub, \a, \t1
.endm

// a += 1.5*ma   b -= 1.5*mb
.macro SUMSUB_15 a b ma mb t0 t1
    sshr        \t0, \ma, #1
    sshr        \t1, \mb, #1
    add         \t0, \t0, \ma
    add         \t1, \t1, \mb
    add         \a,  \a,  \t0
    sub         \b,  \b,  \t1
.endm


82
function dct4x4dc_neon, export=1
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
    ld1        {v0.4h,v1.4h,v2.4h,v3.4h}, [x0]
    movi        v31.4h, #1
    SUMSUB_AB   v4.4h,  v5.4h,  v0.4h,  v1.4h
    SUMSUB_AB   v6.4h,  v7.4h,  v2.4h,  v3.4h
    SUMSUB_AB   v0.4h,  v2.4h,  v4.4h,  v6.4h
    SUMSUB_AB   v3.4h,  v1.4h,  v5.4h,  v7.4h
    transpose   v4.4h,  v6.4h,  v0.4h,  v2.4h
    transpose   v5.4h,  v7.4h,  v1.4h,  v3.4h
    SUMSUB_AB   v0.4h,  v2.4h,  v4.4h,  v6.4h
    SUMSUB_AB   v1.4h,  v3.4h,  v5.4h,  v7.4h
    transpose   v4.2s,  v5.2s,  v0.2s,  v1.2s
    transpose   v6.2s,  v7.2s,  v2.2s,  v3.2s
    add         v16.4h, v4.4h,  v31.4h
    add         v17.4h, v6.4h,  v31.4h
    srhadd      v0.4h,  v4.4h,  v5.4h
    shsub       v1.4h,  v16.4h, v5.4h
    shsub       v2.4h,  v17.4h, v7.4h
    srhadd      v3.4h,  v6.4h,  v7.4h
    st1        {v0.4h,v1.4h,v2.4h,v3.4h}, [x0]
    ret
endfunc

105
function idct4x4dc_neon, export=1
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
    ld1        {v0.4h,v1.4h,v2.4h,v3.4h}, [x0]
    SUMSUB_AB   v4.4h,  v5.4h,  v0.4h,  v1.4h
    SUMSUB_AB   v6.4h,  v7.4h,  v2.4h,  v3.4h
    SUMSUB_AB   v0.4h,  v2.4h,  v4.4h,  v6.4h
    SUMSUB_AB   v3.4h,  v1.4h,  v5.4h,  v7.4h
    transpose   v4.4h,  v6.4h,  v0.4h,  v2.4h
    transpose   v5.4h,  v7.4h,  v1.4h,  v3.4h
    SUMSUB_AB   v0.4h,  v2.4h,  v4.4h,  v6.4h
    SUMSUB_AB   v1.4h,  v3.4h,  v5.4h,  v7.4h
    transpose   v4.2s,  v5.2s,  v0.2s,  v1.2s
    transpose   v6.2s,  v7.2s,  v2.2s,  v3.2s
    SUMSUB_AB   v0.4h,  v1.4h,  v4.4h,  v5.4h
    SUMSUB_AB   v3.4h,  v2.4h,  v6.4h,  v7.4h
    st1        {v0.4h,v1.4h,v2.4h,v3.4h}, [x0]
    ret
endfunc

.macro DCT_1D v0 v1 v2 v3 v4 v5 v6 v7
    SUMSUB_AB   \v1, \v6, \v5, \v6
    SUMSUB_AB   \v3, \v7, \v4, \v7
    add         \v0, \v3, \v1
    add         \v4, \v7, \v7
    add         \v5, \v6, \v6
    sub         \v2, \v3, \v1
    add         \v1, \v4, \v6
    sub         \v3, \v7, \v5
.endm

134
function sub4x4_dct_neon, export=1
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
    mov         x3, #FENC_STRIDE
    mov         x4, #FDEC_STRIDE
    ld1        {v0.s}[0], [x1], x3
    ld1        {v1.s}[0], [x2], x4
    ld1        {v2.s}[0], [x1], x3
    usubl       v16.8h, v0.8b,  v1.8b
    ld1        {v3.s}[0], [x2], x4
    ld1        {v4.s}[0], [x1], x3
    usubl       v17.8h, v2.8b,  v3.8b
    ld1        {v5.s}[0], [x2], x4
    ld1        {v6.s}[0], [x1], x3
    usubl       v18.8h, v4.8b,  v5.8b
    ld1        {v7.s}[0], [x2], x4
    usubl       v19.8h, v6.8b,  v7.8b

    DCT_1D      v0.4h, v1.4h, v2.4h, v3.4h, v16.4h, v17.4h, v18.4h, v19.4h
    transpose4x4.h v0, v1, v2, v3, v4, v5, v6, v7
    DCT_1D      v4.4h, v5.4h, v6.4h, v7.4h, v0.4h, v1.4h, v2.4h, v3.4h
    st1        {v4.4h,v5.4h,v6.4h,v7.4h}, [x0]
    ret
endfunc

157
function sub8x4_dct_neon
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
    ld1        {v0.8b}, [x1], x3
    ld1        {v1.8b}, [x2], x4
    usubl       v16.8h, v0.8b,  v1.8b
    ld1        {v2.8b}, [x1], x3
    ld1        {v3.8b}, [x2], x4
    usubl       v17.8h, v2.8b,  v3.8b
    ld1        {v4.8b}, [x1], x3
    ld1        {v5.8b}, [x2], x4
    usubl       v18.8h, v4.8b,  v5.8b
    ld1        {v6.8b}, [x1], x3
    ld1        {v7.8b}, [x2], x4
    usubl       v19.8h, v6.8b,  v7.8b

    DCT_1D      v0.8h, v1.8h, v2.8h, v3.8h, v16.8h, v17.8h, v18.8h, v19.8h
    transpose4x8.h  v0, v1, v2, v3, v4, v5, v6, v7

    SUMSUB_AB   v16.8h, v19.8h, v0.8h,  v3.8h
    SUMSUB_AB   v17.8h, v18.8h, v1.8h,  v2.8h
    add         v22.8h, v19.8h, v19.8h
    add         v21.8h, v18.8h, v18.8h
    add         v0.8h,  v16.8h, v17.8h
    sub         v1.8h,  v16.8h, v17.8h

    add         v2.8h,  v22.8h, v18.8h
    sub         v3.8h,  v19.8h, v21.8h

    zip1        v4.2d,  v0.2d,  v2.2d
    zip2        v6.2d,  v0.2d,  v2.2d
    zip1        v5.2d,  v1.2d,  v3.2d
    zip2        v7.2d,  v1.2d,  v3.2d

    st1        {v4.8h}, [x0], #16
    st1        {v5.8h}, [x0], #16
    st1        {v6.8h}, [x0], #16
    st1        {v7.8h}, [x0], #16
    ret
endfunc

196
function sub8x8_dct_neon, export=1
197 198 199
    mov         x5,  x30
    mov         x3, #FENC_STRIDE
    mov         x4, #FDEC_STRIDE
200
    bl          sub8x4_dct_neon
201
    mov         x30, x5
202
    b           sub8x4_dct_neon
203 204
endfunc

205
function sub16x16_dct_neon, export=1
206 207 208
    mov         x5,  x30
    mov         x3, #FENC_STRIDE
    mov         x4, #FDEC_STRIDE
209 210
    bl          sub8x4_dct_neon
    bl          sub8x4_dct_neon
211 212
    sub         x1, x1, #8*FENC_STRIDE-8
    sub         x2, x2, #8*FDEC_STRIDE-8
213 214
    bl          sub8x4_dct_neon
    bl          sub8x4_dct_neon
215 216
    sub         x1, x1, #8
    sub         x2, x2, #8
217 218
    bl          sub8x4_dct_neon
    bl          sub8x4_dct_neon
219 220
    sub         x1, x1, #8*FENC_STRIDE-8
    sub         x2, x2, #8*FDEC_STRIDE-8
221
    bl          sub8x4_dct_neon
222
    mov         x30, x5
223
    b           sub8x4_dct_neon
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
endfunc


.macro DCT8_1D type
    SUMSUB_AB   v18.8h, v17.8h, v3.8h,  v4.8h   // s34/d34
    SUMSUB_AB   v19.8h, v16.8h, v2.8h,  v5.8h   // s25/d25
    SUMSUB_AB   v22.8h, v21.8h, v1.8h,  v6.8h   // s16/d16
    SUMSUB_AB   v23.8h, v20.8h, v0.8h,  v7.8h   // s07/d07

    SUMSUB_AB   v24.8h, v26.8h,  v23.8h, v18.8h  // a0/a2
    SUMSUB_AB   v25.8h, v27.8h,  v22.8h, v19.8h  // a1/a3

    SUMSUB_AB   v30.8h, v29.8h,  v20.8h, v17.8h  // a6/a5
    sshr        v23.8h, v21.8h, #1
    sshr        v18.8h, v16.8h, #1
    add         v23.8h, v23.8h, v21.8h
    add         v18.8h, v18.8h, v16.8h
    sub         v30.8h, v30.8h, v23.8h
    sub         v29.8h, v29.8h, v18.8h

    SUMSUB_AB   v28.8h, v31.8h,  v21.8h, v16.8h   // a4/a7
    sshr        v22.8h, v20.8h, #1
    sshr        v19.8h, v17.8h, #1
    add         v22.8h, v22.8h, v20.8h
    add         v19.8h, v19.8h, v17.8h
    add         v22.8h, v28.8h, v22.8h
    add         v31.8h, v31.8h, v19.8h

    SUMSUB_AB      v0.8h,  v4.8h,  v24.8h, v25.8h
    SUMSUB_SHR  2, v1.8h,  v7.8h,  v22.8h, v31.8h, v16.8h, v17.8h
    SUMSUB_SHR  1, v2.8h,  v6.8h,  v26.8h, v27.8h, v18.8h, v19.8h
    SUMSUB_SHR2 2, v3.8h,  v5.8h,  v30.8h, v29.8h, v20.8h, v21.8h
.endm

258
function sub8x8_dct8_neon, export=1
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
    mov         x3, #FENC_STRIDE
    mov         x4, #FDEC_STRIDE
    ld1        {v16.8b}, [x1], x3
    ld1        {v17.8b}, [x2], x4
    ld1        {v18.8b}, [x1], x3
    ld1        {v19.8b}, [x2], x4
    usubl       v0.8h,  v16.8b, v17.8b
    ld1        {v20.8b}, [x1], x3
    ld1        {v21.8b}, [x2], x4
    usubl       v1.8h,  v18.8b, v19.8b
    ld1        {v22.8b}, [x1], x3
    ld1        {v23.8b}, [x2], x4
    usubl       v2.8h,  v20.8b, v21.8b
    ld1        {v24.8b}, [x1], x3
    ld1        {v25.8b}, [x2], x4
    usubl       v3.8h,  v22.8b, v23.8b
    ld1        {v26.8b}, [x1], x3
    ld1        {v27.8b}, [x2], x4
    usubl       v4.8h,  v24.8b, v25.8b
    ld1        {v28.8b}, [x1], x3
    ld1        {v29.8b}, [x2], x4
    usubl       v5.8h,  v26.8b, v27.8b
    ld1        {v30.8b}, [x1], x3
    ld1        {v31.8b}, [x2], x4
    usubl       v6.8h,  v28.8b, v29.8b
    usubl       v7.8h,  v30.8b, v31.8b

    DCT8_1D row
    transpose8x8.h v0, v1, v2, v3, v4, v5, v6, v7, v30, v31
    DCT8_1D col

    st1        {v0.8h,v1.8h,v2.8h,v3.8h}, [x0], #64
    st1        {v4.8h,v5.8h,v6.8h,v7.8h}, [x0], #64
    ret
endfunc

295
function sub16x16_dct8_neon, export=1
296
    mov         x7,  x30
297
    bl          X(sub8x8_dct8_neon)
298 299
    sub         x1,  x1,  #FENC_STRIDE*8 - 8
    sub         x2,  x2,  #FDEC_STRIDE*8 - 8
300
    bl          X(sub8x8_dct8_neon)
301 302
    sub         x1,  x1,  #8
    sub         x2,  x2,  #8
303
    bl          X(sub8x8_dct8_neon)
304 305 306
    mov         x30, x7
    sub         x1,  x1,  #FENC_STRIDE*8 - 8
    sub         x2,  x2,  #FDEC_STRIDE*8 - 8
307
    b           X(sub8x8_dct8_neon)
308 309 310 311 312 313 314 315 316 317 318 319
endfunc


// First part of IDCT (minus final SUMSUB_BA)
.macro IDCT_1D d4 d5 d6 d7 d0 d1 d2 d3
    SUMSUB_AB   \d4, \d5, \d0, \d2
    sshr        \d7, \d1, #1
    sshr        \d6, \d3, #1
    sub         \d7, \d7, \d3
    add         \d6, \d6, \d1
.endm

320
function add4x4_idct_neon, export=1
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
    mov         x2, #FDEC_STRIDE
    ld1        {v0.4h,v1.4h,v2.4h,v3.4h}, [x1]

    IDCT_1D     v4.4h, v5.4h, v6.4h, v7.4h, v0.4h, v1.4h, v2.4h, v3.4h
    ld1        {v28.s}[0], [x0], x2
    SUMSUB_AB   v0.4h, v2.4h, v4.4h, v6.4h
    SUMSUB_AB   v1.4h, v3.4h, v5.4h, v7.4h

    transpose4x4.h v0, v1, v3, v2, v16, v17, v18, v19

    IDCT_1D     v4.4h, v5.4h, v6.4h, v7.4h, v0.4h, v1.4h, v3.4h, v2.4h
    ld1        {v29.s}[0], [x0], x2
    SUMSUB_AB   v0.4h, v2.4h, v4.4h, v6.4h
    SUMSUB_AB   v1.4h, v3.4h, v5.4h, v7.4h

    srshr       v0.4h,  v0.4h,  #6
    srshr       v1.4h,  v1.4h,  #6
    ld1        {v31.s}[0], [x0], x2
    srshr       v2.4h,  v2.4h,  #6
    srshr       v3.4h,  v3.4h,  #6
    ld1        {v30.s}[0], [x0], x2

    sub         x0,  x0,  x2,  lsl #2
    uaddw       v0.8h,  v0.8h,  v28.8b
    uaddw       v1.8h,  v1.8h,  v29.8b
    uaddw       v2.8h,  v2.8h,  v30.8b
    uaddw       v3.8h,  v3.8h,  v31.8b
    sqxtun      v0.8b,  v0.8h
    sqxtun      v1.8b,  v1.8h
    sqxtun      v2.8b,  v2.8h
    sqxtun      v3.8b,  v3.8h

    st1        {v0.s}[0], [x0], x2
    st1        {v1.s}[0], [x0], x2
    st1        {v3.s}[0], [x0], x2
    st1        {v2.s}[0], [x0], x2
    ret
endfunc

360
function add8x4_idct_neon, export=1
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
    ld1        {v0.8h,v1.8h}, [x1], #32
    ld1        {v2.8h,v3.8h}, [x1], #32
    transpose   v20.2d, v21.2d, v0.2d, v2.2d
    transpose   v22.2d, v23.2d, v1.2d, v3.2d
    IDCT_1D     v16.8h, v17.8h, v18.8h, v19.8h, v20.8h, v21.8h, v22.8h, v23.8h
    SUMSUB_AB   v0.8h,  v3.8h,  v16.8h, v18.8h
    SUMSUB_AB   v1.8h,  v2.8h,  v17.8h, v19.8h

    transpose4x8.h v0, v1, v2, v3, v4, v5, v6, v7

    IDCT_1D     v16.8h, v17.8h, v18.8h, v19.8h, v0.8h, v1.8h, v2.8h, v3.8h
    SUMSUB_AB   v0.8h,  v3.8h,  v16.8h, v18.8h
    SUMSUB_AB   v1.8h,  v2.8h,  v17.8h, v19.8h

    srshr       v0.8h,  v0.8h,  #6
    ld1        {v28.8b}, [x0], x2
    srshr       v1.8h,  v1.8h,  #6
    ld1        {v29.8b}, [x0], x2
    srshr       v2.8h,  v2.8h,  #6
    ld1        {v30.8b}, [x0], x2
    srshr       v3.8h,  v3.8h,  #6
    ld1        {v31.8b}, [x0], x2

    sub         x0,  x0,  x2,  lsl #2
    uaddw       v0.8h,  v0.8h,  v28.8b
    uaddw       v1.8h,  v1.8h,  v29.8b
    uaddw       v2.8h,  v2.8h,  v30.8b
    uaddw       v3.8h,  v3.8h,  v31.8b

    sqxtun      v0.8b,  v0.8h
    sqxtun      v1.8b,  v1.8h
    st1        {v0.8b}, [x0], x2
    sqxtun      v2.8b,  v2.8h
    st1        {v1.8b}, [x0], x2
    sqxtun      v3.8b,  v3.8h
    st1        {v2.8b}, [x0], x2
    st1        {v3.8b}, [x0], x2
    ret
endfunc

401
function add8x8_idct_neon, export=1
402 403
    mov             x2, #FDEC_STRIDE
    mov             x5,  x30
404
    bl              X(add8x4_idct_neon)
405
    mov             x30, x5
406
    b               X(add8x4_idct_neon)
407 408
endfunc

409
function add16x16_idct_neon, export=1
410 411
    mov             x2, #FDEC_STRIDE
    mov             x5,  x30
412 413
    bl              X(add8x4_idct_neon)
    bl              X(add8x4_idct_neon)
414
    sub             x0, x0, #8*FDEC_STRIDE-8
415 416
    bl              X(add8x4_idct_neon)
    bl              X(add8x4_idct_neon)
417
    sub             x0, x0, #8
418 419
    bl              X(add8x4_idct_neon)
    bl              X(add8x4_idct_neon)
420
    sub             x0, x0, #8*FDEC_STRIDE-8
421
    bl              X(add8x4_idct_neon)
422
    mov             x30, x5
423
    b               X(add8x4_idct_neon)
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
endfunc

.macro IDCT8_1D type
    SUMSUB_AB   v0.8h,  v1.8h,  v16.8h, v20.8h          // a0/a2
.ifc \type, row
    ld1        {v22.8h,v23.8h}, [x1], #32
.endif
    SUMSUB_SHR  1, v2.8h,  v3.8h,  v18.8h, v22.8h, v16.8h, v20.8h   // a6/a4
    SUMSUB_AB   v16.8h, v18.8h, v21.8h, v19.8h
    SUMSUB_15   v16.8h, v18.8h, v17.8h, v23.8h, v20.8h, v22.8h      // a7/a1
    SUMSUB_AB   v22.8h, v23.8h, v23.8h, v17.8h
    SUMSUB_15   v23.8h, v22.8h, v21.8h, v19.8h, v20.8h, v17.8h      // a5/a3

    SUMSUB_SHR  2, v21.8h, v22.8h, v22.8h, v23.8h, v19.8h, v17.8h   // b3/b5
    SUMSUB_SHR2 2, v20.8h, v23.8h, v16.8h, v18.8h, v19.8h, v17.8h   // b1/b7

    SUMSUB_AB   v18.8h, v2.8h,  v0.8h,  v2.8h           // b0/b6
    SUMSUB_AB   v19.8h, v3.8h,  v1.8h,  v3.8h           // b2/b4

    SUMSUB_AB   v16.8h, v23.8h, v18.8h, v23.8h
    SUMSUB_AB   v17.8h, v22.8h, v19.8h, v22.8h
    SUMSUB_AB   v18.8h, v21.8h, v3.8h,  v21.8h
    SUMSUB_AB   v19.8h, v20.8h, v2.8h,  v20.8h
.endm

449
function add8x8_idct8_neon, export=1
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
    mov         x2,  #FDEC_STRIDE
    ld1        {v16.8h,v17.8h}, [x1], #32
    ld1        {v18.8h,v19.8h}, [x1], #32
    ld1        {v20.8h,v21.8h}, [x1], #32

    IDCT8_1D    row

    transpose8x8.h v16, v17, v18, v19, v20, v21, v22, v23, v30, v31

    IDCT8_1D    col

    ld1        {v0.8b}, [x0], x2
    srshr       v16.8h, v16.8h, #6
    ld1        {v1.8b}, [x0], x2
    srshr       v17.8h, v17.8h, #6
    ld1        {v2.8b}, [x0], x2
    srshr       v18.8h, v18.8h, #6
    ld1        {v3.8b}, [x0], x2
    srshr       v19.8h, v19.8h, #6
    ld1        {v4.8b}, [x0], x2
    srshr       v20.8h, v20.8h, #6
    ld1        {v5.8b}, [x0], x2
    srshr       v21.8h, v21.8h, #6
    ld1        {v6.8b}, [x0], x2
    srshr       v22.8h, v22.8h, #6
    ld1        {v7.8b}, [x0], x2
    srshr       v23.8h, v23.8h, #6
    sub         x0,  x0,  x2,  lsl #3

    uaddw       v16.8h, v16.8h, v0.8b
    uaddw       v17.8h, v17.8h, v1.8b
    uaddw       v18.8h, v18.8h, v2.8b
    sqxtun      v0.8b,  v16.8h
    sqxtun      v1.8b,  v17.8h
    sqxtun      v2.8b,  v18.8h
    uaddw       v19.8h, v19.8h, v3.8b
    st1        {v0.8b}, [x0], x2
    uaddw       v20.8h, v20.8h, v4.8b
    st1        {v1.8b}, [x0], x2
    uaddw       v21.8h, v21.8h, v5.8b
    st1        {v2.8b}, [x0], x2
    sqxtun      v3.8b,  v19.8h
    sqxtun      v4.8b,  v20.8h
    uaddw       v22.8h, v22.8h, v6.8b
    uaddw       v23.8h, v23.8h, v7.8b
    st1        {v3.8b}, [x0], x2
    sqxtun      v5.8b,  v21.8h
    st1        {v4.8b}, [x0], x2
    sqxtun      v6.8b,  v22.8h
    sqxtun      v7.8b,  v23.8h
    st1        {v5.8b}, [x0], x2
    st1        {v6.8b}, [x0], x2
    st1        {v7.8b}, [x0], x2
    ret
endfunc

506
function add16x16_idct8_neon, export=1
507
    mov             x7,  x30
508
    bl              X(add8x8_idct8_neon)
509
    sub             x0,  x0,  #8*FDEC_STRIDE-8
510
    bl              X(add8x8_idct8_neon)
511
    sub             x0,  x0,  #8
512
    bl              X(add8x8_idct8_neon)
513 514
    sub             x0,  x0,  #8*FDEC_STRIDE-8
    mov             x30, x7
515
    b               X(add8x8_idct8_neon)
516 517
endfunc

518
function add8x8_idct_dc_neon, export=1
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
    mov         x2,  #FDEC_STRIDE
    ld1        {v16.4h}, [x1]
    ld1        {v0.8b}, [x0], x2
    srshr       v16.4h, v16.4h, #6
    ld1        {v1.8b}, [x0], x2
    dup         v20.8h, v16.h[0]
    dup         v21.8h, v16.h[1]
    ld1        {v2.8b}, [x0], x2
    dup         v22.8h, v16.h[2]
    dup         v23.8h, v16.h[3]
    ld1        {v3.8b}, [x0], x2
    trn1        v20.2d, v20.2d,  v21.2d
    ld1        {v4.8b}, [x0], x2
    trn1        v21.2d, v22.2d,  v23.2d
    ld1        {v5.8b}, [x0], x2
    neg         v22.8h, v20.8h
    ld1        {v6.8b}, [x0], x2
    neg         v23.8h, v21.8h
    ld1        {v7.8b}, [x0], x2

    sub         x0,  x0,  #8*FDEC_STRIDE

    sqxtun      v20.8b,  v20.8h
    sqxtun      v21.8b,  v21.8h
    sqxtun      v22.8b,  v22.8h
    sqxtun      v23.8b,  v23.8h

    uqadd       v0.8b,  v0.8b,  v20.8b
    uqadd       v1.8b,  v1.8b,  v20.8b
    uqadd       v2.8b,  v2.8b,  v20.8b
    uqadd       v3.8b,  v3.8b,  v20.8b
    uqadd       v4.8b,  v4.8b,  v21.8b
    uqadd       v5.8b,  v5.8b,  v21.8b
    uqadd       v6.8b,  v6.8b,  v21.8b
    uqadd       v7.8b,  v7.8b,  v21.8b
    uqsub       v0.8b,  v0.8b,  v22.8b
    uqsub       v1.8b,  v1.8b,  v22.8b
    uqsub       v2.8b,  v2.8b,  v22.8b
    uqsub       v3.8b,  v3.8b,  v22.8b
    uqsub       v4.8b,  v4.8b,  v23.8b
    uqsub       v5.8b,  v5.8b,  v23.8b
    uqsub       v6.8b,  v6.8b,  v23.8b
    uqsub       v7.8b,  v7.8b,  v23.8b

    st1        {v0.8b}, [x0], x2
    st1        {v1.8b}, [x0], x2
    st1        {v2.8b}, [x0], x2
    st1        {v3.8b}, [x0], x2
    st1        {v4.8b}, [x0], x2
    st1        {v5.8b}, [x0], x2
    st1        {v6.8b}, [x0], x2
    st1        {v7.8b}, [x0], x2
    ret
endfunc

.macro ADD16x4_IDCT_DC dc
    ld1         {v4.16b}, [x0], x3
    dup         v24.8h,  \dc[0]
    dup         v25.8h,  \dc[1]
    ld1         {v5.16b}, [x0], x3
    dup         v26.8h,  \dc[2]
    dup         v27.8h,  \dc[3]
    ld1         {v6.16b}, [x0], x3
    trn1        v24.2d,  v24.2d,  v25.2d
    ld1         {v7.16b}, [x0], x3
    trn1        v25.2d,  v26.2d,  v27.2d
    neg         v26.8h,  v24.8h
    neg         v27.8h,  v25.8h

    sqxtun      v20.8b,  v24.8h
    sqxtun      v21.8b,  v26.8h
    sqxtun2     v20.16b, v25.8h
    sqxtun2     v21.16b, v27.8h

    uqadd        v4.16b, v4.16b, v20.16b
    uqadd        v5.16b, v5.16b, v20.16b
    uqadd        v6.16b, v6.16b, v20.16b
    uqadd        v7.16b, v7.16b, v20.16b

    uqsub        v4.16b, v4.16b, v21.16b
    uqsub        v5.16b, v5.16b, v21.16b
    uqsub        v6.16b, v6.16b, v21.16b
    st1         {v4.16b}, [x2], x3
    uqsub        v7.16b, v7.16b, v21.16b
    st1         {v5.16b}, [x2], x3
    st1         {v6.16b}, [x2], x3
    st1         {v7.16b}, [x2], x3
.endm

608
function add16x16_idct_dc_neon, export=1
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
    mov         x2,  x0
    mov         x3,  #FDEC_STRIDE

    ld1        {v0.4h,v1.4h,v2.4h,v3.4h}, [x1]
    srshr       v0.4h,  v0.4h,  #6
    srshr       v1.4h,  v1.4h,  #6

    ADD16x4_IDCT_DC v0.h
    srshr       v2.4h,  v2.4h,  #6
    ADD16x4_IDCT_DC v1.h
    srshr       v3.4h,  v3.4h,  #6
    ADD16x4_IDCT_DC v2.h
    ADD16x4_IDCT_DC v3.h
    ret
endfunc

625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
.macro sub4x4x2_dct_dc, dst, t0, t1, t2, t3, t4, t5, t6, t7
    ld1        {\t0\().8b}, [x1], x3
    ld1        {\t1\().8b}, [x2], x4
    ld1        {\t2\().8b}, [x1], x3
    ld1        {\t3\().8b}, [x2], x4
    usubl       \t0\().8h,  \t0\().8b,  \t1\().8b
    ld1        {\t4\().8b}, [x1], x3
    ld1        {\t5\().8b}, [x2], x4
    usubl       \t1\().8h,  \t2\().8b,  \t3\().8b
    ld1        {\t6\().8b}, [x1], x3
    ld1        {\t7\().8b}, [x2], x4
    add         \dst\().8h, \t0\().8h,  \t1\().8h
    usubl       \t2\().8h,  \t4\().8b,  \t5\().8b
    usubl       \t3\().8h,  \t6\().8b,  \t7\().8b
    add         \dst\().8h, \dst\().8h, \t2\().8h
    add         \dst\().8h, \dst\().8h, \t3\().8h
.endm

643
function sub8x8_dct_dc_neon, export=1
644 645 646
    mov             x3,  #FENC_STRIDE
    mov             x4,  #FDEC_STRIDE

647 648 649 650 651 652 653
    sub4x4x2_dct_dc  v0, v16, v17, v18, v19, v20, v21, v22, v23
    sub4x4x2_dct_dc  v1, v24, v25, v26, v27, v28, v29, v30, v31

    transpose   v2.2d,  v3.2d,  v0.2d,  v1.2d
    SUMSUB_AB   v0.8h,  v1.8h,  v2.8h,  v3.8h
    transpose   v2.2d,  v3.2d,  v0.2d,  v1.2d
    SUMSUB_AB   v0.8h,  v1.8h,  v2.8h,  v3.8h
654 655
    transpose   v2.2d,  v3.2d,  v0.2d,  v1.2d

656 657
    addp        v0.8h,  v2.8h,  v3.8h
    addp        v0.8h,  v0.8h,  v0.8h
658

659 660 661 662
    st1        {v0.4h}, [x0]
    ret
endfunc

663
function sub8x16_dct_dc_neon, export=1
664 665 666 667 668 669 670 671 672
    mov             x3,  #FENC_STRIDE
    mov             x4,  #FDEC_STRIDE
    sub4x4x2_dct_dc  v0, v16, v17, v18, v19, v20, v21, v22, v23
    sub4x4x2_dct_dc  v1, v24, v25, v26, v27, v28, v29, v30, v31
    sub4x4x2_dct_dc  v2, v16, v17, v18, v19, v20, v21, v22, v23
    sub4x4x2_dct_dc  v3, v24, v25, v26, v27, v28, v29, v30, v31

    addp             v4.8h,  v0.8h,  v2.8h
    addp             v5.8h,  v1.8h,  v3.8h
673

674 675 676 677 678
    transpose   v2.4s,  v3.4s,  v4.4s,  v5.4s
    SUMSUB_AB   v0.8h,  v1.8h,  v2.8h,  v3.8h

    transpose   v2.4s,  v3.4s,  v0.4s,  v1.4s
    SUMSUB_AB   v0.8h,  v1.8h,  v2.8h,  v3.8h
679 680

    transpose   v2.2d,  v3.2d,  v0.2d,  v1.2d
681 682 683 684
    SUMSUB_AB   v0.8h,  v1.8h,  v2.8h,  v3.8h

    trn1        v2.2d,  v0.2d,  v1.2d
    trn2        v3.2d,  v1.2d,  v0.2d
685 686 687

    addp        v0.8h,  v2.8h,  v3.8h

688
    st1        {v0.8h}, [x0]
689 690 691
    ret
endfunc

692
function zigzag_interleave_8x8_cavlc_neon, export=1
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
    mov        x3,  #7
    movi       v31.4s, #1
    ld4        {v0.8h,v1.8h,v2.8h,v3.8h}, [x1],  #64
    ld4        {v4.8h,v5.8h,v6.8h,v7.8h}, [x1],  #64
    umax       v16.8h, v0.8h,  v4.8h
    umax       v17.8h, v1.8h,  v5.8h
    umax       v18.8h, v2.8h,  v6.8h
    umax       v19.8h, v3.8h,  v7.8h
    st1        {v0.8h}, [x0],  #16
    st1        {v4.8h}, [x0],  #16
    umaxp      v16.8h, v16.8h, v17.8h
    umaxp      v18.8h, v18.8h, v19.8h
    st1        {v1.8h}, [x0],  #16
    st1        {v5.8h}, [x0],  #16
    umaxp      v16.8h, v16.8h, v18.8h
    st1        {v2.8h}, [x0],  #16
    st1        {v6.8h}, [x0],  #16
    cmhi       v16.4s, v16.4s, v31.4s
    st1        {v3.8h}, [x0],  #16
    and        v16.16b, v16.16b, v31.16b
    st1        {v7.8h}, [x0],  #16
    st1        {v16.b}[0],    [x2],  #1
    st1        {v16.b}[4],    [x2],  x3
    st1        {v16.b}[8],    [x2],  #1
    st1        {v16.b}[12],   [x2]
    ret
endfunc

721
function zigzag_scan_4x4_frame_neon, export=1
722 723 724 725 726 727 728 729
    movrel      x2, scan4x4_frame
    ld1        {v0.16b,v1.16b}, [x1]
    ld1        {v16.16b,v17.16b}, [x2]
    tbl         v2.16b, {v0.16b,v1.16b}, v16.16b
    tbl         v3.16b, {v0.16b,v1.16b}, v17.16b
    st1        {v2.16b,v3.16b},   [x0]
    ret
endfunc
730 731

.macro zigzag_sub_4x4 f ac
732
function zigzag_sub_4x4\ac\()_\f\()_neon, export=1
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
    mov         x9,  #FENC_STRIDE
    mov         x4,  #FDEC_STRIDE
    movrel      x5,  sub4x4_\f
    mov         x6,  x2
    ld1        {v0.s}[0], [x1], x9
    ld1        {v0.s}[1], [x1], x9
    ld1        {v0.s}[2], [x1], x9
    ld1        {v0.s}[3], [x1], x9
    ld1        {v16.16b}, [x5]
    ld1        {v1.s}[0], [x2], x4
    ld1        {v1.s}[1], [x2], x4
    ld1        {v1.s}[2], [x2], x4
    ld1        {v1.s}[3], [x2], x4
    tbl         v2.16b, {v0.16b}, v16.16b
    tbl         v3.16b, {v1.16b}, v16.16b
    st1        {v0.s}[0], [x6], x4
    usubl       v4.8h,  v2.8b,  v3.8b
.ifc \ac, ac
    dup         h7, v4.h[0]
    ins         v4.h[0], wzr
    fmov        w5,  s7
    strh        w5,  [x3]
.endif
    usubl2      v5.8h,  v2.16b, v3.16b
    st1        {v0.s}[1], [x6], x4
    umax        v6.8h,  v4.8h,  v5.8h
    umaxv       h6,  v6.8h
    st1        {v0.s}[2], [x6], x4
    fmov        w7,  s6
    st1        {v0.s}[3], [x6], x4
    cmp         w7, #0
    st1        {v4.8h,v5.8h},   [x0]
    cset        w0, ne
    ret
endfunc
.endm

zigzag_sub_4x4 field
zigzag_sub_4x4 field, ac
zigzag_sub_4x4 frame
zigzag_sub_4x4 frame, ac

775
function zigzag_scan_4x4_field_neon, export=1
776 777 778 779 780 781 782 783
    movrel      x2, scan4x4_field
    ld1        {v0.8h,v1.8h},   [x1]
    ld1        {v16.16b},       [x2]
    tbl         v0.16b, {v0.16b}, v16.16b
    st1        {v0.8h,v1.8h},   [x0]
    ret
endfunc

784
function zigzag_scan_8x8_frame_neon, export=1
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843
    movrel      x2,  scan8x8_frame
    ld1        {v0.8h,v1.8h},   [x1], #32
    ld1        {v2.8h,v3.8h},   [x1], #32
    ld1        {v4.8h,v5.8h},   [x1], #32
    ld1        {v6.8h,v7.8h},   [x1]
    ld1        {v16.16b,v17.16b}, [x2], #32
    ld1        {v18.16b,v19.16b}, [x2], #32
    ld1        {v20.16b,v21.16b}, [x2], #32
    ld1        {v22.16b,v23.16b}, [x2], #32
    tbl         v24.16b, {v0.16b,v1.16b,v2.16b,v3.16b}, v16.16b
    tbl         v25.16b, {v0.16b,v1.16b,v2.16b,v3.16b}, v17.16b
    tbl         v26.16b, {v0.16b,v1.16b,v2.16b,v3.16b}, v18.16b
    tbl         v27.16b, {v3.16b,v4.16b,v5.16b,v6.16b}, v19.16b
    tbl         v28.16b, {v0.16b,v1.16b,v2.16b,v3.16b}, v20.16b
    tbl         v29.16b, {v4.16b,v5.16b,v6.16b,v7.16b}, v21.16b
    tbl         v30.16b, {v4.16b,v5.16b,v6.16b,v7.16b}, v22.16b
    tbl         v31.16b, {v4.16b,v5.16b,v6.16b,v7.16b}, v23.16b
    mov         v25.h[6], v4.h[0]
    mov         v25.h[7], v5.h[0]
    mov         v26.h[0], v4.h[1]
    mov         v27.h[4], v7.h[0]
    mov         v28.h[7], v4.h[4]
    mov         v29.h[7], v3.h[6]
    mov         v30.h[0], v2.h[7]
    mov         v30.h[1], v3.h[7]
    st1        {v24.8h,v25.8h}, [x0], #32
    st1        {v26.8h,v27.8h}, [x0], #32
    st1        {v28.8h,v29.8h}, [x0], #32
    st1        {v30.8h,v31.8h}, [x0]
    ret
endfunc

#define Z(z)   2*(z), 2*(z)+1
#define T(x,y) Z(x*8+y)
const scan8x8_frame, align=5
    .byte T(0,0), T(1,0), T(0,1), T(0,2)
    .byte T(1,1), T(2,0), T(3,0), T(2,1)
    .byte T(1,2), T(0,3), T(0,4), T(1,3)
    .byte T(2,2), T(3,1), T(4,0), T(5,0)
    .byte T(4,1), T(3,2), T(2,3), T(1,4)
    .byte T(0,5), T(0,6), T(1,5), T(2,4)
#undef T
#define T(x,y) Z((x-3)*8+y)
    .byte T(3,3), T(4,2), T(5,1), T(6,0)
    .byte T(7,0), T(6,1), T(5,2), T(4,3)
#undef T
#define T(x,y) Z((x-0)*8+y)
    .byte T(3,4), T(2,5), T(1,6), T(0,7)
    .byte T(1,7), T(2,6), T(3,5), T(4,4)
#undef T
#define T(x,y) Z((x-4)*8+y)
    .byte T(5,3), T(6,2), T(7,1), T(7,2)
    .byte T(6,3), T(5,4), T(4,5), T(3,6)
    .byte T(2,7), T(3,7), T(4,6), T(5,5)
    .byte T(6,4), T(7,3), T(7,4), T(6,5)
    .byte T(5,6), T(4,7), T(5,7), T(6,6)
    .byte T(7,5), T(7,6), T(6,7), T(7,7)
endconst

844
function zigzag_scan_8x8_field_neon, export=1
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870
    movrel      x2,  scan8x8_field
    ld1        {v0.8h,v1.8h},   [x1], #32
    ld1        {v2.8h,v3.8h},   [x1], #32
    ld1        {v4.8h,v5.8h},   [x1], #32
    ld1        {v6.8h,v7.8h},   [x1]
    ld1        {v16.16b,v17.16b}, [x2], #32
    ld1        {v18.16b,v19.16b}, [x2], #32
    ld1        {v20.16b,v21.16b}, [x2], #32
    ld1        {v22.16b}, [x2]
    ext         v31.16b, v7.16b, v7.16b, #4
    tbl         v24.16b, {v0.16b,v1.16b},               v16.16b
    tbl         v25.16b, {v0.16b,v1.16b,v2.16b,v3.16b}, v17.16b
    tbl         v26.16b, {v1.16b,v2.16b,v3.16b,v4.16b}, v18.16b
    tbl         v27.16b, {v2.16b,v3.16b,v4.16b,v5.16b}, v19.16b
    tbl         v28.16b, {v3.16b,v4.16b,v5.16b,v6.16b}, v20.16b
    tbl         v29.16b, {v4.16b,v5.16b,v6.16b},        v21.16b
    tbl         v30.16b, {v5.16b,v6.16b,v7.16b},        v22.16b
    ext         v31.16b, v6.16b, v31.16b, #12
    st1        {v24.8h,v25.8h}, [x0], #32
    st1        {v26.8h,v27.8h}, [x0], #32
    st1        {v28.8h,v29.8h}, [x0], #32
    st1        {v30.8h,v31.8h}, [x0]
    ret
endfunc

.macro zigzag_sub8x8 f
871
function zigzag_sub_8x8_\f\()_neon, export=1
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008
    movrel      x4,  sub8x8_\f
    mov         x5,  #FENC_STRIDE
    mov         x6,  #FDEC_STRIDE
    mov         x7,  x2
    ld1        {v0.d}[0], [x1], x5
    ld1        {v0.d}[1], [x1], x5
    ld1        {v1.d}[0], [x1], x5
    ld1        {v1.d}[1], [x1], x5
    ld1        {v2.d}[0], [x1], x5
    ld1        {v2.d}[1], [x1], x5
    ld1        {v3.d}[0], [x1], x5
    ld1        {v3.d}[1], [x1]
    ld1        {v4.d}[0], [x2], x6
    ld1        {v4.d}[1], [x2], x6
    ld1        {v5.d}[0], [x2], x6
    ld1        {v5.d}[1], [x2], x6
    ld1        {v6.d}[0], [x2], x6
    ld1        {v6.d}[1], [x2], x6
    ld1        {v7.d}[0], [x2], x6
    ld1        {v7.d}[1], [x2]
    ld1        {v16.16b,v17.16b}, [x4], #32
    ld1        {v18.16b,v19.16b}, [x4], #32
    tbl         v24.16b, {v0.16b,v1.16b,v2.16b,v3.16b}, v16.16b
    tbl         v25.16b, {v0.16b,v1.16b,v2.16b,v3.16b}, v17.16b
    tbl         v26.16b, {v0.16b,v1.16b,v2.16b,v3.16b}, v18.16b
    tbl         v27.16b, {v0.16b,v1.16b,v2.16b,v3.16b}, v19.16b
    tbl         v28.16b, {v4.16b,v5.16b,v6.16b,v7.16b}, v16.16b
    tbl         v29.16b, {v4.16b,v5.16b,v6.16b,v7.16b}, v17.16b
    tbl         v30.16b, {v4.16b,v5.16b,v6.16b,v7.16b}, v18.16b
    tbl         v31.16b, {v4.16b,v5.16b,v6.16b,v7.16b}, v19.16b
    usubl       v4.8h,  v24.8b,  v28.8b
    usubl2      v5.8h,  v24.16b, v28.16b
    usubl       v6.8h,  v25.8b,  v29.8b
    usubl2      v7.8h,  v25.16b, v29.16b
    usubl       v16.8h, v26.8b,  v30.8b
    usubl2      v17.8h, v26.16b, v30.16b
    usubl       v18.8h, v27.8b,  v31.8b
    usubl2      v19.8h, v27.16b, v31.16b
    umax        v20.8h, v4.8h,   v5.8h
    umax        v21.8h, v6.8h,   v7.8h
    umax        v22.8h, v16.8h,  v17.8h
    umax        v23.8h, v18.8h,  v19.8h
    umax        v20.8h, v20.8h,  v21.8h
    umax        v21.8h, v22.8h,  v23.8h
    umax        v20.8h, v20.8h,  v21.8h
    umaxv       h22,    v20.8h
    st1        {v0.d}[0], [x7], x6
    st1        {v0.d}[1], [x7], x6
    st1        {v1.d}[0], [x7], x6
    st1        {v1.d}[1], [x7], x6
    st1        {v2.d}[0], [x7], x6
    st1        {v2.d}[1], [x7], x6
    st1        {v3.d}[0], [x7], x6
    st1        {v3.d}[1], [x7]
    st1        {v4.8h,v5.8h},   [x0], #32
    st1        {v6.8h,v7.8h},   [x0], #32
    st1        {v16.8h,v17.8h}, [x0], #32
    st1        {v18.8h,v19.8h}, [x0]
    fmov        w9,  s22
    cmp         w9, #0
    cset        w0, ne
    ret
endfunc
.endm

zigzag_sub8x8 field
zigzag_sub8x8 frame

#undef T
#define T(x,y) Z(x*8+y)
const scan8x8_field, align=5
    .byte T(0,0), T(0,1), T(0,2), T(1,0)
    .byte T(1,1), T(0,3), T(0,4), T(1,2)
    .byte T(2,0), T(1,3), T(0,5), T(0,6)
    .byte T(0,7), T(1,4), T(2,1), T(3,0)
#undef T
#define T(x,y) Z((x-1)*8+y)
    .byte T(2,2), T(1,5), T(1,6), T(1,7)
    .byte T(2,3), T(3,1), T(4,0), T(3,2)
#undef T
#define T(x,y) Z((x-2)*8+y)
    .byte T(2,4), T(2,5), T(2,6), T(2,7)
    .byte T(3,3), T(4,1), T(5,0), T(4,2)
#undef T
#define T(x,y) Z((x-3)*8+y)
    .byte T(3,4), T(3,5), T(3,6), T(3,7)
    .byte T(4,3), T(5,1), T(6,0), T(5,2)
#undef T
#define T(x,y) Z((x-4)*8+y)
    .byte T(4,4), T(4,5), T(4,6), T(4,7)
    .byte T(5,3), T(6,1), T(6,2), T(5,4)
#undef T
#define T(x,y) Z((x-5)*8+y)
    .byte T(5,5), T(5,6), T(5,7), T(6,3)
    .byte T(7,0), T(7,1), T(6,4), T(6,5)
endconst


#undef T
#define T(y,x) x*8+y
const sub8x8_frame, align=5
    .byte T(0,0), T(1,0), T(0,1), T(0,2)
    .byte T(1,1), T(2,0), T(3,0), T(2,1)
    .byte T(1,2), T(0,3), T(0,4), T(1,3)
    .byte T(2,2), T(3,1), T(4,0), T(5,0)
    .byte T(4,1), T(3,2), T(2,3), T(1,4)
    .byte T(0,5), T(0,6), T(1,5), T(2,4)
    .byte T(3,3), T(4,2), T(5,1), T(6,0)
    .byte T(7,0), T(6,1), T(5,2), T(4,3)
    .byte T(3,4), T(2,5), T(1,6), T(0,7)
    .byte T(1,7), T(2,6), T(3,5), T(4,4)
    .byte T(5,3), T(6,2), T(7,1), T(7,2)
    .byte T(6,3), T(5,4), T(4,5), T(3,6)
    .byte T(2,7), T(3,7), T(4,6), T(5,5)
    .byte T(6,4), T(7,3), T(7,4), T(6,5)
    .byte T(5,6), T(4,7), T(5,7), T(6,6)
    .byte T(7,5), T(7,6), T(6,7), T(7,7)
endconst

const sub8x8_field, align=5
    .byte T(0,0), T(0,1), T(0,2), T(1,0)
    .byte T(1,1), T(0,3), T(0,4), T(1,2)
    .byte T(2,0), T(1,3), T(0,5), T(0,6)
    .byte T(0,7), T(1,4), T(2,1), T(3,0)
    .byte T(2,2), T(1,5), T(1,6), T(1,7)
    .byte T(2,3), T(3,1), T(4,0), T(3,2)
    .byte T(2,4), T(2,5), T(2,6), T(2,7)
    .byte T(3,3), T(4,1), T(5,0), T(4,2)
    .byte T(3,4), T(3,5), T(3,6), T(3,7)
    .byte T(4,3), T(5,1), T(6,0), T(5,2)
    .byte T(4,4), T(4,5), T(4,6), T(4,7)
    .byte T(5,3), T(6,1), T(6,2), T(5,4)
    .byte T(5,5), T(5,6), T(5,7), T(6,3)
    .byte T(7,0), T(7,1), T(6,4), T(6,5)
    .byte T(6,6), T(6,7), T(7,2), T(7,3)
    .byte T(7,4), T(7,5), T(7,6), T(7,7)
endconst