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...
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...
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
This would be sufficent:
mov eax, Value
ror eax, 8
cmp eax, Value
je ValueOkay
so many dependancies...Maybe better avoid working with memory variable second time
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
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
Maybe better avoid working with memory variable second time
Thanks, Mirno - it slipped right by me...
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 :)
work ok... i will try out the other methods, thank you...
btw rol 8, thats nice :)
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
Also you'll stall twice on a P6 core from partial register accesses.
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
:)
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
:)
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
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
Maybe worth that msgbox display compressed string
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 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.
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.
As for compression, all we discuss previousely, IMHO, not a very effective way. Maybe better use scasb.
In the evening (here) I'm moving in one direction :(
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
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
Thanks, bitRAKE
now I go to sleep easy :o :)
now I go to sleep easy :o :)
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