Subject: New bittest.c

From: [email-masked] (Paul D. Smith)
Date: 11 Dec 1997 11:53:39 -0500

I enclose here what I think is a slightly fairer comparison between the
bitfield vs. multiple integer methods, which wraps the integers into a
struct and uses them that way.

I also added an implementation of my originally suggested array
solution, along with SET_FLAG and RESET_FLAG macros.

Unfortunately, I've discovered that GCC itself won't generate annotated
assembly; you have to get GAS for that.  I don't have a copy, and
binutils is a honkin' big package, but I'm working on it :).  But from
an eyeballing of the raw assembly it doesn't look like there's much
difference at all between them.

$ cat bittest.c
#include <stdio.h>
#include <limits.h>

/* struct for using the old method, and adding a new flag member */
typedef struct
{
  unsigned long flag1;
  unsigned long flag2;
} old;

old old_win;

/* Struct for using bitfields */
typedef struct
{
  unsigned int StartIconic:1;       /* 1 */
  unsigned int OnTop:1;             /* 2 */
  unsigned int Sticky:1;
  unsigned int StickyIcon:1;
  unsigned int SuppressIcon:1;      /* 5 */
  unsigned int NoIconTitle:1;
  unsigned int Lenience:1;
  unsigned int WindowListSkip:1;
  unsigned int CirculateSkip:1;
  unsigned int CirculateSkipIcon:1; /* 10 */
  unsigned int FocusPolicy:2; /* MOUSE, SLOPPY, CLICK, NEVER */
  unsigned int ShowOnMap:1;
  unsigned int Border:1;
  unsigned int Title:1;             /* 15 */
  unsigned int Mapped:1;
  unsigned int Iconified:1;
  unsigned int Transient:1;
  unsigned int Raised:1;
  unsigned int Visible:1;
  unsigned int IconOurs:1;
  unsigned int PixmapOurs:1;
  unsigned int ShapedIcon:1;
  unsigned int Maximized:1;         /* 24 */
  unsigned int t25:1;
  unsigned int t26:1;
  unsigned int t27:1;
  unsigned int t28:1;
  unsigned int t29:1;
  unsigned int t30:1;
  unsigned int t31:1;
  unsigned int t32:1;
  unsigned int t33:1;
  unsigned int t34:1;
  unsigned int t35:1;
  unsigned int t36:1;
} bit;

bit bit_win;

/* New method, but use an array and macro instead of bitfields */
typedef struct {
  unsigned long flags[2];
} array;

array array_win;

#define VSZ               (sizeof(unsigned long)*CHAR_BIT)

#define SET_FLAG(_v,_f)   ((_v)[(_f)/VSZ]|=(1<<((_f)-1)%VSZ))
#define RESET_FLAG(_v,_f) ((_v)[(_f)/VSZ]&=~((1<<((_f)-1)%VSZ)))

int tmp;

int
main()
{
    /* bitfields */
    bit_win.Iconified = 1;

    bit_win.t36 = 1;

    bit_win.Iconified = 0;

    bit_win.t36 = 0;

    /* Old way, adding new flag element */
#define OLD_ICONIFIED   2
#define OLD_T36         8  /* 1 << (36 - 32 - 1) */

    old_win.flag1 |= OLD_ICONIFIED;

    old_win.flag2 |= OLD_T36;

    old_win.flag1 &= ~OLD_ICONIFIED;

    old_win.flag2 &= ~OLD_T36;

    /* Use an array */
#define ARRAY_ICONIFIED   2
#define ARRAY_T36         36

    SET_FLAG(array_win.flags, ARRAY_ICONIFIED);

    SET_FLAG(array_win.flags, ARRAY_T36);

    RESET_FLAG(array_win.flags, ARRAY_ICONIFIED);

    RESET_FLAG(array_win.flags, ARRAY_T36);

    return (0);
}
--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked].