#ifdef POWER8_VSX_SLIDEHASH
-#include <altivec.h>
-#include "zbuild.h"
-#include "deflate.h"
-
-static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) {
- vector unsigned short vw, vm, *vp;
- unsigned chunks;
-
- table += entries;
-
- /* Each vector register (chunk) corresponds to 128 bits == 8 Posf,
- * so instead of processing each of the entries in the hash table
- * individually, we can do it in chunks of 8 with vector instructions.
- *
- * This function is only called from slide_hash_power8(), and both calls
- * pass entries as a power of 2 higher than 2^7, as defined by
- * deflateInit2_(), so entries will always be a multiple of 8. */
- chunks = entries >> 3;
- Assert(entries % 8 == 0, "Weird hash table size!");
-
- vw[0] = wsize;
- vw = vec_splat(vw,0);
-
- vp = (vector unsigned short *)table;
-
- do {
- /* Processing 8 elements at a time */
- vp--;
- vm = *vp;
-
- /* This is equivalent to: m >= wsize ? m - wsize : 0
- * Since we are using a saturated unsigned subtraction, any
- * values that are <= wsize will be set to 0, while the others
- * will be subtracted by wsize. */
- *vp = vec_subs(vm,vw);
- } while (--chunks);
-}
-
-void Z_INTERNAL slide_hash_power8(deflate_state *s) {
- uint16_t wsize = s->w_size;
-
- slide_hash_chain(s->head, HASH_SIZE, wsize);
- slide_hash_chain(s->prev, wsize, wsize);
-}
+#define SLIDE_PPC slide_hash_power8
+#include "slide_ppc_tpl.h"
#endif /* POWER8_VSX_SLIDEHASH */
*/
#ifdef PPC_VMX_SLIDEHASH
-#include <altivec.h>
-#include "zbuild.h"
-#include "deflate.h"
-
-static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) {
- const vector unsigned short vmx_wsize = vec_splats(wsize);
- Pos *p = table;
-
- do {
- vector unsigned short value, result;
-
- value = vec_ld(0, p);
- result = vec_subs(value, vmx_wsize);
- vec_st(result, 0, p);
-
- p += 8;
- entries -= 8;
- } while (entries > 0);
-}
-
-void Z_INTERNAL slide_hash_vmx(deflate_state *s) {
- uint16_t wsize = s->w_size;
-
- slide_hash_chain(s->head, HASH_SIZE, wsize);
- slide_hash_chain(s->prev, wsize, wsize);
-}
+#define SLIDE_PPC slide_hash_vmx
+#include "slide_ppc_tpl.h"
#endif /* PPC_VMX_SLIDEHASH */
--- /dev/null
+/* Optimized slide_hash for PowerPC processors
+ * Copyright (C) 2017-2021 Mika T. Lindqvist <postmaster@raasu.org>
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#include <altivec.h>
+#include "zbuild.h"
+#include "deflate.h"
+
+static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) {
+ const vector unsigned short vmx_wsize = vec_splats(wsize);
+ Pos *p = table;
+
+ do {
+ vector unsigned short value, result;
+
+ value = vec_ld(0, p);
+ result = vec_subs(value, vmx_wsize);
+ vec_st(result, 0, p);
+
+ p += 8;
+ entries -= 8;
+ } while (entries > 0);
+}
+
+void Z_INTERNAL SLIDE_PPC(deflate_state *s) {
+ uint16_t wsize = s->w_size;
+
+ slide_hash_chain(s->head, HASH_SIZE, wsize);
+ slide_hash_chain(s->prev, wsize, wsize);
+}