[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-sparse
Subject:    Re: [sparse be] PATCH: (take II) condition branch simplify
From:       Linus Torvalds <torvalds () osdl ! org>
Date:       2004-04-14 22:07:20
Message-ID: Pine.LNX.4.58.0404141457340.12398 () ppc970 ! osdl ! org
[Download RAW message or body]



On Wed, 14 Apr 2004, Christopher Li wrote:
> 
> > could add generic "flag" support to the list entry things by just always
> > using the two low bits of a pointer, or something like that, but maybe
> > it's not worth it.
> 
> Then we have to mask out the lowest two bits to use the pointer? I am not
> sure it is worth while.

Note that _users_ would never have to mask out the low bits, since they 
never access those things directly anyway - only the macros in lib.h would 
ever know about the tags, and the only change would really be the:

	do {							\
		ptr = (__typeof__(ptr)) (__list->list[__i]);	\

line becoming something like

	do {							\
		unsigned long TAG = __list->list[__i];		\
		ptr = (__typeof__(ptr)) (~3UL & TAG);		\
		TAG &= 3;					\

and then you could use the FOR_EACH_PTR() macros as-is, except your list 
traversal would also always see the "TAG" thing while traversing it.

So if you want to mix different pointers on a list, you could do just

	FOR_EACH_PTR(list, ptr) {
		switch (TAG) {
		case PTR_PHI:
			/* ptr is pointer to a phi node */
			phi = (struct phi_node) ptr;
			...
			break;
		case PTR_SYM:
			/* ptr is pointer to a symbol */
			sym = (struct symbol *) ptr;
			...
		}
	} END_FOR_EACH_PTR;

Yeah, I'm not claiming it makes any sense. I'm just claiming that it
wouldn't necessarily be all that hard to do even without having to change
any existing users if we ever want to do something like this ;)

		Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic