Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Test code:
- #include <string.h>
- char* mem_demo_1(char *j)
- { // *BAD* compiler cannot tell pointer alignment, must test
- memset(j, 0, 64);
- return j;
- }
- char* mem_demo_2(void)
- { // *GOOD* compiler can tell pointer alignment
- char * j = malloc(64);
- memset(j, 0, 64);
- return j;
- }
- Compiled with GCC 4.6.3, options -O3. Also tested with -O2, results are about the same.
- mem_demo_1:
- .LFB12:
- .cfi_startproc
- movq %rdi, %rsi
- movl $64, %edx
- testb $1, %sil
- jne .L9
- testb $2, %dil
- jne .L10
- .L3:
- testb $4, %dil
- jne .L11
- .L4:
- movl %edx, %ecx
- xorl %eax, %eax
- shrl $3, %ecx
- testb $4, %dl
- rep stosq
- je .L5
- movl $0, (%rdi)
- addq $4, %rdi
- .L5:
- testb $2, %dl
- je .L6
- movw $0, (%rdi)
- addq $2, %rdi
- .L6:
- andl $1, %edx
- je .L7
- movb $0, (%rdi)
- .L7:
- movq %rsi, %rax
- ret
- .p2align 4,,10
- .p2align 3
- .L9:
- leaq 1(%rsi), %rdi
- movb $0, (%rsi)
- movb $63, %dl
- testb $2, %dil
- je .L3
- .p2align 4,,10
- .p2align 3
- .L10:
- movw $0, (%rdi)
- addq $2, %rdi
- subl $2, %edx
- testb $4, %dil
- je .L4
- .p2align 4,,10
- .p2align 3
- .L11:
- movl $0, (%rdi)
- subl $4, %edx
- addq $4, %rdi
- jmp .L4
- .cfi_endproc
- ...
- mem_demo_2:
- .LFB13:
- .cfi_startproc
- subq $8, %rsp
- .cfi_def_cfa_offset 16
- movl $64, %edi
- call malloc
- movq %rax, %rdx
- movl $8, %ecx
- xorl %eax, %eax
- movq %rdx, %rdi
- rep stosq
- movq %rdx, %rax
- addq $8, %rsp
- .cfi_def_cfa_offset 8
- ret
- .cfi_endproc
Advertisement
Add Comment
Please, Sign In to add comment