Improved binary multiplication for large numbers

This commit is contained in:
Robin Stuart 2018-02-11 08:00:32 +00:00
parent f655eabc12
commit 8bb4d2ce86
6 changed files with 41 additions and 125 deletions

View File

@ -58,7 +58,6 @@
#include <malloc.h> #include <malloc.h>
#endif #endif
#include "common.h" #include "common.h"
#include "large.h"
#include "composite.h" #include "composite.h"
#include "pdf417.h" #include "pdf417.h"
#include "gs1.h" #include "gs1.h"

View File

@ -316,17 +316,8 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) {
for (read = 0; read < strlen(zip); read++) { for (read = 0; read < strlen(zip); read++) {
for (i = 0; i < 112; i++) { binary_multiply(accum, "10");
x_reg[i] = accum[i]; binary_load(x_reg, "0", 1);
}
for (i = 0; i < 9; i++) {
binary_add(accum, x_reg);
}
for (i = 0; i < 112; i++) {
x_reg[i] = 0;
}
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
if (ctoi(zip[read]) & (0x01 << i)) x_reg[i] = 1; if (ctoi(zip[read]) & (0x01 << i)) x_reg[i] = 1;
@ -361,17 +352,8 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) {
for (read = 0; read < strlen(zip_adder); read++) { for (read = 0; read < strlen(zip_adder); read++) {
for (i = 0; i < 112; i++) { binary_multiply(accum, "10");
y_reg[i] = accum[i]; binary_load(y_reg, "0", 1);
}
for (i = 0; i < 9; i++) {
binary_add(accum, y_reg);
}
for (i = 0; i < 112; i++) {
y_reg[i] = 0;
}
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
if (ctoi(zip_adder[read]) & (0x01 << i)) y_reg[i] = 1; if (ctoi(zip_adder[read]) & (0x01 << i)) y_reg[i] = 1;
@ -385,17 +367,8 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) {
/* tracking code */ /* tracking code */
/* multiply by 10 */ /* multiply by 10 */
for (i = 0; i < 112; i++) { binary_multiply(accum, "10");
y_reg[i] = accum[i]; binary_load(y_reg, "0", 1);
}
for (i = 0; i < 9; i++) {
binary_add(accum, y_reg);
}
for (i = 0; i < 112; i++) {
y_reg[i] = 0;
}
/* add first digit of tracker */ /* add first digit of tracker */
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
@ -405,17 +378,8 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) {
binary_add(accum, y_reg); binary_add(accum, y_reg);
/* multiply by 5 */ /* multiply by 5 */
for (i = 0; i < 112; i++) { binary_multiply(accum, "5");
y_reg[i] = accum[i]; binary_load(y_reg, "0", 1);
}
for (i = 0; i < 4; i++) {
binary_add(accum, y_reg);
}
for (i = 0; i < 112; i++) {
y_reg[i] = 0;
}
/* add second digit */ /* add second digit */
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
@ -428,17 +392,8 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) {
for (read = 2; read < strlen(tracker); read++) { for (read = 2; read < strlen(tracker); read++) {
for (i = 0; i < 112; i++) { binary_multiply(accum, "10");
y_reg[i] = accum[i]; binary_load(y_reg, "0", 1);
}
for (i = 0; i < 9; i++) {
binary_add(accum, y_reg);
}
for (i = 0; i < 112; i++) {
y_reg[i] = 0;
}
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
if (ctoi(tracker[read]) & (0x01 << i)) y_reg[i] = 1; if (ctoi(tracker[read]) & (0x01 << i)) y_reg[i] = 1;

View File

@ -115,6 +115,26 @@ void binary_subtract(short int accumulator[], short int input_buffer[]) {
binary_add(accumulator, sub_buffer); binary_add(accumulator, sub_buffer);
} }
void binary_multiply(short int reg[], char data[]) {
/* Multiply the contents of reg[] by a number */
short int temp[112] = {0};
short int accum[112] = {0};
int i;
binary_load(temp, data, strlen(data));
for (i = 0; i < 102; i++) {
if (temp[i] == 1) {
binary_add(accum, reg);
}
shiftup(reg);
}
for (i = 0; i < 112; i++) {
reg[i] = accum[i];
}
}
void shiftdown(short int buffer[]) { void shiftdown(short int buffer[]) {
int i; int i;

View File

@ -42,6 +42,7 @@ extern void binary_subtract(short int accumulator[], short int input_buffer[]);
extern void shiftdown(short int buffer[]); extern void shiftdown(short int buffer[]);
extern void shiftup(short int buffer[]); extern void shiftup(short int buffer[]);
extern short int islarger(short int accum[], short int reg[]); extern short int islarger(short int accum[], short int reg[]);
extern void binary_multiply(short int reg[], char data[]);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -293,14 +293,7 @@ int mailmark(struct zint_symbol *symbol, unsigned char source[], int length) {
for (i = 0; i < 9; i++) { for (i = 0; i < 9; i++) {
switch (pattern[i]) { switch (pattern[i]) {
case 'F': case 'F':
for (j = 0; j < 112; j++) { binary_multiply(b, "26");
temp[j] = b[j];
}
// b *= 26
for (j = 1; j < 26; j++) {
binary_add(b, temp);
}
binary_load(temp, "0", 1); binary_load(temp, "0", 1);
for (j = 0; j < 5; j++) { for (j = 0; j < 5; j++) {
@ -310,14 +303,7 @@ int mailmark(struct zint_symbol *symbol, unsigned char source[], int length) {
binary_add(b, temp); binary_add(b, temp);
break; break;
case 'L': case 'L':
for (j = 0; j < 112; j++) { binary_multiply(b, "20");
temp[j] = b[j];
}
// b *= 20
for (j = 1; j < 20; j++) {
binary_add(b, temp);
}
binary_load(temp, "0", 1); binary_load(temp, "0", 1);
for (j = 0; j < 5; j++) { for (j = 0; j < 5; j++) {
@ -327,14 +313,7 @@ int mailmark(struct zint_symbol *symbol, unsigned char source[], int length) {
binary_add(b, temp); binary_add(b, temp);
break; break;
case 'N': case 'N':
for (j = 0; j < 112; j++) { binary_multiply(b, "10");
temp[j] = b[j];
}
for (j = 1; j < 10; j++) {
// b *= 10
binary_add(b, temp);
}
binary_load(temp, "0", 1); binary_load(temp, "0", 1);
for (j = 0; j < 4; j++) { for (j = 0; j < 4; j++) {
@ -390,14 +369,7 @@ int mailmark(struct zint_symbol *symbol, unsigned char source[], int length) {
binary_add(cdv, destination_postcode); binary_add(cdv, destination_postcode);
// Multiply by 100,000,000 // Multiply by 100,000,000
for (i = 0; i < 8; i++) { binary_multiply(cdv, "100000000");
binary_load(temp, "0", 1);
binary_add(temp, cdv);
for (j = 1; j < 10; j++) {
binary_add(cdv, temp);
}
}
// Add Item ID // Add Item ID
binary_load(temp, "0", 1); binary_load(temp, "0", 1);
@ -408,24 +380,10 @@ int mailmark(struct zint_symbol *symbol, unsigned char source[], int length) {
if (length == 22) { if (length == 22) {
// Barcode C - Multiply by 100 // Barcode C - Multiply by 100
for (i = 0; i < 2; i++) { binary_multiply(cdv, "100");
binary_load(temp, "0", 1);
binary_add(temp, cdv);
for (j = 1; j < 10; j++) {
binary_add(cdv, temp);
}
}
} else { } else {
// Barcode L - Multiply by 1,000,000 // Barcode L - Multiply by 1,000,000
for (i = 0; i < 6; i++) { binary_multiply(cdv, "1000000");
binary_load(temp, "0", 1);
binary_add(temp, cdv);
for (j = 1; j < 10; j++) {
binary_add(cdv, temp);
}
}
} }
// Add Supply Chain ID // Add Supply Chain ID
@ -436,12 +394,7 @@ int mailmark(struct zint_symbol *symbol, unsigned char source[], int length) {
binary_add(cdv, temp); binary_add(cdv, temp);
// Multiply by 15 // Multiply by 15
binary_load(temp, "0", 1); binary_multiply(cdv, "15");
binary_add(temp, cdv);
for (j = 1; j < 15; j++) {
binary_add(cdv, temp);
}
// Add Class // Add Class
binary_load(temp, "0", 1); binary_load(temp, "0", 1);
@ -451,12 +404,7 @@ int mailmark(struct zint_symbol *symbol, unsigned char source[], int length) {
binary_add(cdv, temp); binary_add(cdv, temp);
// Multiply by 5 // Multiply by 5
binary_load(temp, "0", 1); binary_multiply(cdv, "5");
binary_add(temp, cdv);
for (j = 1; j < 5; j++) {
binary_add(cdv, temp);
}
// Add Format // Add Format
binary_load(temp, "0", 1); binary_load(temp, "0", 1);
@ -466,12 +414,7 @@ int mailmark(struct zint_symbol *symbol, unsigned char source[], int length) {
binary_add(cdv, temp); binary_add(cdv, temp);
// Multiply by 4 // Multiply by 4
binary_load(temp, "0", 1); binary_multiply(cdv, "4");
binary_add(temp, cdv);
for (j = 1; j < 4; j++) {
binary_add(cdv, temp);
}
// Add Version ID // Add Version ID
binary_load(temp, "0", 1); binary_load(temp, "0", 1);

View File

@ -53,8 +53,6 @@
#endif #endif
#include "pdf417.h" #include "pdf417.h"
#include "common.h" #include "common.h"
#include "large.h"
/* /*
Three figure numbers in comments give the location of command equivalents in the Three figure numbers in comments give the location of command equivalents in the
original Visual Basic source code file pdf417.frm original Visual Basic source code file pdf417.frm