anybody knows a quik and fast way to check if every four
bytes in a dword are equal to eachother? say i've got a
dword like this: test dd "ABCD", test would definitively fail
but: test dd "AAAA" should be ok...

i thought about something like this:

MOV ECX,VALUE ;say "AAAA"
MOV AX,CX
SHR ECX,16
TEST AX,CX
JZ value_ok

is there a better way? thank you...
Posted on 2002-03-18 10:56:53 by mob
I think on 32-bit system this will work faster. But maybe there is a faster way. Let's move to Algorythm section and ask bitRAKE or The Svin


mov ecx, value
mov eax, ecx
bswap eax
test eax, ecx
jz equal
Posted on 2002-03-18 11:17:04 by masquer
This would be sufficent:
mov eax, Value


ror eax, 8

cmp eax, Value

je ValueOkay
so many dependancies...
Posted on 2002-03-18 11:19:19 by bitRAKE
Maybe better avoid working with memory variable second time
Posted on 2002-03-18 11:25:51 by masquer
test will not suffice, cmp will I think, but not test.

Consider:
01 03 07 0Fh

and 01, 03 == 1 (not 0) for a jump equal and will not jump

Secondly the idea involving BSWAP will not work as it merely tests
A == D, and B == C.

Also the original post will not test A == B == C == D, but AB == CD...

bitRAKE's ror/rol will work as it tests A == D, D == C, C == B, and B == A.
By inference we then know A == C, and A == B, etc.

---- Edit ----
masquer, the reuse of the memory shouldn't be any real performance bottle neck as I would expect the variable to still be in the data cache, what with being re-used only 1 instruction later!

Mirno
Posted on 2002-03-18 11:31:26 by Mirno

Maybe better avoid working with memory variable second time
It'll be in the cache - no cost to use it. :)
Thanks, Mirno - it slipped right by me...
Posted on 2002-03-18 11:40:03 by bitRAKE
oops i wrote test ax,cx? it should be xor ax,cx then it will
work ok... i will try out the other methods, thank you...
btw rol 8, thats nice :)
Posted on 2002-03-18 11:57:11 by mob
Yes XOR will work, but you are still faced with the problem of only comparing AB to CD, not A to B to C to D...

Also you'll stall twice on a P6 core from partial register accesses.

Mirno
Posted on 2002-03-18 12:18:22 by Mirno
Let see at the problem situation

every four bytes in a dword are equal to eachother

So it is enough to see if any one byte equal to each other.
Why bswap will not work:
value db ABCD1234
bswap value = 3412CDAB, so if in value all bytes the same, after bswap value dont change.
I think, thats enough
:)
Posted on 2002-03-18 12:29:52 by masquer
oh, you're right :)

here's the result, it's a little compression engine (that's only the
first part, extraction comes tomorrow...) i never done something
like this before so it's my first attempt. maybe you find a few
leaks here, too... wouldn't be surprised :)

Posted on 2002-03-18 12:35:12 by mob
Looks like runlength encoding. Instead of 13,10 at the end of string just put zero, it is windows app, isnt it? :)
Maybe worth that msgbox display compressed string
Posted on 2002-03-18 12:58:59 by masquer

Let see at the problem situation

So it is enough to see if any one byte equal to each other.
Why bswap will not work:
value db ABCD1234
bswap value = 3412CDAB, so if in value all bytes the same, after bswap value dont change.
I think, thats enough
:)
mov eax, 01020201h
mov ecx, eax
bswap eax ; same thing :)
cmp ecx,eax
je BrokenCode

Sorry, but it doesn't work.
Look at it this way:

AABBCCDD ; original
DDCCBBAA ; bswap

Your just verifying A=D, B=C

My method:

AABBCCDD ; original
DDAABBCC ; ror 8

A=D, B=A, C=B, D=C

They all must be equal.
Posted on 2002-03-18 13:02:11 by bitRAKE
Agree, using shift much more correctly. In the evening (here) I'm moving in one direction :( . My mistake.

As for compression, all we discuss previousely, IMHO, not a very effective way. Maybe better use scasb.
Posted on 2002-03-18 13:23:51 by masquer

In the evening (here) I'm moving in one direction :(
Tomorrow is a new day and rest makes it so. :tongue:
Posted on 2002-03-18 13:43:37 by bitRAKE
mov edx,eax
mov ah,al
bswap edx
xor eax,edx
jne @notpassed

explonations:
let say bytes in eax ABCD
then bswap = DCBA
mov ah,al results to ABDD in eax
if xor edx,eax = 0 then
DCBA
ABDD
1.A=A of course
2.D=A
3.D=B
4. B=C
cause B=C and D=B then D=C
there for
D=A=C=B
Posted on 2002-03-18 13:57:21 by The Svin
Thanks, bitRAKE
now I go to sleep easy :o :)
Posted on 2002-03-18 14:01:29 by masquer

Looks like runlength encoding. Instead of 13,10 at the end of string just put zero, it is windows app, isnt it? Maybe worth that msgbox display compressed string. As for compression, all we discuss previousely, IMHO, not a very effective way. Maybe better use scasb.


masquer that's just a little test, input and output are
displayed in a msgbox so to make it more readable i
added a newline. scasb... you mean loop_1? yup, it
can be optimized but scasb is very slow if i'm not wrong
Posted on 2002-03-19 03:29:16 by mob