Math Processor Unit Library

libmpu – library of arithmetic functions for integer, real, and complex numbers of increased digit capacity

16 Commits   0 Branches   2 Tags
author: kx <kx@radix-linux.su> 2024-12-20 16:11:07 +0300 committer: kx <kx@radix-linux.su> 2024-12-20 16:11:07 +0300 commit: 868b2b66b564b5c00e3a74d10be45db7151627ac parent: cce2ae8d3312493b7653358bb4af201d3271377b
Commit Summary:
Version 1.0.14
Diffstat:
1 file changed, 220 insertions, 0 deletions
diff --git a/mpu/mpu-integer.h b/mpu/mpu-integer.h
new file mode 100644
index 0000000..292398a
--- /dev/null
+++ b/mpu/mpu-integer.h
@@ -0,0 +1,306 @@
+
+/***************************************************************
+  __MPU_INTEGER.H
+
+       This file contains declarations of functions for
+       INTEGER arithmetic operations.
+
+       PART OF : MPU - library .
+
+       USAGE   : Internal only .
+
+       NOTE    : Include "libmpu.h" before this FILE .
+
+       Copyright (C) 2000 - 2024  by Andrew V.Kosteltsev.
+       All Rights Reserved.
+ ***************************************************************/
+
+#ifndef   __MPU_INTEGER_H
+#define   __MPU_INTEGER_H
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+
+extern void iadd_8( __mpu_uint8_t *c, __mpu_uint8_t *a, __mpu_uint8_t *b );
+extern void iadc_8( __mpu_uint8_t *c, __mpu_uint8_t *a, __mpu_uint8_t *b );
+extern void isub_8( __mpu_uint8_t *c, __mpu_uint8_t *a, __mpu_uint8_t *b );
+extern void isbb_8( __mpu_uint8_t *c, __mpu_uint8_t *a, __mpu_uint8_t *b );
+
+extern void iadd_16( __mpu_uint16_t *c, __mpu_uint16_t *a, __mpu_uint16_t *b );
+extern void iadc_16( __mpu_uint16_t *c, __mpu_uint16_t *a, __mpu_uint16_t *b );
+extern void isub_16( __mpu_uint16_t *c, __mpu_uint16_t *a, __mpu_uint16_t *b );
+extern void isbb_16( __mpu_uint16_t *c, __mpu_uint16_t *a, __mpu_uint16_t *b );
+
+extern void iadd_32( __mpu_uint32_t *c, __mpu_uint32_t *a, __mpu_uint32_t *b );
+extern void iadc_32( __mpu_uint32_t *c, __mpu_uint32_t *a, __mpu_uint32_t *b );
+extern void isub_32( __mpu_uint32_t *c, __mpu_uint32_t *a, __mpu_uint32_t *b );
+extern void isbb_32( __mpu_uint32_t *c, __mpu_uint32_t *a, __mpu_uint32_t *b );
+
+extern void iadd_np( EMUSHORT *c, EMUSHORT *a, EMUSHORT *b, int np );
+extern void iadc_np( EMUSHORT *c, EMUSHORT *a, EMUSHORT *b, int np );
+extern void isub_np( EMUSHORT *c, EMUSHORT *a, EMUSHORT *b, int np );
+extern void isbb_np( EMUSHORT *c, EMUSHORT *a, EMUSHORT *b, int np );
+
+
+extern void ishl_8( __mpu_uint8_t *c, __mpu_uint8_t *a );
+extern void ishr_8( __mpu_uint8_t *c, __mpu_uint8_t *a );
+extern void isal_8( __mpu_uint8_t *c, __mpu_uint8_t *a );
+extern void isar_8( __mpu_uint8_t *c, __mpu_uint8_t *a );
+
+extern void ishl_16( __mpu_uint16_t *c, __mpu_uint16_t *a );
+extern void ishr_16( __mpu_uint16_t *c, __mpu_uint16_t *a );
+extern void isal_16( __mpu_uint16_t *c, __mpu_uint16_t *a );
+extern void isar_16( __mpu_uint16_t *c, __mpu_uint16_t *a );
+
+extern void ishl_32( __mpu_uint32_t *c, __mpu_uint32_t *a );
+extern void ishr_32( __mpu_uint32_t *c, __mpu_uint32_t *a );
+extern void isal_32( __mpu_uint32_t *c, __mpu_uint32_t *a );
+extern void isar_32( __mpu_uint32_t *c, __mpu_uint32_t *a );
+
+extern void ishl_np( EMUSHORT *c, EMUSHORT *a, int np );
+extern void ishr_np( EMUSHORT *c, EMUSHORT *a, int np );
+extern void isal_np( EMUSHORT *c, EMUSHORT *a, int np );
+extern void isar_np( EMUSHORT *c, EMUSHORT *a, int np );
+
+
+extern void irol_8( __mpu_uint8_t *c, __mpu_uint8_t *a );
+extern void iror_8( __mpu_uint8_t *c, __mpu_uint8_t *a );
+extern void ircl_8( __mpu_uint8_t *c, __mpu_uint8_t *a );
+extern void ircr_8( __mpu_uint8_t *c, __mpu_uint8_t *a );
+
+extern void irol_16( __mpu_uint16_t *c, __mpu_uint16_t *a );
+extern void iror_16( __mpu_uint16_t *c, __mpu_uint16_t *a );
+extern void ircl_16( __mpu_uint16_t *c, __mpu_uint16_t *a );
+extern void ircr_16( __mpu_uint16_t *c, __mpu_uint16_t *a );
+
+extern void irol_32( __mpu_uint32_t *c, __mpu_uint32_t *a );
+extern void iror_32( __mpu_uint32_t *c, __mpu_uint32_t *a );
+extern void ircl_32( __mpu_uint32_t *c, __mpu_uint32_t *a );
+extern void ircr_32( __mpu_uint32_t *c, __mpu_uint32_t *a );
+
+extern void irol_np( EMUSHORT *c, EMUSHORT *a, int np );
+extern void iror_np( EMUSHORT *c, EMUSHORT *a, int np );
+extern void ircl_np( EMUSHORT *c, EMUSHORT *a, int np );
+extern void ircr_np( EMUSHORT *c, EMUSHORT *a, int np );
+
+
+extern void ishln_8( __mpu_uint8_t *c, __mpu_uint8_t *a, unsigned int b );
+extern void ishrn_8( __mpu_uint8_t *c, __mpu_uint8_t *a, unsigned int b );
+extern void isaln_8( __mpu_uint8_t *c, __mpu_uint8_t *a, unsigned int b );
+extern void isarn_8( __mpu_uint8_t *c, __mpu_uint8_t *a, unsigned int b );
+
+extern void ishln_16( __mpu_uint16_t *c, __mpu_uint16_t *a, unsigned int b );
+extern void ishrn_16( __mpu_uint16_t *c, __mpu_uint16_t *a, unsigned int b );
+extern void isaln_16( __mpu_uint16_t *c, __mpu_uint16_t *a, unsigned int b );
+extern void isarn_16( __mpu_uint16_t *c, __mpu_uint16_t *a, unsigned int b );
+
+extern void ishln_32( __mpu_uint32_t *c, __mpu_uint32_t *a, unsigned int b );
+extern void ishrn_32( __mpu_uint32_t *c, __mpu_uint32_t *a, unsigned int b );
+extern void isaln_32( __mpu_uint32_t *c, __mpu_uint32_t *a, unsigned int b );
+extern void isarn_32( __mpu_uint32_t *c, __mpu_uint32_t *a, unsigned int b );
+
+extern void ishln_np( EMUSHORT *c, EMUSHORT *a, unsigned int b, int np );
+extern void ishrn_np( EMUSHORT *c, EMUSHORT *a, unsigned int b, int np );
+extern void isaln_np( EMUSHORT *c, EMUSHORT *a, unsigned int b, int np );
+extern void isarn_np( EMUSHORT *c, EMUSHORT *a, unsigned int b, int np );
+
+
+extern void iroln_8( __mpu_uint8_t *c, __mpu_uint8_t *a, unsigned int b );
+extern void irorn_8( __mpu_uint8_t *c, __mpu_uint8_t *a, unsigned int b );
+extern void ircln_8( __mpu_uint8_t *c, __mpu_uint8_t *a, unsigned int b );
+extern void ircrn_8( __mpu_uint8_t *c, __mpu_uint8_t *a, unsigned int b );
+
+extern void iroln_16( __mpu_uint16_t *c, __mpu_uint16_t *a, unsigned int b );
+extern void irorn_16( __mpu_uint16_t *c, __mpu_uint16_t *a, unsigned int b );
+extern void ircln_16( __mpu_uint16_t *c, __mpu_uint16_t *a, unsigned int b );
+extern void ircrn_16( __mpu_uint16_t *c, __mpu_uint16_t *a, unsigned int b );
+
+extern void iroln_32( __mpu_uint32_t *c, __mpu_uint32_t *a, unsigned int b );
+extern void irorn_32( __mpu_uint32_t *c, __mpu_uint32_t *a, unsigned int b );
+extern void ircln_32( __mpu_uint32_t *c, __mpu_uint32_t *a, unsigned int b );
+extern void ircrn_32( __mpu_uint32_t *c, __mpu_uint32_t *a, unsigned int b );
+
+extern void iroln_np( EMUSHORT *c, EMUSHORT *a, unsigned int b, int np );
+extern void irorn_np( EMUSHORT *c, EMUSHORT *a, unsigned int b, int np );
+extern void ircln_np( EMUSHORT *c, EMUSHORT *a, unsigned int b, int np );
+extern void ircrn_np( EMUSHORT *c, EMUSHORT *a, unsigned int b, int np );
+
+
+extern void inot_8( __mpu_uint8_t *c, __mpu_uint8_t *a );
+extern void inot_16( __mpu_uint16_t *c, __mpu_uint16_t *a );
+extern void inot_32( __mpu_uint32_t *c, __mpu_uint32_t *a );
+extern void inot_np( EMUSHORT *c, EMUSHORT *a, int np );
+
+extern void ineg_8( __mpu_uint8_t *c, __mpu_uint8_t *a );
+extern void ineg_16( __mpu_uint16_t *c, __mpu_uint16_t *a );
+extern void ineg_32( __mpu_uint32_t *c, __mpu_uint32_t *a );
+extern void ineg_np( EMUSHORT *c, EMUSHORT *a, int np );
+
+extern void iand_8( __mpu_uint8_t *c, __mpu_uint8_t *a, __mpu_uint8_t *b );
+extern void iand_16( __mpu_uint16_t *c, __mpu_uint16_t *a, __mpu_uint16_t *b );
+extern void iand_32( __mpu_uint32_t *c, __mpu_uint32_t *a, __mpu_uint32_t *b );
+extern void iand_np( EMUSHORT *c, EMUSHORT *a, EMUSHORT *b, int np );
+
+extern void itest_8( __mpu_uint8_t *a, __mpu_uint8_t *b );
+extern void itest_16( __mpu_uint16_t *a, __mpu_uint16_t *b );
+extern void itest_32( __mpu_uint32_t *a, __mpu_uint32_t *b );
+extern void itest_np( EMUSHORT *a, EMUSHORT *b, int np );
+
+extern void icmp_8( __mpu_uint8_t *a, __mpu_uint8_t *b );
+extern void icmp_16( __mpu_uint16_t *a, __mpu_uint16_t *b );
+extern void icmp_32( __mpu_uint32_t *a, __mpu_uint32_t *b );
+extern void icmp_np( EMUSHORT *a, EMUSHORT *b, int np );
+
+extern void ior_8( __mpu_uint8_t *c, __mpu_uint8_t *a, __mpu_uint8_t *b );
+extern void ior_16( __mpu_uint16_t *c, __mpu_uint16_t *a, __mpu_uint16_t *b );
+extern void ior_32( __mpu_uint32_t *c, __mpu_uint32_t *a, __mpu_uint32_t *b );
+extern void ior_np( EMUSHORT *c, EMUSHORT *a, EMUSHORT *b, int np );
+
+extern void ixor_8( __mpu_uint8_t *c, __mpu_uint8_t *a, __mpu_uint8_t *b );
+extern void ixor_16( __mpu_uint16_t *c, __mpu_uint16_t *a, __mpu_uint16_t *b );
+extern void ixor_32( __mpu_uint32_t *c, __mpu_uint32_t *a, __mpu_uint32_t *b );
+extern void ixor_np( EMUSHORT *c, EMUSHORT *a, EMUSHORT *b, int np );
+
+extern void iinc_8( __mpu_uint8_t *c, __mpu_uint8_t *a );
+extern void iinc_16( __mpu_uint16_t *c, __mpu_uint16_t *a );
+extern void iinc_32( __mpu_uint32_t *c, __mpu_uint32_t *a );
+extern void iinc_np( EMUSHORT *c, EMUSHORT *a, int np );
+
+extern void idec_8( __mpu_uint8_t *c, __mpu_uint8_t *a );
+extern void idec_16( __mpu_uint16_t *c, __mpu_uint16_t *a );
+extern void idec_32( __mpu_uint32_t *c, __mpu_uint32_t *a );
+extern void idec_np( EMUSHORT *c, EMUSHORT *a, int np );
+
+
+extern void icpy_8( __mpu_uint8_t *c, __mpu_uint8_t *a );
+extern void icpy_16( __mpu_uint16_t *c, __mpu_uint16_t *a );
+extern void icpy_32( __mpu_uint32_t *c, __mpu_uint32_t *a );
+
+extern void icpy_s2l_8to16( __mpu_uint16_t *c, __mpu_uint8_t *a );
+extern void icpy_s2l_8to32( __mpu_uint32_t *c, __mpu_uint8_t *a );
+extern void icpy_s2l_8to_np( EMUSHORT *c, __mpu_uint8_t *a, int np );
+
+extern void icpy_s2l_16to32( __mpu_uint32_t *c, __mpu_uint16_t *a );
+extern void icpy_s2l_16to_np( EMUSHORT *c, __mpu_uint16_t *a, int np );
+
+#if BITS_PER_EMUSHORT > 32
+extern void icpy_s2l_32to_np( EMUSHORT *c, __mpu_uint32_t *a, int np );
+#endif /* BITS_PER_EMUSHORT > 32 */
+
+extern void icpy_l2s_16to8( __mpu_uint8_t *c, __mpu_uint16_t *a );
+extern void icpy_l2s_32to8( __mpu_uint8_t *c, __mpu_uint32_t *a );
+extern void icpy_l2s_np_to8( __mpu_uint8_t *c, EMUSHORT *a, int np );
+
+extern void icpy_l2s_32to16( __mpu_uint16_t *c, __mpu_uint32_t *a );
+extern void icpy_l2s_np_to16( __mpu_uint16_t *c, EMUSHORT *a, int np );
+
+#if BITS_PER_EMUSHORT > 32
+extern void icpy_l2s_np_to32( __mpu_uint32_t *c, EMUSHORT *a, int np );
+#endif /* BITS_PER_EMUSHORT > 32 */
+
+extern void icpy_np( EMUSHORT *c, EMUSHORT *a, int np_c, int np_a );
+
+
+extern void icvt_s2l_8to16( __mpu_uint16_t *c, __mpu_uint8_t *a );
+extern void icvt_s2l_8to32( __mpu_uint32_t *c, __mpu_uint8_t *a );
+extern void icvt_s2l_8to_np( EMUSHORT *c, __mpu_uint8_t *a, int np );
+
+extern void icvt_s2l_16to32( __mpu_uint32_t *c, __mpu_uint16_t *a );
+extern void icvt_s2l_16to_np( EMUSHORT *c, __mpu_uint16_t *a, int np );
+
+#if BITS_PER_EMUSHORT > 32
+extern void icvt_s2l_32to_np( EMUSHORT *c, __mpu_uint32_t *a, int np );
+#endif /* BITS_PER_EMUSHORT > 32 */
+
+extern void icvt_l2s_16to8( __mpu_uint8_t *c, __mpu_uint16_t *a );
+extern void icvt_l2s_32to8( __mpu_uint8_t *c, __mpu_uint32_t *a );
+extern void icvt_l2s_np_to8( __mpu_uint8_t *c, EMUSHORT *a, int np );
+
+extern void icvt_l2s_32to16( __mpu_uint16_t *c, __mpu_uint32_t *a );
+extern void icvt_l2s_np_to16( __mpu_uint16_t *c, EMUSHORT *a, int np );
+
+#if BITS_PER_EMUSHORT > 32
+extern void icvt_l2s_np_to32( __mpu_uint32_t *c, EMUSHORT *a, int np );
+#endif /* BITS_PER_EMUSHORT > 32 */
+
+extern void icvt_np( EMUSHORT *c, EMUSHORT *a, int np_c, int np_a );
+
+
+extern void ixchg_8( __mpu_uint8_t *a, __mpu_uint8_t *b );
+extern void ixchg_16( __mpu_uint16_t *a, __mpu_uint16_t *b );
+extern void ixchg_32( __mpu_uint32_t *a, __mpu_uint32_t *b );
+extern void ixchg_np( EMUSHORT *a, EMUSHORT *b, int np );
+
+
+extern void imul_8( __mpu_uint16_t *prod, __mpu_uint8_t *num, __mpu_uint8_t *mul );
+extern void imul_16( __mpu_uint32_t *prod, __mpu_uint16_t *num, __mpu_uint16_t *mul );
+#if BITS_PER_EMUSHORT > 32 /* 64 bits only */
+extern void imul_32( __mpu_uint64_t *prod, __mpu_uint32_t *num, __mpu_uint32_t *mul );
+#endif /* BITS_PER_EMUSHORT > 32 */
+
+extern void ismul_8( __mpu_uint16_t *prod, __mpu_uint8_t *num, __mpu_uint8_t *mul );
+extern void ismul_16( __mpu_uint32_t *prod, __mpu_uint16_t *num, __mpu_uint16_t *mul );
+#if BITS_PER_EMUSHORT > 32 /* 64 bits only */
+extern void ismul_32( __mpu_uint64_t *prod, __mpu_uint32_t *num, __mpu_uint32_t *mul );
+#endif /* BITS_PER_EMUSHORT > 32 */
+
+
+extern void idiv_8( __mpu_uint8_t *quot, __mpu_uint8_t *rem, __mpu_uint8_t *num, __mpu_uint8_t *den );
+extern void idiv_16( __mpu_uint16_t *quot, __mpu_uint16_t *rem, __mpu_uint16_t *num, __mpu_uint16_t *den );
+#if BITS_PER_EMUSHORT > 32 /* 64 bits only */
+extern void idiv_32( __mpu_uint32_t *quot, __mpu_uint32_t *rem, __mpu_uint32_t *num, __mpu_uint32_t *den );
+#endif /* BITS_PER_EMUSHORT > 32 */
+
+extern void isdiv_8( __mpu_uint8_t *quot, __mpu_uint8_t *rem, __mpu_uint8_t *num, __mpu_uint8_t *den );
+extern void isdiv_16( __mpu_uint16_t *quot, __mpu_uint16_t *rem, __mpu_uint16_t *num, __mpu_uint16_t *den );
+#if BITS_PER_EMUSHORT > 32 /* 64 bits only */
+extern void isdiv_32( __mpu_uint32_t *quot, __mpu_uint32_t *rem, __mpu_uint32_t *num, __mpu_uint32_t *den );
+#endif /* BITS_PER_EMUSHORT > 32 */
+
+
+extern void imul_np( EMUSHORT *prod, EMUSHORT *num, EMUSHORT *mul, int np_prod, int np_num );
+extern void ismul_np( EMUSHORT *prod, EMUSHORT *num, EMUSHORT *mul, int np_prod, int np_num );
+
+extern void idiv_np( EMUSHORT *quot, EMUSHORT *rem, EMUSHORT *num, EMUSHORT *den, int np );
+extern void isdiv_np( EMUSHORT *quot, EMUSHORT *rem, EMUSHORT *num, EMUSHORT *den, int np );
+
+
+extern void iatoi_8( __mpu_uint8_t *c, __mpu_char8_t *str );
+extern void iatoui_8( __mpu_uint8_t *c, __mpu_char8_t *str );
+
+extern void iatoi_16( __mpu_uint16_t *c, __mpu_char8_t *str );
+extern void iatoui_16( __mpu_uint16_t *c, __mpu_char8_t *str );
+
+#if BITS_PER_EMUSHORT > 32 /* 64 bits only */
+extern void iatoi_32( __mpu_uint32_t *c, __mpu_char8_t *str );
+extern void iatoui_32( __mpu_uint32_t *c, __mpu_char8_t *str );
+#endif /* BITS_PER_EMUSHORT > 32 */
+
+extern void iatoi_np( EMUSHORT *c, __mpu_char8_t *str, int np );
+extern void iatoui_np( EMUSHORT *c, __mpu_char8_t *str, int np );
+
+
+extern void iitoa_8( __mpu_char8_t *str, __mpu_uint8_t *a, int radix, int uf );
+extern void iuitoa_8( __mpu_char8_t *str, __mpu_uint8_t *a, int radix, int uf );
+
+extern void iitoa_16( __mpu_char8_t *str, __mpu_uint16_t *a, int radix, int uf );
+extern void iuitoa_16( __mpu_char8_t *str, __mpu_uint16_t *a, int radix, int uf );
+
+#if BITS_PER_EMUSHORT > 32 /* 64 bits only */
+extern void iitoa_32( __mpu_char8_t *str, __mpu_uint32_t *a, int radix, int uf );
+extern void iuitoa_32( __mpu_char8_t *str, __mpu_uint32_t *a, int radix, int uf );
+#endif /* BITS_PER_EMUSHORT > 32 */
+
+extern void iitoa_np( __mpu_char8_t *str, EMUSHORT *a, int radix, int uf, int np );
+extern void iuitoa_np( __mpu_char8_t *str, EMUSHORT *a, int radix, int uf, int np );
+
+
+
+
+#ifdef  __cplusplus
+}   /* ... extern "C" */
+#endif
+
+#endif /* __MPU_INTEGER_H */