diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-09-20 14:13:33 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-09-20 14:24:43 -0700 |
| commit | b9d3527e0ed53c4796ab64b4df7daf0909739807 (patch) | |
| tree | 6cb29ce60e606fc4cfd30dad8b6f88c07a6bf8a7 /src/codegen/c.zig | |
| parent | 5dc251747b4ea65b1c8d3f2b5af62ca83c6d1196 (diff) | |
| download | zig-b9d3527e0ed53c4796ab64b4df7daf0909739807.tar.gz zig-b9d3527e0ed53c4796ab64b4df7daf0909739807.zip | |
stage2: implement comptime `@atomicRmw`
* introduce float_to_int and int_to_float AIR instructionts and
implement for the LLVM backend and C backend.
* Sema: implement `zirIntToFloat`.
* Sema: implement `@atomicRmw` comptime evaluation
- introduce `storePtrVal` for when one needs to store a Value to a
pointer which is a Value, and assert it happens at comptime.
* Value: introduce new functionality:
- intToFloat
- numberAddWrap
- numberSubWrap
- numberMax
- numberMin
- bitwiseAnd
- bitwiseNand (not implemented yet)
- bitwiseOr
- bitwiseXor
* Sema: hook up `zirBitwise` to the new Value bitwise implementations
* Type: rename `isFloat` to `isRuntimeFloat` because it returns `false`
for `comptime_float`.
Diffstat (limited to 'src/codegen/c.zig')
| -rw-r--r-- | src/codegen/c.zig | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 5eb4388a9e..6da791cb46 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -917,6 +917,8 @@ fn genBody(o: *Object, body: []const Air.Inst.Index) error{ AnalysisFail, OutOfM .atomic_rmw => try airAtomicRmw(o, inst), .atomic_load => try airAtomicLoad(o, inst), + .int_to_float, .float_to_int => try airSimpleCast(o, inst), + .atomic_store_unordered => try airAtomicStore(o, inst, toMemoryOrder(.Unordered)), .atomic_store_monotonic => try airAtomicStore(o, inst, toMemoryOrder(.Monotonic)), .atomic_store_release => try airAtomicStore(o, inst, toMemoryOrder(.Release)), @@ -1899,6 +1901,24 @@ fn airArrayToSlice(o: *Object, inst: Air.Inst.Index) !CValue { return local; } +/// Emits a local variable with the result type and initializes it +/// with the operand. +fn airSimpleCast(o: *Object, inst: Air.Inst.Index) !CValue { + if (o.liveness.isUnused(inst)) + return CValue.none; + + const inst_ty = o.air.typeOfIndex(inst); + const local = try o.allocLocal(inst_ty, .Const); + const ty_op = o.air.instructions.items(.data)[inst].ty_op; + const writer = o.writer(); + const operand = try o.resolveInst(ty_op.operand); + + try writer.writeAll(" = "); + try o.writeCValue(writer, operand); + try writer.writeAll(";\n"); + return local; +} + fn airCmpxchg(o: *Object, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue { const ty_pl = o.air.instructions.items(.data)[inst].ty_pl; const extra = o.air.extraData(Air.Cmpxchg, ty_pl.payload).data; |
