spirv: fpext and fptrunc instructions

This commit is contained in:
Ali Chraghi 2023-10-08 16:22:37 +03:30 committed by Robin Voetter
parent d2692af8e2
commit d8b591766a
No known key found for this signature in database
3 changed files with 19 additions and 2 deletions

View file

@ -1957,6 +1957,7 @@ const DeclGen = struct {
.int_from_ptr => try self.airIntFromPtr(inst),
.float_from_int => try self.airFloatFromInt(inst),
.int_from_float => try self.airIntFromFloat(inst),
.fpext, .fptrunc => try self.airFloatCast(inst),
.not => try self.airNot(inst),
.array_to_slice => try self.airArrayToSlice(inst),
@ -2685,6 +2686,23 @@ const DeclGen = struct {
return result_id;
}
fn airFloatCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
if (self.liveness.isUnused(inst)) return null;
const ty_op = self.air.instructions.items(.data)[inst].ty_op;
const operand_id = try self.resolve(ty_op.operand);
const dest_ty = self.typeOfIndex(inst);
const dest_ty_id = try self.resolveTypeId(dest_ty);
const result_id = self.spv.allocId();
try self.func.body.emit(self.spv.gpa, .OpFConvert, .{
.id_result_type = dest_ty_id,
.id_result = result_id,
.float_value = operand_id,
});
return result_id;
}
fn airNot(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
if (self.liveness.isUnused(inst)) return null;
const ty_op = self.air.instructions.items(.data)[inst].ty_op;

View file

@ -230,7 +230,7 @@ fn writeMemoryModel(spv: *SpvModule, target: std.Target) !void {
};
// TODO: Put this in a proper section.
try spv.sections.capabilities.emit(spv.gpa, .OpMemoryModel, .{
try spv.sections.extensions.emit(spv.gpa, .OpMemoryModel, .{
.addressing_model = addressing_model,
.memory_model = memory_model,
});

View file

@ -648,7 +648,6 @@ test "@floatCast cast down" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
{
var double: f64 = 0.001534;