Skip to content

Commit e6ed27e

Browse files
committed
rsecbinary: Require caller-prepared tables
Each caller's gencoeffs procedure delivers the generator coefficients reversed and in the log domain with -1 denoting a zero coefficient, so that the FIFO caches hold the form consumed by the inner loop, and the anti-log tables are built spanning two periods during lazy initialisation so that log-sums resolve without a modulo reduction. Each inner-loop iteration is a single get, log-add, anti-log get, xor and put. The field order parameter is dropped from the interface along with the ECC codeword count, which is the length of the coefficient array.
1 parent 67fde10 commit e6ed27e

7 files changed

Lines changed: 105 additions & 65 deletions

File tree

src/azteccode.ps.src

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,14 @@ begin
252252
coeffs 0 2 copy get 3 index rsprod put % coeffs[0] = coeffs[0] * ai
253253
pop % ai
254254
} for
255-
coeffs
255+
256+
%
257+
% Deliver the coefficients reversed and in the log domain, with -1
258+
% denoting a zero coefficient, as rsecbinary requires
259+
%
260+
[ rsnc 1 sub -1 0 {
261+
coeffs exch get dup 0 ne { rslog exch get } { pop -1 } ifelse
262+
} for ]
256263
} bind def
257264

258265
/azteccode.coeffscache azteccode.coeffscachemax azteccode.coeffscachelimit //fifocache exec def
@@ -289,13 +296,15 @@ begin
289296
/charvals charvals readonly def
290297

291298
%
292-
% Calculate the log and anti-log tables for each GF
299+
% Calculate the log and anti-log tables for each GF, the anti-log
300+
% tables spanning two periods so that log-sums resolve without a
301+
% modulo reduction
293302
%
294303
/rstables [
295304
//azteccode.rsparams {
296305
dup length 0 ne {
297306
aload pop /rspm exch def /rsgf exch def
298-
/rsalog [ 1 rsgf 1 sub { dup 2 mul dup rsgf ge {rspm xor} if } repeat ] def
307+
/rsalog [ 1 rsgf 2 mul 2 sub { dup 2 mul dup rsgf ge {rspm xor} if } repeat ] def
299308
/rslog rsgf array def
300309
1 1 rsgf 1 sub {dup rsalog exch get exch rslog 3 1 roll put} for
301310
[ rslog rsalog ]
@@ -1013,17 +1022,16 @@ begin
10131022
/rscws exch def
10141023

10151024
%
1016-
% Lookup the Reed Solomon error correction parameters for the codeword size
1025+
% Lookup the Reed Solomon log tables for the codeword size
10171026
%
1018-
//azteccode.rsparams rsbt get aload pop /rspm exch def /rsgf-1 exch 1 sub def
10191027
rstables rsbt get aload pop /rsalog exch def /rslog exch def
10201028

10211029
%
10221030
% Function to calculate the product in the field
10231031
%
10241032
/rsprod {
10251033
dup 0 ne { 1 index 0 ne {
1026-
rslog exch get exch rslog exch get add rsgf-1 mod rsalog exch get
1034+
rslog exch get exch rslog exch get add rsalog exch get
10271035
} { pop pop 0 } ifelse } { pop pop 0 } ifelse
10281036
} def
10291037

@@ -1032,7 +1040,7 @@ begin
10321040
(ecc.coeffs) //azteccode.after exec
10331041

10341042
/lfsr rsnc array def
1035-
{rscws exch get} rscws length coeffs rsnc lfsr rslog rsalog rsgf-1 //rsecbinary exec
1043+
{rscws exch get} rscws length coeffs lfsr rslog rsalog //rsecbinary exec
10361044
lfsr
10371045

10381046
(ecc.cws) //azteccode.after exec

src/codeone.ps.src

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,15 @@ begin
284284
/encvals [ avals cvals tvals xvals -1 bvals ] readonly def
285285

286286
%
287-
% Calculate the log and anti-log tables for each Galois field
287+
% Calculate the log and anti-log tables for each Galois field, the
288+
% anti-log tables spanning two periods so that log-sums resolve
289+
% without a modulo reduction
288290
%
289291
/rstables [
290292
//codeone.rsparams {
291293
dup length 0 ne {
292294
aload pop /rspm exch def /rsgf exch def
293-
/rsalog [ 1 rsgf 1 sub { dup 2 mul dup rsgf ge {rspm xor} if } repeat ] def
295+
/rsalog [ 1 rsgf 2 mul 2 sub { dup 2 mul dup rsgf ge {rspm xor} if } repeat ] def
294296
/rslog rsgf array def
295297
1 1 rsgf 1 sub {dup rsalog exch get exch rslog 3 1 roll put} for
296298
[ rslog rsalog ]
@@ -321,7 +323,7 @@ begin
321323
%
322324
/codeone.rsprod {
323325
dup 0 ne { 1 index 0 ne {
324-
rslog exch get exch rslog exch get add gf-1 mod rsalog exch get
326+
rslog exch get exch rslog exch get add rsalog exch get
325327
} { pop pop 0 } ifelse } { pop pop 0 } ifelse
326328
} bind def
327329

@@ -346,7 +348,13 @@ begin
346348
//codeone.rsprod exec put % coeffs[0] = coeffs[0] * ai
347349
pop % ai
348350
} for
349-
coeffs 0 coeffs length 1 sub getinterval
351+
%
352+
% Deliver the coefficients reversed and in the log domain, with -1
353+
% denoting a zero coefficient, as rsecbinary requires
354+
%
355+
[ ecpb 1 sub -1 0 {
356+
coeffs exch get dup 0 ne { rslog exch get } { pop -1 } ifelse
357+
} for ]
350358
} bind def
351359

352360
%
@@ -369,8 +377,6 @@ begin
369377
/ecpb exch def
370378
/rslog rstables rsbt get 0 get def
371379
/rsalog rstables rsbt get 1 get def
372-
/gf rsalog length def
373-
/gf-1 gf 1 sub def
374380
rsbt 10000 mul ecpb add % key = rsbt * 10000 + ecpb
375381
{ //codeone.gencoeffs exec }
376382
{ length }
@@ -1106,7 +1112,7 @@ begin
11061112
/blk exch def
11071113
ecbs blk
11081114
/lfsr ecpb array def
1109-
{cws exch rsbl mul blk add get} dcpb coeffs ecpb lfsr rslog rsalog gf-1 //rsecbinary exec
1115+
{cws exch rsbl mul blk add get} dcpb coeffs lfsr rslog rsalog //rsecbinary exec
11101116
lfsr
11111117
put
11121118
} for

src/datamatrix.ps.src

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,11 @@ begin
283283
/encvals [ Avals Cvals Tvals Xvals Evals Bvals ] readonly def
284284

285285
%
286-
% Calculate the Reed-Solomon log and anti-log tables for GF(256) with prime polynomial 301
286+
% Calculate the Reed-Solomon log and anti-log tables for GF(256) with
287+
% prime polynomial 301, the anti-log table spanning two periods so that
288+
% log-sums resolve without a modulo reduction
287289
%
288-
/rsalog [ 1 255 { dup 2 mul dup 256 ge {301 xor} if } repeat ] readonly def
290+
/rsalog [ 1 510 { dup 2 mul dup 256 ge {301 xor} if } repeat ] readonly def
289291
/rslog 256 array def
290292
1 1 255 {dup rsalog exch get exch rslog 3 1 roll put} for
291293
/rslog rslog readonly def
@@ -311,7 +313,7 @@ begin
311313
%
312314
/datamatrix.rsprod {
313315
dup 0 ne { 1 index 0 ne {
314-
rslog exch get exch rslog exch get add 255 mod rsalog exch get
316+
rslog exch get exch rslog exch get add rsalog exch get
315317
} { pop pop 0 } ifelse } { pop pop 0 } ifelse
316318
} bind def
317319

@@ -335,7 +337,13 @@ begin
335337
//datamatrix.rsprod exec put % coeffs[0] = coeffs[0] * ai
336338
pop % ai
337339
} for
338-
coeffs 0 coeffs length 1 sub getinterval
340+
%
341+
% Deliver the coefficients reversed and in the log domain, with -1
342+
% denoting a zero coefficient, as rsecbinary requires
343+
%
344+
[ k 1 sub -1 0 {
345+
coeffs exch get dup 0 ne { rslog exch get } { pop -1 } ifelse
346+
} for ]
339347
} bind def
340348

341349
%
@@ -1052,7 +1060,7 @@ begin
10521060
} ifelse
10531061
ecbs blk
10541062
/lfsr ecpb array def
1055-
{cws exch rsbl mul blk add get} cwbsize coeffs ecpb lfsr rslog rsalog 255 //rsecbinary exec
1063+
{cws exch rsbl mul blk add get} cwbsize coeffs lfsr rslog rsalog //rsecbinary exec
10561064
lfsr
10571065
put
10581066
} for

src/hanxin.ps.src

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,13 +501,15 @@ begin
501501
//hanxin.latevars begin
502502

503503
%
504-
% Calculate the log and anti-log tables for each Galois field
504+
% Calculate the log and anti-log tables for each Galois field, the
505+
% anti-log tables spanning two periods so that log-sums resolve
506+
% without a modulo reduction
505507
%
506508
/rstables [
507509
//hanxin.rsparams {
508510
dup length 0 ne {
509511
aload pop /rspm exch def /rsgf exch def
510-
/rsalog [ 1 rsgf 1 sub { dup 2 mul dup rsgf ge {rspm xor} if } repeat ] def
512+
/rsalog [ 1 rsgf 2 mul 2 sub { dup 2 mul dup rsgf ge {rspm xor} if } repeat ] def
511513
/rslog rsgf array def
512514
1 1 rsgf 1 sub {dup rsalog exch get exch rslog 3 1 roll put} for
513515
[ rslog rsalog ]
@@ -538,7 +540,7 @@ begin
538540
%
539541
/hanxin.rsprod {
540542
dup 0 ne { 1 index 0 ne {
541-
rslog exch get exch rslog exch get add rsgf-1 mod rsalog exch get
543+
rslog exch get exch rslog exch get add rsalog exch get
542544
} { pop pop 0 } ifelse } { pop pop 0 } ifelse
543545
} bind def
544546

@@ -562,7 +564,13 @@ begin
562564
//hanxin.rsprod exec put % coeffs[0] = coeffs[0] * ai
563565
pop % ai
564566
} for
565-
coeffs 0 coeffs length 1 sub getinterval
567+
%
568+
% Deliver the coefficients reversed and in the log domain, with -1
569+
% denoting a zero coefficient, as rsecbinary requires
570+
%
571+
[ rsnc 1 sub -1 0 {
572+
coeffs exch get dup 0 ne { rslog exch get } { pop -1 } ifelse
573+
} for ]
566574
} bind def
567575

568576
%
@@ -584,7 +592,6 @@ begin
584592
/rsbt exch def
585593
/rsnc exch def
586594
rstables rsbt get aload pop /rsalog exch def /rslog exch def
587-
/rsgf-1 rsalog length 1 sub def
588595
rsbt 10000 mul rsnc add % key = rsbt * 10000 + rsnc
589596
{ //hanxin.gencoeffs exec }
590597
{ length }
@@ -972,7 +979,7 @@ begin
972979
%
973980
(ecc.cws) //hanxin.before exec
974981
/lfsr rsnc array def
975-
{rscws exch get} rscws length coeffs rsnc lfsr rslog rsalog rsgf-1 //rsecbinary exec
982+
{rscws exch get} rscws length coeffs lfsr rslog rsalog //rsecbinary exec
976983
lfsr
977984
(ecc.cws) //hanxin.after exec
978985

src/maxicode.ps.src

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ begin
221221
%
222222
/maxicode.rsprod {
223223
2 copy 0 ne exch 0 ne and {
224-
rslog exch get exch rslog exch get add 63 mod rsalog exch get
224+
rslog exch get exch rslog exch get add rsalog exch get
225225
} { pop pop 0 } ifelse
226226
} bind def
227227

@@ -244,7 +244,13 @@ begin
244244
//maxicode.rsprod exec put % coeffs[0] = coeffs[0] * ai
245245
pop % ai
246246
} for
247-
coeffs 0 k getinterval
247+
%
248+
% Deliver the coefficients reversed and in the log domain, with -1
249+
% denoting a zero coefficient, as rsecbinary requires
250+
%
251+
[ k 1 sub -1 0 {
252+
coeffs exch get dup 0 ne { rslog exch get } { pop -1 } ifelse
253+
} for ]
248254
} bind def
249255

250256
%
@@ -300,9 +306,11 @@ begin
300306
/charvals charvals readonly def
301307

302308
%
303-
% Calculate the Reed-Solomon log and anti-log tables for GF(64)
309+
% Calculate the Reed-Solomon log and anti-log tables for GF(64), the
310+
% anti-log table spanning two periods so that log-sums resolve without
311+
% a modulo reduction
304312
%
305-
/rsalog [ 1 63 { dup 2 mul dup 64 ge {67 xor} if } repeat ] readonly def
313+
/rsalog [ 1 126 { dup 2 mul dup 64 ge {67 xor} if } repeat ] readonly def
306314
/rslog 64 array def
307315
1 1 63 {dup rsalog exch get exch rslog 3 1 roll put} for
308316
/rslog rslog readonly def
@@ -1081,7 +1089,7 @@ begin
10811089
% Calculate the error correction codewords
10821090
%
10831091
/lfsr rsnum array def
1084-
{cwb exch get} cwb length coeffs rsnum lfsr rslog rsalog 63 //rsecbinary exec
1092+
{cwb exch get} cwb length coeffs lfsr rslog rsalog //rsecbinary exec
10851093
lfsr
10861094

10871095
} def

src/qrcode.ps.src

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,11 @@ begin
562562
/charvals charvals readonly def
563563

564564
%
565-
% Calculate the Reed-Solomon log and anti-log tables
565+
% Calculate the Reed-Solomon log and anti-log tables, the latter
566+
% spanning two periods so that log-sums resolve without a modulo
567+
% reduction
566568
%
567-
/rsalog [ 1 255 { dup 2 mul dup 256 ge {285 xor} if } repeat ] readonly def
569+
/rsalog [ 1 510 { dup 2 mul dup 256 ge {285 xor} if } repeat ] readonly def
568570
/rslog 256 array def
569571
1 1 255 {dup rsalog exch get exch rslog 3 1 roll put} for
570572
/rslog rslog readonly def
@@ -641,7 +643,7 @@ begin
641643
%
642644
/qrcode.rsprod {
643645
dup 0 ne { 1 index 0 ne {
644-
rslog exch get exch rslog exch get add 255 mod rsalog exch get
646+
rslog exch get exch rslog exch get add rsalog exch get
645647
} { pop pop 0 } ifelse } { pop pop 0 } ifelse
646648
} bind def
647649

@@ -666,7 +668,13 @@ begin
666668
//qrcode.rsprod exec put % coeffs[0] = coeffs[0] * ai
667669
pop % ai
668670
} for
669-
coeffs 0 coeffs length 1 sub getinterval
671+
%
672+
% Deliver the coefficients reversed and in the log domain, with -1
673+
% denoting a zero coefficient, as rsecbinary requires
674+
%
675+
[ ecpb 1 sub -1 0 {
676+
coeffs exch get dup 0 ne { rslog exch get } { pop -1 } ifelse
677+
} for ]
670678
} bind def
671679

672680
%
@@ -1352,7 +1360,7 @@ begin
13521360
/rscodes {
13531361
/rscws exch def
13541362
/lfsr ecpb array def
1355-
{rscws exch get} rscws length coeffs ecpb lfsr rslog rsalog 255 //rsecbinary exec
1363+
{rscws exch get} rscws length coeffs lfsr rslog rsalog //rsecbinary exec
13561364
lfsr
13571365
} def
13581366

0 commit comments

Comments
 (0)