// File: /workspace/github_cpp_makefile_star2_O1/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 0x2027c
movl $0x2, %ebp
movl $0x10, %r12d
leaq 0x131dc(%rip), %rcx     # 0x33208
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 0x20360
movl $0x1, %ebp
leaq 0x13262(%rip), %rcx     # 0x332b8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x30, %r14d
jmp 0x2019c
movl $0x11, %r14d
jmp 0x2019c
movl $0x41, %r14d
jmp 0x2019c
movl $0x65, %r14d
jmp 0x2019c
movl $0x1, %ebp
movl $0x54, %r14d
jmp 0x2019c
movl $0x64, %r14d
jmp 0x2019c
movl $0x42, %r14d
jmp 0x2019c
movl $0x40, %r14d
jmp 0x2019c
movl $0x1, %ebp
movl $0x50, %r14d
jmp 0x2019c
movl $0x43, %r14d
jmp 0x2019c
movl $0x62, %r14d
jmp 0x2019c
movl $0x68, %r14d
jmp 0x2019c
movl $0x44, %r14d
jmp 0x2019c
movl $0x61, %r14d
jmp 0x2019c
movl $0x22, %r14d
jmp 0x2019c
movl $0x60, %r14d
jmp 0x2019c
movl $0x6a, %r14d
jmp 0x2019c
movl $0x23, %r14d
jmp 0x2019c
movl $0x12, %r14d
jmp 0x2019c
movl $0x53, %r14d
jmp 0x2019c
movl $0x13, %r14d
jmp 0x2019c
movl 0x20(%rbx), %r12d
leal -0x10(%r12), %eax
roll $0x1c, %eax
cmpl $0xf, %eax
ja 0x2039b
movl %r12d, %ebp
shrl $0x4, %ebp
incl %ebp
leaq 0x13113(%rip), %rcx     # 0x33278
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x8, %r14d
jmp 0x2019c
movl $0x52, %r14d
jmp 0x2019c
movl $0x63, %r14d
jmp 0x2019c
movl $0x21, %r14d
jmp 0x2019c
movl $0x69, %r14d
jmp 0x2019c
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 0x284bc
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 0x2019c
movl $0x77, %r14d
jmp 0x2019c
movl $0xc, %r14d
jmp 0x2019c
movl $0xd, %r14d
jmp 0x2019c
movl $0xa, %r14d
jmp 0x2019c
movl $0x34, %r14d
jmp 0x2019c
movl $0xf, %r14d
jmp 0x2019c
movl $0xb, %r14d
jmp 0x2019c
movl $0x9, %r14d
jmp 0x2019c
movl $0x35, %r14d
jmp 0x2019c
movl $0x32, %r14d
jmp 0x2019c
movl $0x37, %r14d
jmp 0x2019c
movl $0x33, %r14d
jmp 0x2019c
movl $0x31, %r14d
jmp 0x2019c
movl $0xe, %r14d
jmp 0x2019c
movl $0x36, %r14d
jmp 0x2019c
movq 0x1bd6d(%rip), %rdi     # 0x3bff0
leaq 0x10d98(%rip), %r12     # 0x31022
movq %r12, %rsi
callq 0x42e0
leaq 0x13106(%rip), %r13     # 0x3339f
movq %rax, %rdi
movq %r13, %rsi
callq 0x42e0
leaq 0x1158c(%rip), %rbp     # 0x31837
movq %rax, %rdi
movq %rbp, %rsi
callq 0x42e0
movq %rax, %rdi
movl $0x13c, %esi            # imm = 0x13C
callq 0x4500
leaq 0x10d77(%rip), %r15     # 0x31041
movq %rax, %rdi
movq %r15, %rsi
callq 0x42e0
leaq 0x20(%r14), %rsi
movq %rax, %rdi
callq 0x4290
leaq 0x131b9(%rip), %rsi     # 0x334a1
movq %rax, %rdi
callq 0x42e0
movq 0x8(%r14), %rsi
movq %rax, %rdi
callq 0x40c0
leaq 0x1415e(%rip), %rsi     # 0x34461
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
callq 0x4170
movq 0x1bcd6(%rip), %rdi     # 0x3bff0
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 0x2c070
jmp 0x2041e
movq 0x1bc89(%rip), %rdi     # 0x3bff0
leaq 0x10cb4(%rip), %rsi     # 0x31022
callq 0x42e0
leaq 0x13025(%rip), %rsi     # 0x3339f
movq %rax, %rdi
callq 0x42e0
leaq 0x114ae(%rip), %rsi     # 0x31837
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
movl $0x107, %esi            # imm = 0x107
jmp 0x203d4
movq 0x1bc4e(%rip), %rdi     # 0x3bff0
leaq 0x10c79(%rip), %rsi     # 0x31022
callq 0x42e0
leaq 0x12fea(%rip), %rsi     # 0x3339f
movq %rax, %rdi
callq 0x42e0
leaq 0x11473(%rip), %rsi     # 0x31837
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
movl $0x119, %esi            # imm = 0x119
callq 0x4500
leaq 0x10c61(%rip), %rsi     # 0x31041
movq %rax, %rdi
callq 0x42e0
leaq 0x20(%r14), %rsi
movq %rax, %rdi
callq 0x4290
leaq 0x1306b(%rip), %rsi     # 0x33466
movq %rax, %rdi
callq 0x42e0
movq 0x8(%r14), %rsi
movq %rax, %rdi
callq 0x40c0
leaq 0x1404b(%rip), %rsi     # 0x34461
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