// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movl 0x10(%rsi), %eax
cmpq $0x1b, %rax
ja 0x1fa90
movl $0x2, %ebp
movl $0x10, %r12d
leaq 0x12a50(%rip), %rcx     # 0x32290
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x20(%rbx), %r12d
leal -0x10(%r12), %eax
roll $0x1c, %eax
cmpl $0xf, %eax
ja 0x1fb74
movl $0x1, %ebp
leaq 0x12ad6(%rip), %rcx     # 0x32340
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x30, %r14d
jmp 0x1f9b0
movl $0x11, %r14d
jmp 0x1f9b0
movl $0x41, %r14d
jmp 0x1f9b0
movl $0x65, %r14d
jmp 0x1f9b0
movl $0x1, %ebp
movl $0x54, %r14d
jmp 0x1f9b0
movl $0x64, %r14d
jmp 0x1f9b0
movl $0x42, %r14d
jmp 0x1f9b0
movl $0x40, %r14d
jmp 0x1f9b0
movl $0x1, %ebp
movl $0x50, %r14d
jmp 0x1f9b0
movl $0x43, %r14d
jmp 0x1f9b0
movl $0x62, %r14d
jmp 0x1f9b0
movl $0x68, %r14d
jmp 0x1f9b0
movl $0x44, %r14d
jmp 0x1f9b0
movl $0x61, %r14d
jmp 0x1f9b0
movl $0x22, %r14d
jmp 0x1f9b0
movl $0x60, %r14d
jmp 0x1f9b0
movl $0x6a, %r14d
jmp 0x1f9b0
movl $0x23, %r14d
jmp 0x1f9b0
movl $0x12, %r14d
jmp 0x1f9b0
movl $0x53, %r14d
jmp 0x1f9b0
movl $0x13, %r14d
jmp 0x1f9b0
movl 0x20(%rbx), %r12d
leal -0x10(%r12), %eax
roll $0x1c, %eax
cmpl $0xf, %eax
ja 0x1fbaf
movl %r12d, %ebp
shrl $0x4, %ebp
incl %ebp
leaq 0x12987(%rip), %rcx     # 0x32300
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x8, %r14d
jmp 0x1f9b0
movl $0x52, %r14d
jmp 0x1f9b0
movl $0x63, %r14d
jmp 0x1f9b0
movl $0x21, %r14d
jmp 0x1f9b0
movl $0x69, %r14d
jmp 0x1f9b0
movl $0x51, %r14d
movl $0x468, %edi            # imm = 0x468
callq 0x42f0
movq %rax, %r15
movq 0x8(%rbx), %rax
movq 0x18(%rbx), %rcx
movq %rax, (%rsp)
movq %r15, %rdi
xorl %esi, %esi
movl %r14d, %edx
xorl %r8d, %r8d
movl %ebp, %r9d
callq 0x27c44
movl %r12d, 0x424(%r15)
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x4f, %r14d
jmp 0x1f9b0
movl $0x77, %r14d
jmp 0x1f9b0
movl $0xc, %r14d
jmp 0x1f9b0
movl $0xd, %r14d
jmp 0x1f9b0
movl $0xa, %r14d
jmp 0x1f9b0
movl $0x34, %r14d
jmp 0x1f9b0
movl $0xf, %r14d
jmp 0x1f9b0
movl $0xb, %r14d
jmp 0x1f9b0
movl $0x9, %r14d
jmp 0x1f9b0
movl $0x35, %r14d
jmp 0x1f9b0
movl $0x32, %r14d
jmp 0x1f9b0
movl $0x37, %r14d
jmp 0x1f9b0
movl $0x33, %r14d
jmp 0x1f9b0
movl $0x31, %r14d
jmp 0x1f9b0
movl $0xe, %r14d
jmp 0x1f9b0
movl $0x36, %r14d
jmp 0x1f9b0
movq 0x1b559(%rip), %rdi     # 0x3aff0
leaq 0x10584(%rip), %r12     # 0x30022
movq %r12, %rsi
callq 0x42e0
leaq 0x1297a(%rip), %r13     # 0x32427
movq %rax, %rdi
movq %r13, %rsi
callq 0x42e0
leaq 0x10dd8(%rip), %rbp     # 0x30897
movq %rax, %rdi
movq %rbp, %rsi
callq 0x42e0
movq %rax, %rdi
movl $0x13c, %esi            # imm = 0x13C
callq 0x4500
leaq 0x10563(%rip), %r15     # 0x30041
movq %rax, %rdi
movq %r15, %rsi
callq 0x42e0
leaq 0x20(%r14), %rsi
movq %rax, %rdi
callq 0x4290
leaq 0x12a2d(%rip), %rsi     # 0x32529
movq %rax, %rdi
callq 0x42e0
movq 0x8(%r14), %rsi
movq %rax, %rdi
callq 0x40c0
leaq 0x139ca(%rip), %rsi     # 0x334e1
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
callq 0x4170
movq 0x1b4c2(%rip), %rdi     # 0x3aff0
movq %r12, %rsi
callq 0x42e0
movq %rax, %rdi
movq %r13, %rsi
callq 0x42e0
movq %rax, %rdi
movq %rbp, %rsi
callq 0x42e0
movq %rax, %rdi
movl $0x13d, %esi            # imm = 0x13D
callq 0x4500
movq %rax, %rdi
movq %r15, %rsi
callq 0x42e0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2b744
jmp 0x1fc32
movq 0x1b475(%rip), %rdi     # 0x3aff0
leaq 0x104a0(%rip), %rsi     # 0x30022
callq 0x42e0
leaq 0x12899(%rip), %rsi     # 0x32427
movq %rax, %rdi
callq 0x42e0
leaq 0x10cfa(%rip), %rsi     # 0x30897
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
movl $0x107, %esi            # imm = 0x107
jmp 0x1fbe8
movq 0x1b43a(%rip), %rdi     # 0x3aff0
leaq 0x10465(%rip), %rsi     # 0x30022
callq 0x42e0
leaq 0x1285e(%rip), %rsi     # 0x32427
movq %rax, %rdi
callq 0x42e0
leaq 0x10cbf(%rip), %rsi     # 0x30897
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
movl $0x119, %esi            # imm = 0x119
callq 0x4500
leaq 0x1044d(%rip), %rsi     # 0x30041
movq %rax, %rdi
callq 0x42e0
leaq 0x20(%r14), %rsi
movq %rax, %rdi
callq 0x4290
leaq 0x128df(%rip), %rsi     # 0x324ee
movq %rax, %rdi
callq 0x42e0
movq 0x8(%r14), %rsi
movq %rax, %rdi
callq 0x40c0
leaq 0x138b7(%rip), %rsi     # 0x334e1
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
callq 0x4170
xorl %edi, %edi
callq 0x4360
movq %rax, %rbx
movl $0x468, %esi            # imm = 0x468
movq %r15, %rdi
callq 0x4300
movq %rbx, %rdi
callq 0x4540
nop