Date: Tue, 11 Jul 2006 07:50:40 -0500 (CDT)
From: Dan Grayson <dan@math.uiuc.edu>
To: Michael Stillman <mike@math.cornell.edu>
CC: dan@math.uiuc.edu
In-reply-to: <65321829-56F1-47A7-8FAB-8E8DAFA92227@math.cornell.edu> (message
	from Michael Stillman on Tue, 11 Jul 2006 08:01:47 -0400)
Subject: Re: monomial size
Reply-to: dan@math.uiuc.edu


Well, if a long is ever 64 bits, we'll be wasting half of each one in this union:

    union pack4 {
      long i;
      struct {
	unsigned char a;
	unsigned char b;
	unsigned char c;
	unsigned char d;
      } ch;
    };

Use the types in util/targettypes.h instead of "long".

By the way, the code below might go faster with fewer if-statements breaking up
the pipeline.  Maybe start with a switch on nvars up to 8, and then a switch on
nvars&3, so you can do 0<=nvars-=4,expon+=4, with one quarter of the tests.
You could even unroll it further by switching on nvars&7.  (Do you have a
benchmark where monomialOrderEncode, which uses it, takes a lot of time?  If
not, these ideas are useless.)

    static void MO_pack4(int nvars, const int *expon, int *slots)
    {
      union pack4 w;
      while (nvars > 0)
	{
	  w.i = 0;
	  if (--nvars >= 0) {
	    w.ch.d = *expon++;
	    if (--nvars >= 0) {
	      w.ch.c = *expon++;
	      if (--nvars >= 0) {
		w.ch.b = *expon++;
		if (--nvars >= 0) w.ch.a = *expon++;
	      }}}
	  *slots++ = w.i;
	}


Also, 

      w.i = expon[0] | expon[1] << 8 | expon[2] << 16 | expon[3] << 24 ;

might be faster than the code above, because it stores to memory just once, as
opposed to four times.  I imagine storing a byte to memory takes just as long
as storing a whole word, and that the manipulations in registers needed to pack
the word up would be much faster.

> From: Michael Stillman <mike@math.cornell.edu>
> Subject: Re: monomial size
> Date: Tue, 11 Jul 2006 08:01:47 -0400
> To: dan@math.uiuc.edu
> 
> Currently, Tiny will still mean 8 bits per exponent, even on 64 bit  
> machines.  What is not yet implemented is MonomialSize=>64.
> 
> On Jul 11, 2006, at 7:57 AM, Dan Grayson wrote:
> 
> >
> > At top level we equate LexTiny with monomial size 8 bits, but in  
> > your code it
> > looks like the meaning is 4 exponents per "word".  So what if in  
> > the future we
> > compile it and a "word" is 64 bits?
> 

