* [PATCH 1/2] sparse: Bump up sizeof(_Bool) to 8 bits
@ 2011-09-26 14:47 Pekka Enberg
2011-09-26 14:47 ` [PATCH 2/2] sparse, llvm: Add support for logical ops Pekka Enberg
0 siblings, 1 reply; 2+ messages in thread
From: Pekka Enberg @ 2011-09-26 14:47 UTC (permalink / raw)
To: linux-sparse; +Cc: Pekka Enberg, Christopher Li, Jeff Garzik, Linus Torvalds
From: Pekka Enberg <penberg@kernel.org>
We need sizeof(_Bool) to be one byte to generate code for boolean expressions
in the LLVM backend.
Cc: Christopher Li <sparse@chrisli.org>
Cc: Jeff Garzik <jgarzik@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
target.c | 2 +-
validation/sizeof-bool.c | 6 +-----
2 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/target.c b/target.c
index 17b228a..6a535bc 100644
--- a/target.c
+++ b/target.c
@@ -14,7 +14,7 @@ int max_alignment = 16;
/*
* Integer data types
*/
-int bits_in_bool = 1;
+int bits_in_bool = 8;
int bits_in_char = 8;
int bits_in_short = 16;
int bits_in_int = 32;
diff --git a/validation/sizeof-bool.c b/validation/sizeof-bool.c
index 6c68748..71ae1bc 100644
--- a/validation/sizeof-bool.c
+++ b/validation/sizeof-bool.c
@@ -4,9 +4,5 @@ static int a(void)
}
/*
* check-name: sizeof(_Bool) is valid
- * check-description: sizeof(_Bool) was rejected because _Bool is not an even
- * number of bytes
- * check-error-start
-sizeof-bool.c:3:16: warning: expression using sizeof bool
- * check-error-end
+ * check-description: sizeof(_Bool) is valid
*/
--
1.7.6.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] sparse, llvm: Add support for logical ops
2011-09-26 14:47 [PATCH 1/2] sparse: Bump up sizeof(_Bool) to 8 bits Pekka Enberg
@ 2011-09-26 14:47 ` Pekka Enberg
0 siblings, 0 replies; 2+ messages in thread
From: Pekka Enberg @ 2011-09-26 14:47 UTC (permalink / raw)
To: linux-sparse; +Cc: Pekka Enberg, Christopher Li, Jeff Garzik, Linus Torvalds
From: Pekka Enberg <penberg@kernel.org>
The generated asm for logical-ops.c test case looks as follows on x86-64:
GCC 4.6:
0000000000000000 <and_bool>:
0: 31 c0 xor %eax,%eax
2: 85 f6 test %esi,%esi
4: 0f 95 c0 setne %al
7: 31 d2 xor %edx,%edx
9: 85 ff test %edi,%edi
b: 0f 95 c2 setne %dl
e: 21 d0 and %edx,%eax
10: c3 retq
0000000000000020 <uand_bool>:
20: 31 c0 xor %eax,%eax
22: 85 f6 test %esi,%esi
24: 0f 95 c0 setne %al
27: 31 d2 xor %edx,%edx
29: 85 ff test %edi,%edi
2b: 0f 95 c2 setne %dl
2e: 21 d0 and %edx,%eax
30: c3 retq
0000000000000040 <or_bool>:
40: 09 fe or %edi,%esi
42: 0f 95 c0 setne %al
45: 0f b6 c0 movzbl %al,%eax
48: c3 retq
0000000000000050 <uor_bool>:
50: 09 fe or %edi,%esi
52: 0f 95 c0 setne %al
55: 0f b6 c0 movzbl %al,%eax
58: c3 retq
Sparse/LLVM:
0000000000000000 <and_bool>:
0: 85 f6 test %esi,%esi
2: 0f 95 c0 setne %al
5: 85 ff test %edi,%edi
7: 0f 95 c1 setne %cl
a: 20 c1 and %al,%cl
c: 0f b6 c1 movzbl %cl,%eax
f: c3 retq
0000000000000010 <uand_bool>:
10: 85 f6 test %esi,%esi
12: 0f 95 c0 setne %al
15: 85 ff test %edi,%edi
17: 0f 95 c1 setne %cl
1a: 20 c1 and %al,%cl
1c: 0f b6 c1 movzbl %cl,%eax
1f: c3 retq
0000000000000020 <or_bool>:
20: 09 f7 or %esi,%edi
22: 0f 95 c0 setne %al
25: 0f b6 c0 movzbl %al,%eax
28: c3 retq
0000000000000030 <uor_bool>:
30: 09 f7 or %esi,%edi
32: 0f 95 c0 setne %al
35: 0f b6 c0 movzbl %al,%eax
38: c3 retq
Cc: Christopher Li <sparse@chrisli.org>
Cc: Jeff Garzik <jgarzik@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
sparse-llvm.c | 23 +++++++++++++++++++----
validation/backend/logical-ops.c | 2 --
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/sparse-llvm.c b/sparse-llvm.c
index b015ea3..a85dfea 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -375,12 +375,27 @@ static void output_op_binary(struct function *fn, struct instruction *insn)
assert(!symbol_is_fp_type(insn->type));
target = LLVMBuildXor(fn->builder, lhs, rhs, target_name);
break;
- case OP_AND_BOOL:
- assert(0);
+ case OP_AND_BOOL: {
+ LLVMValueRef x, y;
+
+ assert(!symbol_is_fp_type(insn->type));
+
+ y = LLVMBuildICmp(fn->builder, LLVMIntNE, lhs, LLVMConstInt(LLVMTypeOf(lhs), 0, 0), "y");
+ x = LLVMBuildICmp(fn->builder, LLVMIntNE, rhs, LLVMConstInt(LLVMTypeOf(rhs), 0, 0), "x");
+
+ target = LLVMBuildAnd(fn->builder, y, x, target_name);
break;
- case OP_OR_BOOL:
- assert(0);
+ }
+ case OP_OR_BOOL: {
+ LLVMValueRef tmp;
+
+ assert(!symbol_is_fp_type(insn->type));
+
+ tmp = LLVMBuildOr(fn->builder, rhs, lhs, "tmp");
+
+ target = LLVMBuildICmp(fn->builder, LLVMIntNE, tmp, LLVMConstInt(LLVMTypeOf(tmp), 0, 0), target_name);
break;
+ }
/* Binary comparison */
case OP_SET_EQ:
diff --git a/validation/backend/logical-ops.c b/validation/backend/logical-ops.c
index 1a0e924..8b2a6a8 100644
--- a/validation/backend/logical-ops.c
+++ b/validation/backend/logical-ops.c
@@ -1,4 +1,3 @@
-#if 0
static int and_bool(int x, int y)
{
return x && y;
@@ -18,7 +17,6 @@ static unsigned int uor_bool(unsigned int x, unsigned int y)
{
return x || y;
}
-#endif
/*
* check-name: Logical operator code generation
--
1.7.6.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-09-26 14:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-26 14:47 [PATCH 1/2] sparse: Bump up sizeof(_Bool) to 8 bits Pekka Enberg
2011-09-26 14:47 ` [PATCH 2/2] sparse, llvm: Add support for logical ops Pekka Enberg
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).