# What is word_aligner function used for?

Status
Not open for further replies.

#### anhnha

##### Full Member level 6
Hi all,
I have read this function in verilog:
Code:
module word_aligner (word_out, word_in);
output		[7: 0]	word_out;
input 		[7: 0]	word_in;
assign word_out = aligned_word(word_in);	   // invoke function

function 	[7: 0] 	aligned_word;	   // function declaration
input 	[7: 0] 	word;
begin
aligned_word = word;
if (aligned_word != 0)
while (aligned_word[7] == 0) aligned_word = aligned_word << 1;
end
endfunction
endmodule
I understand every code line but the problem is that I really don't know where the code is used?
What is the purpose of the function?

#### kel8157

##### Full Member level 2
Remove the unknown number of '0' in the MSBs.
Normally we are advised not to use while loops in RTL.

#### anhnha

##### Full Member level 6
Remove the unknown number of '0' in the MSBs.
Normally we are advised not to use while loops in RTL.
Thank you,
Could you tell me what is the purpose of this function?
I know it remove the unknown number of '0' in the MSBs but why we need to do that?
And as in aligned_word = aligned_word << 1 it is not only remove number of '0' in the MSBs but also add number of '0' in the LSB.

#### kel8157

##### Full Member level 2
Thank you,
Could you tell me what is the purpose of this function?
I know it remove the unknown number of '0' in the MSBs but why we need to do that?
And as in aligned_word = aligned_word << 1 it is not only remove number of '0' in the MSBs but also add number of '0' in the LSB.
Not sure where it's used though.. What's the context?
Could be that next stage want to use the full range of a variable.. or is it to maximize the amplitude before going to a transmitter if it were a wireless chip?

#### anhnha

##### Full Member level 6
What's the context?
I found it in a slide on a web. They don't explain it any more. Only give it as an example using function.

#### kel8157

##### Full Member level 2
I found it in a slide on a web. They don't explain it any more. Only give it as an example using function.
then keep it for future use, or skip it.. the function is very basic and you will see better implementations than that.

- - - Updated - - -

Thank you,
Could you tell me what is the purpose of this function?
I know it remove the unknown number of '0' in the MSBs but why we need to do that?
And as in aligned_word = aligned_word << 1 it is not only remove number of '0' in the MSBs but also add number of '0' in the LSB.
Another example such function may be useful.

When you receive an QAM (16 and above) modulated signal, the amplitude tend to vary with gain settings, that's a problem for demapping.
You try to normalize the amplitude of received symbols, then you can use this kind of function..

Status
Not open for further replies.