authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2022-11-08 16:59:53+01:00
committergravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2022-11-08 16:59:53+01:00
log36e618aef138e9c3612a74f144358cb9574e695f
tree8b864c9ec59c717375b648079982bff3dffd6919
parent7d48cb11389f5dfe73d25e59c1038398a8ba9ca9

crypto.ghash: compatibility with stage1

Defining the selector enum outside the function definition is required for stage1.

1 files changed, 5 insertions(+), 3 deletions(-)

lib/std/crypto/ghash.zig+5-3
...@@ -72,8 +72,10 @@ pub const Ghash = struct {...@@ -72,8 +72,10 @@ pub const Ghash = struct {
72 return Ghash.initForBlockCount(key, math.maxInt(usize));72 return Ghash.initForBlockCount(key, math.maxInt(usize));
73 }73 }
7474
75 const Selector = enum { lo, hi };
76
75 // Carryless multiplication of two 64-bit integers for x86_64.77 // Carryless multiplication of two 64-bit integers for x86_64.
76 inline fn clmulPclmul(x: u128, y: u128, comptime half: enum { lo, hi }) u128 {78 inline fn clmulPclmul(x: u128, y: u128, comptime half: Selector) u128 {
77 if (half == .hi) {79 if (half == .hi) {
78 const product = asm (80 const product = asm (
79 \\ vpclmulqdq $0x11, %[x], %[y], %[out]81 \\ vpclmulqdq $0x11, %[x], %[y], %[out]
...@@ -94,7 +96,7 @@ pub const Ghash = struct {...@@ -94,7 +96,7 @@ pub const Ghash = struct {
94 }96 }
9597
96 // Carryless multiplication of two 64-bit integers for ARM crypto.98 // Carryless multiplication of two 64-bit integers for ARM crypto.
97 inline fn clmulPmull(x: u128, y: u128, comptime half: enum { lo, hi }) u128 {99 inline fn clmulPmull(x: u128, y: u128, comptime half: Selector) u128 {
98 if (half == .hi) {100 if (half == .hi) {
99 const product = asm (101 const product = asm (
100 \\ pmull2 %[out].1q, %[x].2d, %[y].2d102 \\ pmull2 %[out].1q, %[x].2d, %[y].2d
...@@ -115,7 +117,7 @@ pub const Ghash = struct {...@@ -115,7 +117,7 @@ pub const Ghash = struct {
115 }117 }
116118
117 // Software carryless multiplication of two 64-bit integers.119 // Software carryless multiplication of two 64-bit integers.
118 fn clmulSoft(x_: u128, y_: u128, comptime half: enum { lo, hi }) u128 {120 fn clmulSoft(x_: u128, y_: u128, comptime half: Selector) u128 {
119 const x = @truncate(u64, if (half == .hi) x_ >> 64 else x_);121 const x = @truncate(u64, if (half == .hi) x_ >> 64 else x_);
120 const y = @truncate(u64, if (half == .hi) y_ >> 64 else y_);122 const y = @truncate(u64, if (half == .hi) y_ >> 64 else y_);
121123