# [PATCH] block-sha1: make the size member first in the context struct

3 messages from 2009-08-18 to 2009-08-18. Participants: Nicolas Pitre, Johannes Schindelin.
Thread: https://gitlist.dev/t/20648

## Nicolas Pitre, 2009-08-18 00:18

Subject: [PATCH] block-sha1: make the size member first in the context struct
Message-ID: <alpine.LFD.2.00.0908172012591.6044@xanadu.home>
URL: https://gitlist.dev/e/alpine.LFD.2.00.0908172012591.6044%40xanadu.home

```
This is a 64-bit value, hence having it first provides a better 
alignment.

Signed-off-by: Nicolas Pitre <nico@cam.org>

diff --git a/block-sha1/sha1.h b/block-sha1/sha1.h
index 6ff59b2..b864df6 100644
--- a/block-sha1/sha1.h
+++ b/block-sha1/sha1.h
@@ -7,9 +7,9 @@
  */
 
 typedef struct {
+	unsigned long long size;
 	unsigned int H[5];
 	unsigned int W[16];
-	unsigned long long size;
 } blk_SHA_CTX;
 
 void blk_SHA1_Init(blk_SHA_CTX *ctx);

```

## Johannes Schindelin, 2009-08-18 00:24

Subject: Re: [PATCH] block-sha1: make the size member first in the context struct
Message-ID: <alpine.DEB.1.00.0908180223280.8306@pacific.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0908180223280.8306%40pacific.mpi-cbg.de
In-Reply-To: <alpine.LFD.2.00.0908172012591.6044@xanadu.home>

```
Hi,

On Mon, 17 Aug 2009, Nicolas Pitre wrote:

> This is a 64-bit value, hence having it first provides a better 
> alignment.
> 
> Signed-off-by: Nicolas Pitre <nico@cam.org>
> 
> diff --git a/block-sha1/sha1.h b/block-sha1/sha1.h
> index 6ff59b2..b864df6 100644
> --- a/block-sha1/sha1.h
> +++ b/block-sha1/sha1.h
> @@ -7,9 +7,9 @@
>   */
>  
>  typedef struct {
> +	unsigned long long size;
>  	unsigned int H[5];
>  	unsigned int W[16];
> -	unsigned long long size;
>  } blk_SHA_CTX;

By the reasoning suggested in the commit message, should H[5] not go to 
the end?

Ciao,
Dscho

```

## Nicolas Pitre, 2009-08-18 00:39

Subject: Re: [PATCH] block-sha1: make the size member first in the context struct
Message-ID: <alpine.LFD.2.00.0908172035320.6044@xanadu.home>
URL: https://gitlist.dev/e/alpine.LFD.2.00.0908172035320.6044%40xanadu.home
In-Reply-To: <alpine.DEB.1.00.0908180223280.8306@pacific.mpi-cbg.de>

```
On Tue, 18 Aug 2009, Johannes Schindelin wrote:

> Hi,
> 
> On Mon, 17 Aug 2009, Nicolas Pitre wrote:
> 
> > This is a 64-bit value, hence having it first provides a better 
> > alignment.
> > 
> > Signed-off-by: Nicolas Pitre <nico@cam.org>
> > 
> > diff --git a/block-sha1/sha1.h b/block-sha1/sha1.h
> > index 6ff59b2..b864df6 100644
> > --- a/block-sha1/sha1.h
> > +++ b/block-sha1/sha1.h
> > @@ -7,9 +7,9 @@
> >   */
> >  
> >  typedef struct {
> > +	unsigned long long size;
> >  	unsigned int H[5];
> >  	unsigned int W[16];
> > -	unsigned long long size;
> >  } blk_SHA_CTX;
> 
> By the reasoning suggested in the commit message, should H[5] not go to 
> the end?

Both arrays are based of unsigned ints which have the same alignment 
rules.  Furthermore the size and H members are much more used than the W 
member, and keeping them close should help with CPU cache locality.


Nicolas

```
