Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Dauq
Mar 21, 2008

Plastic Jesus posted:

Suggestions? Does any of this make any sense at all?

If you say you're looking into asm as well, the x86 asm code has instructions specifically for finding bytes in strings.
You should look at REP SCANSB for your task, something like this maybe:

mov edi, _string ;your string
mov ecx, [string_length] ;your string's length
mov al, 0
repnz scansb ;the magic, scan for 0
jnz not_found
mov [pointer_to_result], edi
jmp exit_point
not_found:
movd [pointer_to_result], 0
exit_point:

I'm pretty sure nothing a compiler outputs is as efficient as the processor's string scaning instructions.
I'm not really experinced in inlining the asm in various compilers though, the syntax is very different between Intel and that AT&T syntax GCC uses.

Adbot
ADBOT LOVES YOU

Dauq
Mar 21, 2008

Plastic Jesus posted:

I thought about this, but the byte of interest will be part of an integer (and in a register already), not a string of characters.

On a related note, does anyone know if Microsoft's implementation of things like strlen() and strchr() make use of the REP SCAN instructions? I suppose that if I wasn't so lazy I'd just open in up in IDA right now. But I am.

Ok, i misunderstood i thought you were just trying to find the zeros in an array of bytes (your "puc" pointer).

If your integer is in a register the best i can think of is to use shift to right, and compare the byte-sized "low" registor to 0.

;integer in eax
...
mov ecx, 4
test_loop:
cmp al, 0
jz found_zero
shr eax, 8
loop test_loop
found_zero:
...
;position of byte (1-4) in ecx

As for the strlen question, sorry i never checked. :effort:

Dauq
Mar 21, 2008
I'm using read( write( to transfer data through a blocking stream socket in C, on Linux. Both client and server.
What i want to know is will the reads on the client and writes on the server match in size (as long as it is within the maximum receive buffer size ?). Or will the data come fragmented based on packet size, network issues and such and i'd have to rebuild it at the other end ?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply