From 821dac1a7c028e4da64a1347e592816d71a2255a Mon Sep 17 00:00:00 2001 From: Chris Taylor Date: Fri, 19 Apr 2024 18:27:41 +0000 Subject: [PATCH] initial import --- Makefile | 76 +++++++++++++++----- buildflags.mak | 87 ++++++++++++++--------- compat/Makefile | 9 +++ compat/buildflags.mak | 3 +- debian/libpsm2-dev.install | 2 + hash.c | 116 +++++++++++++++++++++++++++++++ hash.h | 61 ++++++++++++++++ include/opa_user.h | 4 ++ libpsm2.spec.in | 20 +----- opa/Makefile | 7 +- opa/opa_debug.c | 8 ++- opa/opa_dwordcpy-generic.c | 10 ++- opa/opa_time.c | 5 +- psm.c | 8 +++ psm_hal_gen1/psm_hal_gen1_spio.c | 16 +++++ psm_hal_gen1/psm_hal_gen1_spio.h | 9 +++ psm_mq_internal.h | 26 +++---- ptl_am/psm_am_internal.h | 3 + util-generic.c | 102 +++++++++++++++++++++++++++ util-generic.h | 87 +++++++++++++++++++++++ 20 files changed, 571 insertions(+), 88 deletions(-) create mode 100644 hash.c create mode 100644 hash.h create mode 100644 util-generic.c create mode 100644 util-generic.h diff --git a/Makefile b/Makefile index 9faeb73..331e68b 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ # # GPL LICENSE SUMMARY # +# Copyright(c) 2024 Tactical Computing Labs, LLC # Copyright(c) 2021 Cornelis Networks. # Copyright(c) 2017 Intel Corporation. # @@ -131,7 +132,9 @@ INCLUDES += -I$(top_srcdir) -I$(top_srcdir)/ptl_ips -I$(OUTDIR) ifneq (x86_64,$(arch)) ifneq (i386,$(arch)) - anerr := $(error Unsupported architecture $(arch)) + ifneq (riscv64,$(arch)) + anerr := $(error Unsupported architecture $(arch)) + endif endif endif @@ -139,11 +142,25 @@ ifndef LIBDIR ifeq (${arch},x86_64) INSTALL_LIB_TARG=/usr/lib64 else - INSTALL_LIB_TARG=/usr/lib + ifeq (${arch},riscv64) + INSTALL_LIB_TARG=/usr/lib64 + else + INSTALL_LIB_TARG=/usr/lib + endif endif else INSTALL_LIB_TARG=${LIBDIR} endif + +ifeq (${arch},riscv64) + LINUX_ARCH=riscv64 + INSTALL_ARCH=riscv +endif +ifeq (${arch},x86_64) + LINUX_ARCH=i386 + INSTALL_ARCH=x86_64 +endif + export DESTDIR export INSTALL_LIB_TARG @@ -168,6 +185,13 @@ nthreads := $(shell echo $$(( `nproc` * 2 )) ) DISTRO := $(shell . /etc/os-release; if [ "$$ID" = "sle_hpc" ]; then ID="sles"; fi; echo $$ID) +UDEVDIR := $(shell $(PKG_CONFIG) --variable=udevdir udev 2>/dev/null) +ifndef UDEVDIR + UDEVDIR = /lib/udev +endif + +export UDEVDIR + # By default the following two variables have the following values: LIBPSM2_COMPAT_CONF_DIR := /etc LIBPSM2_COMPAT_SYM_CONF_DIR := /etc @@ -175,7 +199,7 @@ LIBPSM2_COMPAT_SYM_CONF_DIR := /etc # It then messes up sed operations for PSM_CUDA=1. # So leaving the commented out line here as documentation to NOT set it. # SPEC_FILE_RELEASE_DIST := -UDEV_40_PSM_RULES := %{_udevrulesdir}/40-psm.rules +UDEV_40_PSM_RULES := $(UDEVDIR)/40-psm.rules ifeq (fedora,$(DISTRO)) # On Fedora, we change these two variables to these values: @@ -252,13 +276,6 @@ LDLIBS := -lrt -ldl -lnuma ${EXTRA_LIBS} -pthread PKG_CONFIG ?= pkg-config -UDEVDIR := $(shell $(PKG_CONFIG) --variable=udevdir udev 2>/dev/null) -ifndef UDEVDIR - UDEVDIR = /lib/udev -endif - -export UDEVDIR - # The DIST variable is a name kernel corresponding to: # 1. The name of the directory containing the source code distribution # (see dist: target below). @@ -393,11 +410,11 @@ $(OUTDIR): mkdir -p ${OUTDIR} symlinks: - @test -L $(top_srcdir)/include/linux-x86_64 || \ - ln -sf linux-i386 $(top_srcdir)/include/linux-x86_64 + @test -L $(top_srcdir)/include/linux-$(arch) || \ + ln -sf linux-$(LINUX_ARC) $(top_srcdir)/include/linux-$(arch) cleanlinks: - rm -rf $(top_srcdir)/include/linux-x86_64 + rm -rf $(top_srcdir)/include/linux-$(arch) install: all for subdir in $(SUBDIRS) ; do \ @@ -416,14 +433,16 @@ install: all install -m 0644 -D psm2.h ${DESTDIR}/usr/include/psm2.h install -m 0644 -D psm2_mq.h ${DESTDIR}/usr/include/psm2_mq.h install -m 0644 -D psm2_am.h ${DESTDIR}/usr/include/psm2_am.h -ifneq (fedora,${DISTRO}) +ifeq (fedora,${DISTRO}) install -m 0644 -D 40-psm.rules ${DESTDIR}$(UDEVDIR)/rules.d/40-psm.rules +else + install -m 0644 -D 40-psm.rules ${DESTDIR}$(UDEVDIR)/40-psm.rules endif # The following files and dirs were part of the noship rpm: mkdir -p ${DESTDIR}/usr/include/hfi1diag - mkdir -p ${DESTDIR}/usr/include/hfi1diag/linux-x86_64 - install -m 0644 -D include/linux-x86_64/bit_ops.h ${DESTDIR}/usr/include/hfi1diag/linux-x86_64/bit_ops.h - install -m 0644 -D include/linux-x86_64/sysdep.h ${DESTDIR}/usr/include/hfi1diag/linux-x86_64/sysdep.h + mkdir -p ${DESTDIR}/usr/include/hfi1diag/linux-$(arch) + install -m 0644 -D include/linux-${INSTALL_ARCH}/bit_ops.h ${DESTDIR}/usr/include/hfi1diag/linux-${INSTALL_ARCH}/bit_ops.h + install -m 0644 -D include/linux-${INSTALL_ARCH}/sysdep.h ${DESTDIR}/usr/include/hfi1diag/linux-${INSTALL_ARCH}/sysdep.h install -m 0644 -D include/opa_udebug.h ${DESTDIR}/usr/include/hfi1diag/opa_udebug.h install -m 0644 -D include/opa_debug.h ${DESTDIR}/usr/include/hfi1diag/opa_debug.h install -m 0644 -D include/opa_intf.h ${DESTDIR}/usr/include/hfi1diag/opa_intf.h @@ -446,6 +465,7 @@ endif install -m 0644 -D psm_hal_gen1/hfi1_deprecated_gen1.h ${DESTDIR}/usr/include/hfi1diag/hfi1_deprecated.h rm -fr $(TEMP_INST_DIR) +ifeq (fedora,${DISTRO}) specfile: specfile_clean | $(OUTDIR) sed -e 's/@VERSION@/'${VERSION_RELEASE}'/g' libpsm2.spec.in | \ sed -e 's/@TARGLIB@/'${TARGLIB}'/g' \ @@ -466,6 +486,28 @@ specfile: specfile_clean | $(OUTDIR) else \ sed -i 's;@40_PSM_RULES@;'${UDEV_40_PSM_RULES}';g' ${OUTDIR}/${RPM_NAME}.spec; \ fi +else +specfile: specfile_clean | $(OUTDIR) + sed -e 's/@VERSION@/'${VERSION_RELEASE}'/g' libpsm2.spec.in | \ + sed -e 's/@TARGLIB@/'${TARGLIB}'/g' \ + -e 's/@RPM_NAME@/'${RPM_NAME}'/g' \ + -e 's/@RPM_NAME_BASEEXT@/'${RPM_NAME_BASEEXT}'/g' \ + -e 's/@COMPATLIB@/'${COMPATLIB}'/g' \ + -e 's/@COMPATMAJOR@/'${COMPATMAJOR}'/g' \ + -e 's;@UDEVDIR@;'${UDEVDIR}';g' \ + -e 's/@MAJOR@/'${MAJOR}'/g' \ + -e 's/@MINOR@/'${MINOR}'/g' \ + -e 's:@LIBPSM2_COMPAT_CONF_DIR@:'${LIBPSM2_COMPAT_CONF_DIR}':g' \ + -e 's:@LIBPSM2_COMPAT_SYM_CONF_DIR@:'${LIBPSM2_COMPAT_SYM_CONF_DIR}':g' \ + -e 's;@SPEC_FILE_RELEASE_DIST@;'${SPEC_FILE_RELEASE_DIST}';g' \ + -e 's/@DIST_SHA@/'${DIST_SHA}'/g' > \ + ${OUTDIR}/${RPM_NAME}.spec + if [ -f /etc/redhat-release ] && [ `grep -o "[0-9.]*" /etc/redhat-release | cut -d"." -f1` -lt 7 ]; then \ + sed -i 's;@40_PSM_RULES@;'${UDEVDIR}'/40-psm.rules;g' ${OUTDIR}/${RPM_NAME}.spec; \ + else \ + sed -i 's;@40_PSM_RULES@;'${UDEV_40_PSM_RULES}';g' ${OUTDIR}/${RPM_NAME}.spec; \ + fi +endif # We can't totally prevent two make dist calls in a row from packaging # the previous make dist, unless we switch to using a dedicated ./src folder diff --git a/buildflags.mak b/buildflags.mak index 0ce15aa..7849f88 100644 --- a/buildflags.mak +++ b/buildflags.mak @@ -4,6 +4,7 @@ # # GPL LICENSE SUMMARY # +# Copyright(c) 2024 Tactical Computing Labs, LLC # Copyright(c) 2021 Cornelis Networks. # Copyright(c) 2016 Intel Corporation. # @@ -74,6 +75,13 @@ else anerr := $(error Unknown Fortran compiler arch: ${FCARCH}) endif # gfortran +ifeq (${arch},riscv64) + ARCH=riscv64 +endif +ifeq (${arch},x86_64) + ARCH=i386 +endif + BASECFLAGS := $(BASE_FLAGS) -pthread LDFLAGS += $(BASE_FLAGS) ASFLAGS += $(BASE_FLAGS) @@ -88,7 +96,16 @@ LINKER_SCRIPT := -Wl,--version-script $(LINKER_SCRIPT_FILE) endif WERROR := -Werror -INCLUDES := -I$(top_srcdir)/include -I$(top_srcdir)/mpspawn -I$(top_srcdir)/include/$(os)-$(arch) + +ifeq (${arch},riscv64) +ARCH_INCLUDES=linux-riscv +endif + +ifeq (${arch},x86_64) +ARCH_INCLUDES=linux-i386 +endif + +INCLUDES := -I$(top_srcdir)/include -I$(top_srcdir)/include/$(ARCH_INCLUDES) -I$(top_srcdir)/mpspawn -I$(top_srcdir)/include/$(os)-$(arch) # # use IFS provided hfi1_user.h if installed. @@ -101,48 +118,50 @@ BASECFLAGS +=-Wall $(WERROR) # # test if compiler supports 32B(AVX2)/64B(AVX512F) move instruction. # -ifeq (${CC},icc) - ifeq ($(PSM_DISABLE_AVX2),) - MAVX2=-xATOM_SSE4.2 -DPSM_AVX512 - else - MAVX2=-march=core-avx-i - endif -else - ifeq ($(PSM_DISABLE_AVX2),) - MAVX2=-mavx2 +ifeq (${arch},x86_64) + ifeq (${CC},icc) + ifeq ($(PSM_DISABLE_AVX2),) + MAVX2=-xATOM_SSE4.2 -DPSM_AVX512 + else + MAVX2=-march=core-avx-i + endif else - MAVX2=-mavx + ifeq ($(PSM_DISABLE_AVX2),) + MAVX2=-mavx2 + else + MAVX2=-mavx + endif endif -endif -ifneq (icc,${CC}) - ifeq ($(PSM_DISABLE_AVX2),) - RET := $(shell echo "int main() {}" | ${CC} ${MAVX2} -E -dM -xc - 2>&1 | grep -q AVX2 ; echo $$?) - else - RET := $(shell echo "int main() {}" | ${CC} ${MAVX2} -E -dM -xc - 2>&1 | grep -q AVX ; echo $$?) - anerr := $(warning ***NOTE TO USER**** Disabling AVX2 will harm performance) - endif + ifneq (icc,${CC}) + ifeq ($(PSM_DISABLE_AVX2),) + RET := $(shell echo "int main() {}" | ${CC} ${MAVX2} -E -dM -xc - 2>&1 | grep -q AVX2 ; echo $$?) + else + RET := $(shell echo "int main() {}" | ${CC} ${MAVX2} -E -dM -xc - 2>&1 | grep -q AVX ; echo $$?) + anerr := $(warning ***NOTE TO USER**** Disabling AVX2 will harm performance) + endif - ifeq (0,${RET}) - BASECFLAGS += ${MAVX2} + ifeq (0,${RET}) + BASECFLAGS += ${MAVX2} + else + anerr := $(error Compiler does not support ${MAVX2} ) + endif else - anerr := $(error Compiler does not support ${MAVX2} ) - endif -else BASECFLAGS += ${MAVX2} -endif + endif # This support is dynamic at runtime, so is OK to enable as long as compiler can generate # the code. -ifneq (,${PSM_AVX512}) - ifneq (icc,${CC}) - RET := $(shell echo "int main() {}" | ${CC} -mavx512f -E -dM -xc - 2>&1 | grep -q AVX512 ; echo $$?) - ifeq (0,${RET}) - BASECFLAGS += -mavx512f - else - anerr := $(error Compiler does not support AVX512 ) + ifneq (,${PSM_AVX512}) + ifneq (icc,${CC}) + RET := $(shell echo "int main() {}" | ${CC} -mavx512f -E -dM -xc - 2>&1 | grep -q AVX512 ; echo $$?) + ifeq (0,${RET}) + BASECFLAGS += -mavx512f + else + anerr := $(error Compiler does not support AVX512 ) + endif + BASECFLAGS += -DPSM_AVX512 endif - BASECFLAGS += -DPSM_AVX512 endif endif @@ -183,8 +202,8 @@ endif ifneq (,${PSM_PROFILE}) BASECFLAGS += -DPSM_PROFILE endif -BASECFLAGS += -DNVIDIA_GPU_DIRECT ifneq (,${PSM_CUDA}) + BASECFLAGS += -DNVIDIA_GPU_DIRECT BASECFLAGS += -DPSM_CUDA CUDA_HOME ?= /usr/local/cuda INCLUDES += -I$(CUDA_HOME)/include diff --git a/compat/Makefile b/compat/Makefile index 996b7e9..303f25b 100644 --- a/compat/Makefile +++ b/compat/Makefile @@ -4,6 +4,7 @@ # # GPL LICENSE SUMMARY # +# Copyright(c) 2024 Tactical Computing Labs, LLC # Copyright(c) 2015 Intel Corporation. # # This program is free software; you can redistribute it and/or modify @@ -69,11 +70,19 @@ DEPS:= $(${COMPATLIB}-objs:.o=.d) all .DEFAULT: ${${COMPATLIB}-objs} $(OUTDIR)/${COMPATLIB}.so.${MAJOR} +ifeq (fedora,${DISTRO}) install: all install -m 0644 -D 40-psm-compat.rules ${DESTDIR}$(UDEVDIR)/rules.d/40-psm-compat.rules install -m 0644 -D libpsm2-compat.conf ${DESTDIR}${LIBPSM2_COMPAT_CONF_DIR}/modprobe.d/libpsm2-compat.conf install -m 0755 -D libpsm2-compat.cmds ${DESTDIR}/usr/lib/libpsm2/libpsm2-compat.cmds install -D $(OUTDIR)/${COMPATLIB}.so.${MAJOR} ${DESTDIR}${COMPAT_LIB_TARG}/${COMPATLIB}.so.${MAJOR} +else +install: all + install -m 0644 -D 40-psm-compat.rules ${DESTDIR}$(UDEVDIR)/40-psm-compat.rules + install -m 0644 -D libpsm2-compat.conf ${DESTDIR}${LIBPSM2_COMPAT_CONF_DIR}/modprobe.d/libpsm2-compat.conf + install -m 0755 -D libpsm2-compat.cmds ${DESTDIR}/usr/lib/libpsm2/libpsm2-compat.cmds + install -D $(OUTDIR)/${COMPATLIB}.so.${MAJOR} ${DESTDIR}${COMPAT_LIB_TARG}/${COMPATLIB}.so.${MAJOR} +endif $(OUTDIR)/%.o: $(compat_build_dir)/%.c $(CC) $(CFLAGS) $(BASECFLAGS) $(INCLUDES) -MMD -c $< -o $@ diff --git a/compat/buildflags.mak b/compat/buildflags.mak index db34848..c6c2097 100644 --- a/compat/buildflags.mak +++ b/compat/buildflags.mak @@ -4,6 +4,7 @@ # # GPL LICENSE SUMMARY # +# Copyright(c) 2024 Tactical Computing Labs, LLC # Copyright(c) 2015 Intel Corporation. # # This program is free software; you can redistribute it and/or modify @@ -54,7 +55,7 @@ $(error top_srcdir must be set to include makefile fragment) endif export os ?= $(shell uname -s | tr '[A-Z]' '[a-z]') -export arch := $(shell uname -m | sed -e 's,\(i[456]86\|athlon$$\),i386,') +export arch := $(shell uname -m | sed -e 's,\(i[456]86\|athlon$$\),i386,riscv64') export CCARCH ?= gcc ifeq (${CCARCH},$(filter ${CCARCH},gcc gcc4 icc clang)) diff --git a/debian/libpsm2-dev.install b/debian/libpsm2-dev.install index 81db1ed..5b76757 100644 --- a/debian/libpsm2-dev.install +++ b/debian/libpsm2-dev.install @@ -5,6 +5,8 @@ /usr/include/hfi1diag/hfi1_deprecated_gen1.h /usr/include/hfi1diag/linux-x86_64/bit_ops.h /usr/include/hfi1diag/linux-x86_64/sysdep.h +/usr/include/hfi1diag/linux-riscv/bit_ops.h +/usr/include/hfi1diag/linux-riscv/sysdep.h /usr/include/hfi1diag/opa_udebug.h /usr/include/hfi1diag/opa_debug.h /usr/include/hfi1diag/opa_intf.h diff --git a/hash.c b/hash.c new file mode 100644 index 0000000..6f78b19 --- /dev/null +++ b/hash.c @@ -0,0 +1,116 @@ +/* + This file is provided under a dual BSD/GPLv2 license. When using or + redistributing this file, you may do so under either license. + + GPL LICENSE SUMMARY + + Copyright(c) 2024 Tactical Computing Labs, LLC + Copyright(c) 2021 Cornelis Networks. + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + Contact Information: + Cornelis Networks, www.cornelisnetworks.com + + BSD LICENSE + + Copyright(c) 2024 Tactical Computing Labs, LLC + Copyright(c) 2021 Cornelis Networks. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name of Intel Corporation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef __PSM_HASH_H__ +#define __PSM_HASH_H__ + +inline unsigned hash_64(uint64_t a) +{ +#if defined(__riscv) + uint64_t* p = &a; + uint64_t P = 0x1814141ABLL; // CRC polynomial + uint64_t k1 = 0xA1FA6BECLL; // remainder of x^128 divided by CRC polynomial + uint64_t k2 = 0x9BE9878FLL; // remainder of x^96 divided by CRC polynomial + uint64_t k3 = 0xB1EFC5F6LL; // remainder of x^64 divided by CRC polynomial + uint64_t mu = 0x1FEFF7F62LL; // x^64 divided by CRC polynomial + uint64_t a0, a1, a2, t1, t2; + assert(sizeof(uint64_t) >= 2); + a0 = 0; + // rev8(p[0]); + a1 = rev8(p[0]); + // Main loop: Reduce to 2x 64 bits + for (const uint64_t *t0 = p; t0 != p+1; t0++) + { + a2 = rev8(*t0); + t1 = clmulh(a0, k1); + t2 = clmul(a0, k1); + a0 = a1 ^ t1; + a1 = a2 ^ t2; + } + // Reduce to 64 bit, add 32 bit zero padding + t1 = clmulh(a0, k2); + t2 = clmul(a0, k2); + a0 = (a1 >> 32) ^ t1; + a1 = (a1 << 32) ^ t2; + t2 = clmul(a0, k3); + a1 = a1 ^ t2; + // Barrett Reduction + t1 = clmul(a1 >> 32, mu); + t2 = clmul(t1 >> 32, P); + a0 = a1 ^ t2; + return a0; +#else + _mm_crc32_u64(0, a); + return a; +#endif +} + +inline unsigned hash_32(uint32_t a) { +#if defined(__riscv) + uint32_t * data = &a; + uint32_t P = 0x814141AB; // CRC polynomial (implicit x^32) + //uint32_t mu = 0xFEFF7F62; // x^64 divided by CRC polynomial + uint32_t mu1 = 0xFF7FBFB1; // "mu" with leading 1, shifted right by 1 bit + uint32_t crc = 0; + for (int i = 0; i < length; i++) { + crc ^= rev8(data[i]); + crc = clmulr(crc, mu1); + crc = clmul(crc, P); + } + return crc; +#else + _mm_crc32_u32(0, a); + return a; +#endif +} diff --git a/hash.h b/hash.h new file mode 100644 index 0000000..128fb2a --- /dev/null +++ b/hash.h @@ -0,0 +1,61 @@ +/* + This file is provided under a dual BSD/GPLv2 license. When using or + redistributing this file, you may do so under either license. + + GPL LICENSE SUMMARY + + Copyright(c) 2024 Tactical Computing Labs, LLC + Copyright(c) 2021 Cornelis Networks. + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + Contact Information: + Cornelis Networks, www.cornelisnetworks.com + + BSD LICENSE + + Copyright(c) 2024 Tactical Computing Labs, LLC + Copyright(c) 2021 Cornelis Networks. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name of Intel Corporation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef __PSM_HASH_H__ +#define __PSM_HASH_H__ + +unsigned hash_64(uint64_t a); +unsigned hash_32(uint32_t a); + +#endif diff --git a/include/opa_user.h b/include/opa_user.h index 624b8b2..0666e05 100644 --- a/include/opa_user.h +++ b/include/opa_user.h @@ -5,6 +5,7 @@ GPL LICENSE SUMMARY + Copyright(c) 2024 Tactical Computing Labs, LLC Copyright(c) 2015 Intel Corporation. This program is free software; you can redistribute it and/or modify @@ -223,6 +224,9 @@ void hfi_vsyslog(const char *prefix, int to_console, int level, void hfi_dwordcpy(volatile uint32_t *dest, const uint32_t *src, uint32_t ndwords); +void hfi_qwordcpy(volatile uint64_t *dest, const uint64_t *src, + uint32_t nqwords); + extern uint32_t __hfi_pico_per_cycle; /* only for use in these functions */ /* this is only accurate for reasonably large numbers of cycles (at least tens) */ diff --git a/libpsm2.spec.in b/libpsm2.spec.in index e9ef766..a54d625 100644 --- a/libpsm2.spec.in +++ b/libpsm2.spec.in @@ -4,6 +4,7 @@ # # GPL LICENSE SUMMARY # +# Copyright(c) 2024 Tactical Computing Labs, LLC # Copyright(c) 2017 Intel Corporation. # # This program is free software; you can redistribute it and/or modify @@ -63,7 +64,7 @@ URL: https://github.com/intel/opa-psm2/ Source0: @RPM_NAME@-%{version}.tar.gz # The OPA product is supported on x86_64 only: -ExclusiveArch: x86_64 +#ExclusiveArch: x86_64 BuildRequires: gcc Provides: hfi1-psm @@ -75,29 +76,14 @@ Summary: Intel PSM2 Libraries %endif Provides: @RPM_NAME@ = %{version}-%{release} Provides: @RPM_NAME@%{_isa} = %{version}-%{release} -%if 0%{?suse_version} -BuildRequires: libnuma-devel -Requires: libnuma1 -%else -%if 0%{?rhel}==0 || 0%{?rhel} > 6 -BuildRequires: systemd -BuildRequires: numactl-devel -Requires: numactl-libs -%endif -%endif %package -n @RPM_NAME@-devel Summary: Development files for Intel PSM2 -Requires: %{name}%{?_isa} = %{version}-%{release} Provides: hfi1-psm-devel Obsoletes: hfi1-psm-devel < 1.0.0 %package -n @RPM_NAME@-compat Summary: Compat library for Intel PSM2 -Requires: %{name}%{?_isa} = %{version}-%{release} -%if 0%{?fedora} -Requires: systemd-udev -%endif Provides: hfi1-psm-compat Obsoletes: hfi1-psm-compat < 1.0.0 @@ -166,7 +152,7 @@ make %{?_smp_mflags} %if 0%{?rhel} && 0%{?rhel} < 7 @UDEVDIR@/rules.d/40-psm-compat.rules %else -%{_udevrulesdir}/40-psm-compat.rules +@UDEVDIR@/40-psm-compat.rules %endif @LIBPSM2_COMPAT_SYM_CONF_DIR@/modprobe.d/libpsm2-compat.conf %{_prefix}/lib/libpsm2 diff --git a/opa/Makefile b/opa/Makefile index 2692886..9c5fab3 100644 --- a/opa/Makefile +++ b/opa/Makefile @@ -4,6 +4,7 @@ # # GPL LICENSE SUMMARY # +# Copyright(c) 2024 Tactical Computing Labs, LLC # Copyright(c) 2015 Intel Corporation. # # This program is free software; you can redistribute it and/or modify @@ -63,13 +64,15 @@ top_srcdir := $(this_srcdir)/.. INCLUDES += -I$(top_srcdir) -I$(top_srcdir)/ptl_ips ifeq (${arch},x86_64) PLATFORM_OBJ=opa_dwordcpy-x86_64-fast.o + BUILD_ARCH=${arch} else - PLATFORM_OBJ= + PLATFORM_OBJ=opa_dwordcpy-generic.o + BUILD_ARCH=generic endif ${TARGLIB}-objs := opa_debug.o opa_time.o \ opa_service.o opa_utils.o \ - opa_dwordcpy-$(arch).o opa_sysfs.o opa_syslog.o \ + opa_dwordcpy-$(BUILD_ARCH).o opa_sysfs.o opa_syslog.o \ $(PLATFORM_OBJ) ${TARGLIB}-objs := $(patsubst %.o, $(OUTDIR)/%.o, ${${TARGLIB}-objs}) diff --git a/opa/opa_debug.c b/opa/opa_debug.c index 990441b..3dc59ae 100644 --- a/opa/opa_debug.c +++ b/opa/opa_debug.c @@ -5,6 +5,7 @@ GPL LICENSE SUMMARY + Copyright(c) 2024 Tactical Computing Labs, LLC Copyright(c) 2015 Intel Corporation. This program is free software; you can redistribute it and/or modify @@ -195,8 +196,9 @@ static void hfi_sighdlr(int sig, siginfo_t *p1, void *ucv) "\n%.60s:%u terminated with signal %d", __progname, getpid(), sig); if (ucv) { - static ucontext_t *uc; - uc = (ucontext_t *) ucv; +#if defined(__x86_64__) || defined(__i386__) + static ucontext_t *uc = (ucontext_t *) ucv; +#endif id += snprintf(buf + id, sizeof(buf) - id, " at PC=%lx SP=%lx", #if defined(__x86_64__) (unsigned long)uc->uc_mcontext.gregs[REG_RIP], @@ -204,6 +206,8 @@ static void hfi_sighdlr(int sig, siginfo_t *p1, void *ucv) #elif defined(__i386__) (unsigned long)uc->uc_mcontext.gregs[REG_EIP], (unsigned long)uc->uc_mcontext.gregs[REG_ESP]); +#elif defined(__riscv) || defined(__riscv_xlen) + 0ul, 0ul); #else 0ul, 0ul); #warning No stack pointer or instruction pointer for this arch diff --git a/opa/opa_dwordcpy-generic.c b/opa/opa_dwordcpy-generic.c index dfb7755..7326957 100644 --- a/opa/opa_dwordcpy-generic.c +++ b/opa/opa_dwordcpy-generic.c @@ -5,6 +5,7 @@ GPL LICENSE SUMMARY + Copyright(c) 2024 Tactical Computing Labs, LLC Copyright(c) 2015 Intel Corporation. This program is free software; you can redistribute it and/or modify @@ -54,12 +55,17 @@ /* Copyright (c) 2003-2014 Intel Corporation. All rights reserved. */ #include +#if defined(__x86_64__) #include +#endif #include "opa_intf.h" #include "psm_user.h" -#if defined(__x86_64__) +#ifndef hfi_dwordcpy #define hfi_dwordcpy hfi_dwordcpy_safe +#endif + +#ifndef hfi_qwordcpy #define hfi_qwordcpy hfi_qwordcpy_safe #endif @@ -167,6 +173,7 @@ void hfi_qwordcpy(volatile uint64_t *dest, const uint64_t *src, uint32_t nqwords } } +#if defined(__x86_64__) #ifdef PSM_AVX512 void hfi_pio_blockcpy_512(volatile uint64_t *dest, const uint64_t *src, uint32_t nblock) { @@ -253,6 +260,7 @@ void hfi_pio_blockcpy_128(volatile uint64_t *dest, const uint64_t *src, uint32_t } while ((--nblock) && (dp = dp+4) && (sp = sp+4)); } } +#endif void hfi_pio_blockcpy_64(volatile uint64_t *dest, const uint64_t *src, uint32_t nblock) { diff --git a/opa/opa_time.c b/opa/opa_time.c index 67e28c7..a07200d 100644 --- a/opa/opa_time.c +++ b/opa/opa_time.c @@ -5,6 +5,7 @@ GPL LICENSE SUMMARY + Copyright(c) 2024 Tactical Computing Labs, LLC Copyright(c) 2015 Intel Corporation. This program is free software; you can redistribute it and/or modify @@ -116,14 +117,12 @@ static int timebase_debug; /* off by default */ static int hfi_timebase_isvalid(uint32_t pico_per_cycle) { -#if defined(__x86_64__) || defined(__i386__) /* If pico-per-cycle is less than 200, the clock speed would be greater * than 5 GHz. Similarly, we minimally support a 1GHz clock. * Allow some slop, because newer kernels with HPET can be a few * units off, and we don't want to spend the startup time needlessly */ if (pico_per_cycle >= 198 && pico_per_cycle <= 1005) return 1; -#endif else return 0; } @@ -289,7 +288,9 @@ static uint32_t hfi_timebase_from_cpuinfo(uint32_t old_pico_per_cycle) return new_pico_per_cycle; } +#if defined(__x86_64__) || defined(__i386__) fail: +#endif new_pico_per_cycle = SAFEDEFAULT_PICOS_PER_CYCLE; timebase_warn_always ("Problem obtaining CPU time base, detected to be %d " diff --git a/psm.c b/psm.c index ec1fd88..9588aa7 100644 --- a/psm.c +++ b/psm.c @@ -5,6 +5,7 @@ GPL LICENSE SUMMARY + Copyright(c) 2024 Tactical Computing Labs, LLC Copyright(c) 2021 Cornelis Networks. Copyright(c) 2016 Intel Corporation. @@ -388,6 +389,10 @@ psm2_error_t __psm2_init(int *major, int *minor) psmi_verno_client_val = min(PSMI_VERNO_MAKE(*major, *minor), psmi_verno); + +#if defined(__x86_64__) || defined(__x86_64) || defined(__X86__) || defined(i386) || defined(__i386) || defined(__i386__) || \ + defined(_X86_) || defined(__i486__) || defined(__i586__) || defined(__i686__) + /* Check to see if we need to set Architecture flags to something * besides big core Xeons */ cpuid_t id; @@ -410,6 +415,9 @@ psm2_error_t __psm2_init(int *major, int *minor) psmi_cpu_model = ((id.eax & CPUID_MODEL_MASK) >> 4) | ((id.eax & CPUID_EXMODEL_MASK) >> 12); } +#else + psmi_cpu_model = CPUID_MODEL_UNDEFINED; +#endif psmi_refcount++; /* hfi_debug lives in libhfi.so */ diff --git a/psm_hal_gen1/psm_hal_gen1_spio.c b/psm_hal_gen1/psm_hal_gen1_spio.c index 5444897..f42119b 100644 --- a/psm_hal_gen1/psm_hal_gen1_spio.c +++ b/psm_hal_gen1/psm_hal_gen1_spio.c @@ -5,6 +5,7 @@ GPL LICENSE SUMMARY + Copyright(c) 2024 Tactical Computing Labs, LLC Copyright(c) 2021 Cornelis Networks. Copyright(c) 2017 Intel Corporation. @@ -91,7 +92,11 @@ ips_spio_init(const struct psmi_context *context, struct ptl *ptl, #endif ) { +#if defined(__x86_64__) || defined(__x86_64) || defined(__X86__) || defined(i386) || defined(__i386) || defined(__i386__) || \ + defined(_X86_) || defined(__i486__) || defined(__i586__) || defined(__i686__) + cpuid_t id; +#endif hfp_gen1_pc_private *psm_hw_ctxt = context->psm_hw_ctxt; struct _hfi_ctrl *con_ctrl = psm_hw_ctxt->ctrl; @@ -161,6 +166,8 @@ ips_spio_init(const struct psmi_context *context, struct ptl *ptl, /* * Setup the PIO block copying routines. */ +#if defined(__x86_64__) || defined(__x86_64) || defined(__X86__) || defined(i386) || defined(__i386) || defined(__i386__) || \ + defined(_X86_) || defined(__i486__) || defined(__i586__) || defined(__i686__) get_cpuid(0x1, 0, &id); @@ -186,6 +193,15 @@ ips_spio_init(const struct psmi_context *context, struct ptl *ptl, ctrl->cuda_pio_buffer = NULL; #endif +#else + /* 16B copying supported */ + ctrl->spio_blockcpy_med = hfi_pio_blockcpy_64; + + /* 32B copying supported */ + ctrl->spio_blockcpy_large = ctrl->spio_blockcpy_med; + +#endif + _HFI_PRDBG("ips_spio_init() done\n"); return PSM2_OK; diff --git a/psm_hal_gen1/psm_hal_gen1_spio.h b/psm_hal_gen1/psm_hal_gen1_spio.h index 14bc646..bb3fe0c 100644 --- a/psm_hal_gen1/psm_hal_gen1_spio.h +++ b/psm_hal_gen1/psm_hal_gen1_spio.h @@ -5,6 +5,7 @@ GPL LICENSE SUMMARY + Copyright(c) 2024 Tactical Computing Labs, LLC Copyright(c) 2017 Intel Corporation. This program is free software; you can redistribute it and/or modify @@ -64,16 +65,20 @@ struct ptl; struct ips_proto; struct ips_flow; +#if defined(__x86_64__) /* 64B move instruction support */ #define AVX512F_BIT 16 /* level 07h, ebx */ /* 32B move instruction support */ #define AVX2_BIT 5 /* level 07h, ebx */ /* 16B move instruction support */ #define SSE2_BIT 26 /* level 01h, edx */ +#endif typedef void (*ips_spio_blockcpy_fn_t)(volatile uint64_t *dest, const uint64_t *src, uint32_t nblock); + +#if defined(__x86_64__) #ifdef PSM_AVX512 void hfi_pio_blockcpy_512(volatile uint64_t *dest, const uint64_t *src, uint32_t nblock); @@ -82,15 +87,19 @@ void hfi_pio_blockcpy_256(volatile uint64_t *dest, const uint64_t *src, uint32_t nblock); void hfi_pio_blockcpy_128(volatile uint64_t *dest, const uint64_t *src, uint32_t nblock); +#endif + void hfi_pio_blockcpy_64(volatile uint64_t *dest, const uint64_t *src, uint32_t nblock); static PSMI_HAL_INLINE psm2_error_t ips_spio_init(const psmi_context_t *context, struct ptl *ptl, struct ips_spio *ctrl +#if defined(__x86_64__) #ifdef PSM_AVX512 , int is_avx512_enabled #endif +#endif ); static PSMI_HAL_INLINE psm2_error_t ips_spio_fini(struct ips_spio *ctrl); diff --git a/psm_mq_internal.h b/psm_mq_internal.h index 0a12058..b70f555 100644 --- a/psm_mq_internal.h +++ b/psm_mq_internal.h @@ -5,6 +5,7 @@ GPL LICENSE SUMMARY + Copyright(c) 2024 Tactical Computing Labs, LLC Copyright(c) 2021 Cornelis Networks. Copyright(c) 2016 Intel Corporation. @@ -58,6 +59,10 @@ #ifndef MQ_INT_H #define MQ_INT_H +#if defined(__riscv) +#include +#endif + /* Ugh. smmintrin.h eventually includes mm_malloc.h, which calls malloc */ #ifdef malloc #undef malloc @@ -65,12 +70,16 @@ #ifdef free #undef free #endif +#if !(__riscv) #include +#endif #include "psm_user.h" #include "psm_sysbuf.h" #include "psm2_mock_testing.h" +#include + #if 0 typedef psm2_error_t(*psm_mq_unexpected_callback_fn_t) (psm2_mq_t mq, uint16_t mode, psm2_epaddr_t epaddr, @@ -275,18 +284,11 @@ struct psm2_mq_req { }; }; -PSMI_ALWAYS_INLINE( -unsigned -hash_64(uint64_t a)) -{ - return _mm_crc32_u64(0, a); -} -PSMI_ALWAYS_INLINE( -unsigned -hash_32(uint32_t a)) -{ - return _mm_crc32_u32(0, a); -} +#if defined(__riscv) +#include "util-generic.h" +#endif + +#include "hash.h" void MOCKABLE(psmi_mq_mtucpy)(void *vdest, const void *vsrc, uint32_t nchars); MOCK_DCL_EPILOGUE(psmi_mq_mtucpy); diff --git a/ptl_am/psm_am_internal.h b/ptl_am/psm_am_internal.h index c4c08a5..f7c55e9 100644 --- a/ptl_am/psm_am_internal.h +++ b/ptl_am/psm_am_internal.h @@ -5,6 +5,7 @@ GPL LICENSE SUMMARY + Copyright(c) 2024 Tactical Computing Labs, LLC Copyright(c) 2015 Intel Corporation. This program is free software; you can redistribute it and/or modify @@ -257,6 +258,8 @@ void psmi_am_reqq_add(int amtype, ptl_t *ptl, psm2_epaddr_t epaddr, #define QISEMPTY(flag) (flag < QREADY) #if defined(__x86_64__) || defined(__i386__) # define _QMARK_FLAG_FENCE() asm volatile("" : : : "memory") /* compilerfence */ +#elif defined(__riscv) || defined(__riscv_xlen) +# define _QMARK_FLAG_FENCE() asm volatile("" : : : "memory") /* compilerfence */ #else # error No _QMARK_FLAG_FENCE() defined for this platform #endif diff --git a/util-generic.c b/util-generic.c new file mode 100644 index 0000000..92440b9 --- /dev/null +++ b/util-generic.c @@ -0,0 +1,102 @@ +/* + This file is provided under a dual BSD/GPLv2 license. When using or + redistributing this file, you may do so under either license. + + GPL LICENSE SUMMARY + + Copyright(c) 2024 Tactical Computing Labs, LLC + Copyright(c) 2021 Cornelis Networks. + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + Contact Information: + Cornelis Networks, www.cornelisnetworks.com + + BSD LICENSE + + Copyright(c) 2024 Tactical Computing Labs, LLC + Copyright(c) 2021 Cornelis Networks. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name of Intel Corporation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + + +#include "util.h" + +#if defined(__riscv) && defined(__riscv_xlen) +uint_xlen_t clmul(uint_xlen_t rs1, uint_xlen_t rs2) +{ + uint_xlen_t x = 0; + for (int i = 0; i < XLEN; i++) + if ((rs2 >> i) & 1) + x ^= rs1 << i; + return x; +} + +uint_xlen_t clmulh(uint_xlen_t rs1, uint_xlen_t rs2) +{ + uint_xlen_t x = 0; + for (int i = 1; i < XLEN; i++) + if ((rs2 >> i) & 1) + x ^= rs1 >> (XLEN-i); + return x; +} + +uint_xlen_t clmulr(uint_xlen_t rs1, uint_xlen_t rs2) +{ + uint_xlen_t x = 0; + for (int i = 0; i < XLEN; i++) + if ((rs2 >> i) & 1) + x ^= rs1 >> (XLEN-i-1); + return x; +} + +unsigned int rev8(unsigned int num) +{ + unsigned int NO_OF_BITS = sizeof(num) * 8; + unsigned int reverse_num = 0; + int i = 0; + for (i = 0; i < NO_OF_BITS; i++) { + if ((num & (1 << i))) + reverse_num |= 1 << ((NO_OF_BITS - 1) - i); + } + return reverse_num; +} +#else +uint64_t clmulh(uint_xlen_t rs1, uint_xlen_t rs2) +uint64_t clmul(uint_xlen_t rs1, uint_xlen_t rs2) +uint64_t clmulr(uint_xlen_t rs1, uint_xlen_t rs2){} +unsigned int rev8(unsigned int num){} +#endif diff --git a/util-generic.h b/util-generic.h new file mode 100644 index 0000000..ca7600e --- /dev/null +++ b/util-generic.h @@ -0,0 +1,87 @@ +/* + This file is provided under a dual BSD/GPLv2 license. When using or + redistributing this file, you may do so under either license. + + GPL LICENSE SUMMARY + + Copyright(c) 2024 Tactical Computing Labs, LLC + Copyright(c) 2021 Cornelis Networks. + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + Contact Information: + Cornelis Networks, www.cornelisnetworks.com + + BSD LICENSE + + Copyright(c) 2024 Tactical Computing Labs, LLC + Copyright(c) 2021 Cornelis Networks. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name of Intel Corporation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + + +#ifndef PSM_GENERIC_UTIL +#define PSM_GENERIC_UTIL + +#include + +#if defined(__riscv) && defined(__riscv_xlen) +#if __riscv_xlen == 32 +typedef uint32_t uint_xlen_t; +#define XLEN 32 +#elif __riscv_xlen == 64 +typedef uint64_t uint_xlen_t; +#define XLEN 64 +#endif + +uint_xlen_t clmul(uint_xlen_t rs1, uint_xlen_t rs2); + +uint_xlen_t clmulh(uint_xlen_t rs1, uint_xlen_t rs2); + +uint_xlen_t clmulr(uint_xlen_t rs1, uint_xlen_t rs2); + +unsigned int rev8(unsigned int num); +#else +uint64_t clmul(uint_xlen_t rs1, uint_xlen_t rs2); + +uint64_t clmulh(uint_xlen_t rs1, uint_xlen_t rs2); + +uint64_t clmulr(uint_xlen_t rs1, uint_xlen_t rs2); + +unsigned int rev8(unsigned int num); +#endif + +#endif