[PATCH 1/2] fix-gta02_lis302dl_bitbang.patch

Werner Almesberger werner at openmoko.org
Mon Nov 17 14:33:51 CET 2008


Nelson Castillo wrote:
> I like the ~ because one flipping is done in parallel

That's indeed what happens. However, while GCC seem to recognize
the !! idiom, and thus removes the flipping completely, it doesn't
understand that the ~ and the ! cancel each other out. This is the
assembler difference:

--- 1	2008-11-17 11:28:38.000000000 -0200
+++ 2	2008-11-17 11:28:40.000000000 -0200
@@ -30,10 +30,14 @@
 	b	.L47
 .L48:
 	tst	r6, #7
-	ldreqb	r5, [sl, r6, asr #3]	@ zero_extendqisi2
+	ldreqb	r3, [sl, r6, asr #3]	@ zero_extendqisi2
 	ldr	r0, [r4, #8]
+	mvneq	r3, r3
+	andeq	r5, r3, #255
 	bl	s3c2410_gpio_setpin
-	mov	r1, r5, lsr #7
+	mov	r1, r5, asl #24
+	mvn	r1, r1
+	mov	r1, r1, lsr #31
 	ldr	r0, [r4, #12]
 	bl	s3c2410_gpio_setpin
 	ldr	r0, [r4, #8]

Also, for the reader, it's easier to understand your intention if
you write !! than the double inversion at two different spots.

(Readability should be the main goal. I just included the
assembler output to show that nothing is gained by making the code
more cryptic.)

- Werner



More information about the openmoko-kernel mailing list