REV is driving me crazy
Ale
Posts: 2,363
Well,
I'm now testing the FFT on a real propeller, so I wrote some help and test code. All looks good but the decimate routine.
Symptom: The REV instruction is not behaving as I think. Here is the routine:
I hope it is readable.
This should reverse the addresses from 1 to 1023 using the REV instruction.
As it is a REV something, #10 it means that it will not produce any number beyond 1023 (I tested it with some other program using the '><' spin operator, it looked ok).
Well: either with the second comparison or with the commented-out and or without them... I get different results ! This is very wired... And are the input values around 320 to 380 the ones that produce a wrong output (It does not show in spin !?).
Any idea ?
I'm now testing the FFT on a real propeller, so I wrote some help and test code. All looks good but the decimate routine.
Symptom: The REV instruction is not behaving as I think. Here is the routine:
decimate mov fft_ii,#1 mov fft_ll,cnt_k1_1024 'fft_n ldecimate mov fft_jj,fft_ii rev fft_jj,#10 'BITS_NN cmp fft_ii,fft_jj wc if_nc jmp #ldecimate_5 ' cmp fft_jj,cnt_k1_1024 wc ' if_nc jmp #ldecimate_5 mov fft_fr_ii,fft_ii shl fft_fr_ii,#1 add fft_fr_ii,fft_fr 'and fft_jj,cnt_k1_03ff mov fft_fr_jj,fft_jj rdword fft_tr,fft_fr_ii shl fft_fr_jj,#1 add fft_fr_jj,fft_fr rdword fft_result,fft_fr_jj 'mov fft_tr,cnt_k1_mask wrword fft_tr,fft_fr_jj wrword fft_result,fft_fr_ii ldecimate_5 add fft_ii,#1 cmp fft_ii,fft_ll wc if_c jmp #ldecimate decimate_ret ret
I hope it is readable.
This should reverse the addresses from 1 to 1023 using the REV instruction.
As it is a REV something, #10 it means that it will not produce any number beyond 1023 (I tested it with some other program using the '><' spin operator, it looked ok).
Well: either with the second comparison or with the commented-out and or without them... I get different results ! This is very wired... And are the input values around 320 to 380 the ones that produce a wrong output (It does not show in spin !?).
Any idea ?
Comments
-taken from prop manual
specifically this bit:
you are reversing the lower 32 - 10 = 22 bits.
replace #10 with #22 to reverse the lower 10 bits(0 to 1023)
Hope this helps.
Lee.
Well, thanks again !
·· REV data,#upper· ' #upper is the number of upper bits to clear, and reverse the lower remainder bits
Shift left by x
Reverse the entire 32-bit number
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
The shifter in the Propeller is what's called a "barrel shifter" which does everything
all at once in one clock cycle. Every bit has all the logic to compute all possibilities for
shifts and shift counts.
I'm sure there's a good reason for clearing those upper bits. But it kills reversibility, and it makes it more
difficult to use rev to do some bit permutations.
(Indeed, it's a fun puzzle to consider using a variant of rev that *preserves* the upper bits to perform
arbitrary bit permutations; what permutations are the hardest (require the greatest number of
instructions) to obtain? This is known as the "pancake problem" and it was the subject of one of
Al Zimmermann's programming contests. By the way, there is one of the contests going on now on
recmath.org; they are usually a blast to participate in.)