From 7233a3324aaa5b3995606f24b2b961149219986b Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 17 Mar 2022 17:24:35 -0700 Subject: stage2: implement `@reduce` Notably, Value.eql and Value.hash are improved to treat NaN as equal to itself, so that Type/Value can be hash map keys. Likewise float hashing normalizes the float value before computing the hash. --- src/codegen/c.zig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/codegen/c.zig') diff --git a/src/codegen/c.zig b/src/codegen/c.zig index c0c2031116..c306e0a6b0 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -1731,6 +1731,7 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO .error_name => try airErrorName(f, inst), .splat => try airSplat(f, inst), .shuffle => try airShuffle(f, inst), + .reduce => try airReduce(f, inst), .aggregate_init => try airAggregateInit(f, inst), .union_init => try airUnionInit(f, inst), .prefetch => try airPrefetch(f, inst), @@ -3625,6 +3626,21 @@ fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue { return f.fail("TODO: C backend: implement airShuffle", .{}); } +fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue { + if (f.liveness.isUnused(inst)) return CValue.none; + + const inst_ty = f.air.typeOfIndex(inst); + const reduce = f.air.instructions.items(.data)[inst].reduce; + const operand = try f.resolveInst(reduce.operand); + const writer = f.object.writer(); + const local = try f.allocLocal(inst_ty, .Const); + try writer.writeAll(" = "); + + _ = operand; + _ = local; + return f.fail("TODO: C backend: implement airReduce", .{}); +} + fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { if (f.liveness.isUnused(inst)) return CValue.none; -- cgit v1.2.3