diff options
Diffstat (limited to 'pseudocode/operators/CAST.tosac')
-rw-r--r-- | pseudocode/operators/CAST.tosac | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/pseudocode/operators/CAST.tosac b/pseudocode/operators/CAST.tosac index fac73e3..fd3ce72 100644 --- a/pseudocode/operators/CAST.tosac +++ b/pseudocode/operators/CAST.tosac @@ -12,16 +12,27 @@ for_each(index in shape) { out_t out; if (out_t == bool_t) { out = (in != 0) ? true : false; - } else if (in_t == bool_t) { - out = (in) ? 1 : 0; - } else if (out_t == fp16_t || out_t == bf16_t || out_t == fp32_t) { - out = round_to_nearest_float(in); - } else if (in_t == fp16_t || in_t == bf16_t || in_t == fp32_t) { - out = truncate<out_t>(apply_clip_s<i32_t>(round_to_nearest_int(in), minimum<out_t>, maximum<out_t>)); - } else if (sizeof(out_t) >= sizeof(in_t)) { - out = sign_extend<out_t>(in); + } else if (is_floating_point_type<out_t>()) { + // Conversion to float cases + if (in_t == bool_t) { + out = (in) ? 1.0 : 0.0; + } + if (is_saturating_float_type<out_t>()) { + out = round_to_nearest_float_saturating(in); + } else { + out = round_to_nearest_float_nonsaturating(in); + } } else { - out = truncate<out_t>(in); + // Conversion to integer cases + if (in_t == bool_t) { + out = (in) ? 1 : 0; + } else if (is_floating_point_type<in_t>()) { + out = truncate<out_t>(apply_clip_s<i32_t>(round_to_nearest_int(in), minimum<out_t>, maximum<out_t>)); + } else if (sizeof(out_t) >= sizeof(in_t)) { + out = sign_extend<out_t>(in); + } else { + out = truncate<out_t>(in); + } } - tensor_write<out_t>(output, shape, index, out); + tensor_write<out_t>(output, shape, index, out) } |