gen/genacorn.c
static void shift_down_lfsr(const LFSR *lfsr, int reg)
{
    int bit;
    int offset1;
    int offset2;
    int extra = -1;

    // Shift all bytes but the last down.  We assume that the low byte
    // is already cached in a register from the update_lfsrs() function
    // so we don't need to worry about saving it away now.
    for (bit = 0; bit < (lfsr->len - 16); bit += 8) {
        if (bit < 32)
            offset2 = lfsr->offsetl + (bit / 8);
        else
            offset2 = lfsr->offseth + ((bit - 32) / 8);
        if ((bit + 8) < 32)
            offset1 = lfsr->offsetl + ((bit + 8) / 8);
        else
            offset1 = lfsr->offseth + ((bit + 8 - 32) / 8);
        insn_printf("ldd r%d,Z+%d", temp_reg, offset1);
        if (offset2 != 0)
            insn_printf("std Z+%d,r%d", offset2, temp_reg);
        else
            insn_printf("st Z,r%d", temp_reg);
    }

    // Rotate the register value from the next-higher LFSR into the high byte.
    if (bit < 32)
        offset2 = lfsr->offsetl + (bit / 8);
    else
        offset2 = lfsr->offseth + ((bit - 32) / 8);
    if ((bit + 8) < 32)
        offset1 = lfsr->offsetl + ((bit + 8) / 8);
    else
        offset1 = lfsr->offseth + ((bit + 8 - 32) / 8);
    insn_printf("ldd r%d,Z+%d", temp_reg, offset1);
    alloc_low_reg(&extra);
    bit = lfsr->len % 8;
    if (bit <= 4) {
        insn_printf("clr r%d", extra);
        shift_left_2_regs(extra, reg, bit);
        insn_printf("or r%d,r%d", temp_reg, reg);
        insn_printf("std Z+%d,r%d", offset2, temp_reg);
        insn_printf("std Z+%d,r%d", offset1, extra);
    } else {
        insn_printf("clr r%d", extra);
        shift_right_2_regs(reg, extra, 8 - bit);
        insn_printf("or r%d,r%d", temp_reg, extra);
        insn_printf("std Z+%d,r%d", offset2, temp_reg);
        insn_printf("std Z+%d,r%d", offset1, reg);
    }
    release_reg(&extra);
}
// Shift a LFSR downwards by 8 bits and rotate in a register.
Shift a LFSR downwards by 8 bits and rotate in a register.
Shift a LFSR downwards by 8 bits and rotate in a register .
static void shift_down_lfsr(const LFSR *lfsr, int reg)
{
    int bit;
    int offset1;
    int offset2;
    int extra = -1;
    for (bit = 0; bit < (lfsr->len - 16); bit += 8) {
        if (bit < 32)
            offset2 = lfsr->offsetl + (bit / 8);
        else
            offset2 = lfsr->offseth + ((bit - 32) / 8);
        if ((bit + 8) < 32)
            offset1 = lfsr->offsetl + ((bit + 8) / 8);
        else
            offset1 = lfsr->offseth + ((bit + 8 - 32) / 8);
        insn_printf("ldd r%d,Z+%d", temp_reg, offset1);
        if (offset2 != 0)
            insn_printf("std Z+%d,r%d", offset2, temp_reg);
        else
            insn_printf("st Z,r%d", temp_reg);
    }
    if (bit < 32)
        offset2 = lfsr->offsetl + (bit / 8);
    else
        offset2 = lfsr->offseth + ((bit - 32) / 8);
    if ((bit + 8) < 32)
        offset1 = lfsr->offsetl + ((bit + 8) / 8);
    else
        offset1 = lfsr->offseth + ((bit + 8 - 32) / 8);
    insn_printf("ldd r%d,Z+%d", temp_reg, offset1);
    alloc_low_reg(&extra);
    bit = lfsr->len % 8;
    if (bit <= 4) {
        insn_printf("clr r%d", extra);
        shift_left_2_regs(extra, reg, bit);
        insn_printf("or r%d,r%d", temp_reg, reg);
        insn_printf("std Z+%d,r%d", offset2, temp_reg);
        insn_printf("std Z+%d,r%d", offset1, extra);
    } else {
        insn_printf("clr r%d", extra);
        shift_right_2_regs(reg, extra, 8 - bit);
        insn_printf("or r%d,r%d", temp_reg, extra);
        insn_printf("std Z+%d,r%d", offset2, temp_reg);
        insn_printf("std Z+%d,r%d", offset1, reg);
    }
    release_reg(&extra);
}
static void shift_down_lfsr ( const LFSR * lfsr , int reg ) { int bit ; int offset1 ; int offset2 ; int extra = -1 ; for ( bit = 0 ; bit < ( lfsr -> len - 16 ) ; bit += 8 ) { if ( bit < 32 ) offset2 = lfsr -> offsetl + ( bit / 8 ) ; else offset2 = lfsr -> offseth + ( ( bit - 32 ) / 8 ) ; if ( ( bit + 8 ) < 32 ) offset1 = lfsr -> offsetl + ( ( bit + 8 ) / 8 ) ; else offset1 = lfsr -> offseth + ( ( bit + 8 - 32 ) / 8 ) ; insn_printf ( " " , temp_reg , offset1 ) ; if ( offset2 != 0 ) insn_printf ( " " , offset2 , temp_reg ) ; else insn_printf ( " " , temp_reg ) ; } if ( bit < 32 ) offset2 = lfsr -> offsetl + ( bit / 8 ) ; else offset2 = lfsr -> offseth + ( ( bit - 32 ) / 8 ) ; if ( ( bit + 8 ) < 32 ) offset1 = lfsr -> offsetl + ( ( bit + 8 ) / 8 ) ; else offset1 = lfsr -> offseth + ( ( bit + 8 - 32 ) / 8 ) ; insn_printf ( " " , temp_reg , offset1 ) ; alloc_low_reg ( & extra ) ; bit = lfsr -> len % 8 ; if ( bit <= 4 ) { insn_printf ( " " , extra ) ; shift_left_2_regs ( extra , reg , bit ) ; insn_printf ( " " , temp_reg , reg ) ; insn_printf ( " " , offset2 , temp_reg ) ; insn_printf ( " " , offset1 , extra ) ; } else { insn_printf ( " " , extra ) ; shift_right_2_regs ( reg , extra , 8 - bit ) ; insn_printf ( " " , temp_reg , extra ) ; insn_printf ( " " , offset2 , temp_reg ) ; insn_printf ( " " , offset1 , reg ) ; } release_reg ( & extra ) ; }
Shift a LFSR downwards by 8 bits and rotate in a register.
Shift a LFSR downwards by 8 bits and rotate in a register .
// Shift all bytes but the last down.  We assume that the low byte // is already cached in a register from the update_lfsrs() function // so we don't need to worry about saving it away now. // Rotate the register value from the next-higher LFSR into the high byte.