Code study: division
disassemble,gdb中可以用disassemble命令反汇编。




Write Assembly Code: timer.s
# File: timer.s# ---------------# Returns a 64-bit value for the number of milliseconds since# the computer was restarted.section .text.type milliseconds, @function.globl millisecondsTHOUSAND:.int 1000 # 32-bit intmilliseconds:# your code hererdtsc# Move edx to the upper 32 bits.shlq $32, %rdx# Ensure the upper 32 bits of rax are 0s.shlq $32, %raxshrq $32, %rax# Effectively concatenateaddq %rdx, %rax# Make way for mulq, divqmovq $0x0, %rdx# arithmeticmovq $1000, %rsimulq %rsidivq %rdiret
Code study: loops
loop unrolling





A运行时间是版本B、C版本的两倍,为什么???





