Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Integer roots game

2 views
Skip to first unread message

Kerr-Mudd, John

unread,
Dec 11, 2022, 6:55:28 AM12/11/22
to
On Sun, 11 Dec 2022 11:48:30 +0000
"Kerr-Mudd, John" <ad...@127.0.0.1> wrote:

> On Sun, 11 Dec 2022 09:28:07 GMT
> an...@mips.complang.tuwien.ac.at (Anton Ertl) wrote:
>
>
> [log2 to give a first estimate for a sqrt program]
>
> > P Falth <peter....@gmail.com> writes:
> > >My E5 v2 cpu is the generation before Haswell and do not have the lzcnt opcode.
> > >But it does not flag an error if executed, instead it executes bsr! and give a wrong
> > >result. This is also stated in the Intel manual.
> >
> > Interesting. Looking at the encoding, lzcount is encoded as repne
> > bsr, and the repne prefix normally is ignored except for the string
> > instructions. Apparently nobody encoded bsr with a repne prefix,
> > otherwise they could not have encoded lzcnt in this way.
> >
>
> I just tried a leading zero count in asm, trying "repnz shr ax,1"; the
> assembler (nasm) was OK encoding it but on execution it dropped out
> after one shift, even though the flags register shows 'nz'. This is on a
> 20 year old Pentium.
> Intel's Instruction Reference (ASDM) says rep[] only applies to string ops,
> so I can't really complain.
> I rarely use rep lods[x] though!
>
> xpost to ala, as it's more about asm.
>
/alt/.lang.asm
doh!

--
Bah, and indeed Humbug.

Steve

unread,
Dec 12, 2022, 7:43:36 AM12/12/22
to
Hi,

It seems strange to use such an encoding?

Cheers,

Steve N,

Kerr-Mudd, John

unread,
Dec 12, 2022, 7:57:38 AM12/12/22
to
> Hi,
>
> It seems strange to use such an encoding?
>

Maybe so, but it would've saved a loop.

This was my poor attempt:

Log2b: ; ax<-ln2(ax) ; uses cx [14]
mov cx,16 ; bits per word
push cx
repnz shr ax,1
inc cx ; 1 too many
pop ax
sub ax,cx ;
; ln(0)=-1 fix
jnz .ln0nofix
dec ax
.ln0nofix:
ret


Ok, we can use 'bsr' to find the leading bit these days.

Log2c: ; ax<-ln2(ax) ; uses bx [7]

mov bx,-1
xchg ax,bx
bsr ax,bx ; cpu 386




for rep lods, perhaps size coders use
rep lodsb
rather than
mov bx,cx
mov al,[si+bx]
0 new messages