DJ Bernstein's str library

M

Mark McIntyre

On Thu, 27 Oct 2005 16:48:27 GMT, in comp.lang.c ,
Agreed, in principle.

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

Just because some people think its a losing battle, is no reason to
give up.
 
O

Old Wolf

Peter said:
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;
}

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;
}

Does anyone have any ideas as to why this is done?

Back to the topic at hand...

It is reminiscent of an unrolled loop, but I don't see what
benefit there is. It just looks like a waste of code space
at best.

Normally, unrolled loops are used when it is performing
a set number of iterations -- so you can say do 4 iterations
per loop, so you only need to test the termination condition
1/4 of the time. But these loops are testing the termination
condition every time so it seems there is no advantage.
 
K

Keith Thompson

Peter Davies said:
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.

It's a form of loop unrolling, but I doubt that it's going to do much
good. Normally loop unrolling allows you to avoid the expense of a
test-and-branch on each iteration, but this code does that anyway
(though it avoids 75% of the unconditional branches back to the top of
the loop).

It's possible, but unlikely, that this will be faster than a more
straightforward loop.

I doubt that 4 iterations per loop is based on 4 bytes per word; more
likely it happens to be optimal in the environment in which the code
was developed.
 
D

Default User

Mark said:
On Thu, 27 Oct 2005 16:48:27 GMT, in comp.lang.c ,


Just because some people think its a losing battle, is no reason to
give up.


I don't believe it's a losing battle either. Google makes it tough on
new users to do the right thing by hiding the information. Most of the
ones here have switched once informed.


Brian
 
J

Jordan Abel

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.

What are you on about? He didn't tell _you_ to "**** off" - and,
yes, it's annoying, but it's not like his post didn't have a
References header. It's more annoying to read half a dozen posts
complaining about it than to hit alt-p and fetch the original post
in the first place. He might also have been more inclined to listen
to a friendly "Here's how to get google to let you quote context -
you know, for future reference" then what was basically "go to hell,
you're an asshole for not quoting and oh you wanna know how? search
the goddamn web yourself - and by the way the ideas in your post
also suck". If anyone was told "**** off" by anyone first, it was
him.
 
J

Jordan Abel

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.

I can hit meta-p to fetch previous article, or t to show all headers
then meta-l to fetch by message-id. I'm sure that *checks* pan has a
feature analogous to the second, even if not the first.

And yes, I'll agree that he was in the wrong - but "Poldie" was
downright rude about it. There was no need to be confrontational at
that stage.
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.

How about this:

"Hey, you didn't quote the message text... While I'm sure you didn't
mean to but please keep in mind that others can't see it - I see
you're using google groups. To get google groups to properly quote
text you can <do this>."
 
J

Jordan Abel

Peter Davies wrote:




*plonk*

There is something inherently trollish about shouting "plonk!" as if
anyone cares. He had a very good point - you and others decided to
harp on this one technical mistake while ignoring the interesting
issue brought up in the thread itself. Also, there was no reason to
be as mean about it as - IIRC "Flash Gordon" - was in the first
response.

Also, if you want to get technical about usenet etiquette, how about
putting a proper dash before your sig? it's "-- \n".
 
J

Jordan Abel

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.

"Your post is wrong and you are an asshole for posting it" is not
"instruction" by any stretch of the imagination

Repeat after me: hyphen hyphen space newline.

Normally I wouldn't bother, but you know what they say about casting
the first stone and all that.
 
D

Dik T. Winter

> He had a very good point - you and others decided to
> harp on this one technical mistake while ignoring the interesting
> issue brought up in the thread itself.

But you and some others ignore the possibility that the posting to
which it was an answer never did arrive at the newsserver you are using.
Or where it arrives later, possibly after you have read the response.

There are other possibilities where a context-less reply is unreadable.
For instance when you read the original the day before and in the
plethora of threads you are following you have no idea what it is a
response to.

BTW, when you look in google groups you will find that even there some
threads are seriously broken.
 
C

Christopher Benson-Manica

Jordan Abel said:
I can hit meta-p to fetch previous article, or t to show all headers
then meta-l to fetch by message-id. I'm sure that *checks* pan has a
feature analogous to the second, even if not the first.

Even if the previous article is available (it usually is, for me),
interspersing quotes and the responses to those quotes (as in this
post) makes for vastly more intuitive reading. Not to mention that
toggling back and forth between a reply and the original post(s) is,
at least with tin, distinctly annoying.
"Hey, you didn't quote the message text... While I'm sure you didn't
mean to but please keep in mind that others can't see it - I see
you're using google groups. To get google groups to properly quote
text you can <do this>."

Considering the vast number of times Keith and others have already
described the proper Google posting procedure, it's hard to blame them
for getting testy.
 
C

Christopher Benson-Manica

Jordan Abel said:
There is something inherently trollish about shouting "plonk!" as if
anyone cares.

I really fail to see how a "plonk" can be considered trollish, as by
its nature it prevents the plonker from enjoying the plonked poster's
response.
Also, there was no reason to
be as mean about it as - IIRC "Flash Gordon" - was in the first
response.

The bulk of Flash's ire was directed at Google, not the OP.
Frustration can set in at times.
 
J

Jan Richter

[...]
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.

Some keywords for you to consider are: " Branch-Prediction", " pipelining",
"loop-unrolling"
Wikipedia explains them excellent, and help me understanding.

apart from my earlier posting in this group <[email protected]>
I've learned a bit more about DJB's coding style.

He did that as a try to reduce the number of loops, mainly for older/bad
Compilers,
and for older Hardware.At the time where DJB wrote that code (mid 90s)
Hardware
and compilers are not that good (in optimizing) as they're today.
Because of nowadays "super-scalar" Hardware, and the available well
optimizing
Compilers I guess there is no real need to use such "hand-optimized" code.
My benchmarks on a 486-DX66 CPU, with DJB's str_len() function confirming
that.
There was no difference in using them on a state of the art Pentium IV CPU.

Cheers,
JR
 
F

Flash Gordon

Christopher said:
The bulk of Flash's ire was directed at Google, not the OP.

The bulk was, and indeed is, directed at Google. IIRC I said something
along the lines of "complain at Google for making you look like..."
rather than "you are..."
Frustration can set in at times.

Which, indeed, is why I am sometimes a bit short with people. Sometimes
I'm in a good enough mood to dig out the instructions and post them.

However, I try when possible to also provide feedback on what is said in
the post as well as pointing out the problem of lack of context.
 
P

Poldie

And yes, I'll agree that he was in the wrong - but "Poldie" was
downright rude about it. There was no need to be confrontational at
that stage.

I'd already been told I looked like a fool at that point though, hadn't
I? There was no need to say that I looked like a fool just because I'd
dared to reply without quoting and trimming the post to which I was
responding. Other people have since been far ruder, including
inventing that I'd told people to f*** off etc.

Plonking's got to hurt though, right? If only there was a way of
posting to a Usenet group under a different name...
 
J

Jordan Abel

I'd already been told I looked like a fool at that point though, hadn't
I? There was no need to say that I looked like a fool just because I'd
dared to reply without quoting and trimming the post to which I was
responding. Other people have since been far ruder, including
inventing that I'd told people to f*** off etc.

I myself have a bad 'habit' of not keeping good track of who said what and who
i'm responding to, and getting messed up when the format of attributed text etc
doesn't quite fit my expectations. This is entirely my fault. In this case, I
used your name when I in fact meant "Flash Gordon"
 
J

Jordan Abel

The bulk was, and indeed is, directed at Google. IIRC I said
something along the lines of "complain at Google for making you
look like..." rather than "you are..."


Which, indeed, is why I am sometimes a bit short with people.
Sometimes I'm in a good enough mood to dig out the instructions
and post them.

However, I try when possible to also provide feedback on what is
said in the post as well as pointing out the problem of lack of
context.

Regardless, the damage is done. I counted at least 3-4 people who
plonked him, when in this case I think he really didn't deserve it.
In any case, he seems to have learned his lesson about the quoting,
but the people who plonked him seemed to do so more due to his
reaction at being called on it than for the action itself, perhaps
assuming wrongly that he wouldn't have complained unless he intended
to continue his behavior in the future.

Another factor in this is that google runs its own forums using the
same interface [I won't common on whether this was a good decision
on their part]
 
P

Poldie

Regardless, the damage is done. I counted at least 3-4 people who
plonked him, when in this case I think he really didn't deserve it.
In any case, he seems to have learned his lesson about the quoting,
but the people who plonked him seemed to do so more due to his
reaction at being called on it than for the action itself, perhaps
assuming wrongly that he wouldn't have complained unless he intended
to continue his behavior in the future.

It is rather amazing, isn't it. The people who plonked me evidently
believe I was telling the group as a whole that I don't care for any of
the conventions of Usenet, rather than just telling one person who'd
insulted me and posted a non-sequitor
where to get off.

I've read and posted to Usenet for years now and usually quote and trim
posts I reply to, I don't top-post etc - I just lapsed because I wasn't
thinking about it too much and I was using Google rather than
Thunderbird.

I used to laugh at the `campaign for grumpiness where grumpiness is
due` sig-files but now it's being directed at me it's not so funny...!
Apologies to anyone I genuinely offended!
 

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,171
Messages
2,570,935
Members
47,472
Latest member
KarissaBor

Latest Threads

Top