# sh testcase for ftrc -*- Asm -*-
# mach: all
# as: -isa=shcompact
# ld: -m shelf32

	.include "compact/testutils.inc"

	start

	# ftrc(0.0) = 0.
	fldi0 fr0
	ftrc fr0, fpul
	# check results.
	mov #0, r0
	sts fpul, r1
	cmp/eq r0, r1
	bf wrong
	
	# ftrc(1.5) = 1.
	fldi1 fr0
	fldi1 fr1
	fldi1 fr2
	# double it.
	fadd fr2, fr2
	# form the fraction.
	fdiv fr2, fr1
	fadd fr1, fr0
	# now we've got 1.5 in fr0.
	ftrc fr0, fpul
	# check results.
	mov #1, r0
	sts fpul, r1
	cmp/eq r0, r1
	bf wrong

	# ftrc(-1.5) = -1.
	fldi1 fr0
	fneg fr0
	fldi1 fr1
	fldi1 fr2
	# double it.
	fadd fr2, fr2
	# form the fraction.
	fdiv fr2, fr1
	fneg fr1
	# -1 + -0.5 = -1.5.
	fadd fr1, fr0
	# now we've got 1.5 in fr0.
	ftrc fr0, fpul
	# check results.
	mov #1, r0
	neg r0, r0
	sts fpul, r1
	cmp/eq r0, r1
	bf wrong

	bra double
	nop

wrong:
	fail

double:
	# ftrc(0.0) = 0.
	fldi0 fr0
	_s2d fr0, dr0
	_setpr
	ftrc dr0, fpul
	_clrpr
	# check results.
	mov #0, r0
	sts fpul, r1
	cmp/eq r0, r1
foo:	
	bf wrong2

	# ftrc(1.5) = 1.
	fldi1 fr0
	fldi1 fr2
	fldi1 fr4
	# double it.
	fadd fr4, fr4
	# form 0.5.
	fdiv fr4, fr2
	fadd fr2, fr0
	# now we've got 1.5 in fr0, so do some single->double
	# conversions and perform the ftrc.
	_s2d fr0, dr0
	_s2d fr2, dr2
	_s2d fr4, dr4
	_setpr
	ftrc dr0, fpul
	_clrpr
	
	# check results.
	mov #1, r0
	sts fpul, r1
	cmp/eq r0, r1
	bf wrong2

	# ftrc(-1.5) = -1.
	fldi1 fr0
	fneg fr0
	fldi1 fr2
	fldi1 fr4
	# double it.
	fadd fr4, fr4
	# form the fraction.
	fdiv fr4, fr2
	fneg fr2
	# -1 + -0.5 = -1.5.
	fadd fr2, fr0
	# now we've got 1.5 in fr0, so do some single->double
	# conversions and perform the ftrc.
	_s2d fr0, dr0
	_s2d fr2, dr2
	_s2d fr4, dr4
	_setpr
	ftrc dr0, fpul
	_clrpr
	
	# check results.
	mov #1, r0
	neg r0, r0
	sts fpul, r1
	cmp/eq r0, r1
	bf wrong2

okay:
	pass
wrong2:
	fail
