Module Name:    src
Committed By:   jakllsch
Date:           Sat May 19 18:18:16 UTC 2018

Modified Files:
        src/sys/arch/i386/stand/mbr: gpt.S

Log Message:
Compact crc32 code by 12 bytes of text.

>From dave0 in #NetBSD on Freenode circa December 2017.

Tested in a 32-bit userland harness to produce identical results as old
code for one set of inputs.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/i386/stand/mbr/gpt.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/i386/stand/mbr/gpt.S
diff -u src/sys/arch/i386/stand/mbr/gpt.S:1.1 src/sys/arch/i386/stand/mbr/gpt.S:1.2
--- src/sys/arch/i386/stand/mbr/gpt.S:1.1	Thu Jan  6 01:08:49 2011
+++ src/sys/arch/i386/stand/mbr/gpt.S	Sat May 19 18:18:16 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: gpt.S,v 1.1 2011/01/06 01:08:49 jakllsch Exp $ */
+/*	$NetBSD: gpt.S,v 1.2 2018/05/19 18:18:16 jakllsch Exp $ */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -428,21 +428,14 @@ message_1:
  * %ebx		crc (returned)
  */
 crc32:
-	push	%dx			/* preserve drive number */
-	push	%ax			/* preserve original CRC */
-
-	xorl	%ebx, %ebx
-	decl	%ebx			/* init value */
+	orl	 $-1, %ebx		/* init value */
 1:
-	lodsb				/* load next message byte to %al */
+	xorb	(%si), %bl		/* xoring next message byte with previous result */
+	inc	%si
 	movb	$8, %cl			/* set bit counter */
 2:
-	movb	%al, %dl
-	xorb	%bl, %dl		/* xoring with previous result */
 	shrl	$1, %ebx
-	shrb	$1, %al
-	testb	$1, %dl
-	jz	3f
+	jnc	3f
 crc32_poly = . + 3			/* gross, but saves a few bytes */
 	xorl	$0xedb88320, %ebx	/* EFI CRC32 Polynomial */
 3:
@@ -451,8 +444,6 @@ crc32_poly = . + 3			/* gross, but saves
 	jne	1b
 	notl	%ebx			/* result correction */
 
-	pop	%ax
-	pop	%dx
 	ret
 #endif
 

Reply via email to