Home | History | Annotate | Line # | Download | only in bfin
      1  1.1  christos # mach: bfin
      2  1.1  christos 
      3  1.1  christos // GENERIC CONVOLUTIONAL ENCODER
      4  1.1  christos // This a generic rate 1/n convolutional encoder. It computes n output
      5  1.1  christos // bits for each input bit, based on n generic polynomials.
      6  1.1  christos // It uses the set of BXOR_CC instructions to compute bit XOR
      7  1.1  christos // reduction from a state masked by a polynomial.  For an alternate
      8  1.1  christos // solution based on assembling several partial words, as in
      9  1.1  christos // the BDT benchmark, see file conv_enc.c. The solution presented
     10  1.1  christos // here is slower than conv_enc.c, but more generic.
     11  1.1  christos //
     12  1.1  christos // Forward Shift Register
     13  1.1  christos // -----------------------
     14  1.1  christos // This solution implements the XOR function by shifting the state
     15  1.1  christos // left by one, applying a mask to the state, and reducing
     16  1.1  christos // the result with a bit XOR reduction function.
     17  1.1  christos //    	             ----- XOR------------> G0
     18  1.1  christos // 	             |     |     |  |
     19  1.1  christos //        +------------------------------+
     20  1.1  christos //        | b0 b1 b2 b3          b14 b15 | <- in
     21  1.1  christos //        +------------------------------+
     22  1.1  christos //                   | 	|  |  |	    |
     23  1.1  christos //    	             ----- XOR------------> G1
     24  1.1  christos // Instruction BXOR computes the bit G0 or G1 and stores it into CC
     25  1.1  christos // and also into a destination reg half. Here, we take CC and rotate it
     26  1.1  christos // into an output register.
     27  1.1  christos // However, one can also store the output bit directly by storing
     28  1.1  christos // the register half where this bit is placed. This would result
     29  1.1  christos // in an output structure similar to the one in the original function
     30  1.1  christos // Convolutional_Encode(), where an entire half word holds a bit.
     31  1.1  christos // The resulting execution speed would be roughly twice as fast,
     32  1.1  christos // since there is no need to rotate output bit via CC.
     33  1.1  christos 
     34  1.1  christos .include "testutils.inc"
     35  1.1  christos 	start
     36  1.1  christos 
     37  1.1  christos 	loadsym P0, input;
     38  1.1  christos 	loadsym P1, output;
     39  1.1  christos 
     40  1.1  christos 	R1 = 0;	R2 = 0;R3 = 0;
     41  1.1  christos 
     42  1.1  christos 	R2.L = 0;
     43  1.1  christos 	R2.H = 0xa01d;	// polynom 0
     44  1.1  christos 	R3.L = 0;
     45  1.1  christos 	R3.H = 0x12f4;	// polynom 1
     46  1.1  christos 
     47  1.1  christos 	// load and  CurrentState to upper half of A0
     48  1.1  christos 	A1 = A0 = 0;
     49  1.1  christos 	R0 = 0x0000;
     50  1.1  christos 	A0.w = R0;
     51  1.1  christos 	A0 = A0 << 16;
     52  1.1  christos 
     53  1.1  christos 	// l-loop counter is in P4
     54  1.1  christos 	P4 = 2(Z);
     55  1.1  christos 	// **** START l-LOOP *****
     56  1.1  christos l$0:
     57  1.1  christos 
     58  1.1  christos 	// insert 16 bits of input into lower half of A0
     59  1.1  christos 	// and advance input pointer
     60  1.1  christos 	R0 = W [ P0 ++ ] (Z);
     61  1.1  christos 	A0.L = R0.L;
     62  1.1  christos 
     63  1.1  christos 	P5 = 2 (Z);
     64  1.1  christos 	LSETUP ( m$0 , m$0end ) LC0 = P5;	// **** BEGIN m-LOOP *****
     65  1.1  christos m$0:
     66  1.1  christos 
     67  1.1  christos 	P5 = 8 (Z);
     68  1.1  christos 	LSETUP ( i$1 , i$1end ) LC1 = P5;	// **** BEGIN i-LOOP *****
     69  1.1  christos i$1:
     70  1.1  christos 	R4.L = CC = BXORSHIFT( A0 , R2 );	// polynom0 -> CC
     71  1.1  christos 	R1 = ROT R1 BY 1;			// CC -> R1
     72  1.1  christos 	R4.L = CC = BXOR( A0 , R3 );		// polynom1 -> CC
     73  1.1  christos i$1end:
     74  1.1  christos 	R1 = ROT R1 BY 1;			// CC -> R1
     75  1.1  christos 
     76  1.1  christos 	// store 16 bits of outdata RL1
     77  1.1  christos m$0end:
     78  1.1  christos 	W [ P1 ++ ] = R1;
     79  1.1  christos 
     80  1.1  christos 	P4 += -1;
     81  1.1  christos 	CC = P4 == 0;
     82  1.1  christos 	IF !CC JUMP l$0;	// **** END l-LOOP *****
     83  1.1  christos 
     84  1.1  christos 				// Check results
     85  1.1  christos 	loadsym I2, output;
     86  1.1  christos 	R0.L = W [ I2 ++ ];	DBGA ( R0.L , 0x8c62 );
     87  1.1  christos 	R0.L = W [ I2 ++ ];	DBGA ( R0.L , 0x262e );
     88  1.1  christos 	R0.L = W [ I2 ++ ];	DBGA ( R0.L , 0x5b4d );
     89  1.1  christos 	R0.L = W [ I2 ++ ];	DBGA ( R0.L , 0x834f );
     90  1.1  christos 	pass
     91  1.1  christos 
     92  1.1  christos 	.data
     93  1.1  christos input:
     94  1.1  christos 	.dw 0x999f
     95  1.1  christos 	.dw 0x1999
     96  1.1  christos 
     97  1.1  christos output:
     98  1.1  christos 	.dw 0x0000
     99  1.1  christos 	.dw 0x0000
    100  1.1  christos 	.dw 0x0000
    101  1.1  christos 	.dw 0x0000
    102