
;  GNU C 2.7.2 [AL 1.1, MM 40] RISC NEWS-OS compiled by CC

;  Cc1 defaults:
;  -mmemcpy

;  Cc1 arguments (-G value = 0, Cpu = 3000, ISA = 1):
;  -quiet -dumpbase -O2 -Wall -o

gcc2_compiled.:
__gnu_compiled_c:
	.code
	.align	2
adpcm_tbl:
	.half	233
	.half	-29440
	.half	375
	.half	1793
	.half	233
	.half	29695
	.half	375
	.half	-1538
; APP
	
	.code
	.align 1
	.global adpcm_mix1
adpcm_mix1:
	; %r12 = pch
	; %r13 = mixbuf
;//{{-----------------------------------;
;//	pushn	%r0
;//→* Fri Dec 22 00:19:41 JST 2006 Naoyuki Sawa
;//→- 係数テーブルを変更し、最適化してレジスタを節約できたので、不要になりました。
;//}}-----------------------------------;
	ext	0x5		; 	xld.w	%r4,  320		; %r4  = ADPCMBUFLEN
	ld.w	%r4,0x0
	ld.w	%r5,  [%r12]+		; %r5  = pcm      = pch->pcm     , %r12 = &pch->data
	ld.h	%r6,  [%r12]+		; %r6  = data     = pch->data    , %r12 = &pch->delta
	ld.h	%r7,  [%r12]+		; %r7  = delta    = pch->delta   , %r12 = &pch->progress
	ld.h	%r10, [%r12]+		; %r10 = progress = pch->progress, %r12 = &pch->rate
	ld.h	%r11, [%r12]+		; %r11 = rate     = pch->rate    , %r12 = &pch->len
	ld.w	%r14, [%r12]+		; %r14 = len      = pch->len     , %r12 = &pch->ptr
	ld.w	%r15, [%r12]+		; %r15 = ptr      = pch->ptr     , %r12 = &pch->loop
adpcm_mix1_L10:				; do {
	sub	%r10, %r11		;   progress -= rate 
	jrge	adpcm_mix1_L30	; 	xjrge	adpcm_mix1_L30		;   if(progress < 0) {
	ext	0xfa		; 	xadd	%r10, %r10, 16000	;     progress += SPEAKER_FREQUENCY
	add	%r10,0x0
	cmp	%r6,0x10	; 	xcmp	%r6, 16			;     if(data < (1<<(2+2))) {
	jrge	adpcm_mix1_L20	; 	xjrge	adpcm_mix1_L20
	ld.ub	%r6, [%r15]+		;       data = (*ptr++ | (1<<8)) << 2
	ext	0x4		; 	xoor	%r6, %r6, 256
	or	%r6,0x0
	sla	%r6,0x2		; 	xsla	%r6, 2
adpcm_mix1_L20:				;     }
	ext	0xc		; 	xand	%r9, %r6, 12		;     %r9 = adpcm = data & (3<<2)
	and	%r9,%r6
	sra	%r6,0x2		; 	xsra	%r6, 2			;     data >>= 2
	ext	adpcm_tbl@ah		;     %r9 = adpcm_tbl[adpcm]
	ext	adpcm_tbl@al
;//{{-----------------------------------;
;//	ld.w	%r9, [%r9]		;     %r9[0:15] = adpcm_tbl[adpcm][0], %r9[31:16] = adpcm_tbl[adpcm][1]
;//	mlt.h	%r9, %r7		;     pcm  += (delta*adpcm_tbl[adpcm][0]) >> 8
;//	ld.w	%r0, %alr		;     ※ここでもう一つレジスタをやりくりできれば
;//	xsra	%r0, 8			;     ※先頭のpush %r0と末尾のpop %r0を無くせるのですが…
;//	add	%r5, %r0		;     ※いろいろ試してみたけれど、断念しました。
;//	xsra	%r9, 16			;     %r9[0:15] = adpcm_tbl[adpcm][1]
;//	mlt.h	%r9, %r7		;     delta = (delta*adpcm_tbl[adpcm][1]) >> 8
;//	ld.w	%r7, %alr
;//	xsra	%r7, 8
;//↓* Fri Dec 22 00:19:41 JST 2006 Naoyuki Sawa
	ld.w	%r9, [%r9]		;     %r9[0:15] = adpcm_tbl[adpcm][0], %r9[31:16] = SWAPH(adpcm_tbl[adpcm][1])
	mlt.h	%r9, %r7		;     delta = (delta*adpcm_tbl[adpcm][0]) >> 8
	ld.w	%r7, %alr
	sra	%r7,0x8		; 	xsra	%r7, 8
	swap	%r9, %r9		;     %r9[0:15] = adpcm_tbl[adpcm][1]
	mlt.h	%r9, %r7		;     pcm  += (delta*adpcm_tbl[adpcm][1]) >> 8
	ld.w	%r9, %alr
	sra	%r9,0x8		; 	xsra	%r9, 8
	add	%r5, %r9
;//}}-----------------------------------;
adpcm_mix1_L30:				;   }
	ld.w	%r9, [%r13]		;   *mixbuf++ = pcm
	add	%r9, %r5
	ld.w	[%r13]+, %r9
	sub	%r14,0x1	; 	xsub	%r14, %r14, 1		;   if(!--len) {
	jrne	adpcm_mix1_L50	; 	xjrne	adpcm_mix1_L50
	ld.w	%r9,[%r12]	; 	xld.w	%r9, [%r12+0]		;     %r9 = loop = pch->loop - 1
	sub	%r9,0x1		; 	xsub	%r9, %r9, 1
	jrlt	adpcm_mix1_L40	; 	xjrlt	adpcm_mix1_L40		;     if(loop >= 0) {
	ld.w	[%r12],%r9	; 	xld.w	[%r12+0], %r9		;       pch->loop = loop
	jreq	adpcm_mix1_L60	; 	xjreq	adpcm_mix1_L60		;       if(!loop) break
adpcm_mix1_L40:				;     }
	ld.w	%r5,0x0		; 	xld.w	%r5,  0			;     pcm      = 0
	ld.w	%r6,0x0		; 	xld.w	%r6,  0			;     data     = 0
	ld.w	%r7,0x10	; 	xld.w	%r7,  16		;     delta    = 16
	ld.w	%r10,0x0	; 	xld.w	%r10, 0			;     progress = 0
	ext	0x4		; 	xld.w	%r14, [%r12+4]		;     len      = pch->init_len
	ld.w	%r14,[%r12]
	ext	0x8		; 	xld.w	%r15, [%r12+8]		;     ptr      = pch->init_ptr
	ld.w	%r15,[%r12]
adpcm_mix1_L50:				;   }
	sub	%r4,0x1		; 	xsub	%r4, %r4, 1		; } while(--n)
	jrne	adpcm_mix1_L10	; 	xjrne	adpcm_mix1_L10
adpcm_mix1_L60:
	sub	%r12,0x14	; 	xsub	%r12, %r12, 20		;                           %r12 = &pch->pcm
	ld.w	[%r12]+, %r5		; pch->pcm      = pcm     , %r12 = &pch->data
	ld.h	[%r12]+, %r6		; pch->data     = data    , %r12 = &pch->delta
	ld.h	[%r12]+, %r7		; pch->delta    = delta   , %r12 = &pch->progress
	ld.h	[%r12]+, %r10		; pch->progress = progress, %r12 = &pch->rate
	ld.h	[%r12]+, %r11		; pch->rate     = rate    , %r12 = &pch->len
	ld.w	[%r12]+, %r14		; pch->len      = len     , %r12 = &pch->ptr
	ld.w	[%r12] , %r15		; pch->ptr      = ptr
;//{{-----------------------------------;
;//	popn	%r0
;//→* Fri Dec 22 00:19:41 JST 2006 Naoyuki Sawa
;//→- 係数テーブルを変更し、最適化してレジスタを節約できたので、不要になりました。
;//}}-----------------------------------;
	ret

	
	.code
	.align 1
	.global adpcm_mix2
adpcm_mix2:
	; %r12 = wbuff
	; %r13 = mixbuf
	ext	0x5		; 	xld.w %r4, 320			; ADPCMBUFLEN=320
	ld.w	%r4,0x0
	ext	0x1ff		; 	xld.w %r5, 32767		; SHRT_MAX= 32767
	ld.w	%r5,0x3f
	not %r6, %r5			; SHRT_MIN=-32768
adpcm_mix2_L10:
	ld.w %r7, [%r13]+
	cmp %r7, %r5
	jrle.d	adpcm_mix2_L20	; 	xjrle.d adpcm_mix2_L20
	cmp %r7, %r6			; *delay*
	ld.w %r7, %r5
adpcm_mix2_L20:
	jrge.d	adpcm_mix2_L30	; 	xjrge.d adpcm_mix2_L30
	sub %r4, 1			; *delay*
	ld.w %r7, %r6
adpcm_mix2_L30:
	ld.h [%r12]+, %r7
	jrne	adpcm_mix2_L10	; 	xjrne adpcm_mix2_L10
	ret

