Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 7 Jan 2013 23:19:08 +0400
From: Solar Designer <solar@...nwall.com>
To: john-dev@...ts.openwall.com
Subject: Re: mask-mode speed

On Mon, Jan 07, 2013 at 09:48:27AM -0500, jfoug@....net wrote:
> Here is an extern run. This extern (listed at the end of the post), is probably about as fast as it can be done externally.

Actually, we can do a bit faster.

> void generate()
> {
>     pos = 9;
> 	++word[pos];
> 	while (word[pos] == ':') {
> 		word[pos] = '0';
> 		--pos;
> 		if (pos == -1) { word = 0; return; }
> 		++word[pos];
> 	}
> }

Here's a possible replacement for the above:

void generate()
{
	if (++word[9] <= '9')
		return;
	word[9] = '0';
	pos = 8;
	while (++word[pos] > '9') {
		if (pos) {
			word[pos--] = '0';
		} else {
			word = 0;
			return;
		}
	}
}

The hard-coded 9 and 8 can be avoided with no performance impact by
putting them in variables in init().

The external mode compiler is (mostly) not optimizing - e.g., it does
not detect common subexpressions (and even if it would, quickly reusing
them in the stack-based VM would not always be possible without some
additional rearrangement to keep them on top of stack at the right
times).  So e.g. "++word[pos = 9]" is quicker than "pos = 9;
++word[pos];"  Similarly, directly using this expression as a
conditional in an "if" or "while" statement is quicker than repeating
"word[pos]" in there separately.

Alexander

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.