git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC/PATCH] Optimized PowerPC SHA1 generation for Darwin (OS X)

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Apr 7, 2007, 01:40 UTC
Message-ID
<Pine.LNX.4.64.0704061830350.6730@woody.linux-foundation.org>
In-Reply-To
<20070406234826.GG3854@regex.yaph.org>
On Sat, 7 Apr 2007, Arjen Laarhoven wrote:
Show 5 quoted lines
>
> The compiler toolchain supplied by Apple's Xcode environment has an old
> version (1.38) of the GNU assembler.  It cannot assemble the optimized
> ppc/sha1ppc.S file.  ppc/sha1ppc.S was rewritten into a Perl script
> which outputs the same code, but valid for the Xcode assembler.
Ugh. That's just too ugly.

The Linux version of the GNU assembler can certainly take the same limited input as the old Apple one.

So how about instea dof having two totally different versions of this file, just having *one*, and having a pre-processor that turns it into something that is acceptable to both?

And yes, it could be your perl script, except your perl script is ugly as *hell*. The old C preprocessor code is much nicer than your perl script that does "print" statements.

How about something like the following instead?
 (a) make the register macros expand to something easily 
     greppable/parseable
 (b) have a *separate* preprocessor phase that actually then takes that 
     pattern, and evaluates it to a numeric value.
 (c) assemble the end result

The (a) part is trivial. Just a patch like the appended will make sure that all the registers are now written as "REG[int-expression]", and then all you need is a perl-script or something that can trigger on the regexp

	"REG\[\([^]]*\)\]"
and replace that regex with
	"%eval(\1)"
which is somethign that perl should be designed for.

That way you just have *one* source file (the "sha1ppc.S" one), which is readable, and a simple script to then evaluate the register numbers statically instead of expecting that the assembler can do it (since the Apple one apparently cannot).

So it would just require somebody who knows perl. What's a one-liner perl script to turn a line like

	add REG[((0)+0)%5+6],REG[((0)+0)%5+6],REG[(0)%16+11];
into
	add %6,%6,%11

(ie it just evaluated the expression inside the [] things, and replaced it with the "%<num>" string)?

<Taunting mode>Or maybe perl can't do that in a single line!</Taunting mode>
		Linus
---
diff --git a/ppc/sha1ppc.S b/ppc/sha1ppc.S
index f132696..cc554a4 100644
--- a/ppc/sha1ppc.S
+++ b/ppc/sha1ppc.S
@@ -32,14 +32,14 @@
  * We use registers 6 - 10 for this.  (Registers 27 - 31 hold
  * the previous values.)
  */
-#define RA(t)	(((t)+4)%5+6)
-#define RB(t)	(((t)+3)%5+6)
-#define RC(t)	(((t)+2)%5+6)
-#define RD(t)	(((t)+1)%5+6)
-#define RE(t)	(((t)+0)%5+6)
+#define RA(t)	REG[((t)+4)%5+6]
+#define RB(t)	REG[((t)+3)%5+6]
+#define RC(t)	REG[((t)+2)%5+6]
+#define RD(t)	REG[((t)+1)%5+6]
+#define RE(t)	REG[((t)+0)%5+6]
 
 /* We use registers 11 - 26 for the W values */
-#define W(t)	((t)%16+11)
+#define W(t)	REG[(t)%16+11]
 
 /* Register 5 is used for the constant k */
 
Previous: Junio C HamanoNext: Arjen Laarhoven
Message 3 of 7 in “Optimized PowerPC SHA1 generation for Darwin (OS X)”
  1. Optimized PowerPC SHA1 generation for Darwin (OS X)Arjen Laarhoven, Apr 6, 2007
  2. Junio C HamanoApr 7, 2007
  3. Linus TorvaldsApr 7, 2007
  4. Arjen LaarhovenApr 8, 2007
  5. Karl HasselströmApr 10, 2007
  6. Arjen LaarhovenApr 10, 2007
  7. Karl HasselströmApr 10, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.