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>
#endif
#include "common.h"
#include "large.h"
#include "composite.h"
#include "pdf417.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 (i = 0; i < 112; i++) {
x_reg[i] = accum[i];
}
for (i = 0; i < 9; i++) {
binary_add(accum, x_reg);
}
for (i = 0; i < 112; i++) {
x_reg[i] = 0;
}
binary_multiply(accum, "10");
binary_load(x_reg, "0", 1);
for (i = 0; i < 4; i++) {
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 (i = 0; i < 112; i++) {
y_reg[i] = accum[i];
}
for (i = 0; i < 9; i++) {
binary_add(accum, y_reg);
}
for (i = 0; i < 112; i++) {
y_reg[i] = 0;
}
binary_multiply(accum, "10");
binary_load(y_reg, "0", 1);
for (i = 0; i < 4; i++) {
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 */
/* multiply by 10 */
for (i = 0; i < 112; i++) {
y_reg[i] = accum[i];
}
for (i = 0; i < 9; i++) {
binary_add(accum, y_reg);
}
for (i = 0; i < 112; i++) {
y_reg[i] = 0;
}
binary_multiply(accum, "10");
binary_load(y_reg, "0", 1);
/* add first digit of tracker */
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);
/* multiply by 5 */
for (i = 0; i < 112; i++) {
y_reg[i] = accum[i];
}
for (i = 0; i < 4; i++) {
binary_add(accum, y_reg);
}
for (i = 0; i < 112; i++) {
y_reg[i] = 0;
}
binary_multiply(accum, "5");
binary_load(y_reg, "0", 1);
/* add second digit */
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 (i = 0; i < 112; i++) {
y_reg[i] = accum[i];
}
for (i = 0; i < 9; i++) {
binary_add(accum, y_reg);
}
for (i = 0; i < 112; i++) {
y_reg[i] = 0;
}
binary_multiply(accum, "10");
binary_load(y_reg, "0", 1);
for (i = 0; i < 4; i++) {
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);
}
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[]) {
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 shiftup(short int buffer[]);
extern short int islarger(short int accum[], short int reg[]);
extern void binary_multiply(short int reg[], char data[]);
#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++) {
switch (pattern[i]) {
case 'F':
for (j = 0; j < 112; j++) {
temp[j] = b[j];
}
// b *= 26
for (j = 1; j < 26; j++) {
binary_add(b, temp);
}
binary_multiply(b, "26");
binary_load(temp, "0", 1);
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);
break;
case 'L':
for (j = 0; j < 112; j++) {
temp[j] = b[j];
}
// b *= 20
for (j = 1; j < 20; j++) {
binary_add(b, temp);
}
binary_multiply(b, "20");
binary_load(temp, "0", 1);
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);
break;
case 'N':
for (j = 0; j < 112; j++) {
temp[j] = b[j];
}
for (j = 1; j < 10; j++) {
// b *= 10
binary_add(b, temp);
}
binary_multiply(b, "10");
binary_load(temp, "0", 1);
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);
// Multiply by 100,000,000
for (i = 0; i < 8; i++) {
binary_load(temp, "0", 1);
binary_add(temp, cdv);
for (j = 1; j < 10; j++) {
binary_add(cdv, temp);
}
}
binary_multiply(cdv, "100000000");
// Add Item ID
binary_load(temp, "0", 1);
@ -406,26 +378,12 @@ int mailmark(struct zint_symbol *symbol, unsigned char source[], int length) {
}
binary_add(cdv, temp);
if (length == 22) {
if (length == 22) {
// Barcode C - Multiply by 100
for (i = 0; i < 2; i++) {
binary_load(temp, "0", 1);
binary_add(temp, cdv);
for (j = 1; j < 10; j++) {
binary_add(cdv, temp);
}
}
binary_multiply(cdv, "100");
} else {
// Barcode L - Multiply by 1,000,000
for (i = 0; i < 6; i++) {
binary_load(temp, "0", 1);
binary_add(temp, cdv);
for (j = 1; j < 10; j++) {
binary_add(cdv, temp);
}
}
binary_multiply(cdv, "1000000");
}
// Add Supply Chain ID
@ -436,12 +394,7 @@ int mailmark(struct zint_symbol *symbol, unsigned char source[], int length) {
binary_add(cdv, temp);
// Multiply by 15
binary_load(temp, "0", 1);
binary_add(temp, cdv);
for (j = 1; j < 15; j++) {
binary_add(cdv, temp);
}
binary_multiply(cdv, "15");
// Add Class
binary_load(temp, "0", 1);
@ -451,12 +404,7 @@ int mailmark(struct zint_symbol *symbol, unsigned char source[], int length) {
binary_add(cdv, temp);
// Multiply by 5
binary_load(temp, "0", 1);
binary_add(temp, cdv);
for (j = 1; j < 5; j++) {
binary_add(cdv, temp);
}
binary_multiply(cdv, "5");
// Add Format
binary_load(temp, "0", 1);
@ -466,12 +414,7 @@ int mailmark(struct zint_symbol *symbol, unsigned char source[], int length) {
binary_add(cdv, temp);
// Multiply by 4
binary_load(temp, "0", 1);
binary_add(temp, cdv);
for (j = 1; j < 4; j++) {
binary_add(cdv, temp);
}
binary_multiply(cdv, "4");
// Add Version ID
binary_load(temp, "0", 1);

View File

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