News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

AsciiHextoDword (SSE2 version)

Started by guga, March 08, 2025, 11:29:50 AM

Previous topic - Next topic

guga

Quote from: zedd151 on March 11, 2025, 04:01:26 PMNot bad, NoCforMe. Only slightly slower than guga's algorithm, for 8 char input.

24 cycles -> Ascii Hex to Qword by Guga (Variable Lenght),  Input: 87654321 . Return in EAX: 8 (Bytes)
Output:
D$ 0x87654321
D$ 0x0

30 cycles -> Ascii Hex to Dword by NoCForMe,  Input: 87654321 . Return in EAX: 87654321

31 cycles -> Ascii Hex to Dword by NoCForMe - Registers preserved,  Input: 87654321 . Return in EAX: 87654321

Guga...
Maybe you could optimize that then no need for SSE code, guga? I thought that there would be a much bigger difference between NoCforMe's old skool bytewise algo and yours using SSE...

His version using normal registers is not slow, but the way i did (On the Dword version) was twice as fast. Even the Qword version is a bit faster then using regular x86.

But, it all depends on the needs. using SSE2 on the way i did resulted on a gain of speed of about 2x. Considering that i´m trying to fix a lot of other functions in RosAsm (or others dlls i´m using for other apps), then such gain of speeds are needed.


19 cycles -> Ascii Hex to Dw by Guga (new version. variable lenght),  Input: 87654321 . Return in EAX: 87654321
33 cycles -> Ascii Hex to Qword by Guga (Variable Lenght),  Input: 87654321 . Return in EAX: 8 (Bytes)
Output:
D$ 0x87654321
D$ 0x0
43 cycles -> Ascii Hex to Dword by NoCForMe,  Input: 87654321 . Return in EAX: 87654321
40 cycles -> Ascii Hex to Dword by NoCForMe - Registers preserved,  Input: 87654321 . Return in EAX: 87654321

Press enter to exit...


I don´t know if i use regular x86 can be faster than the way i did right now. At least, i can´t think on a even faster way right now.

Take a look at this attachment. I didn´t modified anything in both codes right now. Just removed the others functions that were also being tested to you compare better.

But...this is a simple benchmark tool. Better would be using JJ´s tool for that, or my Codetune app i uploaded here sometime ago. In all cases, i think it´s only a matter of what is needed.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

NoCforMe

Wellll, it probably could use some error checking.
It occurred to me that if you replaced the bytes in the translation table that didn't correspond to valid hex characters with -1, you could add this code to catch non-hex chars.:
next: XOR EAX, EAX ;Clear entire register.
MOV AL, [ECX] ;Get next ASCII char.
INC ECX
TEST EAX, EAX ;Check for end of string.
JZ done
XLATB
CMP AL, 0FFh ;Is it a valid hex char?
JE error ;  Nope.

error: ; Do what needs to be done to return an error.
Assembly language programming should be fun. That's why I do it.

NoCforMe

Don't worry; I won't feel bad if you don't use my code in your assembler library
(sob, sniffle ...)
Assembly language programming should be fun. That's why I do it.

zedd151

I'll be back tomorrow...
Time for sleeep...
¯\_(ツ)_/¯   :azn:

'As we don't do "requests", show us your code first.'  -  hutch—

guga

Quote from: NoCforMe on March 11, 2025, 04:32:08 PMWellll, it probably could use some error checking.
It occurred to me that if you replaced the bytes in the translation table that didn't correspond to valid hex characters with -1, you could add this code to catch non-hex chars.:
next:    XOR    EAX, EAX        ;Clear entire register.
    MOV    AL, [ECX]        ;Get next ASCII char.
    INC    ECX
    TEST    EAX, EAX        ;Check for end of string.
    JZ    done
    XLATB
    CMP    AL, 0FFh        ;Is it a valid hex char?
    JE    error            ;  Nope.

error:    ; Do what needs to be done to return an error.


Yeah, using a error check is a good way to avoid unneeded results. Also, you have room to make it work for Qword if needed.

But, the better would be test it using JJ´s benchmark tool since it is more accurate then this simple version i made. Or Steve´s also made some Benchmark app a long time ago (Don´t know if i still have it), Siekmanski also has some good tools for testing for speed.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

guga

Quote from: NoCforMe on March 11, 2025, 04:35:30 PMDon't worry; I won't feel bad if you don't use my code in your assembler library
(sob, sniffle ...)

Didn´t say that :bgrin:  :bgrin:  :bgrin: If you code some functions that are needed, not only me but others could also use if you allow it to. It´s not a competition, you know... :cool:  :cool:  :cool: i´m just trying to fix a lot of things in RosAsm right now and looking for alternatives for some very old code that needs to be upgraded and fixed.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

NoCforMe

Oh, I understand. whatever is fine with me. And if you ever want to use any of my code that I post here, please feel free to do so; I make no claims upon it. (I like to use "copyleft".)
Assembly language programming should be fun. That's why I do it.

ognil

#112
Hi Guga,

My five cents... :smiley:

.data

    ; Constants for comparisons
    HexLowerBound db 16 dup(30h)  ; '0'
    HexUpperBound db 16 dup(39h)  ; '9'
    HexALowerBound db 16 dup(41h) ; 'A'
    HexAUpperBound db 16 dup(46h) ; 'F'
    HexaLowerBound db 16 dup(61h) ; 'a'
    HexaUpperBound db 16 dup(66h) ; 'f'

.code
; Input: RCX = pointer to the 16-byte string
; Output: RAX = 1 if all characters are valid hex, 0 otherwise

CheckHexString PROC
    ; Load the 16-byte string into xmm0
    movdqu xmm0, [rcx]

    ; Create constants for comparisons
    movdqa xmm1, xmmword ptr [HexLowerBound] ; '0' (30h)
    movdqa xmm2, xmmword ptr [HexUpperBound] ; '9' (39h)
    movdqa xmm3, xmmword ptr [HexALowerBound]; 'A' (41h)
    movdqa xmm4, xmmword ptr [HexAUpperBound]; 'F' (46h)
    movdqa xmm5, xmmword ptr [HexaLowerBound]; 'a' (61h)
    movdqa xmm6, xmmword ptr [HexaUpperBound]; 'f' (66h)

    ; Compare each byte against the ranges
    pcmpgtb xmm7, xmm0, xmm1  ; xmm7 = (xmm0 > '0')
    pcmpgtb xmm8, xmm2, xmm0  ; xmm8 = ('9' > xmm0)
    pand xmm7, xmm8           ; xmm7 = ('0' <= xmm0 <= '9')

    pcmpgtb xmm9, xmm0, xmm3  ; xmm9 = (xmm0 > 'A')
    pcmpgtb xmm10, xmm4, xmm0 ; xmm10 = ('F' > xmm0)
    pand xmm9, xmm10          ; xmm9 = ('A' <= xmm0 <= 'F')

    pcmpgtb xmm11, xmm0, xmm5 ; xmm11 = (xmm0 > 'a')
    pcmpgtb xmm12, xmm6, xmm0 ; xmm12 = ('f' > xmm0)
    pand xmm11, xmm12         ; xmm11 = ('a' <= xmm0 <= 'f')

    ; Combine all valid ranges
    por xmm7, xmm9            ; xmm7 = (('0' <= xmm0 <= '9') || ('A' <= xmm0 <= 'F'))
    por xmm7, xmm11           ; xmm7 = (('0' <= xmm0 <= '9') || ('A' <= xmm0 <= 'F') || ('a' <= xmm0 <= 'f'))

    ; Extract the mask of valid bytes
    pmovmskb eax, xmm7        ; EAX = bitmask of valid bytes (1 bit per byte)

    ; Check if all 16 bytes are valid (mask should be 0xFFFF)
    cmp eax, 0FFFFh
    sete al                   ; AL = 1 if all bytes are valid, 0 otherwise

    ; Zero-extend AL to RAX
    movzx rax, al
    ret

CheckHexString ENDP
"Not keeping emotions under control is another type of mental distortion."

NoCforMe

Late addition:
If you use my method (AscHex2Bin()) with the error checking I added, you should add this to the hex translation table to cover the remainder of the ASCII character set:
      DB 153 DUP(-1)
That'll return an error for any non-hex character up to the limit (255).
Makes the translation table 256 bytes long, not too bad for size overall.
Assembly language programming should be fun. That's why I do it.

stoo23

QuoteOn the other hand, I respect old people and never argue with them
Hmmmm NOT Lingo eh ???

That is a Direct 'Lingo' Quote !!! used more than once in the past ....
Let alone NOT being true,.. you often DO

So do you suffer from Multiple Personality disorder ??

zedd151

I just call him Pinocchio Pants on Fire.  :biggrin:
¯\_(ツ)_/¯   :azn:

'As we don't do "requests", show us your code first.'  -  hutch—

ognil

#116
I'm glad the impolite old lads are having fun with a new detective game. :badgrin:
It's just not clear who's playing Sherlock Holmes and who's playing Dr. Watson? :badgrin:

Q. Why are old people often mean and rude
A:  1. They may be physically in pain. Adding onto this, chronic pain takes up a LOT of mental bandwidth and energy. Being kind, empathetic, patient, and understanding are intentional acts that take time and effort, which is something we often take for granted.
Pain robs a lot of energy and patience from people, and people will default to being 'snappy', impatient, and presumptuous because it's quicker and more automatic
Chronic pain makes people unhappy and they don't even realize it after awhile.
2. They don't hear well and/or vision failing.
3. They may be socially isolated and depressed. Sometimes depression expresses itself as irritability.
4. Sometimes older people lose their filters. They feel more comfortable doing and saying whatever,    because they really don't care what other people think anymore.
5. They may be unhappy and bitter over how their lives have turned out.
6.Fatigue and a complete refusal to fight to appear positive and hopeful in their final years.
7. They're in pain from various ailments, and this reduces their energy levels and makes them tired and irritable.
8.The world they grew up in and which felt familiar to them has faded, and they dislike or feel no place in a different popular culture.
9.They feel cheated by life, that they worked and sacrificed but did not receive the rewards or comforts they expected.
10.They feel disrespected or unwanted by younger people, and their advice and opinions have been ignored.
11.They were bitter and rude jerks when they were young, and now just have more leisure time to express it.
12.Testosterone deficiency due to decreasing testosterone levels associated with low testicular production, genetic factors, adiposity, and illness. Low testosterone levels in men are associated with sexual dysfunction (low sexual desire, erectile dysfunction), reduced skeletal muscle mass and strength, decreased bone mineral density, increased cardiovascular risk and alterations of the glycometabolic profile.
:undecided:  :sad:
"Not keeping emotions under control is another type of mental distortion."

NoCforMe

STOP POSTING THAT "AI" BULLSHIT!
Assembly language programming should be fun. That's why I do it.

ognil

QuoteSTOP POSTING THIS "AI" BULLSHIT!.

I don't understand why you criticize without being able to give a solution, who can answer my questions.
Maybe someone from the forum? No thanks... :badgrin:
"Not keeping emotions under control is another type of mental distortion."

zedd151

#119
Quote from: ognil on March 19, 2025, 08:47:36 AM
QuoteSTOP POSTING THIS "AI" BULLSHIT!.

I don't understand why you criticize without being able to give a solution
He did give a solution. Stop posting this/that AI Bullshit. (He changed it after you quoted him)
Stop posting ANY and ALL bullshit. An even better solution.

See how that works?  :badgrin:
No one forces you to read anything here, or post here.

You could go back to your empty forum, and talk to yourself.  :biggrin:
Only a half dozen or so members (in name only, not really participating members) there.
No real guests interested in anything there. Only curiosity seekers from here.
No Google search hits leading to there.
No search bots, spiders, web crawlers. No indexing on any web search platform.
No one to interfere with your 'important' work there. (Meant to be very tongue-in-cheek).  :badgrin:
Want 'peace and quiet'?? ... go back there and don't come back. We would like some 'peace and quiet' here too. More easily accomplished without your presence.  :biggrin:

Disclaimer: These are my opinions. These opinions may not reflect the opinions of other members, administration, forum staff, or the general public. If you would like to appeal my opinions, in the immortal words of hutch--, TUFF SHYTE!

Btw, have a nice day!   :smiley:
¯\_(ツ)_/¯   :azn:

'As we don't do "requests", show us your code first.'  -  hutch—