Sema: clean up zirUnaryMath
* pass air_tag instead of zir_tag * also pass eval function so that the branch only happens once and the body of zirUnaryMath is simplified * Value.sqrt: update to handle f80 and f128 in the normalized way that includes handling c_longdouble. Semi-related change: fix incorrect sqrt builtin name for f80 in stage1.
This commit is contained in:
@@ -3265,24 +3265,34 @@ pub const Value = extern union {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sqrt(val: Value, float_type: Type, arena: Allocator) !Value {
|
||||
switch (float_type.tag()) {
|
||||
.f16 => {
|
||||
pub fn sqrt(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
|
||||
switch (float_type.floatBits(target)) {
|
||||
16 => {
|
||||
const f = val.toFloat(f16);
|
||||
return Value.Tag.float_16.create(arena, @sqrt(f));
|
||||
},
|
||||
.f32 => {
|
||||
32 => {
|
||||
const f = val.toFloat(f32);
|
||||
return Value.Tag.float_32.create(arena, @sqrt(f));
|
||||
},
|
||||
.f64 => {
|
||||
64 => {
|
||||
const f = val.toFloat(f64);
|
||||
return Value.Tag.float_64.create(arena, @sqrt(f));
|
||||
},
|
||||
|
||||
// TODO: implement @sqrt for these types
|
||||
.f128, .comptime_float, .c_longdouble => unreachable,
|
||||
|
||||
80 => {
|
||||
if (true) {
|
||||
@panic("TODO implement compiler_rt __sqrtx");
|
||||
}
|
||||
const f = val.toFloat(f80);
|
||||
return Value.Tag.float_80.create(arena, @sqrt(f));
|
||||
},
|
||||
128 => {
|
||||
if (true) {
|
||||
@panic("TODO implement compiler_rt sqrtq");
|
||||
}
|
||||
const f = val.toFloat(f128);
|
||||
return Value.Tag.float_128.create(arena, @sqrt(f));
|
||||
},
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user