1
; vim:filetype=nasm ts=8
3
; libFLAC - Free Lossless Audio Codec library
4
; Copyright (C) 2001,2002,2003,2004,2005,2006,2007 Josh Coalson
6
; Redistribution and use in source and binary forms, with or without
7
; modification, are permitted provided that the following conditions
10
; - Redistributions of source code must retain the above copyright
11
; notice, this list of conditions and the following disclaimer.
13
; - Redistributions in binary form must reproduce the above copyright
14
; notice, this list of conditions and the following disclaimer in the
15
; documentation and/or other materials provided with the distribution.
17
; - Neither the name of the Xiph.org Foundation nor the names of its
18
; contributors may be used to endorse or promote products derived from
19
; this software without specific prior written permission.
21
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
; ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
25
; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26
; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27
; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28
; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29
; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30
; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
cglobal precompute_partition_info_sums_32bit_asm_ia32_
42
; **********************************************************************
44
; void FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
45
; void precompute_partition_info_sums_32bit_(
46
; const FLAC__int32 residual[],
47
; FLAC__uint64 abs_residual_partition_sums[],
49
; unsigned predictor_order,
50
; unsigned min_partition_order,
51
; unsigned max_partition_order
55
cident precompute_partition_info_sums_32bit_asm_ia32_
57
;; peppered throughout the code at major checkpoints are keys like this as to where things are at that point in time
58
;; [esp + 4] const FLAC__int32 residual[]
59
;; [esp + 8] FLAC__uint64 abs_residual_partition_sums[]
60
;; [esp + 12] unsigned blocksize
61
;; [esp + 16] unsigned predictor_order
62
;; [esp + 20] unsigned min_partition_order
63
;; [esp + 24] unsigned max_partition_order
69
;; [esp + 28] const FLAC__int32 residual[]
70
;; [esp + 32] FLAC__uint64 abs_residual_partition_sums[]
71
;; [esp + 36] unsigned blocksize
72
;; [esp + 40] unsigned predictor_order
73
;; [esp + 44] unsigned min_partition_order
74
;; [esp + 48] unsigned max_partition_order
76
;; [esp + 4] default_partition_samples
81
mov [esp], eax ; [esp] <- partitions = 1u << max_partition_order;
84
mov [esp + 4], eax ; [esp + 4] <- default_partition_samples = blocksize >> max_partition_order;
87
; first do max_partition_order
90
sub edi, [esp + 40] ; edi <- end = (unsigned)(-(int)predictor_order) + default_partition_samples
91
xor esi, esi ; esi <- residual_sample = 0
92
xor ecx, ecx ; ecx <- partition = 0
93
mov ebp, [esp + 28] ; ebp <- residual[]
94
xor ebx, ebx ; ebx <- abs_residual_partition_sum = 0;
95
; note we put the updates to 'end' and 'abs_residual_partition_sum' at the end of loop0 and in the initialization above so we could align loop0 and loop1
97
.loop0: ; for(partition = residual_sample = 0; partition < partitions; partition++) {
98
.loop1: ; for( ; residual_sample < end; residual_sample++)
99
mov eax, [ebp + esi * 4]
103
add ebx, eax ; abs_residual_partition_sum += abs(residual[residual_sample]);
104
;@@@@@@ check overflow flag and abort here?
106
cmp esi, edi ; /* since the loop will always run at least once, we can put the loop check down here */
109
add edi, [esp + 4] ; end += default_partition_samples;
111
mov [eax + ecx * 8], ebx ; abs_residual_partition_sums[partition] = abs_residual_partition_sum;
112
mov [eax + ecx * 8 + 4], dword 0
113
xor ebx, ebx ; abs_residual_partition_sum = 0;
115
cmp ecx, [esp] ; /* since the loop will always run at least once, we can put the loop check down here */
119
; now merge partitions for lower orders
121
mov esi, [esp + 32] ; esi <- abs_residual_partition_sums[from_partition==0];
123
lea edi, [esi + eax * 8] ; edi <- abs_residual_partition_sums[to_partition==partitions];
125
sub ecx, byte 1 ; ecx <- partition_order = (int)max_partition_order - 1;
127
.loop2: ; for(; partition_order >= (int)min_partition_order; partition_order--) {
131
shl edx, cl ; const unsigned partitions = 1u << partition_order;
133
.loop3: ; for(i = 0; i < partitions; i++) {
139
mov [edi + 4], ebx ; a_r_p_s[to_partition] = a_r_p_s[from_partition] + a_r_p_s[from_partition+1];
157
%ifdef OBJ_FORMAT_elf
158
section .note.GNU-stack noalloc