| ... | @@ -1220,6 +1220,7 @@ fn genInst(self: *Self, inst: Air.Inst.Index) !WValue { | ... | @@ -1220,6 +1220,7 @@ fn genInst(self: *Self, inst: Air.Inst.Index) !WValue { |
| 1220 | .cond_br => self.airCondBr(inst), | 1220 | .cond_br => self.airCondBr(inst), |
| 1221 | .dbg_stmt => WValue.none, | 1221 | .dbg_stmt => WValue.none, |
| 1222 | .intcast => self.airIntcast(inst), | 1222 | .intcast => self.airIntcast(inst), |
| | 1223 | .fptrunc => self.airFptrunc(inst), |
| 1223 | .fpext => self.airFpext(inst), | 1224 | .fpext => self.airFpext(inst), |
| 1224 | .float_to_int => self.airFloatToInt(inst), | 1225 | .float_to_int => self.airFloatToInt(inst), |
| 1225 | .get_union_tag => self.airGetUnionTag(inst), | 1226 | .get_union_tag => self.airGetUnionTag(inst), |
| ... | @@ -1300,7 +1301,6 @@ fn genInst(self: *Self, inst: Air.Inst.Index) !WValue { | ... | @@ -1300,7 +1301,6 @@ fn genInst(self: *Self, inst: Air.Inst.Index) !WValue { |
| 1300 | .bit_reverse, | 1301 | .bit_reverse, |
| 1301 | .is_err_ptr, | 1302 | .is_err_ptr, |
| 1302 | .is_non_err_ptr, | 1303 | .is_non_err_ptr, |
| 1303 | .fptrunc, | | |
| 1304 | .unwrap_errunion_payload_ptr, | 1304 | .unwrap_errunion_payload_ptr, |
| 1305 | .unwrap_errunion_err_ptr, | 1305 | .unwrap_errunion_err_ptr, |
| 1306 | | 1306 | |
| ... | @@ -3189,23 +3189,40 @@ fn airFpext(self: *Self, inst: Air.Inst.Index) InnerError!WValue { | ... | @@ -3189,23 +3189,40 @@ fn airFpext(self: *Self, inst: Air.Inst.Index) InnerError!WValue { |
| 3189 | if (self.liveness.isUnused(inst)) return WValue{ .none = {} }; | 3189 | if (self.liveness.isUnused(inst)) return WValue{ .none = {} }; |
| 3190 | | 3190 | |
| 3191 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | 3191 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; |
| 3192 | const ty = self.air.typeOfIndex(inst); | 3192 | const dest_ty = self.air.typeOfIndex(inst); |
| 3193 | const wanted_bits = ty.floatBits(self.target); | 3193 | const dest_bits = dest_ty.floatBits(self.target); |
| 3194 | const have_bits = self.air.typeOf(ty_op.operand).floatBits(self.target); | 3194 | const src_bits = self.air.typeOf(ty_op.operand).floatBits(self.target); |
| 3195 | const operand = try self.resolveInst(ty_op.operand); | 3195 | const operand = try self.resolveInst(ty_op.operand); |
| 3196 | | 3196 | |
| 3197 | const have = toWasmBits(have_bits) orelse { | 3197 | if (dest_bits == 64 and src_bits == 32) { |
| 3198 | return self.fail("TODO: Implement 'fpext' for floats with bitsize: {d}", .{have_bits}); | 3198 | const result = try self.allocLocal(dest_ty); |
| 3199 | }; | 3199 | try self.emitWValue(operand); |
| 3200 | const wanted = toWasmBits(wanted_bits) orelse { | 3200 | try self.addTag(.f64_promote_f32); |
| 3201 | return self.fail("TODO: Implement 'fpext' for floats with bitsize: {d}", .{wanted_bits}); | 3201 | try self.addLabel(.local_set, result.local); |
| 3202 | }; | 3202 | return result; |
| 3203 | if (have == wanted) return operand; | 3203 | } else { |
| | 3204 | // TODO: Emit a call to compiler-rt to extend the float. e.g. __extendhfsf2 |
| | 3205 | return self.fail("TODO: Implement 'fpext' for floats with bitsize: {d}", .{dest_bits}); |
| | 3206 | } |
| | 3207 | } |
| 3204 | | 3208 | |
| 3205 | assert(have < wanted); | 3209 | fn airFptrunc(self: *Self, inst: Air.Inst.Index) InnerError!WValue { |
| 3206 | const result = try self.allocLocal(ty); | 3210 | if (self.liveness.isUnused(inst)) return WValue{ .none = {} }; |
| 3207 | try self.emitWValue(operand); | 3211 | |
| 3208 | try self.addTag(.f64_promote_f32); | 3212 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; |
| 3209 | try self.addLabel(.local_set, result.local); | 3213 | const dest_ty = self.air.typeOfIndex(inst); |
| 3210 | return result; | 3214 | const dest_bits = dest_ty.floatBits(self.target); |
| | 3215 | const src_bits = self.air.typeOf(ty_op.operand).floatBits(self.target); |
| | 3216 | const operand = try self.resolveInst(ty_op.operand); |
| | 3217 | |
| | 3218 | if (dest_bits == 32 and src_bits == 64) { |
| | 3219 | const result = try self.allocLocal(dest_ty); |
| | 3220 | try self.emitWValue(operand); |
| | 3221 | try self.addTag(.f32_demote_f64); |
| | 3222 | try self.addLabel(.local_set, result.local); |
| | 3223 | return result; |
| | 3224 | } else { |
| | 3225 | // TODO: Emit a call to compiler-rt to trunc the float. e.g. __truncdfhf2 |
| | 3226 | return self.fail("TODO: Implement 'fptrunc' for floats with bitsize: {d}", .{dest_bits}); |
| | 3227 | } |
| 3211 | } | 3228 | } |