Print this page
5291 x86 {high,low}bit rely on undefined behavior


  49 /
  50         .inline curcpup,0
  51         movl    %gs:0xc, %eax
  52         .end
  53 
  54 /
  55 / return caller
  56 /
  57         .inline caller,0
  58         movl    4(%ebp), %eax
  59         .end
  60 
  61 /
  62 / convert ipl to spl.  This is the identity function for i86
  63 /
  64         .inline ipltospl,0
  65         movl    (%esp), %eax
  66         .end
  67 
  68 /
  69 / find the low order bit in a word
  70 /
  71         .inline lowbit,4
  72         movl    $-1, %eax
  73         bsfl    (%esp), %eax
  74         incl    %eax
  75         .end
  76 
  77 /
  78 / find the high order bit in a word
  79 /
  80         .inline highbit,4
  81         movl    $-1, %eax
  82         bsrl    (%esp), %eax
  83         incl    %eax
  84         .end
  85 
  86 /
  87 / Networking byte order functions (too bad, Intel has the wrong byte order)
  88 /
  89         .inline htonll,4
  90         movl    (%esp), %edx
  91         movl    4(%esp), %eax
  92         bswap   %edx
  93         bswap   %eax
  94         .end
  95 
  96         .inline ntohll,4
  97         movl    (%esp), %edx
  98         movl    4(%esp), %eax
  99         bswap   %edx
 100         bswap   %eax
 101         .end
 102 
 103         .inline htonl,4
 104         movl    (%esp), %eax
 105         bswap   %eax
 106         .end




  49 /
  50         .inline curcpup,0
  51         movl    %gs:0xc, %eax
  52         .end
  53 
  54 /
  55 / return caller
  56 /
  57         .inline caller,0
  58         movl    4(%ebp), %eax
  59         .end
  60 
  61 /
  62 / convert ipl to spl.  This is the identity function for i86
  63 /
  64         .inline ipltospl,0
  65         movl    (%esp), %eax
  66         .end
  67 
  68 /


















  69 / Networking byte order functions (too bad, Intel has the wrong byte order)
  70 /
  71         .inline htonll,4
  72         movl    (%esp), %edx
  73         movl    4(%esp), %eax
  74         bswap   %edx
  75         bswap   %eax
  76         .end
  77 
  78         .inline ntohll,4
  79         movl    (%esp), %edx
  80         movl    4(%esp), %eax
  81         bswap   %edx
  82         bswap   %eax
  83         .end
  84 
  85         .inline htonl,4
  86         movl    (%esp), %eax
  87         bswap   %eax
  88         .end