| ... | @@ -8059,7 +8059,6 @@ fn zirBitwise( | ... | @@ -8059,7 +8059,6 @@ fn zirBitwise( |
| 8059 | rhs_ty.arrayLen(), | 8059 | rhs_ty.arrayLen(), |
| 8060 | }); | 8060 | }); |
| 8061 | } | 8061 | } |
| 8062 | return sema.fail(block, src, "TODO implement support for vectors in zirBitwise", .{}); | | |
| 8063 | } else if (lhs_ty.zigTypeTag() == .Vector or rhs_ty.zigTypeTag() == .Vector) { | 8062 | } else if (lhs_ty.zigTypeTag() == .Vector or rhs_ty.zigTypeTag() == .Vector) { |
| 8064 | return sema.fail(block, src, "mixed scalar and vector operands to binary expression: '{}' and '{}'", .{ | 8063 | return sema.fail(block, src, "mixed scalar and vector operands to binary expression: '{}' and '{}'", .{ |
| 8065 | lhs_ty, | 8064 | lhs_ty, |
| ... | @@ -8075,6 +8074,9 @@ fn zirBitwise( | ... | @@ -8075,6 +8074,9 @@ fn zirBitwise( |
| 8075 | | 8074 | |
| 8076 | if (try sema.resolveMaybeUndefVal(block, lhs_src, casted_lhs)) |lhs_val| { | 8075 | if (try sema.resolveMaybeUndefVal(block, lhs_src, casted_lhs)) |lhs_val| { |
| 8077 | if (try sema.resolveMaybeUndefVal(block, rhs_src, casted_rhs)) |rhs_val| { | 8076 | if (try sema.resolveMaybeUndefVal(block, rhs_src, casted_rhs)) |rhs_val| { |
| | 8077 | if (resolved_type.zigTypeTag() == .Vector) { |
| | 8078 | return sema.fail(block, src, "TODO implement zirBitwise for vectors at comptime", .{}); |
| | 8079 | } |
| 8078 | const result_val = switch (air_tag) { | 8080 | const result_val = switch (air_tag) { |
| 8079 | .bit_and => try lhs_val.bitwiseAnd(rhs_val, sema.arena), | 8081 | .bit_and => try lhs_val.bitwiseAnd(rhs_val, sema.arena), |
| 8080 | .bit_or => try lhs_val.bitwiseOr(rhs_val, sema.arena), | 8082 | .bit_or => try lhs_val.bitwiseOr(rhs_val, sema.arena), |
| ... | @@ -10985,19 +10987,21 @@ fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil | ... | @@ -10985,19 +10987,21 @@ fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil |
| 10985 | const src = inst_data.src(); | 10987 | const src = inst_data.src(); |
| 10986 | const operand = sema.resolveInst(inst_data.operand); | 10988 | const operand = sema.resolveInst(inst_data.operand); |
| 10987 | const operand_ty = sema.typeOf(operand); | 10989 | const operand_ty = sema.typeOf(operand); |
| 10988 | return sema.log2IntType(block, operand_ty, src); | 10990 | const res_ty = try sema.log2IntType(block, operand_ty, src); |
| | 10991 | return sema.addType(res_ty); |
| 10989 | } | 10992 | } |
| 10990 | | 10993 | |
| 10991 | fn zirLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 10994 | fn zirLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 10992 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 10995 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 10993 | const src = inst_data.src(); | 10996 | const src = inst_data.src(); |
| 10994 | const operand = try sema.resolveType(block, src, inst_data.operand); | 10997 | const operand = try sema.resolveType(block, src, inst_data.operand); |
| 10995 | return sema.log2IntType(block, operand, src); | 10998 | const res_ty = try sema.log2IntType(block, operand, src); |
| | 10999 | return sema.addType(res_ty); |
| 10996 | } | 11000 | } |
| 10997 | | 11001 | |
| 10998 | fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) CompileError!Air.Inst.Ref { | 11002 | fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) CompileError!Type { |
| 10999 | switch (operand.zigTypeTag()) { | 11003 | switch (operand.zigTypeTag()) { |
| 11000 | .ComptimeInt => return Air.Inst.Ref.comptime_int_type, | 11004 | .ComptimeInt => return Type.@"comptime_int", |
| 11001 | .Int => { | 11005 | .Int => { |
| 11002 | const bits = operand.bitSize(sema.mod.getTarget()); | 11006 | const bits = operand.bitSize(sema.mod.getTarget()); |
| 11003 | const count = if (bits == 0) | 11007 | const count = if (bits == 0) |
| ... | @@ -11010,16 +11014,24 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi | ... | @@ -11010,16 +11014,24 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi |
| 11010 | } | 11014 | } |
| 11011 | break :blk count; | 11015 | break :blk count; |
| 11012 | }; | 11016 | }; |
| 11013 | const res = try Module.makeIntType(sema.arena, .unsigned, count); | 11017 | return Module.makeIntType(sema.arena, .unsigned, count); |
| 11014 | return sema.addType(res); | | |
| 11015 | }, | 11018 | }, |
| 11016 | else => return sema.fail( | 11019 | .Vector => { |
| 11017 | block, | 11020 | const elem_ty = operand.elemType2(); |
| 11018 | src, | 11021 | const log2_elem_ty = try sema.log2IntType(block, elem_ty, src); |
| 11019 | "bit shifting operation expected integer type, found '{}'", | 11022 | return Type.Tag.vector.create(sema.arena, .{ |
| 11020 | .{operand}, | 11023 | .len = operand.arrayLen(), |
| 11021 | ), | 11024 | .elem_type = log2_elem_ty, |
| | 11025 | }); |
| | 11026 | }, |
| | 11027 | else => {}, |
| 11022 | } | 11028 | } |
| | 11029 | return sema.fail( |
| | 11030 | block, |
| | 11031 | src, |
| | 11032 | "bit shifting operation expected integer type, found '{}'", |
| | 11033 | .{operand}, |
| | 11034 | ); |
| 11023 | } | 11035 | } |
| 11024 | | 11036 | |
| 11025 | fn zirTypeofPeer( | 11037 | fn zirTypeofPeer( |
| ... | @@ -15676,8 +15688,7 @@ fn elemPtr( | ... | @@ -15676,8 +15688,7 @@ fn elemPtr( |
| 15676 | }, | 15688 | }, |
| 15677 | } | 15689 | } |
| 15678 | }, | 15690 | }, |
| 15679 | .Array => return sema.elemPtrArray(block, array_ptr_src, array_ptr, elem_index, elem_index_src), | 15691 | .Array, .Vector => return sema.elemPtrArray(block, array_ptr_src, array_ptr, elem_index, elem_index_src), |
| 15680 | .Vector => return sema.fail(block, src, "TODO implement Sema for elemPtr for vector", .{}), | | |
| 15681 | .Struct => { | 15692 | .Struct => { |
| 15682 | // Tuple field access. | 15693 | // Tuple field access. |
| 15683 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index); | 15694 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index); |