计算IP头部校验和汇编例程

    技术2026-10-06  5

    文件名:checksum.S

    .file "checksum.S" .section .text .type checksum,@function .align 16 .globl checksum checksum: xorq %rax, %rax testq $7, %rdi jne 5f 0: movq %rsi, %rdx movq %rsi, %rcx shrq $3, %rdx je 2f shrq $6, %rcx andq $7, %rdx je 1f addq $1, %rcx leaq -64(%rdi, %rdx, 8), %rdi negq %rdx andq $7, %rdx leaq 1f-1(, %rdx, 4), %rdx jmpq *%rdx .align 16 1: adcq (%rdi), %rax adcq 8(%rdi), %rax adcq 16(%rdi), %rax adcq 24(%rdi), %rax adcq 32(%rdi), %rax adcq 40(%rdi), %rax adcq 48(%rdi), %rax adcq 56(%rdi), %rax leaq 64(%rdi), %rdi decq %rcx jne 1b adcq $0, %rax 2: andq $7, %rsi jne 4f 3: movq %rax, %rdx shrq $32, %rax addl %edx, %eax adcl $0, %eax movl %eax, %edx shrl $16, %eax addw %dx, %ax adcw $0, %ax notw %ax retq 4: leaq (, %rsi, 8), %rcx movq $-1, %rdx negq %rcx shrq %cl, %rdx andq (%rdi), %rdx addq %rdx, %rax adcq $0, %rax jmp 3b 5: testq $1, %rdi jne 9f movq %rdi, %rcx negq %rcx andq $7, %rcx cmpq %rcx, %rsi cmovlq %rsi, %rcx subq %rcx, %rsi testq $4, %rcx je 6f movl (%rdi), %edx addq %rdx, %rax adcq $0, %rax addq $4, %rdi 6: testq $2, %rcx je 7f movzwq (%rdi), %rdx addq %rdx, %rax adcq $0, %rax addq $2, %rdi 7: testq $1, %rcx je 8f movzbq (%rdi), %rdx addq %rdx, %rax adcq $0, %rax addq $1, %rdi 8: testq %rsi, %rsi je 3b jmp 0b 9: movzbw (%rdi), %r8w incq %rdi decq %rsi je 10f call checksum notw %ax xchg %al, %ah addw %r8w, %ax adcw $0, %ax notw %ax retq 10: movw %r8w, %ax notw %ax retq .size checksum, .-checksum

     

     

     

     

     

    Processed: 0.016, SQL: 9