module bits fn test_bits(){ mut i := 0 mut i1:= u64(0) // // --- LeadingZeros --- // // 8 bit i = 1 for x in 0..8 { //C.printf("x:%02x lz: %d cmp: %d\n",i<> 1 } //C.printf("x:%02x lz: %llu cmp: %d\n",byte(i),reverse_8(byte(i)), rv) assert reverse_8(byte(i)) == rv i = (i << 1) + 1 } // 16 bit i = 0 for x in 0..17 { mut rv := u16(0) mut bc := 0 mut n := i for bc < 16 { rv = (rv << 1) | (n & 0x01) bc++ n = n >> 1 } //C.printf("x:%04x lz: %llu cmp: %d\n",u16(i),reverse_16(u16(i)), rv) assert reverse_16(u16(i)) == rv i = (i << 1) + 1 } // 32 bit i = 0 for x in 0..33 { mut rv := u32(0) mut bc := 0 mut n := i for bc < 32 { rv = (rv << 1) | (n & 0x01) bc++ n = n >> 1 } //C.printf("x:%08x lz: %llu cmp: %d\n",u32(i),reverse_32(u32(i)), rv) assert reverse_32(u32(i)) == rv i = (i << 1) + 1 } // 64 bit i1 = 0 for x in 0..64 { mut rv := u64(0) mut bc := 0 mut n := i1 for bc < 64 { rv = (rv << 1) | (n & 0x01) bc++ n = n >> 1 } //C.printf("x:%016llx lz: %016llx cmp: %016llx\n",u64(i1),reverse_64(u64(i1)), rv) assert reverse_64(u64(i1)) == rv i1 = (i1 << 1) + 1 } }