flat assembler
Message board for the users of flat assembler.

Index > Main > Null termination?

Goto page Previous  1, 2, 3, 4  Next
Author
Thread Post new topic Reply to topic
buzzkill



Joined: 15 Mar 2009
Posts: 111
Location: the nether lands
buzzkill
Azu wrote:
I'd really rather not use functions


Not a big fan of structured programming? Very Happy
Post 30 Mar 2009, 18:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17669
Location: In your JS exploiting you and your system
revolution
Azu wrote:
I'd really rather not use functions unless necessary. Each use would be two needless branches. I could use macros, but then I wouldn't be able to optimize at a very fine grain.
Just have three different files, one file have the length prefix code, another the null terminate, etc. then selectively include one of them and test with it.
Post 30 Mar 2009, 18:27
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
buzzkill wrote:
Azu wrote:
I'd really rather not use functions


Not a big fan of structured programming? Very Happy
Structs are fine. They just make it easier to read/write the code and don't effect performance.



revolution wrote:
Azu wrote:
I'd really rather not use functions unless necessary. Each use would be two needless branches. I could use macros, but then I wouldn't be able to optimize at a very fine grain.
Just have three different files, one file have the length prefix code, another the null terminate, etc. then selectively include one of them and test with it.
Okay. I'll write it twice (with prepended lengths and with null termination). I was really hoping I wouldn't have to though.. Sad
Post 30 Mar 2009, 18:27
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17669
Location: In your JS exploiting you and your system
revolution
Azu wrote:
I did. Twice.
Not really, you gave some vague ideas but no hard figures to work with. Proper optimisation requires precise information else you risk getting the wrong outcome.
Post 30 Mar 2009, 18:29
View user's profile Send private message Visit poster's website Reply with quote
buzzkill



Joined: 15 Mar 2009
Posts: 111
Location: the nether lands
buzzkill
Azu wrote:
buzzkill wrote:
Azu wrote:
I'd really rather not use functions


Not a big fan of structured programming? Very Happy
Structs are fine. They just make it easier to read/write the code and don't effect performance.


I meant, normally you would divide your program into functions, each one containing a piece of the total functionality. This helps to keep your program logically structured, and promotes code reuse. If you really think that using functions is a waste because of a call/ret, I wonder what your programs look like...
Post 30 Mar 2009, 18:32
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
revolution wrote:
Azu wrote:
I did. Twice.
Not really, you gave some vague ideas but no hard figures to work with. Proper optimisation requires precise information else you risk getting the wrong outcome.
String comparison (checking if two strings are equal, and at what byte they differ if not) scanning (seeing if a byte (or substring) exists in a string, and at what byte), and copying (setting the bytes in one string to the bytes in another), with strings of varying sizes, and a big load.


buzzkill wrote:
Azu wrote:
buzzkill wrote:
Azu wrote:
I'd really rather not use functions


Not a big fan of structured programming? Very Happy
Structs are fine. They just make it easier to read/write the code and don't effect performance.


I meant, normally you would divide your program into functions, each one containing a piece of the total functionality. This helps to keep your program logically structured, and promotes code reuse. If you really think that using functions is a waste because of a call/ret, I wonder what your programs look like...
Why? Even if I didn't want to optimize individual pieces of code at that level, it would still be better performing to use macros into of functions, and would be just as readable and easy to write.
It might be BIGGER.. but compressing that would be ridiculously easy, and uncompressing it once at the very beginning of execution wouldn't be a big deal performance wise for a long running application.
Post 30 Mar 2009, 18:32
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17669
Location: In your JS exploiting you and your system
revolution
Azu wrote:
String comparison (checking if two strings are equal, and at what byte they differ if not) scanning (seeing if a byte (or substring) exists in a string, and at what byte), and copying (setting the bytes in one string to the bytes in another), with strings of varying sizes, and a big load.
Okay, so what are the ratios of each function? How long are the strings on average? Shortest? Longest? How many strings in total? Length of the search sub-string? Can you store meta data in the DB that has time saving precomputed info? How much of the system time is likely to be spent in string routines compared to other non-string routines? What CPU? What memory size/speed? etc.

I think it would be easier just to code up two or three versions and test.
Post 30 Mar 2009, 18:38
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
revolution wrote:
Azu wrote:
String comparison (checking if two strings are equal, and at what byte they differ if not) scanning (seeing if a byte (or substring) exists in a string, and at what byte), and copying (setting the bytes in one string to the bytes in another), with strings of varying sizes, and a big load.
Okay, so what are the ratios of each function? How long are the strings on average? Shortest? Longest? How many strings in total? Length of the search sub-string? Can you store meta data in the DB that has time saving precomputed info? How much of the system time is likely to be spent in string routines compared to other non-string routines? What CPU? What memory size/speed? etc.

I think it would be easier just to code up two or three versions and test.
Those are unknown except for on my own computer, under some artificial test. Which is why I am trying to figure out which is faster in general.
Post 30 Mar 2009, 18:42
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17669
Location: In your JS exploiting you and your system
revolution
Azu wrote:
Those are unknown except for on my own computer, under some artificial test. Which is why I am trying to figure out which is faster in general.
Exactly, and that is what optimisation is about. Specific situations and specific hardware. There is no such thing as "faster in general" unless you change the underlying algorithms or some other fundamental change.
Post 30 Mar 2009, 18:47
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
revolution wrote:
unless you change the underlying algorithms or some other fundamental change.
That's what I meant. The fundamental basis of how I am going to be using strings. To null, or not to null?
Post 30 Mar 2009, 18:49
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17669
Location: In your JS exploiting you and your system
revolution
But you still need to define how much time is spent processing strings? Is it 10%, 90%, what? I can't imagine an app that needs such a large amount of time just to process strings, but nevertheless, you did say that you want to optimise so naturally that means just for your situation.

String scanning, appending, searching algos etc. are also reliant on the type of strings you use. The length, the composition, the expected match hit position etc. You still need to define your usage model! You don't have to define it to me, but to yourself. And then you can start to make better decisions about what way to move forward with algo selections.
Post 30 Mar 2009, 18:57
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
revolution wrote:
But you still need to define how much time is spent processing strings? Is it 10%, 90%, what? I can't imagine an app that needs such a large amount of time just to process strings, but nevertheless, you did say that you want to optimise so naturally that means just for your situation.

String scanning, appending, searching algos etc. are also reliant on the type of strings you use. The length, the composition, the expected match hit position etc. You still need to define you usage model! You don't have to define it to me, but to yourself. And then you can start to make better decisions about what way to move forward with algo selections.
What I mean is, these things will be varying drastically. I don't know what % are going to be long and what % are going to be short, or how much % of the CPU is going to be used. Under this condition should I base the program on null termination, or prepended length?
Post 30 Mar 2009, 19:02
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17669
Location: In your JS exploiting you and your system
revolution
For example if all your strings are expected to be < 4 bytes then null termination may work out great. But what if all the string are > 1 MB then maybe length prefix is better. What if you need to have a null in the string, well then your decision is easy, length prefix. Hmm, what about an app that uses lots of printf type function calls, well then null termination might be just the thing.
Post 30 Mar 2009, 19:03
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17669
Location: In your JS exploiting you and your system
revolution
Azu wrote:
What I mean is, these things will be varying drastically. I don't know what % are going to be long and what % are going to be short, or how much % of the CPU is going to be used. Under this condition should I base the program on null termination, or prepended length?
Well if you don't know, then how can anyone else know? Nobody is omnipotent! (well not me anyway Wink)
Post 30 Mar 2009, 19:05
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
revolution wrote:
For example if all your strings are expected to be < 4 bytes then null termination may work out great. But what if all the string are > 1 MB then maybe length prefix is better. What if you need to have a null in the string, well then your decision is easy, length prefix. Hmm, what about an app that uses lots of printf type function calls, well then null termination might be just the thing.
If I have to make a guess, it would be around a kilobyte average, maybe.

It would be a bit faster/smaller to be able to use all 256 values per byte instead of having to reserve one for null, but that's not really a deal maker or breaker unless it's a tie or very close..


revolution wrote:
Azu wrote:
What I mean is, these things will be varying drastically. I don't know what % are going to be long and what % are going to be short, or how much % of the CPU is going to be used. Under this condition should I base the program on null termination, or prepended length?
Well if you don't know, then how can anyone else know? Nobody is omnipotent! (well not me anyway Wink)
But I'm not asking those things, you are..
I just want to know which is faster in general for string operations; null or length? Confused
Post 30 Mar 2009, 19:06
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17669
Location: In your JS exploiting you and your system
revolution
Azu wrote:
I just want to know which is faster in general for string operations; null or length? Confused
The same question again. And, strangely enough, the same answer, it depends upon your usage model. Aren't you getting tired of reading that? Wink

But we are starting to get somewhere, you now mention that your strings average 1kb. Okay, so that sounds kind of longish to me so scanning just to get a length would quite probably not be as efficient as a length prefix. But, on the other hand, printf things might benefit from an extra register in the loop so a null terminator might be better. Hmm, you see, it depends upon your usage.
Post 30 Mar 2009, 19:12
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
Thank you. I'll go with prepended length then. If I run out of registers I'll just use the length in memory.
Post 30 Mar 2009, 19:26
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
BTW what's the best way to do something like this?

Code:
var            db var.len
          db 'foo',30+var2
          dw var3
             dd 0,1
var.len               equ $-var    


It doesn't like that var.len is defined after var. =/

Do I have to make a macro for this? Or is there something in FASM that can handle it?

Sorry for the n00b question..
Post 30 Mar 2009, 22:07
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Almost correct
Code:
var.len = $ - var ; ("=" instead of "equ")    
Post 30 Mar 2009, 22:21
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
Perfect. Thanks a bunch Very Happy
Post 30 Mar 2009, 22:23
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.