mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Eger <eger@havoc.gtf.org>
To: "Richard B. Johnson" <root@chaos.analogic.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: 0xdeadbeef vs 0xdeadbeefL
Date: Wed, 7 Jul 2004 00:52:02 -0400	[thread overview]
Message-ID: <20040707045202.GA6536@havoc.gtf.org> (raw)
In-Reply-To: <Pine.LNX.4.53.0407062035040.16334@chaos>

On Tue, Jul 06, 2004 at 08:38:53PM -0400, Richard B. Johnson wrote:
> On Tue, 6 Jul 2004, David Eger wrote:
> 
> > Is there a reason to add the 'L' to such a 32-bit constant like this?
> > There doesn't seem a great rhyme to it in the headers...
> 
> Well if you put the 'name' so we could search for the reason.....

The reason I ask is that I'm going on a cleaning spree of 

include/video/radeon.h

I was trying to debug my code figuring out which flags we were 
setting in GMC_GUI_MASTER_CNTL.  Now radeon.h does have lots of
#defines for what the bits mean, but they're all mixed up, e.g.:

#define GMC_DP_CONVERSION_TEMP_6500                0x00000000
#define GMC_DP_SRC_RECT                            0x02000000
#define GMC_DP_SRC_HOST                            0x03000000
#define GMC_DP_SRC_HOST_BYTEALIGN                  0x04000000
#define GMC_3D_FCN_EN_CLR                          0x00000000
#define GMC_3D_FCN_EN_SET                          0x08000000
#define GMC_DST_CLR_CMP_FCN_LEAVE                  0x00000000
#define GMC_DST_CLR_CMP_FCN_CLEAR                  0x10000000
#define GMC_AUX_CLIP_LEAVE                         0x00000000
#define GMC_AUX_CLIP_CLEAR                         0x20000000
#define GMC_WRITE_MASK_LEAVE                       0x00000000
#define GMC_WRITE_MASK_SET                         0x40000000
#define GMC_CLR_CMP_CNTL_DIS                       (1 << 28)
#define GMC_SRC_DATATYPE_COLOR                     (3 << 12)
#define ROP3_S                                     0x00cc0000
#define ROP3_SRCCOPY                               0x00cc0000
#define ROP3_P                                     0x00f00000
#define ROP3_PATCOPY                               0x00f00000
#define DP_SRC_SOURCE_MASK                         (7    << 24)
#define GMC_BRUSH_NONE                             (15   <<  4)
#define DP_SRC_SOURCE_MEMORY                       (2    << 24)
#define GMC_BRUSH_SOLIDCOLOR                       0x000000d0

This mish-mash makes it impossible to grep for '0x00f0' or 
'0x000000f0' and get the answer I want, as GMC_BRUSH_NONE isn't 
listed in such a form.  So I wrote a little script to standardize
the file, and I noticed that in other sections, we have #defines
like these:

// CLK_PIN_CNTL
#define CLK_PIN_CNTL__OSC_EN_MASK                          0x00000001L
#define CLK_PIN_CNTL__OSC_EN                               0x00000001L
#define CLK_PIN_CNTL__XTL_LOW_GAIN_MASK                    0x00000004L
#define CLK_PIN_CNTL__XTL_LOW_GAIN                         0x00000004L
#define CLK_PIN_CNTL__DONT_USE_XTALIN_MASK                 0x00000010L
#define CLK_PIN_CNTL__DONT_USE_XTALIN                      0x00000010L

As part of the standardization, my script strips the 'L' off
of the constant.  (It's the output of 'eval()'ing the #define in 
Python.)  I was really just wondering if this would break anyone's
code.

Invocation goes like this:

$ (stdlbdef.py | upsidedown.py | stdlbdef.py | upsidedown.py ) < radeon.h > radeon.h.2

Then all of the simple arithmetic #define's are aligned to a uniform
width of hex value within each block of #define's.

-dte

#!/usr/bin/python
#
#  stdlbdef.py
#
# Got a header file where someone has mixed up their constants 
#  willy-nilly, like this?
#
#define GMC_AUX_CLIP_LEAVE                         0x00000000
#define GMC_AUX_CLIP_CLEAR                         0x20000000
#define GMC_WRITE_MASK_LEAVE                       0x00000000
#define GMC_WRITE_MASK_SET                         0x40000000
#define GMC_CLR_CMP_CNTL_DIS                       (1 << 28)
#define GMC_SRC_DATATYPE_COLOR                     (3 << 12)
#
# This script will make them all nice constants... mmmm..

import string
import re
import sys

linesplitter = re.compile("^(?P<a>#define\s+[a-zA-Z0-9_]+\s+)(?P<b>.*)")
hexnum = re.compile("^0[xX][0-9a-fA-F]+$")

l = sys.stdin.readline()
lastsize = 2

while l:
        ma = linesplitter.search(l,0)
        if ma and ma.group("b"):
                exp = ma.group("b").rstrip()
                # process the line
                if hexnum.match(exp,0) and len(exp) >= lastsize:
                        lastsize = len(exp)
                        sys.stdout.write( l )
                else:
                        try:
                                num = eval(exp)
                                q = '0x%x' % num
                                if len(q) < lastsize:
                                        fs = '0x%%0%dx' % (lastsize - 2)
                                        q = fs % num
                                lastsize = len(q)
                                sys.stdout.write( '%s%s\n' % (ma.group("a"), q))
                        except:
                                sys.stdout.write( l )
        else:
                sys.stdout.write( l )
                lastsize = 2
        l = sys.stdin.readline()


#!/usr/bin/python
#
# upsidedown.py
#
#   prints out a file, line by line, starting with the last line, 
#    going to the first

import sys
l = sys.stdin.readlines()
l.reverse()
for i in l:
        sys.stdout.write(i)


  reply	other threads:[~2004-07-07  4:52 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-06 21:56 David Eger
2004-07-07  0:06 ` tom st denis
2004-07-07  3:00   ` viro
2004-07-07 11:10     ` tom st denis
2004-07-07 11:18       ` Prohibited attachment type (was 0xdeadbeef) Richard B. Johnson
2004-07-07 11:48         ` tom st denis
2004-07-07 12:29           ` Jakub Jelinek
2004-07-08  5:52             ` Pavel Machek
2004-07-08 14:03               ` Jakub Jelinek
2004-07-07 12:13         ` R. J. Wysocki
2004-07-07 14:22       ` 0xdeadbeef vs 0xdeadbeefL viro
2004-07-07 18:47         ` tom st denis
2004-07-07 16:30       ` Gabriel Paubert
2004-07-07 18:41         ` tom st denis
2004-07-07 18:47           ` Christoph Hellwig
2004-07-07 18:53             ` tom st denis
2004-07-07 23:17               ` Harald Arnesen
2004-07-08  6:15               ` David Weinehall
2004-07-08  9:32               ` [OT] " Gabriel Paubert
2004-07-08 11:15                 ` viro
2004-07-08 11:55                   ` Gabriel Paubert
2004-07-08 16:41                   ` Andries Brouwer
2004-07-08 17:13                     ` Michael Driscoll
2004-07-08 17:16           ` Horst von Brand
2004-07-10  1:52           ` Andrew Rodland
2004-07-07  0:38 ` Richard B. Johnson
2004-07-07  4:52   ` David Eger [this message]
2004-07-07 11:40     ` Richard B. Johnson
2004-07-07  2:05 Ray Lee
2004-07-07  3:02 ` viro
2004-07-07  5:58   ` Alexandre Oliva
2004-07-07  6:12     ` Ray Lee
2004-07-07  5:55 ` Alexandre Oliva
2004-07-07  6:08   ` Ray Lee
2004-07-07  6:48   ` viro
2004-07-07 17:58     ` Alexandre Oliva
2004-07-12 17:31   ` H. Peter Anvin
2004-07-07  7:30 ` Tomas Szepe
2004-07-07 14:34   ` Jan-Benedict Glaw
2004-07-12 17:50   ` H. Peter Anvin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040707045202.GA6536@havoc.gtf.org \
    --to=eger@havoc.gtf.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=root@chaos.analogic.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®