1 ;*****************************************************************************
2 ;* trellis-64.asm: x86_64 trellis quantization
3 ;*****************************************************************************
4 ;* Copyright (C) 2012 x264 project
6 ;* Authors: Loren Merritt <lorenm@u.washington.edu>
8 ;* This program is free software; you can redistribute it and/or modify
9 ;* it under the terms of the GNU General Public License as published by
10 ;* the Free Software Foundation; either version 2 of the License, or
11 ;* (at your option) any later version.
13 ;* This program is distributed in the hope that it will be useful,
14 ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;* GNU General Public License for more details.
18 ;* You should have received a copy of the GNU General Public License
19 ;* along with this program; if not, write to the Free Software
20 ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
22 ;* This program is also available under a commercial proprietary license.
23 ;* For more information, contact us at licensing@x264.com.
24 ;*****************************************************************************
26 ; This is a pretty straight-forward translation of the C code, except:
27 ; * simd ssd and psy: 2x parallel, handling the 2 candidate values of abs_level.
28 ; * simd trellis_coef0, ZERO_LEVEL_IDX, and the coef0 part of the main loop:
29 ; 4x parallel, handling 4 node_ctxs of the same coef (even if some of those
31 ; * Interprocedural register allocation. Eliminates argument-passing overhead
32 ; to trellis_coef* subroutines. Also reduces codesize.
34 ; Optimizations that I tried, and rejected because they were not faster:
35 ; * Separate loops for node_ctx [4..7] or smaller subsets of [0..3].
36 ; Costs too much icache compared to the negligible speedup.
37 ; * There are only 21 possible sets of live node_ctxs; we could keep track of
38 ; exactly which set we're in and feed that (along with abs_level) into a jump
39 ; table instead of the switch to select a trellis_coef subroutine. This would
40 ; eliminate all branches about which node_ctxs are live, but costs either a
41 ; bunch of icache or a bunch of call/ret, and the jump table itself is
43 ; * Separate versions of trellis_coef* depending on whether we're doing the 1st
44 ; or the 2nd of the two abs_level candidates. This would eliminate some
45 ; branches about if(score is better).
46 ; * Special case more values of coef. I had a coef2 at some intermediate point
47 ; in the optimization process, but it didn't end up worthwhile in conjunction
48 ; with all the other optimizations.
49 ; * Unroll or simd writeback. I don't know why this didn't help.
52 %include "x86util.asm"
57 pd_m16: times 4 dd -16
58 pd_0123: dd 0, 1, 2, 3
59 pd_4567: dd 4, 5, 6, 7
61 pq_128: times 2 dq 128
62 pq_ffffffff: times 2 dq 0xffffffff
65 cextern cabac_transition
66 cextern cabac_size_unary
67 cextern cabac_transition_unary
68 cextern dct4_weight_tab
69 cextern dct8_weight_tab
70 cextern dct4_weight2_tab
71 cextern dct8_weight2_tab
72 cextern last_coeff_flag_offset_8x8
73 cextern significant_coeff_flag_offset_8x8
74 cextern coeff_flag_offset_chroma_422_dc
78 %define TRELLIS_SCORE_BIAS 1<<60
79 %define SIZEOF_NODE 16
80 %define CABAC_SIZE_BITS 8
83 %macro SQUARE 2 ; dst, tmp
84 ; could use pmuldq here, to eliminate the abs. but that would involve
85 ; templating a sse4 version of all of trellis, for negligible speedup.
95 pand m%1, [pq_ffffffff]
99 ;-----------------------------------------------------------------------------
100 ; int trellis_cabac_4x4_psy(
101 ; const int *unquant_mf, const uint8_t *zigzag, int lambda2,
102 ; int last_nnz, dctcoef *orig_coefs, dctcoef *quant_coefs, dctcoef *dct,
103 ; uint8_t *cabac_state_sig, uint8_t *cabac_state_last,
104 ; uint64_t level_state0, uint16_t level_state1,
105 ; int b_ac, dctcoef *fenc_dct, int psy_trellis )
106 ;-----------------------------------------------------------------------------
112 %assign level_tree_size 64*8*2*4 ; could depend on num_coefs, but nonuniform stack size would prevent accessing args from trellis_coef*
113 %assign pad 96 + level_tree_size + 16*SIZEOF_NODE + 16-gprsize-(stack_offset&15)
115 DEFINE_ARGS unquant_mf, zigzag, lambda2, ii, orig_coefs, quant_coefs, dct, cabac_state_sig, cabac_state_last
117 %define level_statem rsp+stack_offset+80 ; r9m, except that we need to index into it (and r10m) as an array
119 %define level_statem rsp+stack_offset+32
121 %define b_acm r11m ; 4x4 only
122 %define b_interlacedm r11m ; 8x8 only
123 %define i_coefsm1 r11m ; dc only
124 %define fenc_dctm r12m
125 %define psy_trellism r13m
127 shl dword b_interlacedm, 6
128 %define dct_weight1_tab dct8_weight_tab
129 %define dct_weight2_tab dct8_weight2_tab
131 %define dct_weight1_tab dct4_weight_tab
132 %define dct_weight2_tab dct4_weight2_tab
136 %define last_nnzm [stack+0]
137 %define zigzagm [stack+8]
141 %define orig_coefsm [stack+16]
142 %define quant_coefsm [stack+24]
143 mov orig_coefsm, orig_coefsq
144 mov quant_coefsm, quant_coefsq
146 %define unquant_mfm [stack+32]
147 %define levelgt1_ctxm [stack+40]
149 %define cost_siglast stack+80
150 %define level_tree stack+96
152 ; trellis_node_t is layed out differently than C.
153 ; struct-of-arrays rather than array-of-structs, for simd.
154 %define nodes_curq r7
155 %define nodes_prevq r8
156 %define node_score(x) x*8
157 %define node_level_idx(x) 64+x*4
158 %define node_cabac_state(x) 96+x*4
159 lea nodes_curq, [level_tree + level_tree_size]
160 lea nodes_prevq, [nodes_curq + 8*SIZEOF_NODE]
161 mov r6, TRELLIS_SCORE_BIAS
162 mov [nodes_curq + node_score(0)], r6
163 mov dword [nodes_curq + node_level_idx(0)], 0
164 movd mm0, [level_statem + 0]
165 punpcklbw mm0, [level_statem + 4]
166 punpcklwd mm0, [level_statem + 8]
167 %define level_state_packed mm0 ; version for copying into node.cabac_state
168 pcmpeqb m7, m7 ; TRELLIS_SCORE_MAX
169 movq [nodes_curq + node_score(1)], m7
170 mova [nodes_curq + node_score(2)], m7
172 %define levels_usedq r4
173 %define levels_usedd r4d
174 mov dword [level_tree], 0
177 %define abs_levelq r9
178 %define abs_leveld r9d
179 %define abs_coefq r14
184 mov dword levelgt1_ctxm, 8
186 mov dword levelgt1_ctxm, 9
189 movd m6, psy_trellism
190 %define psy_trellis m6
192 movd m6, [unquant_mfq]
195 %define unquant_mf m6
199 mov unquant_mfm, unquant_mfq
201 ; Keep a single offset register to PICify all global constants.
202 ; They're all relative to "beginning of this asm file's .text section",
203 ; even tables that aren't in this file.
204 ; (Any address in .text would work, this one was just convenient.)
206 %define GLOBAL +r0-$$
211 TRELLIS_LOOP 0 ; node_ctx 0..3
212 TRELLIS_LOOP 1 ; node_ctx 1..7
215 ; int level = bnode->level_idx;
216 ; for( int i = b_ac; i <= last_nnz; i++ )
217 ; dct[zigzag[i]] = SIGN(level_tree[level].abs_level, orig_coefs[zigzag[i]]);
218 ; level = level_tree[level].next;
222 %if num_coefs == 16 && dc == 0
227 mov r0d, [nodes_curq + node_level_idx(0) + rax*4]
229 movzx r2, byte [zigzagq + iiq]
231 movd m0, [level_tree + r0*4]
232 movzx r0, word [level_tree + r0*4]
234 movd m1, [dctq + r2*SIZEOF_DCTCOEF]
237 movd [dctq + r2*SIZEOF_DCTCOEF], m0
241 mov [dctq + r2*SIZEOF_DCTCOEF], r4w
244 mov r5d, [level_tree + r0*4]
246 mov r4d, dword [dctq + r2*SIZEOF_DCTCOEF]
248 movsx r4d, word [dctq + r2*SIZEOF_DCTCOEF]
256 mov [dctq + r2*SIZEOF_DCTCOEF], r5d
258 mov [dctq + r2*SIZEOF_DCTCOEF], r5w
269 %if num_coefs == 16 && dc == 0
284 %macro TRELLIS_LOOP 1 ; ctx_hi
286 ; if( !quant_coefs[i] )
289 mov abs_leveld, dword [r6 + iiq*SIZEOF_DCTCOEF]
291 movsx abs_leveld, word [r6 + iiq*SIZEOF_DCTCOEF]
294 ; int sigindex = num_coefs == 64 ? significant_coeff_flag_offset_8x8[b_interlaced][i] :
295 ; num_coefs == 8 ? coeff_flag_offset_chroma_422_dc[i] : i;
296 mov r10, cabac_state_sigm
298 mov r6d, b_interlacedm
301 movzx r6d, byte [significant_coeff_flag_offset_8x8 + r6 GLOBAL]
303 movzx r6d, byte [significant_coeff_flag_offset_8x8 + r6 + iiq]
305 movzx r10, byte [r10 + r6]
307 movzx r13, byte [coeff_flag_offset_chroma_422_dc + iiq GLOBAL]
308 movzx r10, byte [r10 + r13]
310 movzx r10, byte [r10 + iiq]
313 test abs_leveld, abs_leveld
314 jnz %%.nonzero_quant_coef
317 ; int cost_sig0 = x264_cabac_size_decision_noup2( &cabac_state_sig[sigindex], 0 )
318 ; * (uint64_t)lambda2 >> ( CABAC_SIZE_BITS - LAMBDA_BITS );
319 ; nodes_cur[0].score -= cost_sig0;
320 movzx r10, word [cabac_entropy + r10*2 GLOBAL]
322 shr r10, CABAC_SIZE_BITS - LAMBDA_BITS
323 sub [nodes_curq + node_score(0)], r10
325 ZERO_LEVEL_IDX %1, cur
328 %%.nonzero_quant_coef:
329 ; int sign_coef = orig_coefs[zigzag[i]];
330 ; int abs_coef = abs( sign_coef );
331 ; int q = abs( quant_coefs[i] );
332 movzx zigzagid, byte [zigzagq+iiq]
336 movd m1, [r6 + zigzagiq*SIZEOF_DCTCOEF]
338 movd m1, [r6 + zigzagiq*SIZEOF_DCTCOEF - 2]
341 punpcklqdq m0, m0 ; quant_coef
342 punpcklqdq m1, m1 ; sign_coef
345 pabsd m2, m1 ; abs_coef
348 pcmpgtd m8, m1 ; sign_mask
354 psubd m0, [sq_1] ; abs_level
357 xchg nodes_curq, nodes_prevq
359 ; if( i < num_coefs-1 )
360 ; int lastindex = num_coefs == 64 ? last_coeff_flag_offset_8x8[i] : i;
361 ; num_coefs == 8 ? coeff_flag_offset_chroma_422_dc[i] : i
362 ; cost_siglast[0] = x264_cabac_size_decision_noup2( &cabac_state_sig[sigindex], 0 );
363 ; cost_sig1 = x264_cabac_size_decision_noup2( &cabac_state_sig[sigindex], 1 );
364 ; cost_siglast[1] = x264_cabac_size_decision_noup2( &cabac_state_last[lastindex], 0 ) + cost_sig1;
365 ; cost_siglast[2] = x264_cabac_size_decision_noup2( &cabac_state_last[lastindex], 1 ) + cost_sig1;
367 %if dc && num_coefs != 8
374 movzx r11, word [cabac_entropy + r10*2 GLOBAL]
376 movzx r12, word [cabac_entropy + r10*2 GLOBAL]
377 mov [cost_siglast+0], r11d
378 mov r10, cabac_state_lastm
380 movzx r6d, byte [last_coeff_flag_offset_8x8 + iiq GLOBAL]
381 movzx r10, byte [r10 + r6]
383 movzx r10, byte [r10 + r13]
385 movzx r10, byte [r10 + iiq]
387 movzx r11, word [cabac_entropy + r10*2 GLOBAL]
389 mov [cost_siglast+4], r11d
392 movzx r10, word [cabac_entropy + r10*2 GLOBAL]
394 mov [cost_siglast+8], r10d
398 ; int unquant_abs_level = ((unquant_mf[zigzag[i]] * abs_level + 128) >> 8);
399 ; int d = abs_coef - unquant_abs_level;
400 ; uint64_t ssd = (int64_t)d*d * coef_weight[i];
402 pmuludq m0, unquant_mf
406 movd m3, [r10 + zigzagiq*4]
408 movd m3, [unquant_mfq + zigzagiq*4]
414 psrld m0, 8 ; unquant_abs_level
423 movd m5, [dct_weight2_tab + zigzagiq*4 GLOBAL]
431 ; int predicted_coef = fenc_dct[zigzag[i]] - sign_coef
432 ; int psy_value = abs(unquant_abs_level + SIGN(predicted_coef, sign_coef));
433 ; int psy_weight = dct_weight_tab[zigzag[i]] * h->mb.i_psy_trellis;
434 ; ssd1[k] -= psy_weight * psy_value;
437 movd m3, [r6 + zigzagiq*SIZEOF_DCTCOEF]
439 movd m3, [r6 + zigzagiq*SIZEOF_DCTCOEF - 2]
440 psrad m3, 16 ; orig_coef
444 psignd m4, m1 ; SIGN(unquant_abs_level, sign_coef)
448 psubd m3, m1 ; predicted_coef
456 movd m1, [dct_weight1_tab + zigzagiq*4 GLOBAL]
457 pmuludq m1, psy_trellis
469 %if dc == 0 && %1 == 0
471 jnz %%.skip_dc_rounding
473 ; Optimize rounding for DC coefficients in DC-only luma 4x4/8x8 blocks.
474 ; int d = abs_coef - ((unquant_abs_level + (sign_coef>>31) + 8)&~15);
475 ; uint64_t ssd = (int64_t)d*d * coef_weight[i];
476 psrad m1, 31 ; sign_coef>>31
479 pand m4, [pd_m16] ; (unquant_abs_level + (sign_coef>>31) + 8)&~15
488 %assign stack_offset_bak stack_offset
492 mov r10, [ssd] ; trellis_coef* args
495 ; for( int j = 0; j < 8; j++ )
496 ; nodes_cur[j].score = TRELLIS_SCORE_MAX;
498 mova [nodes_curq + node_score(0)], m7
499 mova [nodes_curq + node_score(2)], m7
500 %else ; avoid store-forwarding stalls on k8/k10
502 movq [nodes_curq + node_score(0)], m7
504 movq [nodes_curq + node_score(1)], m7
505 movq [nodes_curq + node_score(2)], m7
506 movq [nodes_curq + node_score(3)], m7
508 mova [nodes_curq + node_score(4)], m7
509 mova [nodes_curq + node_score(6)], m7
512 call trellis_coefn.entry%1
513 call trellis_coefn.entry%1b
516 call trellis_coef1.entry%1
517 call trellis_coefn.entry%1b
520 call trellis_coef0_%1
521 call trellis_coef1.entry%1b
525 %if num_coefs == 16 && dc == 0
530 call trellis_bnode_%1
532 %if num_coefs == 16 && dc == 0
541 mov [cost_siglast+0], r6
542 mov [cost_siglast+8], r6d
545 %endmacro ; TRELLIS_LOOP
547 ; just a synonym for %if
554 %macro ZERO_LEVEL_IDX 2 ; ctx_hi, prev
555 ; for( int j = 0; j < 8; j++ )
556 ; nodes_cur[j].level_idx = levels_used;
557 ; level_tree[levels_used].next = (trellis_level_t){ .next = nodes_cur[j].level_idx, .abs_level = 0 };
560 and levels_usedd, ~3 ; allow aligned stores
561 movd m0, levels_usedd
565 IF%1 paddd m1, [pd_4567]
566 mova m2, [nodes_%2q + node_level_idx(0)]
567 IF%1 mova m3, [nodes_%2q + node_level_idx(4)]
568 mova [nodes_curq + node_level_idx(0)], m0
569 IF%1 mova [nodes_curq + node_level_idx(4)], m1
570 mova [level_tree + (levels_usedq+0)*4], m2
571 IF%1 mova [level_tree + (levels_usedq+4)*4], m3
572 add levels_usedd, (1+%1)*4
576 TRELLIS trellis_cabac_4x4, 16, 0, 0
577 TRELLIS trellis_cabac_8x8, 64, 0, 0
578 TRELLIS trellis_cabac_4x4_psy, 16, 0, 1
579 TRELLIS trellis_cabac_8x8_psy, 64, 0, 1
580 TRELLIS trellis_cabac_dc, 16, 1, 0
581 TRELLIS trellis_cabac_chroma_422_dc, 8, 1, 0
583 TRELLIS trellis_cabac_4x4, 16, 0, 0
584 TRELLIS trellis_cabac_8x8, 64, 0, 0
585 TRELLIS trellis_cabac_4x4_psy, 16, 0, 1
586 TRELLIS trellis_cabac_8x8_psy, 64, 0, 1
587 TRELLIS trellis_cabac_dc, 16, 1, 0
588 TRELLIS trellis_cabac_chroma_422_dc, 8, 1, 0
592 %define stack rsp+gprsize
600 global mangle(x264_%1)
603 %assign stack_offset stack_offset_bak+gprsize
606 %macro TRELLIS_BNODE 1 ; ctx_hi
607 clocal trellis_bnode_%1
608 ; int j = ctx_hi?1:0;
609 ; trellis_node_t *bnode = &nodes_cur[j];
610 ; while( ++j < (ctx_hi?8:4) )
611 ; if( nodes_cur[j].score < bnode->score )
612 ; bnode = &nodes_cur[j];
614 mov rax, [nodes_curq + node_score(j)]
618 mov r11, [nodes_curq + node_score(j)]
626 %endmacro ; TRELLIS_BNODE
631 %macro TRELLIS_COEF0 1 ; ctx_hi
632 clocal trellis_coef0_%1
633 ; ssd1 += (uint64_t)cost_sig * lambda2 >> ( CABAC_SIZE_BITS - LAMBDA_BITS );
634 mov r11d, [cost_siglast+0]
636 shr r11, CABAC_SIZE_BITS - LAMBDA_BITS
639 ; nodes_cur[0].score = nodes_prev[0].score + ssd - ssd1;
640 mov scoreq, [nodes_prevq + node_score(0)]
643 mov [nodes_curq + node_score(0)], scoreq
646 mov scoreq, [nodes_prevq + node_score(1)]
647 mov [nodes_curq + node_score(1)], scoreq
648 mova m1, [nodes_prevq + node_score(2)]
649 mova [nodes_curq + node_score(2)], m1
651 mova m1, [nodes_prevq + node_score(4)]
652 mova [nodes_curq + node_score(4)], m1
653 mova m1, [nodes_prevq + node_score(6)]
654 mova [nodes_curq + node_score(6)], m1
656 mov r6d, [nodes_prevq + node_cabac_state(3)]
657 mov [nodes_curq + node_cabac_state(3)], r6d
659 mova m1, [nodes_prevq + node_cabac_state(4)]
660 mova [nodes_curq + node_cabac_state(4)], m1
662 ZERO_LEVEL_IDX %1, prev
664 %endmacro ; TRELLIS_COEF0
670 %macro START_COEF 1 ; gt1
671 ; if( (int64_t)nodes_prev[0].score < 0 ) continue;
672 mov scoreq, [nodes_prevq + node_score(j)]
675 js .ctx %+ nextj_if_invalid
678 ; f8_bits += x264_cabac_size_decision2( &n.cabac_state[coeff_abs_level1_ctx[j]], abs_level > 1 );
680 movzx r6d, byte [nodes_prevq + node_cabac_state(j) + (coeff_abs_level1_offs>>2)] ; >> because node only stores ctx 0 and 4
681 movzx r11, byte [cabac_transition + r6*2 + %1 GLOBAL]
683 movzx r6d, byte [level_statem + coeff_abs_level1_offs]
688 movzx bitsd, word [cabac_entropy + r6*2 GLOBAL]
691 ; unsigned f8_bits = cost_siglast[ j ? 1 : 2 ];
694 add bitsd, [cost_siglast+8]
697 add bitsd, [cost_siglast+4]
699 %endmacro ; START_COEF
702 ; n.score += (uint64_t)f8_bits * lambda2 >> ( CABAC_SIZE_BITS - LAMBDA_BITS );
704 shr bitsq, CABAC_SIZE_BITS - LAMBDA_BITS
707 ; if( n.score < nodes_cur[node_ctx].score )
708 ; SET_LEVEL( n, abs_level );
709 ; nodes_cur[node_ctx] = n;
710 cmp scoreq, [nodes_curq + node_score(node_ctx)]
711 jae .ctx %+ nextj_if_valid
712 mov [nodes_curq + node_score(node_ctx)], scoreq
713 %if j == 2 || (j <= 3 && node_ctx == 4)
714 ; if this node hasn't previously needed to keep track of abs_level cabac_state, import a pristine copy of the input states
715 movd [nodes_curq + node_cabac_state(node_ctx)], level_state_packed
717 ; if we have updated before, then copy cabac_state from the parent node
718 mov r6d, [nodes_prevq + node_cabac_state(j)]
719 mov [nodes_curq + node_cabac_state(node_ctx)], r6d
721 %if j >= 3 ; skip the transition if we're not going to reuse the context
722 mov [nodes_curq + node_cabac_state(node_ctx) + (coeff_abs_level1_offs>>2)], r11b ; delayed from x264_cabac_size_decision2
724 %if %1 && node_ctx == 7
725 mov r6d, levelgt1_ctxm
726 mov [nodes_curq + node_cabac_state(node_ctx) + coeff_abs_levelgt1_offs-6], r10b
728 mov r6d, [nodes_prevq + node_level_idx(j)]
736 mov [level_tree + levels_usedq*4], r6d
737 mov [nodes_curq + node_level_idx(node_ctx)], levels_usedd
745 %assign nextj_if_valid %1+1
746 %assign nextj_if_invalid %2
748 %assign coeff_abs_level1_offs j+1
750 %assign coeff_abs_level1_offs 0
759 add bitsd, 1 << CABAC_SIZE_BITS
765 %assign nextj_if_valid %2
766 %assign nextj_if_invalid %2
768 %assign coeff_abs_level1_offs j+1
769 %assign coeff_abs_levelgt1_offs 5
771 %assign coeff_abs_level1_offs 0
772 %assign coeff_abs_levelgt1_offs j+2 ; this is the one used for all block types except 4:2:2 chroma dc
783 ; if( abs_level >= 15 )
784 ; bits += bs_size_ue_big(...)
785 add bitsd, r5d ; bs_size_ue_big from COEFN_SUFFIX
786 ; n.cabac_state[levelgt1_ctx]
787 %if j == 7 ; && compiling support for 4:2:2
788 mov r6d, levelgt1_ctxm
789 %define coeff_abs_levelgt1_offs r6
792 movzx r10, byte [nodes_prevq + node_cabac_state(j) + coeff_abs_levelgt1_offs-6] ; -6 because node only stores ctx 8 and 9
794 movzx r10, byte [level_statem + coeff_abs_levelgt1_offs]
796 ; f8_bits += cabac_size_unary[abs_level-1][n.cabac_state[levelgt1_ctx[j]]];
798 movzx r6d, word [cabac_size_unary + (r10-128)*2 GLOBAL]
801 movzx r10, byte [cabac_transition_unary + r10-128 GLOBAL]
809 .entry0b: ; ctx_lo, larger of the two abs_level candidates
814 .entry0: ; ctx_lo, smaller of the two abs_level candidates
821 .entry1b: ; ctx_hi, larger of the two abs_level candidates
824 .entry1: ; ctx_hi, smaller of the two abs_level candidates
836 %macro COEFN_PREFIX 1
837 ; int prefix = X264_MIN( abs_level - 1, 14 );
842 .skip_level_suffix%1:
846 %macro COEFN_SUFFIX 1
848 ; bs_size_ue_big( abs_level - 15 ) << CABAC_SIZE_BITS;
849 lea r5d, [abs_levelq-14]
851 shl r5d, CABAC_SIZE_BITS+1
852 add r5d, 1<<CABAC_SIZE_BITS
853 ; int prefix = X264_MIN( abs_level - 1, 14 );
855 jmp .skip_level_suffix%1
864 ; I could fully separate the ctx_lo and ctx_hi versions of coefn, and then
865 ; apply return-on-first-failure to ctx_lo. Or I can use multiple entrypoints
866 ; to merge the common portion of ctx_lo and ctx_hi, and thus reduce codesize.
867 ; I can't do both, as return-on-first-failure doesn't work for ctx_hi.
868 ; The C version has to be fully separate since C doesn't support multiple
869 ; entrypoints. But return-on-first-failure isn't very important here (as
870 ; opposed to coef1), so I might as well reduce codesize.
877 mov zigzagq, zigzagm ; unspill since r1 was clobbered