| ... | @@ -4930,19 +4930,39 @@ fn airMemset(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -4930,19 +4930,39 @@ fn airMemset(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4930 | const dest_ptr = try f.resolveInst(pl_op.operand); | 4930 | const dest_ptr = try f.resolveInst(pl_op.operand); |
| 4931 | const value = try f.resolveInst(extra.lhs); | 4931 | const value = try f.resolveInst(extra.lhs); |
| 4932 | const len = try f.resolveInst(extra.rhs); | 4932 | const len = try f.resolveInst(extra.rhs); |
| 4933 | const writer = f.object.writer(); | | |
| 4934 | | 4933 | |
| 4935 | try writer.writeAll("memset("); | 4934 | const writer = f.object.writer(); |
| 4936 | if (dest_ty.isVolatilePtr()) { | 4935 | if (dest_ty.isVolatilePtr()) { |
| 4937 | // This is wrong, but good enough for now. | 4936 | var u8_ptr_pl = dest_ty.ptrInfo(); |
| 4938 | var remove_volatile_pl = dest_ty.ptrInfo(); | 4937 | u8_ptr_pl.data.pointee_type = Type.u8; |
| 4939 | remove_volatile_pl.data.@"volatile" = false; | 4938 | const u8_ptr_ty = Type.initPayload(&u8_ptr_pl.base); |
| 4940 | const remove_volatile_ty = Type.initPayload(&remove_volatile_pl.base); | | |
| 4941 | | 4939 | |
| 4942 | try writer.writeByte('('); | 4940 | try writer.writeAll("for ("); |
| 4943 | try f.renderTypecast(writer, remove_volatile_ty); | 4941 | const index = try f.allocLocal(Type.usize, .Mut); |
| | 4942 | try writer.writeAll(" = "); |
| | 4943 | try f.object.dg.renderValue(writer, Type.usize, Value.zero, .Initializer); |
| | 4944 | try writer.writeAll("; "); |
| | 4945 | try f.writeCValue(writer, index, .Other); |
| | 4946 | try writer.writeAll(" != "); |
| | 4947 | try f.writeCValue(writer, len, .Other); |
| | 4948 | try writer.writeAll("; "); |
| | 4949 | try f.writeCValue(writer, index, .Other); |
| | 4950 | try writer.writeAll(" += "); |
| | 4951 | try f.object.dg.renderValue(writer, Type.usize, Value.one, .Other); |
| | 4952 | try writer.writeAll(") (("); |
| | 4953 | try f.renderTypecast(writer, u8_ptr_ty); |
| 4944 | try writer.writeByte(')'); | 4954 | try writer.writeByte(')'); |
| | 4955 | try f.writeCValue(writer, dest_ptr, .FunctionArgument); |
| | 4956 | try writer.writeAll(")["); |
| | 4957 | try f.writeCValue(writer, index, .Other); |
| | 4958 | try writer.writeAll("] = "); |
| | 4959 | try f.writeCValue(writer, value, .FunctionArgument); |
| | 4960 | try writer.writeAll(";\n"); |
| | 4961 | |
| | 4962 | return CValue.none; |
| 4945 | } | 4963 | } |
| | 4964 | |
| | 4965 | try writer.writeAll("memset("); |
| 4946 | try f.writeCValue(writer, dest_ptr, .FunctionArgument); | 4966 | try f.writeCValue(writer, dest_ptr, .FunctionArgument); |
| 4947 | try writer.writeAll(", "); | 4967 | try writer.writeAll(", "); |
| 4948 | try f.writeCValue(writer, value, .FunctionArgument); | 4968 | try f.writeCValue(writer, value, .FunctionArgument); |