CPP: return (reduce_scale_by <= 0) ? in_value : in_value / GetScaleMultiplier(reduce_scale_by) ReduceScale cannot cause an overflow.
| 166 | // |
| 167 | // ReduceScale cannot cause an overflow. |
| 168 | llvm::Value* DecimalIR::ReduceScale(llvm::Value* in_value, llvm::Value* reduce_scale_by) { |
| 169 | auto le_zero = ir_builder()->CreateICmpSLE(reduce_scale_by, types()->i32_constant(0)); |
| 170 | // then block |
| 171 | auto then_lambda = [&] { return in_value; }; |
| 172 | |
| 173 | // else block |
| 174 | auto else_lambda = [&] { |
| 175 | // TODO : handle rounding. |
| 176 | llvm::Value* multiplier = GetScaleMultiplier(reduce_scale_by); |
| 177 | return ir_builder()->CreateSDiv(in_value, multiplier); |
| 178 | }; |
| 179 | |
| 180 | return BuildIfElse(le_zero, types()->i128_type(), then_lambda, else_lambda); |
| 181 | } |
| 182 | |
| 183 | /// @brief Fast-path for add |
| 184 | /// Adjust x and y to the same scale, and add them. |
nothing calls this directly
no test coverage detected