From mboxrd@z Thu Jan 1 00:00:00 1970 From: erik quanstrom Date: Thu, 21 Feb 2013 10:37:19 -0500 To: 9fans@9fans.net Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: [9fans] 6c bug Topicbox-Message-UUID: 1c8a84bc-ead8-11e9-9d60-3106f5b1d025 uncomment the prints, and the function will return the correct value. it looks like the compiler is aliasing n and m, from 6c -S: TEXT log2ceil+0(SB),0,$16 MOVQ BP,SI MOVQ BP,AX DECQ ,AX MOVQ BP,CX ANDQ AX,CX CMPQ CX,$0 JEQ ,3(PC) MOVL $1,AX JMP ,2(PC) MOVL $0,AX MOVL AX,BX MOVL SI,DX JMP ,2(PC) JMP ,3(PC) >> CMPQ SI,SI JNE ,2(PC) JMP ,5(PC) MOVQ SI,AX SHRQ $32,AX MOVL AX,DX ADDL $32,BX [etc]. - erik #include #include typedef u64int uintmem; static uchar log2v[256]; void log2init(void) { int i; for(i=3D2; i round up */ n =3D (uint)m; //print("%llux %ux\n", m, n); if(sizeof(uintmem)>sizeof(uint) && n !=3D m){ n =3D (u64int)m>>32; r +=3D 32; } //print("r =3D %d\n", r); if((n>>8) =3D=3D 0) return log2v[n] + r; if((n>>16) =3D=3D 0) return 8 + log2v[n>>8] + r; if((n>>24) =3D=3D 0) return 16 + log2v[n>>16] + r; return 24 + log2v[n>>24] + r; } void main(void) { log2init(); print("%d\n", log2ceil(0x430000000ull)); exits(""); }