From d49c0f1f10d19a94983e4100d2d1eda418695de0 Mon Sep 17 00:00:00 2001 From: Dafenx Date: Tue, 14 Jul 2026 16:10:40 +0200 Subject: [PATCH] Emit Gen5 packed-integer and bit-count ops (#135) Co-authored-by: Dafenx <196083014+Dafenxz0@users.noreply.github.com> --- .../Agc/Gen5SpirvTranslator.Alu.cs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/SharpEmu.Libs/Agc/Gen5SpirvTranslator.Alu.cs b/src/SharpEmu.Libs/Agc/Gen5SpirvTranslator.Alu.cs index 595f5c5..dc0437f 100644 --- a/src/SharpEmu.Libs/Agc/Gen5SpirvTranslator.Alu.cs +++ b/src/SharpEmu.Libs/Agc/Gen5SpirvTranslator.Alu.cs @@ -396,6 +396,14 @@ internal static partial class Gen5SpirvTranslator _module.Constant64(_ulongType, 32))); break; } + case "VBcntU32B32": + result = IAdd( + _module.AddInstruction( + SpirvOp.BitCount, + _uintType, + GetRawSource(instruction, 0)), + GetRawSource(instruction, 1)); + break; case "VMadU32U24": { var left = BitwiseAnd( @@ -702,6 +710,14 @@ internal static partial class Gen5SpirvTranslator result = Ext(58, _uintType, vector); break; } + case "VCvtPkU16U32": + case "VCvtPkI16I32": + result = BitwiseOr( + BitwiseAnd(GetRawSource(instruction, 0), UInt(0xFFFF)), + ShiftLeftLogical( + BitwiseAnd(GetRawSource(instruction, 1), UInt(0xFFFF)), + UInt(16))); + break; default: error = $"unsupported vector opcode {instruction.Opcode}"; return false; @@ -1303,6 +1319,43 @@ internal static partial class Gen5SpirvTranslator Store(_scc, IsNotZero(result)); break; } + case "SAbsdiffI32": + { + var wideLeft = _module.AddInstruction( + SpirvOp.SConvert, + _longType, + Bitcast(_intType, left)); + var wideRight = _module.AddInstruction( + SpirvOp.SConvert, + _longType, + Bitcast(_intType, right)); + var difference = _module.AddInstruction( + SpirvOp.ISub, + _longType, + wideLeft, + wideRight); + result = _module.AddInstruction( + SpirvOp.UConvert, + _uintType, + Ext(5, _longType, difference)); + Store(_scc, IsNotZero(result)); + break; + } + case "SPackLlB32B16": + result = BitwiseOr( + BitwiseAnd(left, UInt(0xFFFF)), + ShiftLeftLogical(right, UInt(16))); + break; + case "SPackLhB32B16": + result = BitwiseOr( + BitwiseAnd(left, UInt(0xFFFF)), + BitwiseAnd(right, UInt(0xFFFF0000))); + break; + case "SPackHhB32B16": + result = BitwiseOr( + ShiftRightLogical(left, UInt(16)), + BitwiseAnd(right, UInt(0xFFFF0000))); + break; case "SCselectB32": result = _module.AddInstruction( SpirvOp.Select,