aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/spirv.zig
diff options
context:
space:
mode:
authorAli Chraghi <alichraghi@proton.me>2023-10-08 16:22:37 +0330
committerRobin Voetter <robin@voetter.nl>2023-10-15 14:00:04 +0200
commitd8b591766ac37090ae77f7b67d0ce6b54c64254e (patch)
treeded231dffce311a893731c8be9f34ad163302bde /src/codegen/spirv.zig
parentd2692af8e2c6e4397f9be94b2b6625ba0e6e725f (diff)
downloadzig-d8b591766ac37090ae77f7b67d0ce6b54c64254e.tar.gz
zig-d8b591766ac37090ae77f7b67d0ce6b54c64254e.zip
spirv: `fpext` and `fptrunc` instructions
Diffstat (limited to 'src/codegen/spirv.zig')
-rw-r--r--src/codegen/spirv.zig18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig
index 7528c40cca..6881b2c598 100644
--- a/src/codegen/spirv.zig
+++ b/src/codegen/spirv.zig
@@ -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;