iquant.s 4.03 KB
/*
 * iquant.s		Thu Aug  3 18:08:27 PDT 1995
 *
 *
 * inverse quantization for MPEG
 *	Inputs:	iq_in_dat	- Input data address
 *		iq_out_dat	- Output data address (can be the same as in_dat)
 *		iq_in_cbp	- Coded Block Pattern
 *		iq_in_intra	- Intra block flag
 *		iq_in_quant	- Quant scale factor address
 *
 *	Outputs:
 *		data at iq_out_dat	- IQ'ed data
 */

/* #define _FIQUANT */
	
#include "iquant.h"


iq:	nop
	nop
	
iquant_init:
	vxor	vconsts, vconsts, vconsts
	
	# setup addresses
	addi	consts_addr, rzero, IQ_CONST_BASE

	# load vconsts
	lqv	vconsts[0], IQ_CONSTS(consts_addr)

	bne	iq_in_intra, rzero, iqmat
	nop

niqmat:
	addi	qmat_addr, consts_addr, NONI_QMAT
	j	load_qmat
	nop

iqmat:
	addi	qmat_addr, consts_addr, INTRA_QMAT

load_qmat:	
	lqv	qmat_r0[0], 0(qmat_addr)
	lqv	qmat_r1[0], 16(qmat_addr)
	lqv	qmat_r2[0], 32(qmat_addr)
	lqv	qmat_r3[0], 48(qmat_addr)
	lqv	qmat_r4[0], 64(qmat_addr)
	lqv	qmat_r5[0], 80(qmat_addr)
	lqv	qmat_r6[0], 96(qmat_addr)
	lqv	qmat_r7[0], 112(qmat_addr)
	

	# get qmat scale factor

	lsv	vconsts[QUANT_LOAD], 0(iq_in_quant)

	###	quant scaling	###
	
	vmudh	qscale, vconsts, vconsts[QUANT]
	
	
iquant_loop:	
	andi	dummy, iq_in_cbp, 1
	bgtz	dummy, iquant_do
	srl	iq_in_cbp, iq_in_cbp, 1
	blez	iq_in_cbp, iquant_done
	addi	iq_in_dat, iq_in_dat, 128
	j	iquant_loop
	addi	iq_out_dat, iq_out_dat, 128
	
iquant_done:	
	jr	return
	nop
		
	
iquant_do:
	
	lqv	in_r0[0],	0(iq_in_dat)
	lqv	in_r1[0],	16(iq_in_dat)
	lqv	in_r2[0],	32(iq_in_dat)
	lqv	in_r3[0],	48(iq_in_dat)
	
	###	get DC term	###

	vmudh	dc,	in_r0,	vconsts[SHIFT_L]


row_scale:
			lqv	in_r4[0],	64(iq_in_dat)
	vmudh	out_r0,	in_r0,	qscale[SCALE2]
			lqv	in_r5[0],	80(iq_in_dat)
	vmudh	out_r1,	in_r1,	qscale[SCALE2]
			lqv	in_r6[0],	96(iq_in_dat)
	vmudh	out_r2,	in_r2,	qscale[SCALE2]
			lqv	in_r7[0],	112(iq_in_dat)
	vmudh	out_r3,	in_r3,	qscale[SCALE2]
			addi	iq_in_dat,	iq_in_dat, 128
	vmudh	out_r4,	in_r4,	qscale[SCALE2]
	vmudh	out_r5,	in_r5,	qscale[SCALE2]
	vmudh	out_r6,	in_r6,	qscale[SCALE2]
	vmudh	out_r7,	in_r7,	qscale[SCALE2]
	

	bne	iq_in_intra,   rzero,	iquant
	nop
	


	###	calculate sign	(stored in in_r?) ###
	
get_sign:	
	vabs	in_r0,	in_r0,	qscale[SCALE]
	vabs	in_r1,	in_r1,	qscale[SCALE]
	vabs	in_r2,	in_r2,	qscale[SCALE]
	vabs	in_r3,	in_r3,	qscale[SCALE]
	vabs	in_r4,	in_r4,	qscale[SCALE]
	vabs	in_r5,	in_r5,	qscale[SCALE]
	vabs	in_r6,	in_r6,	qscale[SCALE]
	vabs	in_r7,	in_r7,	qscale[SCALE]
	
	###	add sign	###

add_sign:
	vadd	out_r0,	in_r0,	out_r0
	vadd	out_r1,	in_r1,	out_r1
	vadd	out_r2,	in_r2,	out_r2
	vadd	out_r3,	in_r3,	out_r3
			lqv	in_r0[0],	0(iq_in_dat)
	vadd	out_r4,	in_r4,	out_r4
			lqv	in_r1[0],	16(iq_in_dat)
	vadd	out_r5,	in_r5,	out_r5
			lqv	in_r2[0],	32(iq_in_dat)
	vadd	out_r6,	in_r6,	out_r6
			lqv	in_r3[0],	48(iq_in_dat)
	vadd	out_r7,	in_r7,	out_r7
	
	
		
iquant:
#ifdef _FIQUANT
	vmulq	out_r0, out_r0, qmat_r0
	vmulq	out_r1, out_r1, qmat_r1
	vmulq	out_r2, out_r2, qmat_r2
	vmulq	out_r3, out_r3, qmat_r3
	vmulq	out_r4, out_r4, qmat_r4
			sqv	out_r0[0],	0(iq_out_dat)
	vmulq	out_r5, out_r5, qmat_r5
			sqv	out_r1[0],	16(iq_out_dat)
	vmulq	out_r6, out_r6, qmat_r6
			sqv	out_r2[0],	32(iq_out_dat)
	vmulq	out_r7, out_r7, qmat_r7
			sqv	out_r3[0],	48(iq_out_dat)
			sqv	out_r4[0],	64(iq_out_dat)
#else
	vmulq	out_r0, out_r0,	qmat_r0
	vmacq	out_r0, vzero,	vzero

	vmulq	out_r1,	out_r1,	qmat_r1
	vmacq	out_r1, vzero,	vzero

	vmulq	out_r2,	out_r2,	qmat_r2
	vmacq	out_r2,	vzero,	vzero
			sqv	out_r0[0],	0(iq_out_dat)

	vmulq	out_r3,	out_r3,	qmat_r3
	vmacq	out_r3,	vzero,	vzero
			sqv	out_r1[0],	16(iq_out_dat)

	vmulq	out_r4,	out_r4,	qmat_r4
	vmacq	out_r4,	vzero,	vzero
			sqv	out_r2[0],	32(iq_out_dat)
		
	vmulq	out_r5,	out_r5,	qmat_r5
	vmacq	out_r5,	vzero,	vzero
			sqv	out_r3[0],	48(iq_out_dat)

	vmulq	out_r6,	out_r6,	qmat_r6
	vmacq	out_r6,	vzero,	vzero
			sqv	out_r4[0],	64(iq_out_dat)

	vmulq	out_r7,	out_r7,	qmat_r7
	vmacq	out_r7,	vzero,	vzero
#endif
	
	sqv	out_r5[0],	80(iq_out_dat)
	sqv	out_r6[0],	96(iq_out_dat)
	sqv	out_r7[0],	112(iq_out_dat)
	
	blez	iq_in_cbp,	iquant_done
	ssv	dc[0],		0(iq_out_dat)
	j	iquant_loop
	addi	iq_out_dat,	iq_out_dat,	128
	
#include "iquant_un.h"