{
if( !buf || buf_len < 16 ){
return PACKAGE_PARSE_ERROR;
}
memcpy( a, buf, 4 );
memcpy( b, buf + 4, 4 );
memcpy( c, buf + 8, 4 );
memcpy( d, buf + 12, 4 );
return PACKAGE_PARSE_OK;
}
int parse_package( int* a, int* b, int* c, int* d, char* buf, int buf_len )
{
if( !buf || buf_len < 16 ){
return PACKAGE_PARSE_ERROR;
}
memcpy( a, buf, 4 );
memcpy( b, buf + 4, 4 );
memcpy( c, buf + 8, 4 );
memcpy( d, buf + 12, 4 );
return PACKAGE_PARSE_OK;
}
[cpp]
int parse_package2( int* a, int* b, int* c, int* d, char* buf, int buf_len )
{
int* ibuf;
if( !buf || buf_len < 16 ){
return PACKAGE_PARSE_ERROR;
}
ibuf = buf;
*a = ibuf[0];
*b = ibuf[1];
*c = ibuf[2];
*d = ibuf[3];
return PACKAGE_PARSE_OK;
}
int parse_package2( int* a, int* b, int* c, int* d, char* buf, int buf_len )
{
int* ibuf;
if( !buf || buf_len < 16 ){
return PACKAGE_PARSE_ERROR;
}
ibuf = buf;
*a = ibuf[0];
*b = ibuf[1];
*c = ibuf[2];
*d = ibuf[3];
return PACKAGE_PARSE_OK;
}
parse_package汇编代码:
[cpp]
parse_package:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $48, %rsp
movq %rdi, -8(%rbp)
movq %rsi, -16(%rbp)
movq %rdx, -24(%rbp)
movq %rcx, -32(%rbp)
movq %r8, -40(%rbp)
movl %r9d, -44(%rbp)
cmpq $0, -40(%rbp)
je .L2
cmpl $15, -44(%rbp)
jg .L3
.L2:
movl $-1, %eax
jmp .L4.
L3:
movq -40(%rbp), %rcx
movq -8(%rbp), %rax
movl $4, %edx
movq %rcx, %rsi
movq %rax, %rdi
call memcpy
movq -40(%rbp), %rax
leaq 4(%rax), %rcx
movq -16(%rbp), %rax
movl $4, %edx
movq %rcx, %rsi
movq %rax, %rdi
call memcpy
movq -40(%rbp), %rax
leaq 8(%rax), %rcx
movq -24(%rbp), %rax
movl $4, %edx
movq %rcx, %rsi
movq %rax, %rdi
call memcpy
movq -40(%rbp), %rax
leaq 12(%rax), %rcx
movq -32(%rbp), %rax
movl $4, %edx
movq %rcx, %rsi
movq %rax, %rdi
call memcpy
movl $0, %eax
parse_package:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $48, %rsp
movq %rdi, -8(%rbp)
movq %rsi, -16(%rbp)
movq %rdx, -24(%rbp)
movq %rcx, -32(%rbp)
movq %r8, -40(%rbp)
movl %r9d, -44(%rbp)
cmpq $0, -40(%rbp)
je .L2
cmpl $15, -44(%rbp)
jg .L3
.L2:
movl $-1, %eax
jmp .L4.
L3:
movq -40(%rbp), %rcx
movq -8(%rbp), %rax
movl $4, %edx
movq %rcx, %rsi
movq %rax, %rdi
call memcpy
movq -40(%rbp), %rax
leaq 4(%rax), %rcx
movq -16(%rb