mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 16:18:52 +00:00
Change min/max runtime behaviour to match IEEE 754-2019
This commit is contained in:
@@ -124,11 +124,29 @@ gb_internal lbValue lb_emit_select(lbProcedure *p, lbValue cond, lbValue x, lbVa
|
|||||||
gb_internal lbValue lb_emit_min(lbProcedure *p, Type *t, lbValue x, lbValue y) {
|
gb_internal lbValue lb_emit_min(lbProcedure *p, Type *t, lbValue x, lbValue y) {
|
||||||
x = lb_emit_conv(p, x, t);
|
x = lb_emit_conv(p, x, t);
|
||||||
y = lb_emit_conv(p, y, t);
|
y = lb_emit_conv(p, y, t);
|
||||||
|
if (is_type_float(t)) {
|
||||||
|
// NOTE(bill): f either operand is a NaN, returns NaN. Otherwise returns the lesser of the two arguments.
|
||||||
|
// -0.0 is considered to be less than +0.0 for this intrinsic.
|
||||||
|
// These semantics are specified by IEEE 754-2019.
|
||||||
|
LLVMValueRef args[2] = {x.value, y.value};
|
||||||
|
LLVMTypeRef types[1] = {lb_type(p->module, t)};
|
||||||
|
LLVMValueRef v = lb_call_intrinsic(p, "llvm.minimum", args, gb_count_of(args), types, gb_count_of(types));
|
||||||
|
return {v, t};
|
||||||
|
}
|
||||||
return lb_emit_select(p, lb_emit_comp(p, Token_Lt, x, y), x, y);
|
return lb_emit_select(p, lb_emit_comp(p, Token_Lt, x, y), x, y);
|
||||||
}
|
}
|
||||||
gb_internal lbValue lb_emit_max(lbProcedure *p, Type *t, lbValue x, lbValue y) {
|
gb_internal lbValue lb_emit_max(lbProcedure *p, Type *t, lbValue x, lbValue y) {
|
||||||
x = lb_emit_conv(p, x, t);
|
x = lb_emit_conv(p, x, t);
|
||||||
y = lb_emit_conv(p, y, t);
|
y = lb_emit_conv(p, y, t);
|
||||||
|
if (is_type_float(t)) {
|
||||||
|
// NOTE(bill): If either operand is a NaN, returns NaN. Otherwise returns the greater of the two arguments.
|
||||||
|
// -0.0 is considered to be less than +0.0 for this intrinsic.
|
||||||
|
// These semantics are specified by IEEE 754-2019.
|
||||||
|
LLVMValueRef args[2] = {x.value, y.value};
|
||||||
|
LLVMTypeRef types[1] = {lb_type(p->module, t)};
|
||||||
|
LLVMValueRef v = lb_call_intrinsic(p, "llvm.maximum", args, gb_count_of(args), types, gb_count_of(types));
|
||||||
|
return {v, t};
|
||||||
|
}
|
||||||
return lb_emit_select(p, lb_emit_comp(p, Token_Gt, x, y), x, y);
|
return lb_emit_select(p, lb_emit_comp(p, Token_Gt, x, y), x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user