473,796 Members | 2,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DJ Bernstein's str library

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.

--
Peter Davies

Nov 15 '05 #1
92 3101
Isn't it just an example of an unrolled loop, reducing the overhead (if
any) of the test for termination of the for loop?

Nov 15 '05 #2
Poldie wrote:
Isn't it
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.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 15 '05 #3
On 2005-10-27, Flash Gordon <sp**@flash-gordon.me.uk> wrote:
Poldie wrote:
Isn't it


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.

--
I was half-tempted to not quote you.
Nov 15 '05 #4
> 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.

Nov 15 '05 #5
In article <qt************ @news.flash-gordon.me.uk>,
Flash Gordon <sp**@flash-gordon.me.uk> wrote:
Poldie wrote:
Isn't it


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).

Nov 15 '05 #6
> 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!

Nov 15 '05 #7
On Thu, 27 Oct 2005 13:20:50 +0000, Kenny McCormack whinged:
In article <qt************ @news.flash-gordon.me.uk>,
Flash Gordon <sp**@flash-gordon.me.uk> whinged:

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

--
Peter Davies

Nov 15 '05 #8
On 2005-10-27, Poldie <Po****@gmail.c om> wrote:
Provide context, there is no guarantee that everyone who
sees your post

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.

--
Neil Cerutti
Nov 15 '05 #9
> It's obviously your right to hold that attitude, but it is only
to your advantage if you prefer being ostracized.


Who are you calling an ostrich?

Nov 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6475
by: pieter.breed | last post by:
Hi All, The company I work for has traditionally used COM/ActiveX for the solutions that it provides. We are in the process of moving to .NET and a few applications have been written in VB.NET up to this point. Some of the applications are class libraries which need to be callable via the COM interface from some of the older applications. Could someone please explain to me the issues involved in deploying such a class library?
4
3375
by: womanontheinside | last post by:
I have a library which was written in C, you call a function, it provides the result by a callback to specific function names. I am trying to wrap the calls to this inside a class, but this causes a problem with the callbacks, for example: class X { public: add(); };
3
4270
by: K.S.Liang | last post by:
Hi all, 1> If there are more than one dynamic linking libraries in the file system, how do I know which one is loaded into system? Any C library or system call can tell me which *.so or *.sl is active? Can the setting of LD_LIBRARY_PATH guanrantee that the correct one is executed? 2> In MS-WINDOWS, once a DLL is loaded by one allication, this DLL will be used by the subsequent appication. Does UNIX have the same
19
2519
by: Deniz Bahar | last post by:
Hi, I would like to call one of my functions the exact name as an existing C library function (for example K&R2 exercises asks me to make an atof function). If I don't include the header with the declaration for the C library function (stdlib.h in this case) then define/declare my own function with the same name, am I safe? It seems to work on my compiler, but I wonder if this is portable or even acceptable? thx
3
1593
by: Manny Silva | last post by:
Hi, I would like to create a static library that uses and in effect adds to another static library. I could simply add functionality to the existing library, but functionally it doesn't really belong there... that is, the one library is very inspecific. The Library I need to create will be project specific, and I prefer not to have to mix the two... in any case, I tried to create a library that referenced the first library. I added...
1
7107
by: Jim | last post by:
Have fully operational software package developed on VB.NET that worked until Jan 1 2003, with early stage deployments on Oct 10, Oct 23, Nov 11, Dec 12 and Dec 30. When attempted final deployment on Jan 2, 2004 got following messages and errors... I reset everything and tried several times agian. Then erased the setup project and tried to rebuild a new one with the same errors. PLease note... ALL this this code ran perfectly five minutes...
10
1822
by: mwt | last post by:
So in a further attempt to learn some Python, I've taken the little Library program (http://groups.google.com/group/comp.lang.python/browse_thread/thread/f6a9ccf1bc136f84) I wrote and added several features to it. Readers now quit when they've read all the books in the Library. Books know how many times they've been read. Best of all, you can now create your own list of books to read! Again, the point of all this is to get used to...
10
2693
by: Julian | last post by:
I get the following error when i try to link a fortran library to a c++ code in .NET 2005. LINK : fatal error LNK1104: cannot open file 'libc.lib' the code was working fine when built using .NET2003. also, when I do not try to link the fortran library (just to see if that was the cause), it builds the exe without any problems. i don't even know how to begin addressing this problem...any help would be
0
4094
by: JosAH | last post by:
Greetings, the last two article parts described the design and implementation of the text Processor which spoonfeeds paragraphs of text to the LibraryBuilder. The latter object organizes, cleans up and stores the text being fed to it. Finally the LibrayBuilder is able to produce a Library which is the topic of this part of the article. Introduction
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9535
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10467
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10244
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4130
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.