DJ Bernstein's str library

P

Peter Davies

Hi all,

Plagued by the (to me) non-obvious functionality of DJB's str.h library, I
started looking at the source and what I saw took a while to make sense.

Each function runs an infinite loop, which iterates though a char* - in
order to search for needles or calculate a string length or whatever. What
got me was that each of the infinite loops held 4 identical statements:

for (;;) {
if (!*t) break; if (*t == ch) break; ++t;
if (!*t) break; if (*t == ch) break; ++t;
if (!*t) break; if (*t == ch) break; ++t;
if (!*t) break; if (*t == ch) break; ++t;
}
(in str_chr.c) and

for (;;) {
if (!*t) return t - s; ++t;
if (!*t) return t - s; ++t;
if (!*t) return t - s; ++t;
if (!*t) return t - s; ++t;
}
(in str_len.c)

Does anyone have any ideas as to why this is done? All I can think of is
that 4 chars=32bits and that nicely fills a register.
 
P

Poldie

Isn't it just an example of an unrolled loop, reducing the overhead (if
any) of the test for termination of the for loop?
 
F

Flash Gordon

Poldie said:

Isn't what? Provide context, there is no guarantee that everyone who
sees your post has seen the message you are responding to. Search the
group for "Google context" to find out how much of a problem this is and
how to work around the crap interface Google provide. Then complain at
Google for them making you look like a fool.
> just an example of an unrolled loop, reducing the overhead (if
any) of the test for termination of the for loop?

Once upon a time compilers were not very good at optimising. These days
you are generally better off leaving it to the compiler.
 
J

Jordan Abel

Isn't what? Provide context, there is no guarantee that everyone who
sees your post has seen the message you are responding to.

And that is why the References: header was invented.

yes, it's irritating. so is reading people complaining about it.
 
P

Poldie

Provide context, there is no guarantee that everyone who
sees your post
etc etc

Yawn. Guess what - I don't care.
Once upon a time compilers were not very good at optimising. These days
you are generally better off leaving it to the compiler.

He wasn't asking if optimization is worth performing 'these days' - he
was asking if perhaps that technique was related to registers, and I
was telling him that I didn't think it was. Your opinion of the
efficiency of current compiler optimization techniques is irrelevant.
 
K

Kenny McCormack

Isn't what? Provide context, there is no guarantee that everyone who
sees your post has seen the message you are responding to. Search the
group for "Google context" to find out how much of a problem this is and
how to work around the crap interface Google provide. Then complain at
Google for them making you look like a fool.

You (and others, such as Keith) are wasting your breath. They'll never get
it. And I'll tell you why.

Imagine that there's a mouse - and the mouse is the Usenet. You and I can
see that it is a mouse and we behave accordingly. But now there is a class
of users (we'll call them "googlers") that are wearing these funny weird
glasses that make them see not a mouse, but an elephant. Seeing an
elephant (i.e., the Usenet as a web page), they also behave accordingly.
And no amount of verbiage from us is going to convince them that it's not
an elephant - that it is only a mouse.

To make this more clear, to a googler, it doesn't make any sense to "quote"
(whatever the heck that is...), in fact, to do would be absurd, when all
the rest of the articles in the thread are right there in front of their
faces (just as clear as the trunk on that mouse, er, elephant). And no
amount of verbiage from us is going to convince them not to believe what
they see. The point is you can *never* convince someone that what they see
isn't reality. The only way you can address the problem is to help them
fix their eyesight (or help them remove their funny glasses).
 
P

Poldie

But now there is a class
of users (we'll call them "googlers") that are wearing these funny weird
glasses

There is also a class of users (we'll call them "net nerds") who spend
an inordinate amount of time on the internet, and who seem to suffer
delusions of grandeur which make it very very important to them that
every last character they type is preserved, in perfect context, for
all eternity, and the very thought that some people might be treating
the odd thread in the odd group with less than complete seriousness and
simply trying to answer a poster's question is just beyond the pale.

You are hereby served with the requirement that you admonish 25 Usenet
posters for top-posting in the next 60 minutes. Go get'em, tiger!
 
P

Peter Davies

[schnip]

Please continue whinging here. It will help me and others who are
interested in the original thread to differentiate between usefulness and
fluff.

Note that you are not the first to complain about Google and its effect on
Usenet. However much I may agree with your opinions on that topic, it is
in my opinion extremely rude to hijack threads for the purposes of being
bitchy.
 
N

Neil Cerutti

etc etc

Yawn. Guess what - I don't care.

It's obviously your right to hold that attitude, but it is only
to your advantage if you prefer being ostracized.
 
I

Ian Malone

Poldie said:
There is also a class of users (we'll call them "net nerds") who spend

Googlers is a better pun.
an inordinate amount of time on the internet, and who seem to suffer
delusions of grandeur which make it very very important to them that
every last character they type is preserved, in perfect context, for
all eternity, and the very thought that some people might be treating
the odd thread in the odd group with less than complete seriousness and
simply trying to answer a poster's question is just beyond the pale.

Actually, it's exactly the opposite. News servers throw away old
posts, google keeps them. If someone replys to a thread from last
week without context I haven't a clue what they're talking about
(since I use thunderbird and a news server). I'm not going to
bother looking for the context in google, because it will often
be a waste of time, so I ignore it.

Remember that posts are write once read many. The normal rule of
good writing therefore applys; people won't read what you have
written unless you make it easy for them.

(And, finally, odds-on the poster will remember what they wrote;
no-one else will. If you want a conversation rather than a
discussion there's always email.)
 
K

Kenny McCormack

Peter Davies said:
Note that you are not the first to complain about Google and its effect on
Usenet. However much I may agree with your opinions on that topic, it is
in my opinion extremely rude to hijack threads for the purposes of being
bitchy.

Um, point taken. But my point is that's exactly what the repetitive
bitching, by the "regulars", which boils down to "Don't respond as if
you're responding from Google" (which, as they are, is obviously the
natural [and, dare I say, proper] thing for them to do), amounts to.
 
K

Kenny McCormack

It's obviously your right to hold that attitude, but it is only
to your advantage if you prefer being ostracized.

Or admired by myself and others like me.
 
P

Poldie

Googlers is a better pun.

Depends upon what you're punning - I was punning on Googlers, in which
case using the same word wouldn't really have had the same hilarious
comedic effect.
Actually, it's exactly the opposite. News servers throw away old
posts, google keeps them. If someone replys to a thread from last
week without context I haven't a clue what they're talking about

If they have my response then they'll almost certainly have the
original post, especially if - as in this case - the response is posted
soon after the original post.
If you want a conversation rather than a discussion there's always email

Maybe later.
 
D

Default User

Jordan said:
And that is why the References: header was invented.
Bull.

yes, it's irritating. so is reading people complaining about it.

The main way the new Google users (which are flooding usenet) are going
to find out how to behave properly is if people instruct them. You are
in the wrong here.


Brian
 
D

Default User

Peter Davies wrote:

Please continue whinging here. It will help me and others who are
interested in the original thread to differentiate between usefulness
and fluff.


*plonk*



Brian
 
K

Kenny McCormack

Default User said:
The main way the new Google users (which are flooding usenet) are going
to find out how to behave properly is if people instruct them. You are
in the wrong here.

Agreed, in principle.

But, with Google as with all things Microsoft, in a very short while, it's
just not going to matter.
 
M

Martin Ambuhl

Poldie said:
etc etc

Yawn. Guess what - I don't care.

Guess what - you have just shown your disdain for the other readers of
this newsgroup. Good luck with any questions you might have in the
future. The people who know the answers but whom you have told to ****
off will not be reading your posts.

*PLONK*
 
K

Keith Thompson

Poldie said:
etc etc

Yawn. Guess what - I don't care.

You probably think you don't need to care because you read this
newsgroup through Google. Google provides a badly flawed interface,
but one of its virtues is that it makes it easy to see previous
articles. The majority of us, including most of the regulars, *don't*
use Google, so we can't see older articles as easily as you can.

Those who don't take the time to show some consideration for the rest
of us are far less likely to be able to participate in any meaningful
way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,170
Messages
2,570,925
Members
47,468
Latest member
Fannie44U3

Latest Threads

Top