aboutsummaryrefslogtreecommitdiff
path: root/src/ARMeilleure/Instructions/InstEmitSimdHashHelper.cs
blob: a672b159f1db3315680ed1f3bbfd38baf9b84ce9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using ARMeilleure.IntermediateRepresentation;
using ARMeilleure.Translation;
using System;

using static ARMeilleure.IntermediateRepresentation.Operand.Factory;

namespace ARMeilleure.Instructions
{
    static class InstEmitSimdHashHelper
    {
        public static Operand EmitSha256h(ArmEmitterContext context, Operand x, Operand y, Operand w, bool part2)
        {
            if (Optimizations.UseSha)
            {
                Operand src1 = context.AddIntrinsic(Intrinsic.X86Shufps, y, x, Const(0xbb));
                Operand src2 = context.AddIntrinsic(Intrinsic.X86Shufps, y, x, Const(0x11));
                Operand w2 = context.AddIntrinsic(Intrinsic.X86Punpckhqdq, w, w);

                Operand round2 = context.AddIntrinsic(Intrinsic.X86Sha256Rnds2, src1, src2, w);
                Operand round4 = context.AddIntrinsic(Intrinsic.X86Sha256Rnds2, src2, round2, w2);

                Operand res = context.AddIntrinsic(Intrinsic.X86Shufps, round4, round2, Const(part2 ? 0x11 : 0xbb));

                return res;
            }

            String method = part2 ? nameof(SoftFallback.HashUpper) : nameof(SoftFallback.HashLower);
            return context.Call(typeof(SoftFallback).GetMethod(method), x, y, w);
        }

        public static Operand EmitSha256su0(ArmEmitterContext context, Operand x, Operand y)
        {
            if (Optimizations.UseSha)
            {
                return context.AddIntrinsic(Intrinsic.X86Sha256Msg1, x, y);
            }

            return context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Sha256SchedulePart1)), x, y);
        }

        public static Operand EmitSha256su1(ArmEmitterContext context, Operand x, Operand y, Operand z)
        {
            if (Optimizations.UseSha && Optimizations.UseSsse3)
            {
                Operand extr = context.AddIntrinsic(Intrinsic.X86Palignr, z, y, Const(4));
                Operand tmp = context.AddIntrinsic(Intrinsic.X86Paddd, extr, x);

                Operand res = context.AddIntrinsic(Intrinsic.X86Sha256Msg2, tmp, z);

                return res;
            }

            return context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Sha256SchedulePart2)), x, y, z);
        }
    }
}