* [PATCH] Add __builtin_popcountl
@ 2006-10-26 17:47 Matthew Wilcox
2006-10-26 18:43 ` Al Viro
0 siblings, 1 reply; 4+ messages in thread
From: Matthew Wilcox @ 2006-10-26 17:47 UTC (permalink / raw)
To: linux-sparse
IA-64 uses __builtin_popcountl() which wasn't a function sparse knew
about. This patch adds it. I've never looked at sparse before, so this
is a hack-and-run job. Please feel free to rewrite it if it doesn't suit.
Signed-off-by: Matthew Wilcox <matthew@wil.cx>
diff --git a/symbol.c b/symbol.c
index 6c91112..388e19d 100644
--- a/symbol.c
+++ b/symbol.c
@@ -592,6 +592,29 @@ static int evaluate_choose(struct expres
return 1;
}
+static int arguments_popcountl(struct expression *expr)
+{
+ struct expression_list *arglist = expr->args;
+ struct expression *arg;
+ int i = 0;
+
+ FOR_EACH_PTR (arglist, arg) {
+ if (!evaluate_expression(arg))
+ return 0;
+ i++;
+ } END_FOR_EACH_PTR(arg);
+ if (i < 1) {
+ sparse_error(expr->pos,
+ "not enough arguments for __builtin_popcountl");
+ return 0;
+ } if (i > 1) {
+ sparse_error(expr->pos,
+ "too many arguments for __builtin_popcountl");
+ return 0;
+ }
+ return 1;
+}
+
static int expand_expect(struct expression *expr, int cost)
{
struct expression *arg = first_ptr_list((struct ptr_list *) expr->args);
@@ -744,6 +767,11 @@ static struct symbol_op choose_op = {
.args = arguments_choose,
};
+static struct symbol_op popcountl_op = {
+ .evaluate = evaluate_to_integer,
+ .args = arguments_popcountl,
+};
+
/*
* Builtin functions
*/
@@ -754,6 +782,7 @@ static struct sym_init eval_init_table[]
{ "__builtin_warning", &builtin_fn_type, MOD_TOPLEVEL, &warning_op },
{ "__builtin_expect", &builtin_fn_type, MOD_TOPLEVEL, &expect_op },
{ "__builtin_choose_expr", &builtin_fn_type, MOD_TOPLEVEL, &choose_op },
+ { "__builtin_popcountl", &builtin_fn_type, MOD_TOPLEVEL, &popcountl_op },
{ NULL, NULL, 0 }
};
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Add __builtin_popcountl
2006-10-26 17:47 [PATCH] Add __builtin_popcountl Matthew Wilcox
@ 2006-10-26 18:43 ` Al Viro
2006-10-26 18:56 ` Linus Torvalds
0 siblings, 1 reply; 4+ messages in thread
From: Al Viro @ 2006-10-26 18:43 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: linux-sparse
On Thu, Oct 26, 2006 at 11:47:30AM -0600, Matthew Wilcox wrote:
>
> IA-64 uses __builtin_popcountl() which wasn't a function sparse knew
> about. This patch adds it. I've never looked at sparse before, so this
> is a hack-and-run job. Please feel free to rewrite it if it doesn't suit.
AFAICS, that's way over the top. That kind of stuff is needed only
when builtin can't be described as a normal function. This, OTOH...
diff --git a/lib.c b/lib.c
--- a/lib.c
+++ b/lib.c
@@ -467,6 +467,16 @@ void declare_builtin_functions(void)
add_pre_buffer("extern void __builtin_trap(void);\n");
add_pre_buffer("extern int __builtin_ffs(int);\n");
add_pre_buffer("extern void *__builtin_alloca(__SIZE_TYPE__);\n");
+ add_pre_buffer("extern int __builtin_popcount(unsigned int);\n");
+ add_pre_buffer("extern int __builtin_popcountl(unsigned long);\n");
+ add_pre_buffer("extern void __builtin_prefetch (const void *, ...);\n");
+ add_pre_buffer("extern long __builtin_alpha_extbl(long, long);\n");
+ add_pre_buffer("extern long __builtin_alpha_extwl(long, long);\n");
+ add_pre_buffer("extern long __builtin_alpha_insbl(long, long);\n");
+ add_pre_buffer("extern long __builtin_alpha_inswl(long, long);\n");
+ add_pre_buffer("extern long __builtin_alpha_insql(long, long);\n");
+ add_pre_buffer("extern long __builtin_alpha_inslh(long, long);\n");
+ add_pre_buffer("extern long __builtin_alpha_cmpbge(long, long);\n");
}
void create_builtin_stream(void)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Add __builtin_popcountl
2006-10-26 18:43 ` Al Viro
@ 2006-10-26 18:56 ` Linus Torvalds
2006-10-26 19:19 ` Al Viro
0 siblings, 1 reply; 4+ messages in thread
From: Linus Torvalds @ 2006-10-26 18:56 UTC (permalink / raw)
To: Al Viro; +Cc: Matthew Wilcox, linux-sparse
On Thu, 26 Oct 2006, Al Viro wrote:
>
> AFAICS, that's way over the top. That kind of stuff is needed only
> when builtin can't be described as a normal function. This, OTOH...
On the other hand, adding "true" builtin functions is actually a lot
cheaper than adding bogus code to be parsed explicitly.
So I'd actually prefer a way to have a table to describe and initialize
these things, as a way to make it a lot more efficient, and without the
silly preprocessor buffer hacks..
The preprocessor hack is certainly simple, but it's not what you really
want in real life.
Linus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Add __builtin_popcountl
2006-10-26 18:56 ` Linus Torvalds
@ 2006-10-26 19:19 ` Al Viro
0 siblings, 0 replies; 4+ messages in thread
From: Al Viro @ 2006-10-26 19:19 UTC (permalink / raw)
To: Linus Torvalds; +Cc: Matthew Wilcox, linux-sparse
On Thu, Oct 26, 2006 at 11:56:00AM -0700, Linus Torvalds wrote:
>
>
> On Thu, 26 Oct 2006, Al Viro wrote:
> >
> > AFAICS, that's way over the top. That kind of stuff is needed only
> > when builtin can't be described as a normal function. This, OTOH...
>
> On the other hand, adding "true" builtin functions is actually a lot
> cheaper than adding bogus code to be parsed explicitly.
>
> So I'd actually prefer a way to have a table to describe and initialize
> these things, as a way to make it a lot more efficient, and without the
> silly preprocessor buffer hacks..
>
> The preprocessor hack is certainly simple, but it's not what you really
> want in real life.
Well... Keep in mind that those _are_ functions; i.e. unlike something
like __builtin_choose_expr() you can pass such puppy to a function
expecting a callback, etc.
So it's not enough to special-case them; we really need types for those
symbols. I don't think that it will be more efficient in the end.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-10-26 19:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-26 17:47 [PATCH] Add __builtin_popcountl Matthew Wilcox
2006-10-26 18:43 ` Al Viro
2006-10-26 18:56 ` Linus Torvalds
2006-10-26 19:19 ` Al Viro
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).