This commit is contained in:
2026-07-19 21:41:34 -05:00
parent 59b158b1c9
commit 27833003ce
3 changed files with 95 additions and 7 deletions
+4 -3
View File
@@ -14,6 +14,7 @@ ASM_ARM64 := src/kernels/fossbench-arm64.S
ASM_AMD64 := src/kernels/fossbench-amd64.S ASM_AMD64 := src/kernels/fossbench-amd64.S
ASM_I386 := src/kernels/fossbench-i386.S ASM_I386 := src/kernels/fossbench-i386.S
ASM_PPC32 := src/kernels/fossbench-ppc32be.S ASM_PPC32 := src/kernels/fossbench-ppc32be.S
SRC_PPC32 := src/kernels/fossbench-ppc32be-chacha.c
ASM_PPC64 := src/kernels/fossbench-ppc64be.S ASM_PPC64 := src/kernels/fossbench-ppc64be.S
ASM_PPC32LE := src/kernels/fossbench-ppc32le.S ASM_PPC32LE := src/kernels/fossbench-ppc32le.S
ASM_PPC64LE := src/kernels/fossbench-ppc64le.S ASM_PPC64LE := src/kernels/fossbench-ppc64le.S
@@ -37,7 +38,7 @@ else ifneq (,$(filter ppcle powerpcle ppc32le powerpc32le,$(HOST_ARCH)))
HOST_KERNEL := $(ASM_PPC32LE) HOST_KERNEL := $(ASM_PPC32LE)
else ifneq (,$(filter ppc powerpc ppc32 powerpc32,$(HOST_ARCH))) else ifneq (,$(filter ppc powerpc ppc32 powerpc32,$(HOST_ARCH)))
HOST_ARCHNAME := ppc32be HOST_ARCHNAME := ppc32be
HOST_KERNEL := $(ASM_PPC32) HOST_KERNEL := $(ASM_PPC32) $(SRC_PPC32)
else ifneq (,$(filter ppc64 powerpc64,$(HOST_ARCH))) else ifneq (,$(filter ppc64 powerpc64,$(HOST_ARCH)))
HOST_ARCHNAME := ppc64be HOST_ARCHNAME := ppc64be
HOST_KERNEL := $(ASM_PPC64) HOST_KERNEL := $(ASM_PPC64)
@@ -154,8 +155,8 @@ $(DIST)/fossbench-linux-i386: $(DRIVER) $(DRIVER_DEPS) $(ASM_I386) | $(DIST)
$(CC_I386) -m32 -march=pentium4 -fno-pie -no-pie $(CFLAGS) $(PTHREAD) $(LDFLAGS) -o $@ $(DRIVER) $(ASM_I386) $(LDLIBS) $(CC_I386) -m32 -march=pentium4 -fno-pie -no-pie $(CFLAGS) $(PTHREAD) $(LDFLAGS) -o $@ $(DRIVER) $(ASM_I386) $(LDLIBS)
@echo "built $@" @echo "built $@"
$(DIST)/fossbench-linux-ppc32be: $(DRIVER) $(DRIVER_DEPS) $(ASM_PPC32) | $(DIST) $(DIST)/fossbench-linux-ppc32be: $(DRIVER) $(DRIVER_DEPS) $(ASM_PPC32) $(SRC_PPC32) | $(DIST)
$(CC_PPC32BE) $(CFLAGS) $(PTHREAD) $(LDFLAGS) -o $@ $(DRIVER) $(ASM_PPC32) $(LDLIBS) $(CC_PPC32BE) $(CFLAGS) $(PTHREAD) $(LDFLAGS) -o $@ $(DRIVER) $(ASM_PPC32) $(SRC_PPC32) $(LDLIBS)
@echo "built $@" @echo "built $@"
$(DIST)/fossbench-linux-ppc64be: $(DRIVER) $(DRIVER_DEPS) $(ASM_PPC64) | $(DIST) $(DIST)/fossbench-linux-ppc64be: $(DRIVER) $(DRIVER_DEPS) $(ASM_PPC64) | $(DIST)
+87
View File
@@ -0,0 +1,87 @@
/*
* Baseline 32-bit PowerPC ChaCha20 kernel.
*
* The Wii's Broadway CPU has no AltiVec, so this target must not use the
* vectorized implementation emitted for 74xx PowerPC processors. Keep the
* byte loads and stores explicit: ChaCha20 words are little-endian while this
* target is big-endian.
*/
#include <stdint.h>
static uint32_t load32le(const uint8_t *p)
{
return (uint32_t)p[0] | (uint32_t)p[1] << 8 |
(uint32_t)p[2] << 16 | (uint32_t)p[3] << 24;
}
static void store32le(uint8_t *p, uint32_t x)
{
p[0] = (uint8_t)x;
p[1] = (uint8_t)(x >> 8);
p[2] = (uint8_t)(x >> 16);
p[3] = (uint8_t)(x >> 24);
}
static uint32_t rotl32(uint32_t x, unsigned int n)
{
return (x << n) | (x >> (32 - n));
}
#define QR(a, b, c, d) do { \
x[a] += x[b]; x[d] = rotl32(x[d] ^ x[a], 16); \
x[c] += x[d]; x[b] = rotl32(x[b] ^ x[c], 12); \
x[a] += x[b]; x[d] = rotl32(x[d] ^ x[a], 8); \
x[c] += x[d]; x[b] = rotl32(x[b] ^ x[c], 7); \
} while (0)
uint64_t fb_chacha20(uint8_t *buf, uint64_t len,
const uint8_t key[32], uint64_t rounds)
{
static const uint32_t sigma[4] = {
0x61707865, 0x3320646e, 0x79622d32, 0x6b206574
};
uint32_t base[16] = {0}, x[16];
uint32_t checksum = 0, counter = 0;
uint64_t pass, off;
int i, r;
len &= ~(uint64_t)63;
if (len == 0 || rounds == 0)
return 0;
for (i = 0; i < 4; i++)
base[i] = sigma[i];
for (i = 0; i < 8; i++)
base[4 + i] = load32le(key + 4 * i);
for (pass = 0; pass < rounds; pass++) {
for (off = 0; off < len; off += 64, counter++) {
base[12] = counter;
for (i = 0; i < 16; i++)
x[i] = base[i];
for (r = 0; r < 10; r++) {
QR(0, 4, 8, 12); QR(1, 5, 9, 13);
QR(2, 6, 10, 14); QR(3, 7, 11, 15);
QR(0, 5, 10, 15); QR(1, 6, 11, 12);
QR(2, 7, 8, 13); QR(3, 4, 9, 14);
}
for (i = 0; i < 16; i++) {
uint32_t word = x[i] + base[i];
uint8_t stream[4];
int j;
store32le(stream, word);
for (j = 0; j < 4; j++)
buf[off + 4 * i + j] ^= stream[j];
checksum ^= word;
}
}
}
return checksum;
}
#undef QR
+4 -4
View File
@@ -1121,11 +1121,11 @@ fb_compress:
.long .LC46 .long .LC46
.section ".text" .section ".text"
.align 2 .align 2
.globl fb_chacha20 .globl fb_chacha20_altivec
.LCL5: .LCL5:
.long .LCTOC1-.LCF5 .long .LCTOC1-.LCF5
.type fb_chacha20, @function .type fb_chacha20_altivec, @function
fb_chacha20: fb_chacha20_altivec:
.cfi_startproc .cfi_startproc
stwu 1,-608(1) stwu 1,-608(1)
.cfi_def_cfa_offset 608 .cfi_def_cfa_offset 608
@@ -1966,7 +1966,7 @@ fb_chacha20:
stb 9,63(23) stb 9,63(23)
b .L133 b .L133
.cfi_endproc .cfi_endproc
.size fb_chacha20, .-fb_chacha20 .size fb_chacha20_altivec, .-fb_chacha20_altivec
.section ".got2","aw" .section ".got2","aw"
.LC50: .LC50:
.long .LC49 .long .LC49