Synthesis of truncate function
Note that your return value has a dynamic length. In synthesis, this implies a physical bus that has a varying number of bits, which most certainly is not synthesizable. Try padding the return value with zeros so that it can have a constant width...that shouldn't make any difference to the later AND operation.