Skip to content

x86_64: more #23924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions lib/std/crypto/Certificate.zig
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ const Date = struct {
while (month < date.month) : (month += 1) {
const days: u64 = std.time.epoch.getDaysInMonth(
date.year,
@as(std.time.epoch.Month, @enumFromInt(month)),
@enumFromInt(month),
);
sec += days * std.time.epoch.secs_per_day;
}
Expand All @@ -623,15 +623,13 @@ const Date = struct {
};

pub fn parseTimeDigits(text: *const [2]u8, min: u8, max: u8) !u8 {
const result = if (use_vectors) result: {
const nn: @Vector(2, u16) = .{ text[0], text[1] };
const zero: @Vector(2, u16) = .{ '0', '0' };
const mm: @Vector(2, u16) = .{ 10, 1 };
break :result @reduce(.Add, (nn -% zero) *% mm);
} else std.fmt.parseInt(u8, text, 10) catch return error.CertificateTimeInvalid;
const nn: @Vector(2, u16) = .{ text[0], text[1] };
const zero: @Vector(2, u16) = .{ '0', '0' };
const mm: @Vector(2, u16) = .{ 10, 1 };
const result = @reduce(.Add, (nn -% zero) *% mm);
if (result < min) return error.CertificateTimeInvalid;
if (result > max) return error.CertificateTimeInvalid;
return @truncate(result);
return @intCast(result);
}

test parseTimeDigits {
Expand All @@ -647,14 +645,12 @@ test parseTimeDigits {
}

pub fn parseYear4(text: *const [4]u8) !u16 {
const result = if (use_vectors) result: {
const nnnn: @Vector(4, u32) = .{ text[0], text[1], text[2], text[3] };
const zero: @Vector(4, u32) = .{ '0', '0', '0', '0' };
const mmmm: @Vector(4, u32) = .{ 1000, 100, 10, 1 };
break :result @reduce(.Add, (nnnn -% zero) *% mmmm);
} else std.fmt.parseInt(u16, text, 10) catch return error.CertificateTimeInvalid;
const nnnn: @Vector(4, u32) = .{ text[0], text[1], text[2], text[3] };
const zero: @Vector(4, u32) = .{ '0', '0', '0', '0' };
const mmmm: @Vector(4, u32) = .{ 1000, 100, 10, 1 };
const result = @reduce(.Add, (nnnn -% zero) *% mmmm);
if (result > 9999) return error.CertificateTimeInvalid;
return @truncate(result);
return @intCast(result);
}

test parseYear4 {
Expand Down Expand Up @@ -858,7 +854,7 @@ pub const der = struct {

pub fn parse(bytes: []const u8, index: u32) Element.ParseError!Element {
var i = index;
const identifier = @as(Identifier, @bitCast(bytes[i]));
const identifier: Identifier = @bitCast(bytes[i]);
i += 1;
const size_byte = bytes[i];
i += 1;
Expand All @@ -872,7 +868,7 @@ pub const der = struct {
};
}

const len_size = @as(u7, @truncate(size_byte));
const len_size: u7 = @truncate(size_byte);
if (len_size > @sizeOf(u32)) {
return error.CertificateFieldHasInvalidLength;
}
Expand Down Expand Up @@ -1244,5 +1240,3 @@ pub const rsa = struct {
return res;
}
};

const use_vectors = @import("builtin").zig_backend != .stage2_x86_64;
2 changes: 0 additions & 2 deletions lib/std/crypto/timing_safe.zig
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ test eql {
}

test "eql (vectors)" {
if (@import("builtin").zig_backend == .stage2_x86_64) return error.SkipZigTest;

const random = std.crypto.random;
const expect = std.testing.expect;
var a: [100]u8 = undefined;
Expand Down
13 changes: 5 additions & 8 deletions lib/std/http/Client.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const net = std.net;
const Uri = std.Uri;
const Allocator = mem.Allocator;
const assert = std.debug.assert;
const use_vectors = builtin.zig_backend != .stage2_x86_64;

const Client = @This();
const proto = @import("protocol.zig");
Expand Down Expand Up @@ -594,13 +593,10 @@ pub const Response = struct {
}

fn parseInt3(text: *const [3]u8) u10 {
if (use_vectors) {
const nnn: @Vector(3, u8) = text.*;
const zero: @Vector(3, u8) = .{ '0', '0', '0' };
const mmm: @Vector(3, u10) = .{ 100, 10, 1 };
return @reduce(.Add, @as(@Vector(3, u10), nnn -% zero) *% mmm);
}
return std.fmt.parseInt(u10, text, 10) catch unreachable;
const nnn: @Vector(3, u8) = text.*;
const zero: @Vector(3, u8) = .{ '0', '0', '0' };
const mmm: @Vector(3, u10) = .{ 100, 10, 1 };
return @reduce(.Add, (nnn -% zero) *% mmm);
}

test parseInt3 {
Expand Down Expand Up @@ -1796,5 +1792,6 @@ pub fn fetch(client: *Client, options: FetchOptions) !FetchResult {
}

test {
_ = Response;
_ = &initDefaultProxies;
}
35 changes: 14 additions & 21 deletions lib/std/http/HeadParser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,21 @@ pub fn feed(p: *HeadParser, bytes: []const u8) usize {
continue;
},
else => {
const Vector = @Vector(vector_len, u8);
// const BoolVector = @Vector(vector_len, bool);
const BitVector = @Vector(vector_len, u1);
const SizeVector = @Vector(vector_len, u8);

const chunk = bytes[index..][0..vector_len];
const matches = if (use_vectors) matches: {
const Vector = @Vector(vector_len, u8);
// const BoolVector = @Vector(vector_len, bool);
const BitVector = @Vector(vector_len, u1);
const SizeVector = @Vector(vector_len, u8);

const v: Vector = chunk.*;
const matches_r: BitVector = @bitCast(v == @as(Vector, @splat('\r')));
const matches_n: BitVector = @bitCast(v == @as(Vector, @splat('\n')));
const matches_or: SizeVector = matches_r | matches_n;

break :matches @reduce(.Add, matches_or);
} else matches: {
var matches: u8 = 0;
for (chunk) |byte| switch (byte) {
'\r', '\n' => matches += 1,
else => {},
};
break :matches matches;
};
const v: Vector = chunk.*;
// depends on https://github.com/ziglang/zig/issues/19755
// const matches_r: BitVector = @bitCast(v == @as(Vector, @splat('\r')));
// const matches_n: BitVector = @bitCast(v == @as(Vector, @splat('\n')));
const matches_r: BitVector = @select(u1, v == @as(Vector, @splat('\r')), @as(Vector, @splat(1)), @as(Vector, @splat(0)));
const matches_n: BitVector = @select(u1, v == @as(Vector, @splat('\n')), @as(Vector, @splat(1)), @as(Vector, @splat(0)));
const matches_or: SizeVector = matches_r | matches_n;

const matches = @reduce(.Add, matches_or);
switch (matches) {
0 => {},
1 => switch (chunk[vector_len - 1]) {
Expand Down Expand Up @@ -357,7 +351,6 @@ inline fn intShift(comptime T: type, x: anytype) T {

const HeadParser = @This();
const std = @import("std");
const use_vectors = builtin.zig_backend != .stage2_x86_64;
const builtin = @import("builtin");

test feed {
Expand Down
6 changes: 5 additions & 1 deletion lib/std/zig/Zir.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2142,7 +2142,7 @@ pub const Inst = struct {
ref_start_index = static_len,
_,

pub const static_len = 101;
pub const static_len = 105;

pub fn toRef(i: Index) Inst.Ref {
return @enumFromInt(@intFromEnum(Index.ref_start_index) + @intFromEnum(i));
Expand Down Expand Up @@ -2190,6 +2190,7 @@ pub const Inst = struct {
u80_type,
u128_type,
i128_type,
u256_type,
usize_type,
isize_type,
c_char_type,
Expand Down Expand Up @@ -2234,6 +2235,7 @@ pub const Inst = struct {
vector_8_u8_type,
vector_16_u8_type,
vector_32_u8_type,
vector_64_u8_type,
vector_4_i16_type,
vector_8_i16_type,
vector_16_i16_type,
Expand All @@ -2248,7 +2250,9 @@ pub const Inst = struct {
vector_4_i64_type,
vector_2_u64_type,
vector_4_u64_type,
vector_1_u128_type,
vector_2_u128_type,
vector_1_u256_type,
vector_4_f16_type,
vector_8_f16_type,
vector_2_f32_type,
Expand Down
1 change: 0 additions & 1 deletion lib/std/zon/parse.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3091,7 +3091,6 @@ test "std.zon free on error" {

test "std.zon vector" {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/15330
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/15329

const gpa = std.testing.allocator;

Expand Down
4 changes: 4 additions & 0 deletions src/Air.zig
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@ pub const Inst = struct {
u80_type = @intFromEnum(InternPool.Index.u80_type),
u128_type = @intFromEnum(InternPool.Index.u128_type),
i128_type = @intFromEnum(InternPool.Index.i128_type),
u256_type = @intFromEnum(InternPool.Index.u256_type),
usize_type = @intFromEnum(InternPool.Index.usize_type),
isize_type = @intFromEnum(InternPool.Index.isize_type),
c_char_type = @intFromEnum(InternPool.Index.c_char_type),
Expand Down Expand Up @@ -1006,6 +1007,7 @@ pub const Inst = struct {
vector_8_u8_type = @intFromEnum(InternPool.Index.vector_8_u8_type),
vector_16_u8_type = @intFromEnum(InternPool.Index.vector_16_u8_type),
vector_32_u8_type = @intFromEnum(InternPool.Index.vector_32_u8_type),
vector_64_u8_type = @intFromEnum(InternPool.Index.vector_64_u8_type),
vector_4_i16_type = @intFromEnum(InternPool.Index.vector_4_i16_type),
vector_8_i16_type = @intFromEnum(InternPool.Index.vector_8_i16_type),
vector_16_i16_type = @intFromEnum(InternPool.Index.vector_16_i16_type),
Expand All @@ -1020,7 +1022,9 @@ pub const Inst = struct {
vector_4_i64_type = @intFromEnum(InternPool.Index.vector_4_i64_type),
vector_2_u64_type = @intFromEnum(InternPool.Index.vector_2_u64_type),
vector_4_u64_type = @intFromEnum(InternPool.Index.vector_4_u64_type),
vector_1_u128_type = @intFromEnum(InternPool.Index.vector_1_u128_type),
vector_2_u128_type = @intFromEnum(InternPool.Index.vector_2_u128_type),
vector_1_u256_type = @intFromEnum(InternPool.Index.vector_1_u256_type),
vector_4_f16_type = @intFromEnum(InternPool.Index.vector_4_f16_type),
vector_8_f16_type = @intFromEnum(InternPool.Index.vector_8_f16_type),
vector_2_f32_type = @intFromEnum(InternPool.Index.vector_2_f32_type),
Expand Down
23 changes: 23 additions & 0 deletions src/InternPool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4548,6 +4548,7 @@ pub const Index = enum(u32) {
u80_type,
u128_type,
i128_type,
u256_type,
usize_type,
isize_type,
c_char_type,
Expand Down Expand Up @@ -4594,6 +4595,7 @@ pub const Index = enum(u32) {
vector_8_u8_type,
vector_16_u8_type,
vector_32_u8_type,
vector_64_u8_type,
vector_4_i16_type,
vector_8_i16_type,
vector_16_i16_type,
Expand All @@ -4608,7 +4610,9 @@ pub const Index = enum(u32) {
vector_4_i64_type,
vector_2_u64_type,
vector_4_u64_type,
vector_1_u128_type,
vector_2_u128_type,
vector_1_u256_type,
vector_4_f16_type,
vector_8_f16_type,
vector_2_f32_type,
Expand Down Expand Up @@ -5022,6 +5026,11 @@ pub const static_keys = [_]Key{
.bits = 128,
} },

.{ .int_type = .{
.signedness = .unsigned,
.bits = 256,
} },

.{ .simple_type = .usize },
.{ .simple_type = .isize },
.{ .simple_type = .c_char },
Expand Down Expand Up @@ -5125,6 +5134,8 @@ pub const static_keys = [_]Key{
.{ .vector_type = .{ .len = 16, .child = .u8_type } },
// @Vector(32, u8)
.{ .vector_type = .{ .len = 32, .child = .u8_type } },
// @Vector(64, u8)
.{ .vector_type = .{ .len = 64, .child = .u8_type } },
// @Vector(4, i16)
.{ .vector_type = .{ .len = 4, .child = .i16_type } },
// @Vector(8, i16)
Expand Down Expand Up @@ -5153,8 +5164,12 @@ pub const static_keys = [_]Key{
.{ .vector_type = .{ .len = 2, .child = .u64_type } },
// @Vector(8, u64)
.{ .vector_type = .{ .len = 4, .child = .u64_type } },
// @Vector(1, u128)
.{ .vector_type = .{ .len = 1, .child = .u128_type } },
// @Vector(2, u128)
.{ .vector_type = .{ .len = 2, .child = .u128_type } },
// @Vector(1, u256)
.{ .vector_type = .{ .len = 1, .child = .u256_type } },
// @Vector(4, f16)
.{ .vector_type = .{ .len = 4, .child = .f16_type } },
// @Vector(8, f16)
Expand Down Expand Up @@ -11767,6 +11782,7 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
.u80_type,
.u128_type,
.i128_type,
.u256_type,
.usize_type,
.isize_type,
.c_char_type,
Expand Down Expand Up @@ -11811,6 +11827,7 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
.vector_8_u8_type,
.vector_16_u8_type,
.vector_32_u8_type,
.vector_64_u8_type,
.vector_4_i16_type,
.vector_8_i16_type,
.vector_16_i16_type,
Expand All @@ -11825,7 +11842,9 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
.vector_4_i64_type,
.vector_2_u64_type,
.vector_4_u64_type,
.vector_1_u128_type,
.vector_2_u128_type,
.vector_1_u256_type,
.vector_4_f16_type,
.vector_8_f16_type,
.vector_2_f32_type,
Expand Down Expand Up @@ -12108,6 +12127,7 @@ pub fn zigTypeTag(ip: *const InternPool, index: Index) std.builtin.TypeId {
.u80_type,
.u128_type,
.i128_type,
.u256_type,
.usize_type,
.isize_type,
.c_char_type,
Expand Down Expand Up @@ -12159,6 +12179,7 @@ pub fn zigTypeTag(ip: *const InternPool, index: Index) std.builtin.TypeId {
.vector_8_u8_type,
.vector_16_u8_type,
.vector_32_u8_type,
.vector_64_u8_type,
.vector_4_i16_type,
.vector_8_i16_type,
.vector_16_i16_type,
Expand All @@ -12173,7 +12194,9 @@ pub fn zigTypeTag(ip: *const InternPool, index: Index) std.builtin.TypeId {
.vector_4_i64_type,
.vector_2_u64_type,
.vector_4_u64_type,
.vector_1_u128_type,
.vector_2_u128_type,
.vector_1_u256_type,
.vector_4_f16_type,
.vector_8_f16_type,
.vector_2_f32_type,
Expand Down
4 changes: 4 additions & 0 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36594,6 +36594,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
.u80_type,
.u128_type,
.i128_type,
.u256_type,
.usize_type,
.isize_type,
.c_char_type,
Expand Down Expand Up @@ -36634,6 +36635,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
.vector_8_u8_type,
.vector_16_u8_type,
.vector_32_u8_type,
.vector_64_u8_type,
.vector_4_i16_type,
.vector_8_i16_type,
.vector_16_i16_type,
Expand All @@ -36648,7 +36650,9 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
.vector_4_i64_type,
.vector_2_u64_type,
.vector_4_u64_type,
.vector_1_u128_type,
.vector_2_u128_type,
.vector_1_u256_type,
.vector_4_f16_type,
.vector_8_f16_type,
.vector_2_f32_type,
Expand Down
Loading
Loading