authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-05-02 03:24:04-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-05-03 04:25:14-04:00
log9ccdbca635a3b5a26b65ab8e52533d3acc8f2f5e
treeda608c7ad4fc308a7707863d7cc917e4af41b02f
parent31429a4e8649961624878d11e1bb330107013086

x86_64: implement fabs


6 files changed, 52 insertions(+), 7 deletions(-)

src/arch/x86_64/CodeGen.zig+14-6
......@@ -1458,14 +1458,13 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
14581458 .log,
14591459 .log2,
14601460 .log10,
1461 .fabs,
14621461 .floor,
14631462 .ceil,
14641463 .round,
14651464 .trunc_float,
14661465 => try self.airUnaryMath(inst),
14671466
1468 .neg => try self.airNeg(inst),
1467 .neg, .fabs => try self.airFloatSign(inst),
14691468
14701469 .add_with_overflow => try self.airAddSubWithOverflow(inst),
14711470 .sub_with_overflow => try self.airAddSubWithOverflow(inst),
......@@ -4185,7 +4184,7 @@ fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {
41854184 return self.finishAir(inst, dst_mcv, .{ ty_op.operand, .none, .none });
41864185}
41874186
4188fn airNeg(self: *Self, inst: Air.Inst.Index) !void {
4187fn airFloatSign(self: *Self, inst: Air.Inst.Index) !void {
41894188 const un_op = self.air.instructions.items(.data)[inst].un_op;
41904189 const ty = self.air.typeOf(un_op);
41914190 const ty_bits = ty.floatBits(self.target.*);
......@@ -4228,10 +4227,19 @@ fn airNeg(self: *Self, inst: Air.Inst.Index) !void {
42284227 const dst_lock = self.register_manager.lockReg(dst_mcv.register);
42294228 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);
42304229
4230 const tag = self.air.instructions.items(.tag)[inst];
42314231 try self.genBinOpMir(switch (ty_bits) {
4232 32 => .xorps,
4233 64 => .xorpd,
4234 else => return self.fail("TODO implement airNeg for {}", .{
4232 32 => switch (tag) {
4233 .neg => .xorps,
4234 .fabs => .andnps,
4235 else => unreachable,
4236 },
4237 64 => switch (tag) {
4238 .neg => .xorpd,
4239 .fabs => .andnpd,
4240 else => unreachable,
4241 },
4242 else => return self.fail("TODO implement airFloatSign for {}", .{
42354243 ty.fmt(self.bin_file.options.module.?),
42364244 }),
42374245 }, vec_ty, dst_mcv, sign_mcv);
src/arch/x86_64/Encoding.zig+6
......@@ -268,23 +268,29 @@ pub const Mnemonic = enum {
268268 movd,
269269 // SSE
270270 addss,
271 andps,
272 andnps,
271273 cmpss,
272274 cvtsi2ss,
273275 divss,
274276 maxss, minss,
275277 movss,
276278 mulss,
279 orps,
277280 subss,
278281 ucomiss,
279282 xorps,
280283 // SSE2
281284 addsd,
285 andpd,
286 andnpd,
282287 //cmpsd,
283288 cvtsd2ss, cvtsi2sd, cvtss2sd,
284289 divsd,
285290 maxsd, minsd,
286291 movq, //movd, movsd,
287292 mulsd,
293 orpd,
288294 subsd,
289295 ucomisd,
290296 xorpd,
src/arch/x86_64/Lower.zig+6
......@@ -94,6 +94,8 @@ pub fn lowerMir(lower: *Lower, inst: Mir.Inst) Error![]const Instruction {
9494 .xor,
9595
9696 .addss,
97 .andnps,
98 .andps,
9799 .cmpss,
98100 .cvtsi2ss,
99101 .divss,
......@@ -101,11 +103,14 @@ pub fn lowerMir(lower: *Lower, inst: Mir.Inst) Error![]const Instruction {
101103 .minss,
102104 .movss,
103105 .mulss,
106 .orps,
104107 .roundss,
105108 .subss,
106109 .ucomiss,
107110 .xorps,
108111 .addsd,
112 .andnpd,
113 .andpd,
109114 .cmpsd,
110115 .cvtsd2ss,
111116 .cvtsi2sd,
......@@ -115,6 +120,7 @@ pub fn lowerMir(lower: *Lower, inst: Mir.Inst) Error![]const Instruction {
115120 .minsd,
116121 .movsd,
117122 .mulsd,
123 .orpd,
118124 .roundsd,
119125 .subsd,
120126 .ucomisd,
src/arch/x86_64/Mir.zig+12
......@@ -168,6 +168,10 @@ pub const Inst = struct {
168168
169169 /// Add single precision floating point values
170170 addss,
171 /// Bitwise logical and of packed single precision floating-point values
172 andps,
173 /// Bitwise logical and not of packed single precision floating-point values
174 andnps,
171175 /// Compare scalar single-precision floating-point values
172176 cmpss,
173177 /// Convert doubleword integer to scalar single-precision floating-point value
......@@ -182,6 +186,8 @@ pub const Inst = struct {
182186 movss,
183187 /// Multiply scalar single-precision floating-point values
184188 mulss,
189 /// Bitwise logical or of packed single precision floating-point values
190 orps,
185191 /// Round scalar single-precision floating-point values
186192 roundss,
187193 /// Subtract scalar single-precision floating-point values
......@@ -192,6 +198,10 @@ pub const Inst = struct {
192198 xorps,
193199 /// Add double precision floating point values
194200 addsd,
201 /// Bitwise logical and not of packed double precision floating-point values
202 andnpd,
203 /// Bitwise logical and of packed double precision floating-point values
204 andpd,
195205 /// Compare scalar double-precision floating-point values
196206 cmpsd,
197207 /// Convert scalar double-precision floating-point value to scalar single-precision floating-point value
......@@ -210,6 +220,8 @@ pub const Inst = struct {
210220 movsd,
211221 /// Multiply scalar double-precision floating-point values
212222 mulsd,
223 /// Bitwise logical or of packed double precision floating-point values
224 orpd,
213225 /// Round scalar double-precision floating-point values
214226 roundsd,
215227 /// Subtract scalar double-precision floating-point values
src/arch/x86_64/encodings.zig+12
......@@ -832,6 +832,10 @@ pub const table = [_]Entry{
832832 // SSE
833833 .{ .addss, .rm, &.{ .xmm, .xmm_m32 }, &.{ 0xf3, 0x0f, 0x58 }, 0, .sse },
834834
835 .{ .andnps, .rm, &.{ .xmm, .xmm_m128 }, &.{ 0x0f, 0x55 }, 0, .sse },
836
837 .{ .andps, .rm, &.{ .xmm, .xmm_m128 }, &.{ 0x0f, 0x54 }, 0, .sse },
838
835839 .{ .cmpss, .rmi, &.{ .xmm, .xmm_m32, .imm8 }, &.{ 0xf3, 0x0f, 0xc2 }, 0, .sse },
836840
837841 .{ .cvtsi2ss, .rm, &.{ .xmm, .rm32 }, &.{ 0xf3, 0x0f, 0x2a }, 0, .sse },
......@@ -848,6 +852,8 @@ pub const table = [_]Entry{
848852
849853 .{ .mulss, .rm, &.{ .xmm, .xmm_m32 }, &.{ 0xf3, 0x0f, 0x59 }, 0, .sse },
850854
855 .{ .orps, .rm, &.{ .xmm, .xmm_m128 }, &.{ 0x0f, 0x56 }, 0, .sse },
856
851857 .{ .subss, .rm, &.{ .xmm, .xmm_m32 }, &.{ 0xf3, 0x0f, 0x5c }, 0, .sse },
852858
853859 .{ .ucomiss, .rm, &.{ .xmm, .xmm_m32 }, &.{ 0x0f, 0x2e }, 0, .sse },
......@@ -857,6 +863,10 @@ pub const table = [_]Entry{
857863 // SSE2
858864 .{ .addsd, .rm, &.{ .xmm, .xmm_m64 }, &.{ 0xf2, 0x0f, 0x58 }, 0, .sse2 },
859865
866 .{ .andnpd, .rm, &.{ .xmm, .xmm_m128 }, &.{ 0x66, 0x0f, 0x55 }, 0, .sse2 },
867
868 .{ .andpd, .rm, &.{ .xmm, .xmm_m128 }, &.{ 0x66, 0x0f, 0x54 }, 0, .sse2 },
869
860870 .{ .cmpsd, .rmi, &.{ .xmm, .xmm_m64, .imm8 }, &.{ 0xf2, 0x0f, 0xc2 }, 0, .sse2 },
861871
862872 .{ .cvtsd2ss, .rm, &.{ .xmm, .xmm_m64 }, &.{ 0xf2, 0x0f, 0x5a }, 0, .sse2 },
......@@ -883,6 +893,8 @@ pub const table = [_]Entry{
883893
884894 .{ .mulsd, .rm, &.{ .xmm, .xmm_m64 }, &.{ 0xf2, 0x0f, 0x59 }, 0, .sse2 },
885895
896 .{ .orpd, .rm, &.{ .xmm, .xmm_m128 }, &.{ 0x66, 0x0f, 0x56 }, 0, .sse2 },
897
886898 .{ .subsd, .rm, &.{ .xmm, .xmm_m64 }, &.{ 0xf2, 0x0f, 0x5c }, 0, .sse2 },
887899
888900 .{ .movsd, .rm, &.{ .xmm, .xmm_m64 }, &.{ 0xf2, 0x0f, 0x10 }, 0, .sse2 },
test/behavior/floatop.zig+2-1
......@@ -96,7 +96,8 @@ test "negative f128 floatToInt at compile-time" {
9696}
9797
9898test "@sqrt" {
99 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
99 if (builtin.zig_backend == .stage2_x86_64 and
100 comptime !std.Target.x86.featureSetHasAll(builtin.cpu.features, .{ .sse, .sse2, .sse4_1 })) return error.SkipZigTest; // TODO
100101 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
101102 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
102103 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO