Permalink
Browse files

Optimizations back on, more mask tweaks (checking fixed is more expen…

…sive now, so put it after the &&)
  • Loading branch information...
1 parent 0159ca2 commit 0453ffa2819367e641d2a5f34c14e85547cc6a02 tz committed Feb 26, 2010
Showing with 15 additions and 22 deletions.
  1. +1 −1 Makefile
  2. +1 −1 Makefile.avr
  3. +13 −20 qrencode.c
View
@@ -1,4 +1,4 @@
-CFLAGS:=-Wall -g -Os
+CFLAGS:=-Wall -g -O6
#CC=avr-gcc -mmcu=atmega328p
CC=gcc
View
@@ -9,7 +9,7 @@ CPU=atmega328p
PORT=/dev/ttyUSB0
XTAL=8000000 #Arduino 3.3v Pro
-CFLAGS=-g -DF_CPU=$(XTAL) -I ../uart -DTXBUFBITS=8 -DRXBUFBITS=8
+CFLAGS=-g -DF_CPU=$(XTAL) -I ../uart -DTXBUFBITS=8 -DRXBUFBITS=8 -O
.elf.dsm:
avr-objdump --disassemble -S $^ >$@
View
@@ -231,14 +231,14 @@ static void fillframe(void)
// Masking
static unsigned applymask(unsigned char m)
{
- unsigned char x, y, r3x, r3y, d3x, t = 0;
+ unsigned char x, y, r3x, r3y;
int b = 0;
switch (m) {
case 0:
for (y = 0; y < WD; y++)
for (x = 0; x < WD; x++) {
- if (!ismasked(x, y) && !((x + y) & 1))
+ if (!((x + y) & 1) && !ismasked(x, y))
TOGQRBIT(x, y);
if (QRBIT(x, y)) // count excess whites v.s blacks
b++;
@@ -249,7 +249,7 @@ static unsigned applymask(unsigned char m)
case 1:
for (y = 0; y < WD; y++)
for (x = 0; x < WD; x++) {
- if (!ismasked(x, y) && !(y & 1))
+ if (!(y & 1) && !ismasked(x, y))
TOGQRBIT(x, y);
if (QRBIT(x, y)) // count excess whites v.s blacks
b++;
@@ -262,7 +262,7 @@ static unsigned applymask(unsigned char m)
for (r3x = 0, x = 0; x < WD; x++, r3x++) {
if (r3x == 3)
r3x = 0;
- if (!ismasked(x, y) && !(r3x))
+ if (!r3x && !ismasked(x, y))
TOGQRBIT(x, y);
if (QRBIT(x, y)) // count excess whites v.s blacks
b++;
@@ -274,16 +274,11 @@ static unsigned applymask(unsigned char m)
for (r3y = 0, y = 0; y < WD; y++, r3y++) {
if (r3y == 3)
r3y = 0;
- for (r3x = 0, x = 0; x < WD; x++, r3x++) {
+ for (r3x = r3y, x = 0; x < WD; x++, r3x++) {
if (r3x == 3)
r3x = 0;
- if (!ismasked(x, y)) {
- t = r3x + r3y;
- if (t > 2)
- t -= 3;
- if (!t)
- TOGQRBIT(x, y);
- }
+ if (!r3x && !ismasked(x, y))
+ TOGQRBIT(x, y);
if (QRBIT(x, y)) // count excess whites v.s blacks
b++;
else
@@ -293,12 +288,12 @@ static unsigned applymask(unsigned char m)
break;
case 4:
for (y = 0; y < WD; y++)
- for (r3x = 0, d3x = 0, x = 0; x < WD; x++, r3x++) {
+ for (r3x = 0, r3y = ((y>>1)&1), x = 0; x < WD; x++, r3x++) {
if (r3x == 3) {
r3x = 0;
- d3x++;
+ r3y = !r3y;
}
- if (!ismasked(x, y) && !(((y >> 1) + d3x) & 1))
+ if (!r3y && !ismasked(x, y))
TOGQRBIT(x, y);
if (QRBIT(x, y)) // count excess whites v.s blacks
b++;
@@ -313,15 +308,14 @@ static unsigned applymask(unsigned char m)
for (r3x = 0, x = 0; x < WD; x++, r3x++) {
if (r3x == 3)
r3x = 0;
- if (!ismasked(x, y) && !((x & y & 1) + (!!r3x & !!r3y)))
+ if (!((x & y & 1) + !(!r3x | !r3y)) && !ismasked(x, y))
TOGQRBIT(x, y);
if (QRBIT(x, y)) // count excess whites v.s blacks
b++;
else
b--;
}
}
-
break;
case 6:
for (r3y = 0, y = 0; y < WD; y++, r3y++) {
@@ -330,15 +324,14 @@ static unsigned applymask(unsigned char m)
for (r3x = 0, x = 0; x < WD; x++, r3x++) {
if (r3x == 3)
r3x = 0;
- if (!ismasked(x, y) && !(((x & y & 1) + (r3x && (r3x == r3y))) & 1))
+ if (!(((x & y & 1) + (r3x && (r3x == r3y))) & 1) && !ismasked(x, y))
TOGQRBIT(x, y);
if (QRBIT(x, y)) // count excess whites v.s blacks
b++;
else
b--;
}
}
-
break;
case 7:
for (r3y = 0, y = 0; y < WD; y++, r3y++) {
@@ -347,7 +340,7 @@ static unsigned applymask(unsigned char m)
for (r3x = 0, x = 0; x < WD; x++, r3x++) {
if (r3x == 3)
r3x = 0;
- if (!ismasked(x, y) && !(((r3x && (r3x == r3y)) + ((x + y) & 1)) & 1))
+ if (!(((r3x && (r3x == r3y)) + ((x + y) & 1)) & 1) && !ismasked(x, y))
TOGQRBIT(x, y);
if (QRBIT(x, y)) // count excess whites v.s blacks
b++;

0 comments on commit 0453ffa

Please sign in to comment.