// File: estwings57[P]CasHMC/sources/HMCController.cpp
// Function: CasHMC::HMCController::ConvTranIntoPacket(CasHMC::Transaction*)
Packet *HMCController::ConvTranIntoPacket(Transaction *tran)
{
	unsigned packetLength;
	unsigned reqDataSize=16;
	PacketCommandType cmdtype;
	
	switch(tran->transactionType) {
		case DATA_READ:
			packetLength = 1; //header + tail
			reqDataSize = tran->dataSize;
			switch(tran->dataSize) {
				case 16:	cmdtype = RD16;		break;
				case 32:	cmdtype = RD32;		break;
				case 48:	cmdtype = RD48;		break;
				case 64:	cmdtype = RD64;		break;
				case 80:	cmdtype = RD80;		break;
				case 96:	cmdtype = RD96;		break;
				case 112:	cmdtype = RD112;	break;
				case 128:	cmdtype = RD128;	break;
				case 256:	cmdtype = RD256;	break;
				default:
					ERROR(header<<"  == Error - WRONG transaction data size  (CurrentClock : "<<currentClockCycle<<")");
					exit(0);
			}
			break;
		case DATA_WRITE:		
			packetLength = tran->dataSize /*[byte] Size of data*/ / 16 /*packet 16-byte*/ + 1 /*header + tail*/;
			reqDataSize = tran->dataSize;
			switch(tran->dataSize) {
				case 16:	cmdtype = WR16;		break;
				case 32:	cmdtype = WR32;		break;
				case 48:	cmdtype = WR48;		break;
				case 64:	cmdtype = WR64;		break;
				case 80:	cmdtype = WR80;		break;
				case 96:	cmdtype = WR96;		break;
				case 112:	cmdtype = WR112;	break;
				case 128:	cmdtype = WR128;	break;
				case 256:	cmdtype = WR256;	break;
				default:
					ERROR(header<<"  == Error - WRONG transaction data size  (CurrentClock : "<<currentClockCycle<<")");
					exit(0);
			}
			break;
		//Arithmetic atomic
		case ATM_2ADD8:		cmdtype = _2ADD8;	packetLength = 2;	break;
		case ATM_ADD16:		cmdtype = ADD16;	packetLength = 2;	break;
		case ATM_P_2ADD8:	cmdtype = P_2ADD8;	packetLength = 2;	break;
		case ATM_P_ADD16:	cmdtype = P_ADD16;	packetLength = 2;	break;
		case ATM_2ADDS8R:	cmdtype = _2ADDS8R;	packetLength = 2;	break;
		case ATM_ADDS16R:	cmdtype = ADDS16R;	packetLength = 2;	break;
		case ATM_INC8:		cmdtype = INC8;		packetLength = 1;	break;
		case ATM_P_INC8:	cmdtype = P_INC8;	packetLength = 1;	break;
		//Boolean atomic
		case ATM_XOR16:		cmdtype = XOR16;	packetLength = 2;	break;
		case ATM_OR16:		cmdtype = OR16;		packetLength = 2;	break;
		case ATM_NOR16:		cmdtype = NOR16;	packetLength = 2;	break;
		case ATM_AND16:		cmdtype = AND16;	packetLength = 2;	break;
		case ATM_NAND16:	cmdtype = NAND16;	packetLength = 2;	break;
		//Comparison atomic
		case ATM_CASGT8:	cmdtype = CASGT8;	packetLength = 2;	break;
		case ATM_CASLT8:	cmdtype = CASLT8;	packetLength = 2;	break;
		case ATM_CASGT16:	cmdtype = CASGT16;	packetLength = 2;	break;
		case ATM_CASLT16:	cmdtype = CASLT16;	packetLength = 2;	break;
		case ATM_CASEQ8:	cmdtype = CASEQ8;	packetLength = 2;	break;
		case ATM_CASZERO16:	cmdtype = CASZERO16;packetLength = 2;	break;
		case ATM_EQ16:		cmdtype = EQ16;		packetLength = 2;	break;
		case ATM_EQ8:		cmdtype = EQ8;		packetLength = 2;	break;
		//Bitwise atomic
		case ATM_BWR:		cmdtype = BWR;		packetLength = 2;	break;
		case ATM_P_BWR:		cmdtype = P_BWR;	packetLength = 2;	break;
		case ATM_BWR8R:		cmdtype = BWR8R;	packetLength = 2;	break;
		case ATM_SWAP16:	cmdtype = SWAP16;	packetLength = 2;	break;
			
		default:
			ERROR(header<<"   == Error - WRONG transaction type  (CurrentClock : "<<currentClockCycle<<")");
			ERROR(*tran);
			exit(0);
			break;
	}
	//packet, cmd, addr, cub, lng, *lat
	Packet *newPacket = new Packet(REQUEST, cmdtype, tran->address, 0, packetLength, tran->trace);
	newPacket->reqDataSize = reqDataSize;
	return newPacket;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x10, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x40(%rbp)
subq $0x1b, %rax
ja 0x381ab
movq -0x40(%rbp), %rax
leaq 0x1b569(%rip), %rcx     # 0x53218
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x1, -0x14(%rbp)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x4c(%rbp)
subl $0x10, %eax
je 0x37d2e
jmp 0x37cda
movl -0x4c(%rbp), %eax
subl $0x20, %eax
je 0x37d3a
jmp 0x37ce4
movl -0x4c(%rbp), %eax
subl $0x30, %eax
je 0x37d46
jmp 0x37cee
movl -0x4c(%rbp), %eax
subl $0x40, %eax
je 0x37d52
jmp 0x37cf8
movl -0x4c(%rbp), %eax
subl $0x50, %eax
je 0x37d5e
jmp 0x37d02
movl -0x4c(%rbp), %eax
subl $0x60, %eax
je 0x37d6a
jmp 0x37d0c
movl -0x4c(%rbp), %eax
subl $0x70, %eax
je 0x37d76
jmp 0x37d16
movl -0x4c(%rbp), %eax
subl $0x80, %eax
je 0x37d82
jmp 0x37d22
movl -0x4c(%rbp), %eax
subl $0x100, %eax            # imm = 0x100
je 0x37d8e
jmp 0x37d9a
movl $0x30, -0x1c(%rbp)
jmp 0x37e3b
movl $0x31, -0x1c(%rbp)
jmp 0x37e3b
movl $0x32, -0x1c(%rbp)
jmp 0x37e3b
movl $0x33, -0x1c(%rbp)
jmp 0x37e3b
movl $0x34, -0x1c(%rbp)
jmp 0x37e3b
movl $0x35, -0x1c(%rbp)
jmp 0x37e3b
movl $0x36, -0x1c(%rbp)
jmp 0x37e3b
movl $0x37, -0x1c(%rbp)
jmp 0x37e3b
movl $0x77, -0x1c(%rbp)
jmp 0x37e3b
movq 0x2e24f(%rip), %rdi     # 0x65ff0
leaq 0x19292(%rip), %rsi     # 0x5103a
callq 0x4380
movq %rax, %rdi
leaq 0x1b550(%rip), %rsi     # 0x53307
callq 0x4380
movq %rax, %rdi
leaq 0x19a6f(%rip), %rsi     # 0x51835
callq 0x4380
movq %rax, %rdi
movl $0x107, %esi            # imm = 0x107
callq 0x4610
movq %rax, %rdi
leaq 0x19277(%rip), %rsi     # 0x51059
callq 0x4380
movq -0x48(%rbp), %rsi
movq %rax, %rdi
addq $0x20, %rsi
callq 0x4320
movq %rax, %rdi
leaq 0x1b5cd(%rip), %rsi     # 0x533ce
callq 0x4380
movq %rax, %rdi
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x40f0
movq %rax, %rdi
leaq 0x1c559(%rip), %rsi     # 0x54379
callq 0x4380
movq %rax, %rdi
movq 0x2e181(%rip), %rsi     # 0x65fb0
callq 0x43c0
xorl %edi, %edi
callq 0x4460
jmp 0x382b4
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
shrl $0x4, %eax
incl %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x50(%rbp)
subl $0x10, %eax
je 0x37ebe
jmp 0x37e6a
movl -0x50(%rbp), %eax
subl $0x20, %eax
je 0x37eca
jmp 0x37e74
movl -0x50(%rbp), %eax
subl $0x30, %eax
je 0x37ed6
jmp 0x37e7e
movl -0x50(%rbp), %eax
subl $0x40, %eax
je 0x37ee2
jmp 0x37e88
movl -0x50(%rbp), %eax
subl $0x50, %eax
je 0x37eee
jmp 0x37e92
movl -0x50(%rbp), %eax
subl $0x60, %eax
je 0x37efa
jmp 0x37e9c
movl -0x50(%rbp), %eax
subl $0x70, %eax
je 0x37f06
jmp 0x37ea6
movl -0x50(%rbp), %eax
subl $0x80, %eax
je 0x37f12
jmp 0x37eb2
movl -0x50(%rbp), %eax
subl $0x100, %eax            # imm = 0x100
je 0x37f1e
jmp 0x37f2a
movl $0x8, -0x1c(%rbp)
jmp 0x37fcb
movl $0x9, -0x1c(%rbp)
jmp 0x37fcb
movl $0xa, -0x1c(%rbp)
jmp 0x37fcb
movl $0xb, -0x1c(%rbp)
jmp 0x37fcb
movl $0xc, -0x1c(%rbp)
jmp 0x37fcb
movl $0xd, -0x1c(%rbp)
jmp 0x37fcb
movl $0xe, -0x1c(%rbp)
jmp 0x37fcb
movl $0xf, -0x1c(%rbp)
jmp 0x37fcb
movl $0x4f, -0x1c(%rbp)
jmp 0x37fcb
movq 0x2e0bf(%rip), %rdi     # 0x65ff0
leaq 0x19102(%rip), %rsi     # 0x5103a
callq 0x4380
movq %rax, %rdi
leaq 0x1b3c0(%rip), %rsi     # 0x53307
callq 0x4380
movq %rax, %rdi
leaq 0x198df(%rip), %rsi     # 0x51835
callq 0x4380
movq %rax, %rdi
movl $0x119, %esi            # imm = 0x119
callq 0x4610
movq %rax, %rdi
leaq 0x190e7(%rip), %rsi     # 0x51059
callq 0x4380
movq -0x48(%rbp), %rsi
movq %rax, %rdi
addq $0x20, %rsi
callq 0x4320
movq %rax, %rdi
leaq 0x1b43d(%rip), %rsi     # 0x533ce
callq 0x4380
movq %rax, %rdi
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x40f0
movq %rax, %rdi
leaq 0x1c3c9(%rip), %rsi     # 0x54379
callq 0x4380
movq %rax, %rdi
movq 0x2dff1(%rip), %rsi     # 0x65fb0
callq 0x43c0
xorl %edi, %edi
callq 0x4460
jmp 0x382b4
movl $0x12, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x13, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x22, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x23, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x52, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x53, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x50, -0x1c(%rbp)
movl $0x1, -0x14(%rbp)
jmp 0x382b4
movl $0x54, -0x1c(%rbp)
movl $0x1, -0x14(%rbp)
jmp 0x382b4
movl $0x40, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x41, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x42, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x43, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x44, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x60, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x61, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x62, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x63, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x64, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x65, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x68, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x69, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x11, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x21, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x51, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movl $0x6a, -0x1c(%rbp)
movl $0x2, -0x14(%rbp)
jmp 0x382b4
movq 0x2de3e(%rip), %rdi     # 0x65ff0
leaq 0x18e81(%rip), %rsi     # 0x5103a
callq 0x4380
movq %rax, %rdi
leaq 0x1b13f(%rip), %rsi     # 0x53307
callq 0x4380
movq %rax, %rdi
leaq 0x1965e(%rip), %rsi     # 0x51835
callq 0x4380
movq %rax, %rdi
movl $0x13c, %esi            # imm = 0x13C
callq 0x4610
movq %rax, %rdi
leaq 0x18e66(%rip), %rsi     # 0x51059
callq 0x4380
movq -0x48(%rbp), %rsi
movq %rax, %rdi
addq $0x20, %rsi
callq 0x4320
movq %rax, %rdi
leaq 0x1b1f7(%rip), %rsi     # 0x53409
callq 0x4380
movq %rax, %rdi
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x40f0
movq %rax, %rdi
leaq 0x1c148(%rip), %rsi     # 0x54379
callq 0x4380
movq %rax, %rdi
movq 0x2dd70(%rip), %rsi     # 0x65fb0
callq 0x43c0
movq 0x2dda4(%rip), %rdi     # 0x65ff0
leaq 0x18de7(%rip), %rsi     # 0x5103a
callq 0x4380
movq %rax, %rdi
leaq 0x1b0a5(%rip), %rsi     # 0x53307
callq 0x4380
movq %rax, %rdi
leaq 0x195c4(%rip), %rsi     # 0x51835
callq 0x4380
movq %rax, %rdi
movl $0x13d, %esi            # imm = 0x13D
callq 0x4610
movq %rax, %rdi
leaq 0x18dcc(%rip), %rsi     # 0x51059
callq 0x4380
movq %rax, %rdi
movq -0x10(%rbp), %rsi
callq 0x4a3b0
movq %rax, %rdi
movq 0x2dd08(%rip), %rsi     # 0x65fb0
callq 0x43c0
xorl %edi, %edi
callq 0x4460
movl $0x468, %edi            # imm = 0x468
callq 0x4390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x58(%rbp)
movl -0x1c(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq 0x18(%rax), %rcx
movl -0x14(%rbp), %r9d
movq %rsp, %rax
movq %rsi, (%rax)
xorl %r8d, %r8d
movl %r8d, %esi
callq 0x43a90
jmp 0x382ee
movq -0x58(%rbp), %rax
movq %rax, -0x28(%rbp)
movl -0x18(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x424(%rax)
movq -0x28(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
movq -0x58(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x468, %esi            # imm = 0x468
callq 0x43a0
movq -0x30(%rbp), %rdi
callq 0x4630