Small codegen refactor to avoid duplicate code when bit casting