/*
 * Does the cfadd64 instruction set the carry flag?
 */

#include "dspsc.h"

         unsigned long long one, two;
volatile unsigned long long result;
volatile int carry;

void addcf64();

main()
{
	read_dspsc();
	dspsc.ISAT = 1;
	write_dspsc();

	printf("ull size is %d\n", sizeof(one));
        one = 0xffffffffffffffffULL;
        two = 0x0000000000000002ULL;
	result = 0x0000000000000000ULL;
	addcf64();
        printf("Op 1: %llu\n", one);
        printf("Op 2: %llu\n", two);
        printf("Result: %llu\n", result);
        printf("Carry: %d\n", carry);
}
	
void addcf64()
{

	// Clear carry flag
	asm("msr CPSR_flg,#0");

	asm("ldr	r3, =one");	// r3 = &one
	asm("nop; nop; nop; nop; nop;");
	asm("cfldr64	mvdx4, [r3]");	// mvdx4 = one
	asm("ldr	r3, =two");	// r3 = &two
	asm("nop; nop; nop; nop; nop;");
	asm("cfldr64	mvdx5, [r3]");	// mvdx5 = two

        asm("cfadd64   mvdx6, mvdx5, mvdx4");

        asm("movcc	r0, #0");
        asm("movcs	r0, #1");

	asm("ldr	r3, =result");	// r3 = &result
	asm("nop; nop; nop; nop; nop;");
	asm("cfstr64	mvdx6, [r3]");	// result = mvdx6
	asm("ldr	r3, =carry");	// r3 = &result
	asm("str	r0, [r3]");	// carry = r0
}

