// File: /workspace/github_cpp_makefile_star2_O2/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 0x17d55
pushq $0x2
popq %rbp
pushq $0x10
popq %r12
leaq 0xe698(%rip), %rcx      # 0x26280
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 0x17e39
pushq $0x1
popq %rbp
leaq 0xe720(%rip), %rcx      # 0x26330
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
pushq $0x30
jmp 0x17cc8
pushq $0x11
jmp 0x17cc8
pushq $0x41
jmp 0x17cc8
pushq $0x65
jmp 0x17cc8
pushq $0x1
popq %rbp
pushq $0x54
jmp 0x17cc8
pushq $0x64
jmp 0x17cc8
pushq $0x42
jmp 0x17cc8
pushq $0x40
jmp 0x17cc8
pushq $0x1
popq %rbp
pushq $0x50
jmp 0x17cc8
pushq $0x43
jmp 0x17cc8
pushq $0x62
jmp 0x17cc8
pushq $0x68
jmp 0x17cc8
pushq $0x44
jmp 0x17cc8
pushq $0x61
jmp 0x17cc8
pushq $0x22
jmp 0x17cc8
pushq $0x60
jmp 0x17cc8
pushq $0x6a
jmp 0x17cc8
pushq $0x23
jmp 0x17cc8
pushq $0x12
jmp 0x17cc8
pushq $0x53
jmp 0x17cc8
pushq $0x13
jmp 0x17cc8
movl 0x20(%rbx), %r12d
leal -0x10(%r12), %eax
roll $0x1c, %eax
cmpl $0xf, %eax
ja 0x17e74
movl %r12d, %ebp
shrl $0x4, %ebp
incl %ebp
leaq 0xe647(%rip), %rcx      # 0x262f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
pushq $0x8
jmp 0x17cc8
pushq $0x52
jmp 0x17cc8
pushq $0x63
jmp 0x17cc8
pushq $0x21
jmp 0x17cc8
pushq $0x69
jmp 0x17cc8
pushq $0x51
popq %r14
movl $0x468, %edi            # imm = 0x468
callq 0x4310
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 0x1dd04
movl %r12d, 0x424(%r15)
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x4f
jmp 0x17cc8
pushq $0x77
jmp 0x17cc8
pushq $0xc
jmp 0x17cc8
pushq $0xd
jmp 0x17cc8
pushq $0xa
jmp 0x17cc8
pushq $0x34
jmp 0x17cc8
pushq $0xf
jmp 0x17cc8
pushq $0xb
jmp 0x17cc8
pushq $0x9
jmp 0x17cc8
pushq $0x35
jmp 0x17cc8
pushq $0x32
jmp 0x17cc8
pushq $0x37
jmp 0x17cc8
pushq $0x33
jmp 0x17cc8
pushq $0x31
jmp 0x17cc8
pushq $0xe
jmp 0x17cc8
pushq $0x36
jmp 0x17cc8
movq 0x19294(%rip), %rdi     # 0x30ff0
leaq 0xc2bf(%rip), %r12      # 0x24022
movq %r12, %rsi
callq 0x4300
leaq 0xe6a5(%rip), %r13      # 0x26417
movq %rax, %rdi
movq %r13, %rsi
callq 0x4300
leaq 0xcaf3(%rip), %rbp      # 0x24877
movq %rax, %rdi
movq %rbp, %rsi
callq 0x4300
movq %rax, %rdi
movl $0x13c, %esi            # imm = 0x13C
callq 0x44f0
leaq 0xc29e(%rip), %r15      # 0x24041
movq %rax, %rdi
movq %r15, %rsi
callq 0x4300
leaq 0x20(%r14), %rsi
movq %rax, %rdi
callq 0x42b0
leaq 0xe758(%rip), %rsi      # 0x26519
movq %rax, %rdi
callq 0x4300
movq 0x8(%r14), %rsi
movq %rax, %rdi
callq 0x40d0
leaq 0xf6f5(%rip), %rsi      # 0x274d1
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
callq 0x4180
movq 0x191fd(%rip), %rdi     # 0x30ff0
movq %r12, %rsi
callq 0x4300
movq %rax, %rdi
movq %r13, %rsi
callq 0x4300
movq %rax, %rdi
movq %rbp, %rsi
callq 0x4300
movq %rax, %rdi
movl $0x13d, %esi            # imm = 0x13D
callq 0x44f0
movq %rax, %rdi
movq %r15, %rsi
callq 0x4300
movq %rax, %rdi
movq %rbx, %rsi
callq 0x20aca
jmp 0x17ef7
movq 0x191b0(%rip), %rdi     # 0x30ff0
leaq 0xc1db(%rip), %rsi      # 0x24022
callq 0x4300
leaq 0xe5c4(%rip), %rsi      # 0x26417
movq %rax, %rdi
callq 0x4300
leaq 0xca15(%rip), %rsi      # 0x24877
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
movl $0x107, %esi            # imm = 0x107
jmp 0x17ead
movq 0x19175(%rip), %rdi     # 0x30ff0
leaq 0xc1a0(%rip), %rsi      # 0x24022
callq 0x4300
leaq 0xe589(%rip), %rsi      # 0x26417
movq %rax, %rdi
callq 0x4300
leaq 0xc9da(%rip), %rsi      # 0x24877
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
movl $0x119, %esi            # imm = 0x119
callq 0x44f0
leaq 0xc188(%rip), %rsi      # 0x24041
movq %rax, %rdi
callq 0x4300
leaq 0x20(%r14), %rsi
movq %rax, %rdi
callq 0x42b0
leaq 0xe60a(%rip), %rsi      # 0x264de
movq %rax, %rdi
callq 0x4300
movq 0x8(%r14), %rsi
movq %rax, %rdi
callq 0x40d0
leaq 0xf5e2(%rip), %rsi      # 0x274d1
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
callq 0x4180
xorl %edi, %edi
callq 0x4370
movq %rax, %rbx
movl $0x468, %esi            # imm = 0x468
movq %r15, %rdi
callq 0x4320
movq %rbx, %rdi
callq 0x4520