| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #ifdef HAVE_CONFIG_H |
| #include <config.h> |
| #endif |
| |
| #include <errno.h> /* errno(3) */ |
| #include <string.h> /* strcpy(3) */ |
| #include <strings.h> /* bzero(3) */ |
| |
| #include <libmpu.h> |
| #include <mpu-context.h> |
| |
| #include <mpu-emutype.h> |
| #include <mpu-integer.h> |
| |
| #include <mpu-char.h> |
| #include <mpu-symbols.h> |
| |
| #include <mpu-math-errno.h> |
| #include <mpu-mtherr.h> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void iadd_8( __mpu_uint8_t *c, __mpu_uint8_t *a, __mpu_uint8_t *b ) |
| { |
| __mpu_uint16_t rc, op1, op2; |
| signed int carry, sign = 0; |
| |
| __CLEAR_IFLAGS; |
| |
| carry = __MFLAG(CF); |
| |
| |
| rc = ((__mpu_uint16_t) (*a) & 0x0f) + |
| ((__mpu_uint16_t) (*b) & 0x0f) + carry; |
| if( rc & 0x10 ) __STA; |
| |
| |
| rc = (__mpu_uint16_t) (*a) + |
| (__mpu_uint16_t) (*b) + carry; |
| if( rc & 0x100 ) __STC; |
| else __CLC; |
| |
| if( __MPARITY(rc) ) __STP; |
| |
| |
| op1 = (__mpu_uint16_t) (*a); |
| op2 = (__mpu_uint16_t) (*b); |
| if( op1 & 0x80 ) op1 |= 0x100; |
| if( op2 & 0x80 ) op2 |= 0x100; |
| |
| rc = op1 + op2 + carry; |
| if( rc & 0x100 ) carry = 1; |
| else carry = 0; |
| if( rc & 0x80 ) sign = 1; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| if( sign ) __STS; |
| else __CLS; |
| |
| *c = (__mpu_uint8_t) rc; |
| if( *c == 0 ) __STZ; |
| } |
| |
| |
| void iadc_8( __mpu_uint8_t *c, __mpu_uint8_t *a, __mpu_uint8_t *b ) |
| { |
| __mpu_uint16_t rc, op1, op2; |
| signed int carry, sign = 0; |
| |
| carry = __MFLAG(CF); |
| |
| __CLEAR_IFLAGS; |
| |
| |
| rc = ((__mpu_uint16_t) (*a) & 0x0f) + |
| ((__mpu_uint16_t) (*b) & 0x0f) + carry; |
| if( rc & 0x10 ) __STA; |
| |
| |
| rc = (__mpu_uint16_t) (*a) + |
| (__mpu_uint16_t) (*b) + carry; |
| if( rc & 0x100 ) __STC; |
| else __CLC; |
| |
| if( __MPARITY(rc) ) __STP; |
| |
| |
| op1 = (__mpu_uint16_t) (*a); |
| op2 = (__mpu_uint16_t) (*b); |
| if( op1 & 0x80 ) op1 |= 0x100; |
| if( op2 & 0x80 ) op2 |= 0x100; |
| |
| rc = op1 + op2 + carry; |
| if( rc & 0x100 ) carry = 1; |
| else carry = 0; |
| if( rc & 0x80 ) sign = 1; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| if( sign ) __STS; |
| else __CLS; |
| |
| *c = (__mpu_uint8_t) rc; |
| if( *c == 0 ) __STZ; |
| } |
| |
| |
| void isub_8( __mpu_uint8_t *c, __mpu_uint8_t *a, __mpu_uint8_t *b ) |
| { |
| __mpu_uint16_t rc, op1, op2; |
| signed int carry, sign = 0; |
| |
| __CLEAR_IFLAGS; |
| |
| carry = __MFLAG(CF); |
| |
| |
| rc = ((__mpu_uint16_t) (*a) & 0x0f) - |
| ((__mpu_uint16_t) (*b) & 0x0f) - carry; |
| if( rc & 0x10 ) __STA; |
| |
| |
| rc = (__mpu_uint16_t) (*a) - |
| (__mpu_uint16_t) (*b) - carry; |
| if( rc & 0x100 ) __STC; |
| else __CLC; |
| |
| if( __MPARITY(rc) ) __STP; |
| |
| |
| op1 = (__mpu_uint16_t) (*a); |
| op2 = (__mpu_uint16_t) (*b); |
| if( op1 & 0x80 ) op1 |= 0x100; |
| if( op2 & 0x80 ) op2 |= 0x100; |
| |
| rc = op1 - op2 - carry; |
| if( rc & 0x100 ) carry = 1; |
| else carry = 0; |
| if( rc & 0x80 ) sign = 1; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| if( sign ) __STS; |
| else __CLS; |
| |
| *c = (__mpu_uint8_t) rc; |
| if( *c == 0 ) __STZ; |
| } |
| |
| |
| void isbb_8( __mpu_uint8_t *c, __mpu_uint8_t *a, __mpu_uint8_t *b ) |
| { |
| __mpu_uint16_t rc, op1, op2; |
| signed int carry, sign = 0; |
| |
| carry = __MFLAG(CF); |
| |
| __CLEAR_IFLAGS; |
| |
| |
| rc = ((__mpu_uint16_t) (*a) & 0x0f) - |
| ((__mpu_uint16_t) (*b) & 0x0f) - carry; |
| if( rc & 0x10 ) __STA; |
| |
| |
| rc = (__mpu_uint16_t) (*a) - |
| (__mpu_uint16_t) (*b) - carry; |
| if( rc & 0x100 ) __STC; |
| else __CLC; |
| |
| if( __MPARITY(rc) ) __STP; |
| |
| |
| op1 = (__mpu_uint16_t) (*a); |
| op2 = (__mpu_uint16_t) (*b); |
| if( op1 & 0x80 ) op1 |= 0x100; |
| if( op2 & 0x80 ) op2 |= 0x100; |
| |
| rc = op1 - op2 - carry; |
| if( rc & 0x100 ) carry = 1; |
| else carry = 0; |
| if( rc & 0x80 ) sign = 1; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| if( sign ) __STS; |
| else __CLS; |
| |
| *c = (__mpu_uint8_t) rc; |
| if( *c == 0 ) __STZ; |
| } |
| |
| |
| |
| |
| |
| void iadd_16( __mpu_uint16_t *c, __mpu_uint16_t *a, __mpu_uint16_t *b ) |
| { |
| __mpu_uint32_t rc, op1, op2; |
| signed int carry, sign = 0; |
| |
| __CLEAR_IFLAGS; |
| |
| carry = __MFLAG(CF); |
| |
| |
| rc = ((__mpu_uint32_t) (*a) & 0x0f) + |
| ((__mpu_uint32_t) (*b) & 0x0f) + carry; |
| if( rc & 0x10 ) __STA; |
| |
| |
| rc = (__mpu_uint32_t) (*a) + |
| (__mpu_uint32_t) (*b) + carry; |
| if( rc & 0x10000 ) __STC; |
| else __CLC; |
| |
| if( __MPARITY(rc) ) __STP; |
| |
| |
| op1 = (__mpu_uint32_t) (*a); |
| op2 = (__mpu_uint32_t) (*b); |
| if( op1 & 0x8000 ) op1 |= 0x10000; |
| if( op2 & 0x8000 ) op2 |= 0x10000; |
| |
| rc = op1 + op2 + carry; |
| if( rc & 0x10000 ) carry = 1; |
| else carry = 0; |
| if( rc & 0x8000 ) sign = 1; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| if( sign ) __STS; |
| else __CLS; |
| |
| *c = (__mpu_uint16_t) rc; |
| if( *c == 0 ) __STZ; |
| } |
| |
| |
| void iadc_16( __mpu_uint16_t *c, __mpu_uint16_t *a, __mpu_uint16_t *b ) |
| { |
| __mpu_uint32_t rc, op1, op2; |
| signed int carry, sign = 0; |
| |
| carry = __MFLAG(CF); |
| |
| __CLEAR_IFLAGS; |
| |
| |
| rc = ((__mpu_uint32_t) (*a) & 0x0f) + |
| ((__mpu_uint32_t) (*b) & 0x0f) + carry; |
| if( rc & 0x10 ) __STA; |
| |
| |
| rc = (__mpu_uint32_t) (*a) + |
| (__mpu_uint32_t) (*b) + carry; |
| if( rc & 0x10000 ) __STC; |
| else __CLC; |
| |
| if( __MPARITY(rc) ) __STP; |
| |
| |
| op1 = (__mpu_uint32_t) (*a); |
| op2 = (__mpu_uint32_t) (*b); |
| if( op1 & 0x8000 ) op1 |= 0x10000; |
| if( op2 & 0x8000 ) op2 |= 0x10000; |
| |
| rc = op1 + op2 + carry; |
| if( rc & 0x10000 ) carry = 1; |
| else carry = 0; |
| if( rc & 0x8000 ) sign = 1; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| if( sign ) __STS; |
| else __CLS; |
| |
| *c = (__mpu_uint16_t) rc; |
| if( *c == 0 ) __STZ; |
| } |
| |
| |
| void isub_16( __mpu_uint16_t *c, __mpu_uint16_t *a, __mpu_uint16_t *b ) |
| { |
| __mpu_uint32_t rc, op1, op2; |
| signed int carry, sign = 0; |
| |
| __CLEAR_IFLAGS; |
| |
| carry = __MFLAG(CF); |
| |
| |
| rc = ((__mpu_uint32_t) (*a) & 0x0f) - |
| ((__mpu_uint32_t) (*b) & 0x0f) - carry; |
| if( rc & 0x10 ) __STA; |
| |
| |
| rc = (__mpu_uint32_t) (*a) - |
| (__mpu_uint32_t) (*b) - carry; |
| if( rc & 0x10000 ) __STC; |
| else __CLC; |
| |
| if( __MPARITY(rc) ) __STP; |
| |
| |
| op1 = (__mpu_uint32_t) (*a); |
| op2 = (__mpu_uint32_t) (*b); |
| if( op1 & 0x8000 ) op1 |= 0x10000; |
| if( op2 & 0x8000 ) op2 |= 0x10000; |
| |
| rc = op1 - op2 - carry; |
| if( rc & 0x10000 ) carry = 1; |
| else carry = 0; |
| if( rc & 0x8000 ) sign = 1; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| if( sign ) __STS; |
| else __CLS; |
| |
| *c = (__mpu_uint16_t) rc; |
| if( *c == 0 ) __STZ; |
| } |
| |
| |
| void isbb_16( __mpu_uint16_t *c, __mpu_uint16_t *a, __mpu_uint16_t *b ) |
| { |
| __mpu_uint32_t rc, op1, op2; |
| signed int carry, sign = 0; |
| |
| carry = __MFLAG(CF); |
| |
| __CLEAR_IFLAGS; |
| |
| |
| rc = ((__mpu_uint32_t) (*a) & 0x0f) - |
| ((__mpu_uint32_t) (*b) & 0x0f) - carry; |
| if( rc & 0x10 ) __STA; |
| |
| |
| rc = (__mpu_uint32_t) (*a) - |
| (__mpu_uint32_t) (*b) - carry; |
| if( rc & 0x10000 ) __STC; |
| else __CLC; |
| |
| if( __MPARITY(rc) ) __STP; |
| |
| |
| op1 = (__mpu_uint32_t) (*a); |
| op2 = (__mpu_uint32_t) (*b); |
| if( op1 & 0x8000 ) op1 |= 0x10000; |
| if( op2 & 0x8000 ) op2 |= 0x10000; |
| |
| rc = op1 - op2 - carry; |
| if( rc & 0x10000 ) carry = 1; |
| else carry = 0; |
| if( rc & 0x8000 ) sign = 1; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| if( sign ) __STS; |
| else __CLS; |
| |
| *c = (__mpu_uint16_t) rc; |
| if( *c == 0 ) __STZ; |
| } |
| |
| |
| |
| |
| |
| void iadd_32( __mpu_uint32_t *c, __mpu_uint32_t *a, __mpu_uint32_t *b ) |
| { |
| __mpu_uint64_t rc, op1, op2; |
| signed int carry, sign = 0; |
| |
| __CLEAR_IFLAGS; |
| |
| carry = __MFLAG(CF); |
| |
| |
| rc = ((__mpu_uint64_t) (*a) & 0x0f) + |
| ((__mpu_uint64_t) (*b) & 0x0f) + carry; |
| if( rc & 0x10 ) __STA; |
| |
| |
| rc = (__mpu_uint64_t) (*a) + |
| (__mpu_uint64_t) (*b) + carry; |
| if( rc & 0x100000000 ) __STC; |
| else __CLC; |
| |
| if( __MPARITY(rc) ) __STP; |
| |
| |
| op1 = (__mpu_uint64_t) (*a); |
| op2 = (__mpu_uint64_t) (*b); |
| if( op1 & 0x80000000 ) op1 |= 0x100000000; |
| if( op2 & 0x80000000 ) op2 |= 0x100000000; |
| |
| rc = op1 + op2 + carry; |
| if( rc & 0x100000000 ) carry = 1; |
| else carry = 0; |
| if( rc & 0x80000000 ) sign = 1; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| if( sign ) __STS; |
| else __CLS; |
| |
| *c = (__mpu_uint32_t) rc; |
| if( *c == 0 ) __STZ; |
| } |
| |
| |
| void iadc_32( __mpu_uint32_t *c, __mpu_uint32_t *a, __mpu_uint32_t *b ) |
| { |
| __mpu_uint64_t rc, op1, op2; |
| signed int carry, sign = 0; |
| |
| carry = __MFLAG(CF); |
| |
| __CLEAR_IFLAGS; |
| |
| |
| rc = ((__mpu_uint64_t) (*a) & 0x0f) + |
| ((__mpu_uint64_t) (*b) & 0x0f) + carry; |
| if( rc & 0x10 ) __STA; |
| |
| |
| rc = (__mpu_uint64_t) (*a) + |
| (__mpu_uint64_t) (*b) + carry; |
| if( rc & 0x100000000 ) __STC; |
| else __CLC; |
| |
| if( __MPARITY(rc) ) __STP; |
| |
| |
| op1 = (__mpu_uint64_t) (*a); |
| op2 = (__mpu_uint64_t) (*b); |
| if( op1 & 0x80000000 ) op1 |= 0x100000000; |
| if( op2 & 0x80000000 ) op2 |= 0x100000000; |
| |
| rc = op1 + op2 + carry; |
| if( rc & 0x100000000 ) carry = 1; |
| else carry = 0; |
| if( rc & 0x80000000 ) sign = 1; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| if( sign ) __STS; |
| else __CLS; |
| |
| *c = (__mpu_uint32_t) rc; |
| if( *c == 0 ) __STZ; |
| } |
| |
| |
| void isub_32( __mpu_uint32_t *c, __mpu_uint32_t *a, __mpu_uint32_t *b ) |
| { |
| __mpu_uint64_t rc, op1, op2; |
| signed int carry, sign = 0; |
| |
| __CLEAR_IFLAGS; |
| |
| carry = __MFLAG(CF); |
| |
| |
| rc = ((__mpu_uint64_t) (*a) & 0x0f) - |
| ((__mpu_uint64_t) (*b) & 0x0f) - carry; |
| if( rc & 0x10 ) __STA; |
| |
| |
| rc = (__mpu_uint64_t) (*a) - |
| (__mpu_uint64_t) (*b) - carry; |
| if( rc & 0x100000000 ) __STC; |
| else __CLC; |
| |
| if( __MPARITY(rc) ) __STP; |
| |
| |
| op1 = (__mpu_uint64_t) (*a); |
| op2 = (__mpu_uint64_t) (*b); |
| if( op1 & 0x80000000 ) op1 |= 0x100000000; |
| if( op2 & 0x80000000 ) op2 |= 0x100000000; |
| |
| rc = op1 - op2 - carry; |
| if( rc & 0x100000000 ) carry = 1; |
| else carry = 0; |
| if( rc & 0x80000000 ) sign = 1; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| if( sign ) __STS; |
| else __CLS; |
| |
| *c = (__mpu_uint32_t) rc; |
| if( *c == 0 ) __STZ; |
| } |
| |
| |
| void isbb_32( __mpu_uint32_t *c, __mpu_uint32_t *a, __mpu_uint32_t *b ) |
| { |
| __mpu_uint64_t rc, op1, op2; |
| signed int carry, sign = 0; |
| |
| carry = __MFLAG(CF); |
| |
| __CLEAR_IFLAGS; |
| |
| |
| rc = ((__mpu_uint64_t) (*a) & 0x0f) - |
| ((__mpu_uint64_t) (*b) & 0x0f) - carry; |
| if( rc & 0x10 ) __STA; |
| |
| |
| rc = (__mpu_uint64_t) (*a) - |
| (__mpu_uint64_t) (*b) - carry; |
| if( rc & 0x100000000 ) __STC; |
| else __CLC; |
| |
| if( __MPARITY(rc) ) __STP; |
| |
| |
| op1 = (__mpu_uint64_t) (*a); |
| op2 = (__mpu_uint64_t) (*b); |
| if( op1 & 0x80000000 ) op1 |= 0x100000000; |
| if( op2 & 0x80000000 ) op2 |= 0x100000000; |
| |
| rc = op1 - op2 - carry; |
| if( rc & 0x100000000 ) carry = 1; |
| else carry = 0; |
| if( rc & 0x80000000 ) sign = 1; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| if( sign ) __STS; |
| else __CLS; |
| |
| *c = (__mpu_uint32_t) rc; |
| if( *c == 0 ) __STZ; |
| } |
| |
| |
| |
| |
| |
| void iadd_np( EMUSHORT *c, EMUSHORT *a, EMUSHORT *b, int np ) |
| { |
| EMULONG rc, op1, op2; |
| EMUSHORT *x, *y; |
| signed int carry, sign = 0, zero = 0; |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"iadd_np (emushort)" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| carry = __MFLAG(CF); |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1; |
| y = b + np - 1; |
| i = np - 1; |
| #else |
| x = a; |
| y = b; |
| i = 0; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| while( i > 0 ) |
| #else |
| while( i < np - 1 ) |
| #endif |
| { |
| rc = (EMULONG) (*x) + |
| (EMULONG) (*y) + __MFLAG(CF); |
| if( rc & MASK_CARRY ) __STC; |
| else __CLC; |
| c[i] = (EMUSHORT) rc; |
| if( c[i] ) zero |= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; --y; --i; |
| #else |
| ++x; ++y; ++i; |
| #endif |
| } |
| |
| carry = __MFLAG(CF); |
| |
| |
| rc = (EMULONG) (*x) + |
| (EMULONG) (*y) + carry; |
| if( rc & MASK_CARRY ) __STC; |
| else __CLC; |
| |
| |
| op1 = (EMULONG) (*x); |
| op2 = (EMULONG) (*y); |
| if( op1 & MASK_SIGN ) op1 |= MASK_CARRY; |
| if( op2 & MASK_SIGN ) op2 |= MASK_CARRY; |
| |
| rc = op1 + op2 + carry; |
| if( rc & MASK_CARRY ) carry = 1; |
| else carry = 0; |
| if( rc & MASK_SIGN ) sign = 1; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| if( sign ) __STS; |
| else __CLS; |
| |
| c[i] = (EMUSHORT) rc; |
| if( c[i] ) zero |= 1; |
| zero ^= 1; |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| } |
| |
| |
| void iadc_np( EMUSHORT *c, EMUSHORT *a, EMUSHORT *b, int np ) |
| { |
| EMULONG rc, op1, op2; |
| EMUSHORT *x, *y; |
| signed int carry, sign = 0, zero = 0; |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"iadc_np (emushort)" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS_WITHOUT_CARRY; |
| |
| carry = __MFLAG(CF); |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1; |
| y = b + np - 1; |
| i = np - 1; |
| #else |
| x = a; |
| y = b; |
| i = 0; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| while( i > 0 ) |
| #else |
| while( i < np - 1 ) |
| #endif |
| { |
| rc = (EMULONG) (*x) + |
| (EMULONG) (*y) + __MFLAG(CF); |
| if( rc & MASK_CARRY ) __STC; |
| else __CLC; |
| c[i] = (EMUSHORT) rc; |
| if( c[i] ) zero |= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; --y; --i; |
| #else |
| ++x; ++y; ++i; |
| #endif |
| } |
| |
| carry = __MFLAG(CF); |
| |
| |
| rc = (EMULONG) (*x) + |
| (EMULONG) (*y) + carry; |
| if( rc & MASK_CARRY ) __STC; |
| else __CLC; |
| |
| |
| op1 = (EMULONG) (*x); |
| op2 = (EMULONG) (*y); |
| if( op1 & MASK_SIGN ) op1 |= MASK_CARRY; |
| if( op2 & MASK_SIGN ) op2 |= MASK_CARRY; |
| |
| rc = op1 + op2 + carry; |
| if( rc & MASK_CARRY ) carry = 1; |
| else carry = 0; |
| if( rc & MASK_SIGN ) sign = 1; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| if( sign ) __STS; |
| else __CLS; |
| |
| c[i] = (EMUSHORT) rc; |
| if( c[i] ) zero |= 1; |
| zero ^= 1; |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| } |
| |
| |
| void isub_np( EMUSHORT *c, EMUSHORT *a, EMUSHORT *b, int np ) |
| { |
| EMULONG rc, op1, op2; |
| EMUSHORT *x, *y; |
| signed int carry, sign = 0, zero = 0; |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"isub_np (emushort)" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| carry = __MFLAG(CF); |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1; |
| y = b + np - 1; |
| i = np - 1; |
| #else |
| x = a; |
| y = b; |
| i = 0; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| while( i > 0 ) |
| #else |
| while( i < np - 1 ) |
| #endif |
| { |
| rc = (EMULONG) (*x) - |
| (EMULONG) (*y) - __MFLAG(CF); |
| if( rc & MASK_CARRY ) __STC; |
| else __CLC; |
| c[i] = (EMUSHORT) rc; |
| if( c[i] ) zero |= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; --y; --i; |
| #else |
| ++x; ++y; ++i; |
| #endif |
| } |
| |
| carry = __MFLAG(CF); |
| |
| |
| rc = (EMULONG) (*x) - |
| (EMULONG) (*y) - carry; |
| if( rc & MASK_CARRY ) __STC; |
| else __CLC; |
| |
| |
| op1 = (EMULONG) (*x); |
| op2 = (EMULONG) (*y); |
| if( op1 & MASK_SIGN ) op1 |= MASK_CARRY; |
| if( op2 & MASK_SIGN ) op2 |= MASK_CARRY; |
| |
| rc = op1 + op2 + carry; |
| if( rc & MASK_CARRY ) carry = 1; |
| else carry = 0; |
| if( rc & MASK_SIGN ) sign = 1; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| if( sign ) __STS; |
| else __CLS; |
| |
| c[i] = (EMUSHORT) rc; |
| if( c[i] ) zero |= 1; |
| zero ^= 1; |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| } |
| |
| |
| void isbb_np( EMUSHORT *c, EMUSHORT *a, EMUSHORT *b, int np ) |
| { |
| EMULONG rc, op1, op2; |
| EMUSHORT *x, *y; |
| signed int carry, sign = 0, zero = 0; |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"isbb_np (emushort)" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS_WITHOUT_CARRY; |
| |
| carry = __MFLAG(CF); |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1; |
| y = b + np - 1; |
| i = np - 1; |
| #else |
| x = a; |
| y = b; |
| i = 0; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| while( i > 0 ) |
| #else |
| while( i < np - 1 ) |
| #endif |
| { |
| rc = (EMULONG) (*x) - |
| (EMULONG) (*y) - __MFLAG(CF); |
| if( rc & MASK_CARRY ) __STC; |
| else __CLC; |
| c[i] = (EMUSHORT) rc; |
| if( c[i] ) zero |= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; --y; --i; |
| #else |
| ++x; ++y; ++i; |
| #endif |
| } |
| |
| carry = __MFLAG(CF); |
| |
| |
| rc = (EMULONG) (*x) - |
| (EMULONG) (*y) - carry; |
| if( rc & MASK_CARRY ) __STC; |
| else __CLC; |
| |
| |
| op1 = (EMULONG) (*x); |
| op2 = (EMULONG) (*y); |
| if( op1 & MASK_SIGN ) op1 |= MASK_CARRY; |
| if( op2 & MASK_SIGN ) op2 |= MASK_CARRY; |
| |
| rc = op1 + op2 + carry; |
| if( rc & MASK_CARRY ) carry = 1; |
| else carry = 0; |
| if( rc & MASK_SIGN ) sign = 1; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| if( sign ) __STS; |
| else __CLS; |
| |
| c[i] = (EMUSHORT) rc; |
| if( c[i] ) zero |= 1; |
| zero ^= 1; |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void ishl_8( __mpu_uint8_t *c, __mpu_uint8_t *a ) |
| { |
| __mpu_uint8_t *x; |
| signed int carry = 0, sign = 0; |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| if( *x & 0x80 ) { carry = 1; __STC; } |
| |
| *c = (*x) << 1; |
| if( *c == 0 ) __STZ; |
| |
| if( *c & 0x80 ) { sign = 1; __STS; } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| } |
| |
| |
| void ishr_8( __mpu_uint8_t *c, __mpu_uint8_t *a ) |
| { |
| __mpu_uint8_t *x, save_sign; |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| save_sign = *x & 0x80; |
| if( save_sign ) __STO; |
| |
| if( *x & 1 ) __STC; |
| |
| *c = (*x) >> 1; |
| if( *c == 0 ) __STZ; |
| if( *c & 0x80 ) __STS; |
| |
| if( __MPARITY(*c) ) __STP; |
| } |
| |
| |
| void isal_8( __mpu_uint8_t *c, __mpu_uint8_t *a ) |
| { |
| __mpu_uint8_t *x; |
| signed int carry = 0, sign = 0; |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| if( *x & 0x80 ) { carry = 1; __STC; } |
| |
| *c = (*x) << 1; |
| if( *c == 0 ) __STZ; |
| |
| if( *c & 0x80 ) { sign = 1; __STS; } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| } |
| |
| |
| void isar_8( __mpu_uint8_t *c, __mpu_uint8_t *a ) |
| { |
| __mpu_uint8_t *x, save_sign; |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| save_sign = *x & 0x80; |
| if( save_sign ) __STS; |
| |
| if( *x & 1 ) __STC; |
| |
| *c = (*x) >> 1; |
| *c |= save_sign; |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| } |
| |
| |
| |
| |
| |
| void ishl_16( __mpu_uint16_t *c, __mpu_uint16_t *a ) |
| { |
| __mpu_uint16_t *x; |
| signed int carry = 0, sign = 0; |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| if( *x & 0x8000 ) { carry = 1; __STC; } |
| |
| *c = (*x) << 1; |
| if( *c == 0 ) __STZ; |
| |
| if( *c & 0x8000 ) { sign = 1; __STS; } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| } |
| |
| |
| void ishr_16( __mpu_uint16_t *c, __mpu_uint16_t *a ) |
| { |
| __mpu_uint16_t *x, save_sign; |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| save_sign = *x & 0x8000; |
| if( save_sign ) __STO; |
| |
| if( *x & 1 ) __STC; |
| |
| *c = (*x) >> 1; |
| if( *c == 0 ) __STZ; |
| if( *c & 0x8000 ) __STS; |
| |
| if( __MPARITY(*c) ) __STP; |
| } |
| |
| |
| void isal_16( __mpu_uint16_t *c, __mpu_uint16_t *a ) |
| { |
| __mpu_uint16_t *x; |
| signed int carry = 0, sign = 0; |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| if( *x & 0x8000 ) { carry = 1; __STC; } |
| |
| *c = (*x) << 1; |
| if( *c == 0 ) __STZ; |
| |
| if( *c & 0x8000 ) { sign = 1; __STS; } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| } |
| |
| |
| void isar_16( __mpu_uint16_t *c, __mpu_uint16_t *a ) |
| { |
| __mpu_uint16_t *x, save_sign; |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| save_sign = *x & 0x8000; |
| if( save_sign ) __STS; |
| |
| if( *x & 1 ) __STC; |
| |
| *c = (*x) >> 1; |
| *c |= save_sign; |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| } |
| |
| |
| |
| |
| |
| void ishl_32( __mpu_uint32_t *c, __mpu_uint32_t *a ) |
| { |
| __mpu_uint32_t *x; |
| signed int carry = 0, sign = 0; |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| if( *x & 0x80000000 ) { carry = 1; __STC; } |
| |
| *c = (*x) << 1; |
| if( *c == 0 ) __STZ; |
| |
| if( *c & 0x80000000 ) { sign = 1; __STS; } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| } |
| |
| |
| void ishr_32( __mpu_uint32_t *c, __mpu_uint32_t *a ) |
| { |
| __mpu_uint32_t *x, save_sign; |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| save_sign = *x & 0x80000000; |
| if( save_sign ) __STO; |
| |
| if( *x & 1 ) __STC; |
| |
| *c = (*x) >> 1; |
| if( *c == 0 ) __STZ; |
| if( *c & 0x80000000 ) __STS; |
| |
| if( __MPARITY(*c) ) __STP; |
| } |
| |
| |
| void isal_32( __mpu_uint32_t *c, __mpu_uint32_t *a ) |
| { |
| __mpu_uint32_t *x; |
| signed int carry = 0, sign = 0; |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| if( *x & 0x80000000 ) { carry = 1; __STC; } |
| |
| *c = (*x) << 1; |
| if( *c == 0 ) __STZ; |
| |
| if( *c & 0x80000000 ) { sign = 1; __STS; } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| } |
| |
| |
| void isar_32( __mpu_uint32_t *c, __mpu_uint32_t *a ) |
| { |
| __mpu_uint32_t *x, save_sign; |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| save_sign = *x & 0x80000000; |
| if( save_sign ) __STS; |
| |
| if( *x & 1 ) __STC; |
| |
| *c = (*x) >> 1; |
| *c |= save_sign; |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| } |
| |
| |
| |
| |
| |
| void ishl_np( EMUSHORT *c, EMUSHORT *a, int np ) |
| { |
| EMUSHORT *x, *y; |
| signed int carry, sign, zero = 1; |
| signed int i = 0; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"ishl_np (emushort)" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS_WITHOUT_CARRY; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1; |
| y = c + np - 1; |
| #else |
| x = a; |
| y = c; |
| #endif |
| |
| carry = 0; |
| |
| while( i < np ) |
| { |
| if( carry ) __STC; |
| else __CLC; |
| |
| if( *x & MASK_SIGN ) carry = 1; |
| else carry = 0; |
| |
| *y = (*x) << 1; |
| *y |= __MFLAG(CF); |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; --y; |
| #else |
| ++x; ++y; |
| #endif |
| ++i; |
| } |
| |
| if( zero ) { __STZ; } else { __CLZ; } |
| if( carry ) { __STC; } else { __CLC; } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++y; |
| #else |
| --y; |
| #endif |
| if( *y & MASK_SIGN ) __STS; |
| |
| sign = __MFLAG(SF); |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| } |
| |
| |
| void ishr_np( EMUSHORT *c, EMUSHORT *a, int np ) |
| { |
| EMUSHORT *x, *y, save_sign; |
| signed int carry, zero = 1; |
| signed int i = 0; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"ishr_np (emushort)" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS_WITHOUT_CARRY; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a; |
| y = c; |
| #else |
| x = a + np - 1; |
| y = c + np - 1; |
| #endif |
| |
| carry = 0; |
| |
| save_sign = *x & MASK_SIGN; |
| if( save_sign ) __STO; |
| |
| while( i < np ) |
| { |
| if( carry ) __STC; |
| else __CLC; |
| |
| if( *x & 1 ) carry = 1; |
| else carry = 0; |
| |
| *y = (*x) >> 1; |
| if( __MFLAG(CF) ) *y |= MASK_SIGN; |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++x; ++y; |
| #else |
| --x; --y; |
| #endif |
| ++i; |
| } |
| |
| if( zero ) { __STZ; } else { __CLZ; } |
| if( carry ) { __STC; } else { __CLC; } |
| } |
| |
| |
| void isal_np( EMUSHORT *c, EMUSHORT *a, int np ) |
| { |
| EMUSHORT *x, *y; |
| signed int carry, sign, zero = 1; |
| signed int i = 0; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"isal_np (emushort)" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS_WITHOUT_CARRY; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1; |
| y = c + np - 1; |
| #else |
| x = a; |
| y = c; |
| #endif |
| |
| carry = 0; |
| |
| while( i < np ) |
| { |
| if( carry ) __STC; |
| else __CLC; |
| |
| if( *x & MASK_SIGN ) carry = 1; |
| else carry = 0; |
| |
| *y = (*x) << 1; |
| *y |= __MFLAG(CF); |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; --y; |
| #else |
| ++x; ++y; |
| #endif |
| ++i; |
| } |
| |
| if( zero ) { __STZ; } else { __CLZ; } |
| if( carry ) { __STC; } else { __CLC; } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++y; |
| #else |
| --y; |
| #endif |
| if( *y & MASK_SIGN ) __STS; |
| |
| sign = __MFLAG(SF); |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| } |
| |
| |
| void isar_np( EMUSHORT *c, EMUSHORT *a, int np ) |
| { |
| EMUSHORT *x, *y, save_sign; |
| signed int carry, zero = 1; |
| signed int i = 0; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"isar_np (emushort)" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS_WITHOUT_CARRY; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a; |
| y = c; |
| #else |
| x = a + np - 1; |
| y = c + np - 1; |
| #endif |
| |
| carry = 0; |
| |
| save_sign = *x & MASK_SIGN; |
| if( save_sign ) __STS; |
| |
| while( i < np ) |
| { |
| if( carry ) __STC; |
| else __CLC; |
| |
| if( *x & 1 ) carry = 1; |
| else carry = 0; |
| |
| *y = (*x) >> 1; |
| if( __MFLAG(CF) ) *y |= MASK_SIGN; |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++x; ++y; |
| #else |
| --x; --y; |
| #endif |
| ++i; |
| } |
| |
| if( zero ) { __STZ; } else { __CLZ; } |
| if( carry ) { __STC; } else { __CLC; } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c; |
| #else |
| y = c + np - 1; |
| #endif |
| if( save_sign ) { *y |= save_sign; __CLZ; } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void irol_8( __mpu_uint8_t *c, __mpu_uint8_t *a ) |
| { |
| __mpu_uint8_t *x; |
| signed int carry = 0, sign = 0; |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| if( *x & 0x80 ) __STC; |
| |
| *c = (*x) << 1; |
| if( __MFLAG(CF) ) { *c |= 1; } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x80 ) __STS; |
| |
| if( __MFLAG(SF) ) sign = 1; |
| if( __MFLAG(CF) ) carry = 1; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| } |
| |
| |
| void iror_8( __mpu_uint8_t *c, __mpu_uint8_t *a ) |
| { |
| __mpu_uint8_t *x; |
| signed int sign = 0, save_sign = 0; |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| if( *x & 0x80 ) save_sign = 1; |
| |
| if( *x & 1 ) __STC; |
| |
| *c = (*x) >> 1; |
| if( __MFLAG(CF) ) { *c |= 0x80; __STS; } |
| |
| if( *c == 0 ) __STZ; |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( __MFLAG(SF) ) sign = 1; |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| void ircl_8( __mpu_uint8_t *c, __mpu_uint8_t *a ) |
| { |
| __mpu_uint8_t *x; |
| signed int carry = 0, sign = 0, zero = 0; |
| |
| |
| __CLA; __CLO; __CLS; __CLV; |
| |
| zero = __MFLAG(ZF); |
| |
| x = a; |
| if( *x & 0x80 ) carry = 1; |
| |
| *c = (*x) << 1; |
| if( __MFLAG(CF) ) *c |= 0x01; |
| if( *c ) zero &= 0; |
| else zero &= 1; |
| |
| if( zero ) { __STZ; } else { __CLZ; } |
| if( carry ) { __STC; } else { __CLC; } |
| |
| if( *c & 0x80 ) { sign = 1; __STS; } |
| |
| |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| } |
| |
| |
| void ircr_8( __mpu_uint8_t *c, __mpu_uint8_t *a ) |
| { |
| __mpu_uint8_t *x; |
| signed int carry = 0, sign = 0, zero = 0, save_carry = 0; |
| |
| |
| __CLA; __CLO; __CLP; __CLV; |
| |
| zero = __MFLAG(ZF); |
| |
| x = a; |
| if( *x & 0x80 ) sign = 1; |
| if( __MFLAG(CF) ) save_carry = 1; |
| |
| if( *x & 1 ) carry = 1; |
| |
| *c = (*x) >> 1; |
| if( save_carry ) *c |= 0x80; |
| if( *c ) zero &= 0; |
| else zero &= 1; |
| |
| if( zero ) { __STZ; } else { __CLZ; } |
| if( carry ) { __STC; } else { __CLC; } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| |
| |
| if( (!save_carry && sign) || (save_carry && !sign) ) __STO; |
| } |
| |
| |
| |
| |
| |
| void irol_16( __mpu_uint16_t *c, __mpu_uint16_t *a ) |
| { |
| __mpu_uint16_t *x; |
| signed int carry = 0, sign = 0; |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| if( *x & 0x8000 ) __STC; |
| |
| *c = (*x) << 1; |
| if( __MFLAG(CF) ) { *c |= 1; } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x8000 ) __STS; |
| |
| if( __MFLAG(SF) ) sign = 1; |
| if( __MFLAG(CF) ) carry = 1; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| } |
| |
| |
| void iror_16( __mpu_uint16_t *c, __mpu_uint16_t *a ) |
| { |
| __mpu_uint16_t *x; |
| signed int sign = 0, save_sign = 0; |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| if( *x & 0x8000 ) save_sign = 1; |
| |
| if( *x & 1 ) __STC; |
| |
| *c = (*x) >> 1; |
| if( __MFLAG(CF) ) { *c |= 0x8000; __STS; } |
| |
| if( *c == 0 ) __STZ; |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( __MFLAG(SF) ) sign = 1; |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| void ircl_16( __mpu_uint16_t *c, __mpu_uint16_t *a ) |
| { |
| __mpu_uint16_t *x; |
| signed int carry = 0, sign = 0, zero = 0; |
| |
| |
| __CLA; __CLO; __CLS; __CLV; |
| |
| zero = __MFLAG(ZF); |
| |
| x = a; |
| if( *x & 0x8000 ) carry = 1; |
| |
| *c = (*x) << 1; |
| if( __MFLAG(CF) ) *c |= 0x0001; |
| if( *c ) zero &= 0; |
| else zero &= 1; |
| |
| if( zero ) { __STZ; } else { __CLZ; } |
| if( carry ) { __STC; } else { __CLC; } |
| |
| if( *c & 0x8000 ) { sign = 1; __STS; } |
| |
| |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| } |
| |
| |
| void ircr_16( __mpu_uint16_t *c, __mpu_uint16_t *a ) |
| { |
| __mpu_uint16_t *x; |
| signed int carry = 0, sign = 0, zero = 0, save_carry = 0; |
| |
| |
| __CLA; __CLO; __CLP; __CLV; |
| |
| zero = __MFLAG(ZF); |
| |
| x = a; |
| if( *x & 0x8000 ) sign = 1; |
| if( __MFLAG(CF) ) save_carry = 1; |
| |
| if( *x & 1 ) carry = 1; |
| |
| *c = (*x) >> 1; |
| if( save_carry ) *c |= 0x8000; |
| if( *c ) zero &= 0; |
| else zero &= 1; |
| |
| if( zero ) { __STZ; } else { __CLZ; } |
| if( carry ) { __STC; } else { __CLC; } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| |
| |
| if( (!save_carry && sign) || (save_carry && !sign) ) __STO; |
| } |
| |
| |
| |
| |
| |
| void irol_32( __mpu_uint32_t *c, __mpu_uint32_t *a ) |
| { |
| __mpu_uint32_t *x; |
| signed int carry = 0, sign = 0; |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| if( *x & 0x80000000 ) __STC; |
| |
| *c = (*x) << 1; |
| if( __MFLAG(CF) ) { *c |= 1; } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x80000000 ) __STS; |
| |
| if( __MFLAG(SF) ) sign = 1; |
| if( __MFLAG(CF) ) carry = 1; |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| } |
| |
| |
| void iror_32( __mpu_uint32_t *c, __mpu_uint32_t *a ) |
| { |
| __mpu_uint32_t *x; |
| signed int sign = 0, save_sign = 0; |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| if( *x & 0x80000000 ) save_sign = 1; |
| |
| if( *x & 1 ) __STC; |
| |
| *c = (*x) >> 1; |
| if( __MFLAG(CF) ) { *c |= 0x80000000; __STS; } |
| |
| if( *c == 0 ) __STZ; |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( __MFLAG(SF) ) sign = 1; |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| void ircl_32( __mpu_uint32_t *c, __mpu_uint32_t *a ) |
| { |
| __mpu_uint32_t *x; |
| signed int carry = 0, sign = 0, zero = 0; |
| |
| |
| __CLA; __CLO; __CLS; __CLV; |
| |
| zero = __MFLAG(ZF); |
| |
| x = a; |
| if( *x & 0x80000000 ) carry = 1; |
| |
| *c = (*x) << 1; |
| if( __MFLAG(CF) ) *c |= 0x00000001; |
| if( *c ) zero &= 0; |
| else zero &= 1; |
| |
| if( zero ) { __STZ; } else { __CLZ; } |
| if( carry ) { __STC; } else { __CLC; } |
| |
| if( *c & 0x80000000 ) { sign = 1; __STS; } |
| |
| |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| } |
| |
| |
| void ircr_32( __mpu_uint32_t *c, __mpu_uint32_t *a ) |
| { |
| __mpu_uint32_t *x; |
| signed int carry = 0, sign = 0, zero = 0, save_carry = 0; |
| |
| |
| __CLA; __CLO; __CLP; __CLV; |
| |
| zero = __MFLAG(ZF); |
| |
| x = a; |
| if( *x & 0x80000000 ) sign = 1; |
| if( __MFLAG(CF) ) save_carry = 1; |
| |
| if( *x & 1 ) carry = 1; |
| |
| *c = (*x) >> 1; |
| if( save_carry ) *c |= 0x80000000; |
| if( *c ) zero &= 0; |
| else zero &= 1; |
| |
| if( zero ) { __STZ; } else { __CLZ; } |
| if( carry ) { __STC; } else { __CLC; } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| |
| |
| if( (!save_carry && sign) || (save_carry && !sign) ) __STO; |
| } |
| |
| |
| |
| |
| |
| void irol_np( EMUSHORT *c, EMUSHORT *a, int np ) |
| { |
| EMUSHORT *x, *y; |
| signed int carry, sign = 0, zero = 1; |
| signed int i = 0; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"irol_np (emushort)" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS_WITHOUT_CARRY; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1; |
| y = c + np - 1; |
| #else |
| x = a; |
| y = c; |
| #endif |
| |
| carry = 0; |
| |
| while( i < np ) |
| { |
| if( carry ) __STC; |
| else __CLC; |
| |
| if( *x & MASK_SIGN ) carry = 1; |
| else carry = 0; |
| |
| *y = (*x) << 1; |
| *y |= __MFLAG(CF); |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; --y; |
| #else |
| ++x; ++y; |
| #endif |
| ++i; |
| } |
| |
| if( zero ) { __STZ; } else { __CLZ; } |
| if( carry ) { __STC; } else { __CLC; } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++y; |
| #else |
| --y; |
| #endif |
| if( *y & MASK_SIGN ) __STS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c + np - 1; |
| #else |
| y = c; |
| #endif |
| if( carry ) { *y |= 1; __CLZ; } |
| |
| sign = __MFLAG(SF); |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| } |
| |
| |
| void iror_np( EMUSHORT *c, EMUSHORT *a, int np ) |
| { |
| EMUSHORT *x, *y; |
| signed int carry, zero = 1, sign = 0, save_sign = 0; |
| signed int i = 0; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"iror_np (emushort)" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS_WITHOUT_CARRY; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a; |
| y = c; |
| #else |
| x = a + np - 1; |
| y = c + np - 1; |
| #endif |
| |
| carry = 0; |
| |
| if( *x & MASK_SIGN ) save_sign = 1; |
| |
| while( i < np ) |
| { |
| if( carry ) __STC; |
| else __CLC; |
| |
| if( *x & 1 ) carry = 1; |
| else carry = 0; |
| |
| *y = (*x) >> 1; |
| if( __MFLAG(CF) ) *y |= MASK_SIGN; |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++x; ++y; |
| #else |
| --x; --y; |
| #endif |
| ++i; |
| } |
| |
| if( zero ) { __STZ; } else { __CLZ; } |
| if( carry ) { __STC; } else { __CLC; } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c; |
| #else |
| y = c + np - 1; |
| #endif |
| if( carry ) { *y |= MASK_SIGN; __STS; __CLZ; } |
| |
| sign = __MFLAG(SF); |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| void ircl_np( EMUSHORT *c, EMUSHORT *a, int np ) |
| { |
| EMUSHORT *x, *y; |
| signed int carry = 0, sign = 0, zero = 1, save_zero = 0; |
| signed int i = 0; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"ircl_np (emushort)" ); |
| return; |
| } |
| |
| |
| __CLA; __CLO; __CLS; __CLV; |
| |
| save_zero = __MFLAG(ZF); |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1; |
| y = c + np - 1; |
| #else |
| x = a; |
| y = c; |
| #endif |
| |
| carry = __MFLAG(CF); |
| |
| while( i < np ) |
| { |
| if( carry ) __STC; |
| else __CLC; |
| |
| if( *x & MASK_SIGN ) carry = 1; |
| else carry = 0; |
| |
| *y = (*x) << 1; |
| *y |= __MFLAG(CF); |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; |
| --y; |
| #else |
| ++x; |
| ++y; |
| #endif |
| ++i; |
| } |
| |
| save_zero &= zero; |
| |
| if( save_zero ) { __STZ; } else { __CLZ; } |
| if( carry ) { __STC; } else { __CLC; } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++y; |
| #else |
| --y; |
| #endif |
| if( *y & MASK_SIGN ) __STS; |
| |
| |
| |
| sign = __MFLAG(SF); |
| |
| if( (!carry && sign) || (carry && !sign) ) __STO; |
| } |
| |
| |
| void ircr_np( EMUSHORT *c, EMUSHORT *a, int np ) |
| { |
| EMUSHORT *x, *y; |
| signed int carry, sign = 0, zero = 1, save_zero = 0, save_carry = 0; |
| signed int i = 0; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"ircr_np (emushort)" ); |
| return; |
| } |
| |
| |
| __CLA; __CLO; __CLP; __CLV; |
| |
| save_zero = __MFLAG(ZF); |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a; |
| y = c; |
| #else |
| x = a + np - 1; |
| y = c + np - 1; |
| #endif |
| |
| carry = __MFLAG(CF); |
| |
| if( *x & MASK_SIGN ) sign = 1; |
| if( carry ) save_carry = 1; |
| |
| while( i < np ) |
| { |
| if( carry ) __STC; |
| else __CLC; |
| |
| if( *x & 1 ) carry = 1; |
| else carry = 0; |
| |
| *y = (*x) >> 1; |
| if( __MFLAG(CF) ) *y |= MASK_SIGN; |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++x; ++y; |
| #else |
| --x; --y; |
| #endif |
| ++i; |
| } |
| |
| save_zero &= zero; |
| |
| if( save_zero ) { __STZ; } else { __CLZ; } |
| if( carry ) { __STC; } else { __CLC; } |
| |
| |
| |
| if( (!save_carry && sign) || (save_carry && !sign) ) __STO; |
| } |
| |
| |
| |
| |
| |
| static EMUSHORT _POW_EMUSHORT( __mpu_int32_t x, __mpu_int32_t y ) |
| { |
| __mpu_int32_t z; |
| __mpu_int32_t n = y; |
| |
| if( y < 0 ) n = -n; |
| |
| for( z = 1; ; x *= x ) |
| { |
| if( (n & 1) != 0 ) z *= x; |
| if( (n >>= 1) == 0 ) return( y < 0 ? (EMUSHORT)(1/z) : (EMUSHORT)z ); |
| } |
| } |
| |
| #define N_PARTS(b) ((b)>>POW2) |
| #define N_BITS(b) ((b)&(BITS_PER_EMUSHORT-1)) |
| |
| #define MASK_LEAST_BITS(b) (_POW_EMUSHORT(2,(b))-1) |
| #define MASK_HIGEST_BITS(b) (~(_POW_EMUSHORT(2,(b))-1)) |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void ishln_8( __mpu_uint8_t *c, __mpu_uint8_t *a, unsigned int b ) |
| { |
| signed int carry, sign, save_carry = 0, save_sign = 0; |
| |
| if( b > BITS_PER_BYTE ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"ishln_8" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| if( *a & 0x80 ) save_sign = 1; |
| if( *a & 1 ) save_carry = 1; |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_BYTE ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( b == BITS_PER_BYTE ) |
| { |
| *c = 0; |
| |
| if( save_carry ) __STC; |
| |
| __STZ; __CLS; __CLP; |
| |
| if( save_sign ) __STO; |
| } |
| |
| return; |
| |
| } |
| |
| carry = (*c >> ((BITS_PER_BYTE-b)&(BITS_PER_BYTE-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| *c = *c << b; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x80 ) __STS; |
| |
| sign = __MFLAG(SF); |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| void ishrn_8( __mpu_uint8_t *c, __mpu_uint8_t *a, unsigned int b ) |
| { |
| signed int carry, save_sign = 0; |
| |
| if( b > BITS_PER_BYTE ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"ishrn_8" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| if( *a & 0x80 ) save_sign = 1; |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_BYTE ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( b == BITS_PER_BYTE ) |
| { |
| *c = 0; |
| |
| if( save_sign ) __STC; |
| |
| __STZ; __CLS; __CLP; |
| |
| if( save_sign ) __STO; |
| } |
| |
| return; |
| |
| } |
| |
| carry = (*c >> ((b-1)&(BITS_PER_BYTE-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| *c = *c >> b; |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( save_sign ) __STO; |
| } |
| |
| |
| void isaln_8( __mpu_uint8_t *c, __mpu_uint8_t *a, unsigned int b ) |
| { |
| signed int carry, sign, save_carry = 0, save_sign = 0; |
| |
| if( b > BITS_PER_BYTE ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"isaln_8" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| if( *a & 0x80 ) save_sign = 1; |
| if( *a & 1 ) save_carry = 1; |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_BYTE ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( b == BITS_PER_BYTE ) |
| { |
| *c = 0; |
| |
| if( save_carry ) __STC; |
| |
| __STZ; __CLS; __CLP; |
| |
| if( save_sign ) __STO; |
| } |
| |
| return; |
| |
| } |
| |
| |
| carry = (*c >> ((BITS_PER_BYTE-b)&(BITS_PER_BYTE-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| *c = *c << b; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x80 ) __STS; |
| |
| sign = __MFLAG(SF); |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| void isarn_8( __mpu_uint8_t *c, __mpu_uint8_t *a, unsigned int b ) |
| { |
| __mpu_uint8_t save_sign = 0; |
| signed int carry, sign; |
| |
| if( b > BITS_PER_BYTE ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"isarn_8" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| if( *a & 0x80 ) { save_sign = 0xff; __STS; } |
| |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_BYTE ) |
| { |
| |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( b == BITS_PER_BYTE ) |
| { |
| *c = save_sign; |
| |
| if( save_sign == 0 ) __STZ; |
| |
| sign = __MFLAG(SF); |
| if( sign ) __STC; |
| else __CLC; |
| |
| if( __MPARITY(*c) ) __STP; |
| } |
| |
| return; |
| |
| } |
| |
| carry = (*c >> ((b-1)&(BITS_PER_BYTE-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| *c = *c >> b; |
| |
| sign = __MFLAG(SF); |
| if( sign ) |
| *c |= 0xff << (BITS_PER_BYTE-b); |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| |
| |
| } |
| |
| |
| |
| |
| |
| #define BITS_PER_TWO_BYTES 16 |
| |
| |
| void ishln_16( __mpu_uint16_t *c, __mpu_uint16_t *a, unsigned int b ) |
| { |
| signed int carry, sign, save_carry = 0, save_sign = 0; |
| |
| if( b > BITS_PER_TWO_BYTES ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"ishln_16" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| if( *a & 0x8000 ) save_sign = 1; |
| if( *a & 1 ) save_carry = 1; |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_TWO_BYTES ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( b == BITS_PER_TWO_BYTES ) |
| { |
| *c = 0; |
| |
| if( save_carry ) __STC; |
| |
| __STZ; __CLS; __CLP; |
| |
| if( save_sign ) __STO; |
| } |
| |
| return; |
| |
| } |
| |
| carry = (*c >> ((BITS_PER_TWO_BYTES-b)&(BITS_PER_TWO_BYTES-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| *c = *c << b; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x8000 ) __STS; |
| |
| sign = __MFLAG(SF); |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| void ishrn_16( __mpu_uint16_t *c, __mpu_uint16_t *a, unsigned int b ) |
| { |
| signed int carry, save_sign = 0; |
| |
| if( b > BITS_PER_TWO_BYTES ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"ishrn_16" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| if( *a & 0x8000 ) save_sign = 1; |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_TWO_BYTES ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( b == BITS_PER_TWO_BYTES ) |
| { |
| *c = 0; |
| |
| if( save_sign ) __STC; |
| |
| __STZ; __CLS; __CLP; |
| |
| if( save_sign ) __STO; |
| } |
| |
| return; |
| |
| } |
| |
| carry = (*c >> ((b-1)&(BITS_PER_TWO_BYTES-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| *c = *c >> b; |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( save_sign ) __STO; |
| } |
| |
| |
| void isaln_16( __mpu_uint16_t *c, __mpu_uint16_t *a, unsigned int b ) |
| { |
| signed int carry, sign, save_carry = 0, save_sign = 0; |
| |
| if( b > BITS_PER_TWO_BYTES ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"isaln_16" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| if( *a & 0x8000 ) save_sign = 1; |
| if( *a & 1 ) save_carry = 1; |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_TWO_BYTES ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( b == BITS_PER_TWO_BYTES ) |
| { |
| *c = 0; |
| |
| if( save_carry ) __STC; |
| |
| __STZ; __CLS; __CLP; |
| |
| if( save_sign ) __STO; |
| } |
| |
| return; |
| |
| } |
| |
| |
| carry = (*c >> ((BITS_PER_TWO_BYTES-b)&(BITS_PER_TWO_BYTES-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| *c = *c << b; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x8000 ) __STS; |
| |
| sign = __MFLAG(SF); |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| void isarn_16( __mpu_uint16_t *c, __mpu_uint16_t *a, unsigned int b ) |
| { |
| __mpu_uint16_t save_sign = 0; |
| signed int carry, sign; |
| |
| if( b > BITS_PER_TWO_BYTES ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"isarn_16" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| if( *a & 0x8000 ) { save_sign = 0xffff; __STS; } |
| |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_TWO_BYTES ) |
| { |
| |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( b == BITS_PER_TWO_BYTES ) |
| { |
| *c = save_sign; |
| |
| if( save_sign == 0 ) __STZ; |
| |
| sign = __MFLAG(SF); |
| if( sign ) __STC; |
| else __CLC; |
| |
| if( __MPARITY(*c) ) __STP; |
| } |
| |
| return; |
| |
| } |
| |
| carry = (*c >> ((b-1)&(BITS_PER_TWO_BYTES-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| *c = *c >> b; |
| |
| sign = __MFLAG(SF); |
| if( sign ) |
| *c |= 0xffff << (BITS_PER_TWO_BYTES-b); |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| |
| |
| } |
| |
| |
| |
| |
| #define BITS_PER_FOUR_BYTES 32 |
| |
| |
| void ishln_32( __mpu_uint32_t *c, __mpu_uint32_t *a, unsigned int b ) |
| { |
| signed int carry, sign, save_carry = 0, save_sign = 0; |
| |
| if( b > BITS_PER_FOUR_BYTES ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"ishln_32" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| if( *a & 0x80000000 ) save_sign = 1; |
| if( *a & 1 ) save_carry = 1; |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_FOUR_BYTES ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( b == BITS_PER_FOUR_BYTES ) |
| { |
| *c = 0; |
| |
| if( save_carry ) __STC; |
| |
| __STZ; __CLS; __CLP; |
| |
| if( save_sign ) __STO; |
| } |
| |
| return; |
| |
| } |
| |
| carry = (*c >> ((BITS_PER_FOUR_BYTES-b)&(BITS_PER_FOUR_BYTES-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| *c = *c << b; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x80000000 ) __STS; |
| |
| sign = __MFLAG(SF); |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| void ishrn_32( __mpu_uint32_t *c, __mpu_uint32_t *a, unsigned int b ) |
| { |
| signed int carry, save_sign = 0; |
| |
| if( b > BITS_PER_FOUR_BYTES ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"ishrn_32" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| if( *a & 0x80000000 ) save_sign = 1; |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_FOUR_BYTES ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( b == BITS_PER_FOUR_BYTES ) |
| { |
| *c = 0; |
| |
| if( save_sign ) __STC; |
| |
| __STZ; __CLS; __CLP; |
| |
| if( save_sign ) __STO; |
| } |
| |
| return; |
| |
| } |
| |
| carry = (*c >> ((b-1)&(BITS_PER_FOUR_BYTES-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| *c = *c >> b; |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( save_sign ) __STO; |
| } |
| |
| |
| void isaln_32( __mpu_uint32_t *c, __mpu_uint32_t *a, unsigned int b ) |
| { |
| signed int carry, sign, save_carry = 0, save_sign = 0; |
| |
| if( b > BITS_PER_FOUR_BYTES ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"isaln_32" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| if( *a & 0x80000000 ) save_sign = 1; |
| if( *a & 1 ) save_carry = 1; |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_FOUR_BYTES ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( b == BITS_PER_FOUR_BYTES ) |
| { |
| *c = 0; |
| |
| if( save_carry ) __STC; |
| |
| __STZ; __CLS; __CLP; |
| |
| if( save_sign ) __STO; |
| } |
| |
| return; |
| |
| } |
| |
| |
| carry = (*c >> ((BITS_PER_FOUR_BYTES-b)&(BITS_PER_FOUR_BYTES-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| *c = *c << b; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x80000000 ) __STS; |
| |
| sign = __MFLAG(SF); |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| void isarn_32( __mpu_uint32_t *c, __mpu_uint32_t *a, unsigned int b ) |
| { |
| __mpu_uint32_t save_sign = 0; |
| signed int carry, sign; |
| |
| if( b > BITS_PER_FOUR_BYTES ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"isarn_32" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| if( *a & 0x80000000 ) { save_sign = 0xffffffff; __STS; } |
| |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_FOUR_BYTES ) |
| { |
| |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( b == BITS_PER_FOUR_BYTES ) |
| { |
| *c = save_sign; |
| |
| if( save_sign == 0 ) __STZ; |
| |
| sign = __MFLAG(SF); |
| if( sign ) __STC; |
| else __CLC; |
| |
| if( __MPARITY(*c) ) __STP; |
| } |
| |
| return; |
| |
| } |
| |
| carry = (*c >> ((b-1)&(BITS_PER_FOUR_BYTES-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| *c = *c >> b; |
| |
| sign = __MFLAG(SF); |
| if( sign ) |
| *c |= 0xffffffff << (BITS_PER_FOUR_BYTES-b); |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| |
| |
| } |
| |
| |
| |
| |
| |
| void ishln_np( EMUSHORT *c, EMUSHORT *a, unsigned int b, int np ) |
| { |
| EMUSHORT *x, *y, tmp; |
| signed int carry, save_carry = 0, sign, save_sign = 0, zero = 1; |
| signed int i, n_parts, n_bits; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"ishln_np (emushort)" ); |
| return; |
| } |
| |
| if( b > BITS_PER_EMUSHORT * np ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"ishln_np (emushort)" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1; |
| #else |
| x = a; |
| #endif |
| if( *x & 1 ) save_carry = 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a; |
| y = c; |
| #else |
| x = a + np - 1; |
| y = c + np - 1; |
| #endif |
| |
| if( *x & MASK_SIGN ) save_sign = 1; |
| |
| n_parts = N_PARTS(b); |
| |
| if( b == 0 || n_parts == np ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| i = np; |
| while( i > 0 ) |
| { |
| *y = *x; |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++x; ++y; |
| #else |
| --x; --y; |
| #endif |
| --i; |
| } |
| if( zero ) __STZ; |
| |
| if( n_parts == np ) |
| { |
| y = c; |
| |
| i = np; |
| while( i > 0 ) { *y = 0; ++y; --i; } |
| |
| if( save_carry ) __STC; |
| |
| __STZ; __CLS; |
| |
| if( save_sign ) __STO; |
| } |
| |
| return; |
| |
| } |
| |
| n_bits = N_BITS(b); |
| |
| if( n_parts == 0 ) |
| { |
| x = a; |
| y = c; |
| |
| i = np; |
| while( i > 0 ) { *y = *x; ++x; ++y; --i; } |
| } |
| |
| if( n_parts ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + n_parts; |
| y = c + n_parts; |
| #else |
| x = a + np - 1 - n_parts; |
| y = c + np - 1 - n_parts; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( *(x - 1) & 1 ) __STC; |
| #else |
| if( *(x + 1) & 1 ) __STC; |
| #endif |
| |
| i = np - n_parts; |
| while( i > 0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(y - n_parts) = *x; |
| #else |
| *(y + n_parts) = *x; |
| #endif |
| |
| if( *x ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++x; ++y; |
| #else |
| --x; --y; |
| #endif |
| --i; |
| } |
| |
| i = n_parts; |
| while( i > 0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --y; |
| #else |
| ++y; |
| #endif |
| *y = 0; |
| |
| zero &= 1; |
| |
| --i; |
| } |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c; |
| #else |
| y = c + np - 1; |
| #endif |
| if( *y & MASK_SIGN ) __STS; |
| |
| sign = __MFLAG(SF); |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| |
| } |
| |
| if( n_bits ) |
| { |
| zero = 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c; |
| #else |
| y = c + np - 1; |
| #endif |
| |
| carry = BIT(y,(BITS_PER_EMUSHORT-n_bits)); |
| if( carry ) __STC; |
| else __CLC; |
| |
| *y = *y << n_bits; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++y; |
| #else |
| --y; |
| #endif |
| |
| i = np - 1; |
| while( i > 0 ) |
| { |
| tmp = *y; |
| *y = *y << n_bits; |
| |
| tmp = tmp >> (BITS_PER_EMUSHORT-n_bits); |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(y - 1) |= tmp; |
| #else |
| *(y + 1) |= tmp; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( *(y - 1) ) zero &= 0; |
| #else |
| if( *(y + 1) ) zero &= 0; |
| #endif |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++y; |
| #else |
| --y; |
| #endif |
| --i; |
| } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( *(y - 1) ) zero &= 0; |
| #else |
| if( *(y + 1) ) zero &= 0; |
| #endif |
| else zero &= 1; |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c; |
| #else |
| y = c + np - 1; |
| #endif |
| if( *y & MASK_SIGN ) __STS; |
| else __CLS; |
| |
| sign = __MFLAG(SF); |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| else __CLO; |
| |
| } |
| |
| } |
| |
| |
| void ishrn_np( EMUSHORT *c, EMUSHORT *a, unsigned int b, int np ) |
| { |
| EMUSHORT *x, *y, tmp; |
| signed int carry, save_sign = 0, zero = 1; |
| signed int i, n_parts, n_bits; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"ishrn_np (emushort)" ); |
| return; |
| } |
| |
| if( b > BITS_PER_EMUSHORT * np ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"ishrn_np (emushort)" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a; |
| y = c; |
| #else |
| x = a + np - 1; |
| y = c + np - 1; |
| #endif |
| |
| if( *x & MASK_SIGN ) save_sign = 1; |
| |
| n_parts = N_PARTS(b); |
| |
| if( b == 0 || n_parts == np ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| i = np; |
| while( i > 0 ) |
| { |
| *y = *x; |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++x; ++y; |
| #else |
| --x; --y; |
| #endif |
| --i; |
| } |
| if( zero ) __STZ; |
| |
| if( n_parts == np ) |
| { |
| y = c; |
| |
| i = np; |
| while( i > 0 ) { *y = 0; ++y; --i; } |
| |
| if( save_sign ) __STC; |
| |
| __STZ; __CLS; |
| |
| if( save_sign ) __STO; |
| } |
| |
| return; |
| |
| } |
| |
| n_bits = N_BITS(b); |
| |
| if( n_parts == 0 ) |
| { |
| x = a; |
| y = c; |
| |
| i = np; |
| while( i > 0 ) { *y = *x; ++x; ++y; --i; } |
| } |
| |
| if( n_parts ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1 - n_parts; |
| y = c + np - 1 - n_parts; |
| #else |
| x = a + n_parts; |
| y = c + n_parts; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( *(x + 1) & MASK_SIGN ) __STC; |
| #else |
| if( *(x - 1) & MASK_SIGN ) __STC; |
| #endif |
| |
| i = np - n_parts; |
| while( i > 0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(y + n_parts) = *x; |
| #else |
| *(y - n_parts) = *x; |
| #endif |
| |
| if( *x ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; --y; |
| #else |
| ++x; ++y; |
| #endif |
| --i; |
| } |
| |
| i = n_parts; |
| while( i > 0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++y; |
| #else |
| --y; |
| #endif |
| *y = 0; |
| |
| zero &= 1; |
| |
| --i; |
| } |
| |
| if( zero ) __STZ; |
| |
| |
| if( save_sign ) __STO; |
| |
| } |
| |
| if( n_bits ) |
| { |
| zero = 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c + np - 1; |
| #else |
| y = c; |
| #endif |
| |
| carry = BIT(y,(n_bits-1)); |
| if( carry ) __STC; |
| else __CLC; |
| |
| *y = *y >> n_bits; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --y; |
| #else |
| ++y; |
| #endif |
| |
| i = np - 1; |
| while( i > 0 ) |
| { |
| tmp = *y; |
| *y = *y >> n_bits; |
| |
| tmp = tmp << (BITS_PER_EMUSHORT-n_bits); |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(y + 1) |= tmp; |
| #else |
| *(y - 1) |= tmp; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( *(y + 1) ) zero &= 0; |
| #else |
| if( *(y - 1) ) zero &= 0; |
| #endif |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --y; |
| #else |
| ++y; |
| #endif |
| --i; |
| } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( *(y + 1) ) zero &= 0; |
| #else |
| if( *(y - 1) ) zero &= 0; |
| #endif |
| else zero &= 1; |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| |
| if( save_sign ) __STO; |
| else __CLO; |
| |
| } |
| |
| } |
| |
| |
| void isaln_np( EMUSHORT *c, EMUSHORT *a, unsigned int b, int np ) |
| { |
| EMUSHORT *x, *y, tmp; |
| signed int carry, sign, save_carry = 0, save_sign = 0, zero = 1; |
| signed int i, n_parts, n_bits; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"isaln_np (emushort)" ); |
| return; |
| } |
| |
| if( b > BITS_PER_EMUSHORT * np ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"isaln_np (emushort)" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1; |
| #else |
| x = a; |
| #endif |
| if( *x & 1 ) save_carry = 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a; |
| y = c; |
| #else |
| x = a + np - 1; |
| y = c + np - 1; |
| #endif |
| |
| if( *x & MASK_SIGN ) save_sign = 1; |
| |
| n_parts = N_PARTS(b); |
| |
| if( b == 0 || n_parts == np ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| i = np; |
| while( i > 0 ) |
| { |
| *y = *x; |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++x; ++y; |
| #else |
| --x; --y; |
| #endif |
| --i; |
| } |
| if( zero ) __STZ; |
| |
| if( n_parts == np ) |
| { |
| y = c; |
| |
| i = np; |
| while( i > 0 ) { *y = 0; ++y; --i; } |
| |
| if( save_carry ) __STC; |
| |
| __STZ; __CLS; |
| |
| if( save_sign ) __STO; |
| } |
| |
| return; |
| |
| } |
| |
| n_bits = N_BITS(b); |
| |
| if( n_parts == 0 ) |
| { |
| x = a; |
| y = c; |
| |
| i = np; |
| while( i > 0 ) { *y = *x; ++x; ++y; --i; } |
| } |
| |
| if( n_parts ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + n_parts; |
| y = c + n_parts; |
| #else |
| x = a + np - 1 - n_parts; |
| y = c + np - 1 - n_parts; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( *(x - 1) & 1 ) __STC; |
| #else |
| if( *(x + 1) & 1 ) __STC; |
| #endif |
| |
| i = np - n_parts; |
| while( i > 0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(y - n_parts) = *x; |
| #else |
| *(y + n_parts) = *x; |
| #endif |
| |
| if( *x ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++x; ++y; |
| #else |
| --x; --y; |
| #endif |
| --i; |
| } |
| |
| i = n_parts; |
| while( i > 0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --y; |
| #else |
| ++y; |
| #endif |
| *y = 0; |
| |
| zero &= 1; |
| |
| --i; |
| } |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c; |
| #else |
| y = c + np - 1; |
| #endif |
| if( *y & MASK_SIGN ) __STS; |
| |
| sign = __MFLAG(SF); |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| |
| } |
| |
| if( n_bits ) |
| { |
| zero = 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c; |
| #else |
| y = c + np - 1; |
| #endif |
| |
| carry = BIT(y,(BITS_PER_EMUSHORT-n_bits)); |
| if( carry ) __STC; |
| else __CLC; |
| |
| *y = *y << n_bits; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++y; |
| #else |
| --y; |
| #endif |
| |
| i = np - 1; |
| while( i > 0 ) |
| { |
| tmp = *y; |
| *y = *y << n_bits; |
| |
| tmp = tmp >> (BITS_PER_EMUSHORT-n_bits); |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(y - 1) |= tmp; |
| #else |
| *(y + 1) |= tmp; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( *(y - 1) ) zero &= 0; |
| #else |
| if( *(y + 1) ) zero &= 0; |
| #endif |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++y; |
| #else |
| --y; |
| #endif |
| --i; |
| } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( *(y - 1) ) zero &= 0; |
| #else |
| if( *(y + 1) ) zero &= 0; |
| #endif |
| else zero &= 1; |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c; |
| #else |
| y = c + np - 1; |
| #endif |
| if( *y & MASK_SIGN ) __STS; |
| else __CLS; |
| |
| sign = __MFLAG(SF); |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| else __CLO; |
| |
| } |
| |
| } |
| |
| |
| void isarn_np( EMUSHORT *c, EMUSHORT *a, unsigned int b, int np ) |
| { |
| EMUSHORT *x, *y, tmp, save_sign = 0; |
| signed int carry, sign, zero = 1; |
| signed int i, n_parts, n_bits; |
| |
| if( np == 0 ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"isarn_np (emushort)" ); |
| return; |
| } |
| |
| if( b > BITS_PER_EMUSHORT * np ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"isarn_np (emushort)" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a; |
| y = c; |
| #else |
| x = a + np - 1; |
| y = c + np - 1; |
| #endif |
| |
| if( *x & MASK_SIGN ) { save_sign = MASK_ALL_BITS; __STS; } |
| |
| |
| n_parts = N_PARTS(b); |
| |
| if( b == 0 || n_parts == np ) |
| { |
| |
| |
| i = np; |
| while( i > 0 ) |
| { |
| *y = *x; |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++x; ++y; |
| #else |
| --x; --y; |
| #endif |
| --i; |
| } |
| if( zero ) __STZ; |
| |
| if( n_parts == np ) |
| { |
| y = c; |
| |
| i = np; |
| while( i > 0 ) { *y = save_sign; ++y; --i; } |
| |
| if( save_sign == 0 ) __STZ; |
| |
| sign = __MFLAG(SF); |
| if( sign ) __STC; |
| else __CLC; |
| } |
| |
| return; |
| |
| } |
| |
| n_bits = N_BITS(b); |
| |
| if( n_parts == 0 ) |
| { |
| x = a; |
| y = c; |
| |
| i = np; |
| while( i > 0 ) { *y = *x; ++x; ++y; --i; } |
| } |
| |
| if( n_parts ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1 - n_parts; |
| y = c + np - 1 - n_parts; |
| #else |
| x = a + n_parts; |
| y = c + n_parts; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( *(x + 1) & MASK_SIGN ) __STC; |
| #else |
| if( *(x - 1) & MASK_SIGN ) __STC; |
| #endif |
| |
| i = np - n_parts; |
| while( i > 0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(y + n_parts) = *x; |
| #else |
| *(y - n_parts) = *x; |
| #endif |
| |
| if( *x ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; --y; |
| #else |
| ++x; ++y; |
| #endif |
| --i; |
| } |
| |
| i = n_parts; |
| while( i > 0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++y; |
| #else |
| --y; |
| #endif |
| *y = save_sign; |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| --i; |
| } |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| |
| |
| |
| } |
| |
| if( n_bits ) |
| { |
| zero = 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c + np - 1; |
| #else |
| y = c; |
| #endif |
| |
| carry = BIT(y,(n_bits-1)); |
| if( carry ) __STC; |
| else __CLC; |
| |
| *y = *y >> n_bits; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --y; |
| #else |
| ++y; |
| #endif |
| |
| i = np - 1; |
| while( i > 0 ) |
| { |
| tmp = *y; |
| *y = *y >> n_bits; |
| |
| tmp = tmp << (BITS_PER_EMUSHORT-n_bits); |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(y + 1) |= tmp; |
| #else |
| *(y - 1) |= tmp; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( *(y + 1) ) zero &= 0; |
| #else |
| if( *(y - 1) ) zero &= 0; |
| #endif |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --y; |
| #else |
| ++y; |
| #endif |
| --i; |
| } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++y; |
| #else |
| --y; |
| #endif |
| if( __MFLAG(SF) ) |
| *y |= MASK_HIGEST_BITS((EMUSHORT)(BITS_PER_EMUSHORT-n_bits)); |
| |
| if( *(y) ) zero &= 0; |
| else zero &= 1; |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| |
| |
| |
| } |
| |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void iroln_8( __mpu_uint8_t *c, __mpu_uint8_t *a, unsigned int b ) |
| { |
| __mpu_uint8_t tmp; |
| signed int carry, sign, save_sign = 0; |
| |
| if( b > BITS_PER_BYTE ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"iroln_8" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| if( *a & 0x80 ) save_sign = 1; |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_BYTE ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( b == BITS_PER_BYTE ) |
| { |
| if( *c & 1 ) __STC; |
| } |
| |
| return; |
| |
| } |
| |
| |
| carry = (*c >> ((BITS_PER_BYTE-b)&(BITS_PER_BYTE-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| tmp = *c; |
| *c = *c << b; |
| |
| tmp = tmp >> (BITS_PER_BYTE-b); |
| *c |= tmp; |
| |
| if( *c == 0 ) __STZ; |
| |
| if( *c & 0x80 ) __STS; |
| if( __MPARITY(*c) ) __STP; |
| |
| sign = __MFLAG(SF); |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| void irorn_8( __mpu_uint8_t *c, __mpu_uint8_t *a, unsigned int b ) |
| { |
| __mpu_uint8_t tmp; |
| signed int carry, sign, save_sign = 0; |
| |
| if( b > BITS_PER_BYTE ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"irorn_8" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| if( *a & 0x80 ) save_sign = 1; |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_BYTE ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( b == BITS_PER_BYTE ) |
| { |
| if( save_sign ) __STC; |
| else __CLC; |
| } |
| |
| return; |
| |
| } |
| |
| |
| carry = (*c >> ((b-1)&(BITS_PER_BYTE-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| tmp = *c; |
| *c = *c >> b; |
| |
| tmp = tmp << (BITS_PER_BYTE-b); |
| *c |= tmp; |
| |
| if( *c == 0 ) __STZ; |
| |
| if( *c & 0x80 ) __STS; |
| if( __MPARITY(*c) ) __STP; |
| |
| sign = __MFLAG(SF); |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| void ircln_8( __mpu_uint8_t *c, __mpu_uint8_t *a, unsigned int b ) |
| { |
| __mpu_uint8_t tmp, save_carry = 0; |
| signed int carry, sign, save_sign = 0, zero = 0, save_parity; |
| |
| if( b > BITS_PER_BYTE ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"ircln_8" ); |
| return; |
| } |
| |
| |
| __CLA; __CLO; __CLS; __CLV; |
| |
| zero = __MFLAG(ZF); |
| |
| if( *a & 0x80 ) save_sign = 1; |
| if( __MFLAG(CF) ) save_carry = 0x80; |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_BYTE ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| if( *c == 0 ) zero &= 1; |
| else zero &= 0; |
| if( zero ) { __STZ; } else { __CLZ; } |
| |
| |
| if( b != BITS_PER_BYTE ) __CLC; |
| if( b == BITS_PER_BYTE ) |
| { |
| save_parity = __MFLAG(PF); |
| ishr_8( c, c ); |
| if( save_parity ) { __STP; } else { __CLP; } |
| |
| if( save_carry ) |
| { |
| *c |= save_carry; |
| |
| __CLZ; __STS; |
| |
| if( !save_sign ) __STO; |
| else __CLO; |
| } |
| } |
| |
| return; |
| |
| } |
| |
| carry = (*c >> ((BITS_PER_BYTE-b)&(BITS_PER_BYTE-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| tmp = *c; |
| *c = *c << b; |
| |
| tmp = tmp >> (BITS_PER_BYTE-b); |
| |
| tmp = tmp >> 1; |
| if( save_carry ) |
| tmp |= ((__mpu_uint8_t)1 << ((b-1)&(BITS_PER_BYTE-1))); |
| |
| *c |= tmp; |
| |
| if( *c ) zero &= 0; |
| else zero &= 1; |
| if( zero ) { __STZ; } else { __CLZ; } |
| |
| if( *c & 0x80 ) __STS; |
| |
| |
| sign = __MFLAG(SF); |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| void ircrn_8( __mpu_uint8_t *c, __mpu_uint8_t *a, unsigned int b ) |
| { |
| __mpu_uint8_t tmp, save_carry = 0; |
| signed int carry = 0, sign = 0, zero = 0, save_sign = 0; |
| |
| if( b > BITS_PER_BYTE ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"ircrn_8" ); |
| return; |
| } |
| |
| |
| __CLA; __CLO; __CLP; __CLV; |
| |
| zero = __MFLAG(ZF); |
| |
| if( *a & 0x80 ) save_sign = 1; |
| if( __MFLAG(CF) ) save_carry = 1; |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_BYTE ) |
| { |
| if( *c ) zero &= 0; |
| else zero &= 1; |
| if( zero ) { __STZ; } else { __CLZ; } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| |
| if( b != BITS_PER_BYTE ) __CLC; |
| if( b == BITS_PER_BYTE ) |
| { |
| sign = __MFLAG(SF); |
| ishl_8( c, c ); |
| if( sign ) __STS; |
| else __CLS; |
| sign = 0; |
| |
| if( save_carry ) |
| { |
| *c |= save_carry; |
| |
| __CLZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c & 0x80 ) sign = 1; |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| else __CLO; |
| } |
| } |
| |
| return; |
| |
| } |
| |
| carry = (*c >> ((b-1)&(BITS_PER_BYTE-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| tmp = *c; |
| *c = *c >> b; |
| |
| tmp = tmp << (BITS_PER_BYTE-b); |
| |
| tmp = tmp << 1; |
| if( save_carry ) |
| tmp |= ((__mpu_uint8_t)1 << ((BITS_PER_BYTE-b)&(BITS_PER_BYTE-1))); |
| |
| *c |= tmp; |
| |
| if( *c ) zero &= 0; |
| else zero &= 1; |
| if( zero ) { __STZ; } else { __CLZ; } |
| |
| if( *c & 0x80 ) sign = 1; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| |
| |
| |
| void iroln_16( __mpu_uint16_t *c, __mpu_uint16_t *a, unsigned int b ) |
| { |
| __mpu_uint16_t tmp; |
| signed int carry, sign, save_sign = 0; |
| |
| if( b > BITS_PER_TWO_BYTES ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"iroln_16" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| if( *a & 0x8000 ) save_sign = 1; |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_TWO_BYTES ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( b == BITS_PER_TWO_BYTES ) |
| { |
| if( *c & 1 ) __STC; |
| } |
| |
| return; |
| |
| } |
| |
| |
| carry = (*c >> ((BITS_PER_TWO_BYTES-b)&(BITS_PER_TWO_BYTES-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| tmp = *c; |
| *c = *c << b; |
| |
| tmp = tmp >> (BITS_PER_TWO_BYTES-b); |
| *c |= tmp; |
| |
| if( *c == 0 ) __STZ; |
| |
| if( *c & 0x8000 ) __STS; |
| if( __MPARITY(*c) ) __STP; |
| |
| sign = __MFLAG(SF); |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| void irorn_16( __mpu_uint16_t *c, __mpu_uint16_t *a, unsigned int b ) |
| { |
| __mpu_uint16_t tmp; |
| signed int carry, sign, save_sign = 0; |
| |
| if( b > BITS_PER_TWO_BYTES ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"irorn_16" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| if( *a & 0x8000 ) save_sign = 1; |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_TWO_BYTES ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( b == BITS_PER_TWO_BYTES ) |
| { |
| if( save_sign ) __STC; |
| else __CLC; |
| } |
| |
| return; |
| |
| } |
| |
| |
| carry = (*c >> ((b-1)&(BITS_PER_TWO_BYTES-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| tmp = *c; |
| *c = *c >> b; |
| |
| tmp = tmp << (BITS_PER_TWO_BYTES-b); |
| *c |= tmp; |
| |
| if( *c == 0 ) __STZ; |
| |
| if( *c & 0x8000 ) __STS; |
| if( __MPARITY(*c) ) __STP; |
| |
| sign = __MFLAG(SF); |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| void ircln_16( __mpu_uint16_t *c, __mpu_uint16_t *a, unsigned int b ) |
| { |
| __mpu_uint16_t tmp, save_carry = 0; |
| signed int carry, sign, save_sign = 0, zero = 0, save_parity; |
| |
| if( b > BITS_PER_TWO_BYTES ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"ircln_16" ); |
| return; |
| } |
| |
| |
| __CLA; __CLO; __CLS; __CLV; |
| |
| zero = __MFLAG(ZF); |
| |
| if( *a & 0x8000 ) save_sign = 1; |
| if( __MFLAG(CF) ) save_carry = 0x8000; |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_TWO_BYTES ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| if( *c == 0 ) zero &= 1; |
| else zero &= 0; |
| if( zero ) { __STZ; } else { __CLZ; } |
| |
| |
| if( b != BITS_PER_TWO_BYTES ) __CLC; |
| if( b == BITS_PER_TWO_BYTES ) |
| { |
| save_parity = __MFLAG(PF); |
| ishr_16( c, c ); |
| if( save_parity ) { __STP; } else { __CLP; } |
| |
| if( save_carry ) |
| { |
| *c |= save_carry; |
| |
| __CLZ; __STS; |
| |
| if( !save_sign ) __STO; |
| else __CLO; |
| } |
| } |
| |
| return; |
| |
| } |
| |
| carry = (*c >> ((BITS_PER_TWO_BYTES-b)&(BITS_PER_TWO_BYTES-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| tmp = *c; |
| *c = *c << b; |
| |
| tmp = tmp >> (BITS_PER_TWO_BYTES-b); |
| |
| tmp = tmp >> 1; |
| if( save_carry ) |
| tmp |= ((__mpu_uint16_t)1 << ((b-1)&(BITS_PER_TWO_BYTES-1))); |
| |
| *c |= tmp; |
| |
| if( *c ) zero &= 0; |
| else zero &= 1; |
| if( zero ) { __STZ; } else { __CLZ; } |
| |
| if( *c & 0x8000 ) __STS; |
| |
| |
| sign = __MFLAG(SF); |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| void ircrn_16( __mpu_uint16_t *c, __mpu_uint16_t *a, unsigned int b ) |
| { |
| __mpu_uint16_t tmp, save_carry = 0; |
| signed int carry = 0, sign = 0, zero = 0, save_sign = 0; |
| |
| if( b > BITS_PER_TWO_BYTES ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"ircrn_16" ); |
| return; |
| } |
| |
| |
| __CLA; __CLO; __CLP; __CLV; |
| |
| zero = __MFLAG(ZF); |
| |
| if( *a & 0x8000 ) save_sign = 1; |
| if( __MFLAG(CF) ) save_carry = 1; |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_TWO_BYTES ) |
| { |
| if( *c ) zero &= 0; |
| else zero &= 1; |
| if( zero ) { __STZ; } else { __CLZ; } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| |
| if( b != BITS_PER_TWO_BYTES ) __CLC; |
| if( b == BITS_PER_TWO_BYTES ) |
| { |
| sign = __MFLAG(SF); |
| ishl_16( c, c ); |
| if( sign ) __STS; |
| else __CLS; |
| sign = 0; |
| |
| if( save_carry ) |
| { |
| *c |= save_carry; |
| |
| __CLZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c & 0x8000 ) sign = 1; |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| else __CLO; |
| } |
| } |
| |
| return; |
| |
| } |
| |
| carry = (*c >> ((b-1)&(BITS_PER_TWO_BYTES-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| tmp = *c; |
| *c = *c >> b; |
| |
| tmp = tmp << (BITS_PER_TWO_BYTES-b); |
| |
| tmp = tmp << 1; |
| if( save_carry ) |
| tmp |= ((__mpu_uint16_t)1 << ((BITS_PER_TWO_BYTES-b)&(BITS_PER_TWO_BYTES-1))); |
| |
| *c |= tmp; |
| |
| if( *c ) zero &= 0; |
| else zero &= 1; |
| if( zero ) { __STZ; } else { __CLZ; } |
| |
| if( *c & 0x8000 ) sign = 1; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| |
| |
| |
| void iroln_32( __mpu_uint32_t *c, __mpu_uint32_t *a, unsigned int b ) |
| { |
| __mpu_uint32_t tmp; |
| signed int carry, sign, save_sign = 0; |
| |
| if( b > BITS_PER_FOUR_BYTES ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"iroln_32" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| if( *a & 0x80000000 ) save_sign = 1; |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_FOUR_BYTES ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( b == BITS_PER_FOUR_BYTES ) |
| { |
| if( *c & 1 ) __STC; |
| } |
| |
| return; |
| |
| } |
| |
| |
| carry = (*c >> ((BITS_PER_FOUR_BYTES-b)&(BITS_PER_FOUR_BYTES-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| tmp = *c; |
| *c = *c << b; |
| |
| tmp = tmp >> (BITS_PER_FOUR_BYTES-b); |
| *c |= tmp; |
| |
| if( *c == 0 ) __STZ; |
| |
| if( *c & 0x80000000 ) __STS; |
| if( __MPARITY(*c) ) __STP; |
| |
| sign = __MFLAG(SF); |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| void irorn_32( __mpu_uint32_t *c, __mpu_uint32_t *a, unsigned int b ) |
| { |
| __mpu_uint32_t tmp; |
| signed int carry, sign, save_sign = 0; |
| |
| if( b > BITS_PER_FOUR_BYTES ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"irorn_32" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| if( *a & 0x80000000 ) save_sign = 1; |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_FOUR_BYTES ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| if( *c == 0 ) __STZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( b == BITS_PER_FOUR_BYTES ) |
| { |
| if( save_sign ) __STC; |
| else __CLC; |
| } |
| |
| return; |
| |
| } |
| |
| |
| carry = (*c >> ((b-1)&(BITS_PER_FOUR_BYTES-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| tmp = *c; |
| *c = *c >> b; |
| |
| tmp = tmp << (BITS_PER_FOUR_BYTES-b); |
| *c |= tmp; |
| |
| if( *c == 0 ) __STZ; |
| |
| if( *c & 0x80000000 ) __STS; |
| if( __MPARITY(*c) ) __STP; |
| |
| sign = __MFLAG(SF); |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| void ircln_32( __mpu_uint32_t *c, __mpu_uint32_t *a, unsigned int b ) |
| { |
| __mpu_uint32_t tmp, save_carry = 0; |
| signed int carry, sign, save_sign = 0, zero = 0, save_parity; |
| |
| if( b > BITS_PER_FOUR_BYTES ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"ircln_32" ); |
| return; |
| } |
| |
| |
| __CLA; __CLO; __CLS; __CLV; |
| |
| zero = __MFLAG(ZF); |
| |
| if( *a & 0x80000000 ) save_sign = 1; |
| if( __MFLAG(CF) ) save_carry = 0x80000000; |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_FOUR_BYTES ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| if( *c == 0 ) zero &= 1; |
| else zero &= 0; |
| if( zero ) { __STZ; } else { __CLZ; } |
| |
| |
| if( b != BITS_PER_FOUR_BYTES ) __CLC; |
| if( b == BITS_PER_FOUR_BYTES ) |
| { |
| save_parity = __MFLAG(PF); |
| ishr_32( c, c ); |
| if( save_parity ) { __STP; } else { __CLP; } |
| |
| if( save_carry ) |
| { |
| *c |= save_carry; |
| |
| __CLZ; __STS; |
| |
| if( !save_sign ) __STO; |
| else __CLO; |
| } |
| } |
| |
| return; |
| |
| } |
| |
| carry = (*c >> ((BITS_PER_FOUR_BYTES-b)&(BITS_PER_FOUR_BYTES-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| tmp = *c; |
| *c = *c << b; |
| |
| tmp = tmp >> (BITS_PER_FOUR_BYTES-b); |
| |
| tmp = tmp >> 1; |
| if( save_carry ) |
| tmp |= ((__mpu_uint32_t)1 << ((b-1)&(BITS_PER_FOUR_BYTES-1))); |
| |
| *c |= tmp; |
| |
| if( *c ) zero &= 0; |
| else zero &= 1; |
| if( zero ) { __STZ; } else { __CLZ; } |
| |
| if( *c & 0x80000000 ) __STS; |
| |
| |
| sign = __MFLAG(SF); |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| void ircrn_32( __mpu_uint32_t *c, __mpu_uint32_t *a, unsigned int b ) |
| { |
| __mpu_uint32_t tmp, save_carry = 0; |
| signed int carry = 0, sign = 0, zero = 0, save_sign = 0; |
| |
| if( b > BITS_PER_FOUR_BYTES ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"ircrn_32" ); |
| return; |
| } |
| |
| |
| __CLA; __CLO; __CLP; __CLV; |
| |
| zero = __MFLAG(ZF); |
| |
| if( *a & 0x80000000 ) save_sign = 1; |
| if( __MFLAG(CF) ) save_carry = 1; |
| |
| *c = *a; |
| |
| if( b == 0 || b == BITS_PER_FOUR_BYTES ) |
| { |
| if( *c ) zero &= 0; |
| else zero &= 1; |
| if( zero ) { __STZ; } else { __CLZ; } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| |
| if( b != BITS_PER_FOUR_BYTES ) __CLC; |
| if( b == BITS_PER_FOUR_BYTES ) |
| { |
| sign = __MFLAG(SF); |
| ishl_32( c, c ); |
| if( sign ) __STS; |
| else __CLS; |
| sign = 0; |
| |
| if( save_carry ) |
| { |
| *c |= save_carry; |
| |
| __CLZ; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c & 0x80000000 ) sign = 1; |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| else __CLO; |
| } |
| } |
| |
| return; |
| |
| } |
| |
| carry = (*c >> ((b-1)&(BITS_PER_FOUR_BYTES-1)))&1; |
| if( carry ) __STC; |
| else __CLC; |
| |
| tmp = *c; |
| *c = *c >> b; |
| |
| tmp = tmp << (BITS_PER_FOUR_BYTES-b); |
| |
| tmp = tmp << 1; |
| if( save_carry ) |
| tmp |= ((__mpu_uint32_t)1 << ((BITS_PER_FOUR_BYTES-b)&(BITS_PER_FOUR_BYTES-1))); |
| |
| *c |= tmp; |
| |
| if( *c ) zero &= 0; |
| else zero &= 1; |
| if( zero ) { __STZ; } else { __CLZ; } |
| |
| if( *c & 0x80000000 ) sign = 1; |
| if( __MPARITY(*c) ) __STP; |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| } |
| |
| |
| |
| |
| |
| void iroln_np( EMUSHORT *c, EMUSHORT *a, unsigned int b, int np ) |
| { |
| EMUSHORT *x, *y, tmp, temp, *ptemp = 0; |
| signed int carry, sign, save_sign = 0, zero = 1; |
| signed int i, n_parts, n_bits; |
| |
| errno = 0; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"iroln_np (emushort)" ); |
| return; |
| } |
| |
| if( b > BITS_PER_EMUSHORT * np ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"iroln_np (emushort)" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a; |
| y = c; |
| #else |
| x = a + np - 1; |
| y = c + np - 1; |
| #endif |
| |
| if( *x & MASK_SIGN ) save_sign = 1; |
| |
| n_parts = N_PARTS(b); |
| |
| if( b == 0 || n_parts == np ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| i = np; |
| while( i > 0 ) |
| { |
| *y = *x; |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++x; ++y; |
| #else |
| --x; --y; |
| #endif |
| --i; |
| } |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --y; |
| #else |
| ++y; |
| #endif |
| |
| if( n_parts == np ) |
| { |
| if( *y & 1 ) __STC; |
| else __CLC; |
| } |
| |
| return; |
| |
| } |
| |
| n_bits = N_BITS(b); |
| |
| if( n_parts == 0 ) |
| { |
| x = a; |
| y = c; |
| |
| i = np; |
| while( i > 0 ) { *y = *x; ++x; ++y; --i; } |
| } |
| |
| if( n_parts ) |
| { |
| |
| ptemp = (EMUSHORT *)__mpu_sbrk( (int)(n_parts*SIZE_OF_EMUSHORT) ); |
| if( !ptemp ) |
| { |
| |
| return; |
| } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a; |
| #else |
| x = a + np - 1; |
| #endif |
| |
| i = n_parts; |
| while( i > 0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ptemp[n_parts-i] = *x; |
| #else |
| ptemp[i-1] = *x; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++x; |
| #else |
| --x; |
| #endif |
| --i; |
| } |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + n_parts; |
| y = c + n_parts; |
| #else |
| x = a + np - 1 - n_parts; |
| y = c + np - 1 - n_parts; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( *(x - 1) & 1 ) __STC; |
| #else |
| if( *(x + 1) & 1 ) __STC; |
| #endif |
| |
| i = np - n_parts; |
| while( i > 0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(y - n_parts) = *x; |
| #else |
| *(y + n_parts) = *x; |
| #endif |
| |
| if( *x ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++x; ++y; |
| #else |
| --x; --y; |
| #endif |
| --i; |
| } |
| |
| i = 0; |
| while( i < n_parts ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --y; *y = ptemp[n_parts-1-i]; |
| #else |
| ++y; *y = ptemp[i]; |
| #endif |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| ++i; |
| } |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c; |
| #else |
| y = c + np - 1; |
| #endif |
| if( *y & MASK_SIGN ) __STS; |
| |
| sign = __MFLAG(SF); |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| |
| |
| __mpu_sbrk( -(int)(n_parts*SIZE_OF_EMUSHORT) ); |
| |
| |
| } |
| |
| if( n_bits ) |
| { |
| zero = 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c; |
| #else |
| y = c + np - 1; |
| #endif |
| |
| carry = BIT(y,(BITS_PER_EMUSHORT-n_bits)); |
| if( carry ) __STC; |
| else __CLC; |
| |
| |
| temp = *y; |
| temp = temp >> (BITS_PER_EMUSHORT-n_bits); |
| |
| |
| *y = *y << n_bits; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++y; |
| #else |
| --y; |
| #endif |
| |
| i = np - 1; |
| while( i > 0 ) |
| { |
| tmp = *y; |
| *y = *y << n_bits; |
| |
| tmp = tmp >> (BITS_PER_EMUSHORT-n_bits); |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(y - 1) |= tmp; |
| #else |
| *(y + 1) |= tmp; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( *(y - 1) ) zero &= 0; |
| #else |
| if( *(y + 1) ) zero &= 0; |
| #endif |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++y; |
| #else |
| --y; |
| #endif |
| --i; |
| } |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --y; |
| #else |
| ++y; |
| #endif |
| |
| |
| *y |= temp; |
| |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c; |
| #else |
| y = c + np - 1; |
| #endif |
| if( *y & MASK_SIGN ) __STS; |
| else __CLS; |
| |
| sign = __MFLAG(SF); |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| else __CLO; |
| |
| } |
| |
| } |
| |
| |
| void irorn_np( EMUSHORT *c, EMUSHORT *a, unsigned int b, int np ) |
| { |
| EMUSHORT *x, *y, tmp, temp, *ptemp = 0; |
| signed int carry, sign, save_sign = 0, zero = 1; |
| signed int i, n_parts, n_bits; |
| |
| errno = 0; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"irorn_np (emushort)" ); |
| return; |
| } |
| |
| if( b > BITS_PER_EMUSHORT * np ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"irorn_np (emushort)" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a; |
| y = c; |
| #else |
| x = a + np - 1; |
| y = c + np - 1; |
| #endif |
| |
| if( *x & MASK_SIGN ) save_sign = 1; |
| |
| n_parts = N_PARTS(b); |
| |
| if( b == 0 || n_parts == np ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| i = np; |
| while( i > 0 ) |
| { |
| *y = *x; |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++x; ++y; |
| #else |
| --x; --y; |
| #endif |
| --i; |
| } |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| if( n_parts == np ) |
| { |
| if( save_sign ) __STC; |
| else __CLC; |
| } |
| |
| return; |
| |
| } |
| |
| n_bits = N_BITS(b); |
| |
| if( n_parts == 0 ) |
| { |
| x = a; |
| y = c; |
| |
| i = np; |
| while( i > 0 ) { *y = *x; ++x; ++y; --i; } |
| } |
| |
| if( n_parts ) |
| { |
| |
| ptemp = (EMUSHORT *)__mpu_sbrk( (int)(n_parts*SIZE_OF_EMUSHORT) ); |
| if( !ptemp ) |
| { |
| |
| return; |
| } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1; |
| #else |
| x = a; |
| #endif |
| |
| i = 0; |
| while( i < n_parts ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ptemp[n_parts-1-i] = *x; |
| #else |
| ptemp[i] = *x; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; |
| #else |
| ++x; |
| #endif |
| ++i; |
| } |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1 - n_parts; |
| y = c + np - 1 - n_parts; |
| #else |
| x = a + n_parts; |
| y = c + n_parts; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( *(x + 1) & MASK_SIGN ) __STC; |
| #else |
| if( *(x - 1) & MASK_SIGN ) __STC; |
| #endif |
| |
| i = np - n_parts; |
| while( i > 0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(y + n_parts) = *x; |
| #else |
| *(y - n_parts) = *x; |
| #endif |
| |
| if( *x ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; --y; |
| #else |
| ++x; ++y; |
| #endif |
| --i; |
| } |
| |
| i = n_parts; |
| while( i > 0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++y; *y = ptemp[n_parts-i]; |
| #else |
| --y; *y = ptemp[i-1]; |
| #endif |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| --i; |
| } |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c; |
| #else |
| y = c + np - 1; |
| #endif |
| if( *y & MASK_SIGN ) __STS; |
| |
| sign = __MFLAG(SF); |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| |
| |
| __mpu_sbrk( -(int)(n_parts*SIZE_OF_EMUSHORT) ); |
| |
| |
| } |
| |
| if( n_bits ) |
| { |
| zero = 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c + np - 1; |
| #else |
| y = c; |
| #endif |
| |
| carry = BIT(y,(n_bits-1)); |
| if( carry ) __STC; |
| else __CLC; |
| |
| |
| temp = *y; |
| temp = temp << (BITS_PER_EMUSHORT-n_bits); |
| |
| |
| *y = *y >> n_bits; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --y; |
| #else |
| ++y; |
| #endif |
| |
| i = np - 1; |
| while( i > 0 ) |
| { |
| tmp = *y; |
| *y = *y >> n_bits; |
| |
| tmp = tmp << (BITS_PER_EMUSHORT-n_bits); |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(y + 1) |= tmp; |
| #else |
| *(y - 1) |= tmp; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( *(y + 1) ) zero &= 0; |
| #else |
| if( *(y - 1) ) zero &= 0; |
| #endif |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --y; |
| #else |
| ++y; |
| #endif |
| --i; |
| } |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++y; |
| #else |
| --y; |
| #endif |
| |
| |
| *y |= temp; |
| |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c; |
| #else |
| y = c + np - 1; |
| #endif |
| if( *y & MASK_SIGN ) __STS; |
| else __CLS; |
| |
| sign = __MFLAG(SF); |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| else __CLO; |
| |
| } |
| |
| } |
| |
| |
| void ircln_np( EMUSHORT *c, EMUSHORT *a, unsigned int b, int np ) |
| { |
| EMUSHORT *x, *y, tmp, temp, *ptemp = 0, save_carry = 0; |
| signed int carry, sign, save_sign = 0, zero = 1, save_zero = 0, save_parity; |
| signed int save_part_carry = 0; |
| signed int i, n_parts, n_bits; |
| |
| errno = 0; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"ircln_np (emushort)" ); |
| return; |
| } |
| |
| if( b > BITS_PER_EMUSHORT * np ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"ircln_np (emushort)" ); |
| return; |
| } |
| |
| |
| __CLA; __CLO; __CLS; __CLV; |
| |
| save_zero = __MFLAG(ZF); |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a; |
| y = c; |
| #else |
| x = a + np - 1; |
| y = c + np - 1; |
| #endif |
| |
| if( *x & MASK_SIGN ) save_sign = 1; |
| if( __MFLAG(CF) ) save_carry = MASK_SIGN; |
| |
| n_parts = N_PARTS(b); |
| |
| if( b == 0 || n_parts == np ) |
| { |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| i = np; |
| while( i > 0 ) |
| { |
| *y = *x; |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++x; ++y; |
| #else |
| --x; --y; |
| #endif |
| --i; |
| } |
| save_zero &= zero; |
| if( save_zero ) __STZ; |
| else __CLZ; |
| |
| |
| if( n_parts != np ) __CLC; |
| if( n_parts == np ) |
| { |
| save_parity = __MFLAG(PF); |
| ishr_np( c, c, np ); |
| if( save_parity ) __STP; |
| else __CLP; |
| |
| if( save_carry ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c; |
| #else |
| y = c + np - 1; |
| #endif |
| *y |= save_carry; |
| |
| __CLZ; __STS; |
| |
| if( !save_sign ) __STO; |
| else __CLO; |
| } |
| } |
| |
| return; |
| |
| } |
| |
| n_bits = N_BITS(b); |
| |
| if( n_parts == 0 ) |
| { |
| x = a; |
| y = c; |
| |
| i = np; |
| while( i > 0 ) { *y = *x; ++x; ++y; --i; } |
| } |
| |
| if( n_parts ) |
| { |
| |
| ptemp = (EMUSHORT *)__mpu_sbrk( (int)(n_parts*SIZE_OF_EMUSHORT) ); |
| if( !ptemp ) |
| { |
| |
| return; |
| } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a; |
| #else |
| x = a + np - 1; |
| #endif |
| |
| i = n_parts; |
| while( i > 0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ptemp[n_parts-i] = *x; |
| #else |
| ptemp[i-1] = *x; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++x; |
| #else |
| --x; |
| #endif |
| --i; |
| } |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + n_parts; |
| y = c + n_parts; |
| #else |
| x = a + np - 1 - n_parts; |
| y = c + np - 1 - n_parts; |
| #endif |
| |
| i = np - n_parts; |
| while( i > 0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(y - n_parts) = *x; |
| #else |
| *(y + n_parts) = *x; |
| #endif |
| |
| if( *x ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++x; ++y; |
| #else |
| --x; --y; |
| #endif |
| --i; |
| } |
| |
| |
| save_parity = __MFLAG(PF); |
| ishr_np( ptemp, ptemp, n_parts ); |
| if( save_parity ) __STP; |
| else __CLP; |
| |
| |
| i = 0; |
| while( i < n_parts ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --y; *y = ptemp[n_parts-1-i]; |
| #else |
| ++y; *y = ptemp[i]; |
| #endif |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| ++i; |
| } |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c + np - n_parts; |
| #else |
| y = c + n_parts - 1; |
| #endif |
| *y |= save_carry; |
| if( save_carry ) zero &= 0; |
| else zero &= 1; |
| |
| |
| save_zero &= zero; |
| if( save_zero ) __STZ; |
| else __CLZ; |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c; |
| #else |
| y = c + np - 1; |
| #endif |
| if( *y & MASK_SIGN ) __STS; |
| else __CLS; |
| |
| |
| |
| sign = __MFLAG(SF); |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| else __CLO; |
| |
| |
| __mpu_sbrk( -(int)(n_parts*SIZE_OF_EMUSHORT) ); |
| |
| |
| } |
| |
| if( n_bits ) |
| { |
| zero = 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c; |
| #else |
| y = c + np - 1; |
| #endif |
| |
| carry = __MFLAG(CF); |
| |
| if( n_parts == 0 ) |
| { |
| if( carry ) save_carry = 1; |
| } |
| |
| if( n_parts ) |
| { |
| if( carry ) save_part_carry = 1; |
| } |
| |
| carry = BIT(y,(BITS_PER_EMUSHORT-n_bits)); |
| if( carry ) __STC; |
| else __CLC; |
| |
| |
| temp = *y; |
| temp = temp >> (BITS_PER_EMUSHORT-n_bits); |
| |
| |
| *y = *y << n_bits; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| #else |
| --y; |
| #endif |
| |
| i = np - 1; |
| while( i > 0 ) |
| { |
| tmp = *y; |
| *y = *y << n_bits; |
| |
| tmp = tmp >> (BITS_PER_EMUSHORT-n_bits); |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(y - 1) |= tmp; |
| #else |
| *(y + 1) |= tmp; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( *(y - 1) ) zero &= 0; |
| #else |
| if( *(y + 1) ) zero &= 0; |
| #endif |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++y; |
| #else |
| --y; |
| #endif |
| --i; |
| } |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --y; |
| #else |
| ++y; |
| #endif |
| |
| |
| if( n_parts == 0 ) |
| { |
| temp = temp >> 1; |
| if( save_carry ) SET_BIT( &temp, n_bits-1 ); |
| } |
| if( n_parts ) |
| { |
| temp = temp >> 1; |
| if( save_part_carry ) |
| SET_BIT( &temp, n_bits-1 ); |
| } |
| *y |= temp; |
| |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| save_zero = __MFLAG(ZF); |
| save_zero &= zero; |
| if( save_zero ) __STZ; |
| else __CLZ; |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c; |
| #else |
| y = c + np - 1; |
| #endif |
| if( *y & MASK_SIGN ) __STS; |
| else __CLS; |
| |
| |
| |
| sign = __MFLAG(SF); |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| else __CLO; |
| |
| } |
| |
| } |
| |
| |
| void ircrn_np( EMUSHORT *c, EMUSHORT *a, unsigned int b, int np ) |
| { |
| EMUSHORT *x, *y, tmp, temp, *ptemp = 0, save_carry = 0; |
| signed int carry, sign = 0, save_sign = 0, zero = 1, save_zero; |
| signed int save_part_carry = 0; |
| signed int i, n_parts, n_bits; |
| |
| errno = 0; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"ircrn_np (emushort)" ); |
| return; |
| } |
| |
| if( b > BITS_PER_EMUSHORT * np ) |
| { |
| |
| __integer_invalid_shift( (__mpu_char8_t *)"ircrn_np (emushort)" ); |
| return; |
| } |
| |
| |
| __CLA; __CLO; __CLP; __CLV; |
| |
| save_zero = __MFLAG(ZF); |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a; |
| y = c; |
| #else |
| x = a + np - 1; |
| y = c + np - 1; |
| #endif |
| |
| if( *x & MASK_SIGN ) save_sign = 1; |
| if( __MFLAG(CF) ) save_carry = 1; |
| |
| n_parts = N_PARTS(b); |
| |
| if( b == 0 || n_parts == np ) |
| { |
| i = np; |
| while( i > 0 ) |
| { |
| *y = *x; |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++x; ++y; |
| #else |
| --x; --y; |
| #endif |
| --i; |
| } |
| save_zero &= zero; |
| if( save_zero ) __STZ; |
| else __CLZ; |
| |
| |
| if( n_parts != np ) __CLC; |
| if( n_parts == np ) |
| { |
| sign = __MFLAG(SF); |
| ishl_np( c, c, np ); |
| if( sign ) __STS; |
| else __CLS; |
| sign = 0; |
| |
| if( save_carry ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c + np - 1; |
| #else |
| y = c; |
| #endif |
| *y |= save_carry; |
| |
| __CLZ; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c; |
| #else |
| y = c + np - 1; |
| #endif |
| if( *y & MASK_SIGN ) sign = 1; |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| else __CLO; |
| } |
| } |
| |
| return; |
| |
| } |
| |
| n_bits = N_BITS(b); |
| |
| if( n_parts == 0 ) |
| { |
| x = a; |
| y = c; |
| |
| i = np; |
| while( i > 0 ) { *y = *x; ++x; ++y; --i; } |
| } |
| |
| if( n_parts ) |
| { |
| |
| ptemp = (EMUSHORT *)__mpu_sbrk( (int)(n_parts*SIZE_OF_EMUSHORT) ); |
| if( !ptemp ) |
| { |
| |
| return; |
| } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1; |
| #else |
| x = a; |
| #endif |
| |
| i = 0; |
| while( i < n_parts ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ptemp[n_parts-1-i] = *x; |
| #else |
| ptemp[i] = *x; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; |
| #else |
| ++x; |
| #endif |
| ++i; |
| } |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1 - n_parts; |
| y = c + np - 1 - n_parts; |
| #else |
| x = a + n_parts; |
| y = c + n_parts; |
| #endif |
| |
| i = np - n_parts; |
| while( i > 0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(y + n_parts) = *x; |
| #else |
| *(y - n_parts) = *x; |
| #endif |
| |
| if( *x ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; --y; |
| #else |
| ++x; ++y; |
| #endif |
| --i; |
| } |
| |
| |
| save_sign = __MFLAG(SF); |
| ishl_np( ptemp, ptemp, n_parts ); |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| |
| i = n_parts; |
| while( i > 0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++y; *y = ptemp[n_parts-i]; |
| #else |
| --y; *y = ptemp[i-1]; |
| #endif |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| --i; |
| } |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c + n_parts - 1; |
| #else |
| y = c + np - n_parts; |
| #endif |
| *y |= save_carry; |
| if( save_carry ) zero &= 0; |
| else zero &= 1; |
| |
| |
| save_zero &= zero; |
| if( save_zero ) __STZ; |
| else __CLZ; |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c; |
| #else |
| y = c + np - 1; |
| #endif |
| if( *y & MASK_SIGN ) sign = 1; |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| else __CLO; |
| |
| |
| __mpu_sbrk( -(int)(n_parts*SIZE_OF_EMUSHORT) ); |
| |
| |
| } |
| |
| if( n_bits ) |
| { |
| zero = 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c + np - 1; |
| #else |
| y = c; |
| #endif |
| |
| carry = __MFLAG(CF); |
| |
| if( n_parts == 0 ) |
| { |
| if( carry ) save_carry = 1; |
| } |
| |
| if( n_parts ) |
| { |
| if( carry ) save_part_carry = 1; |
| } |
| |
| carry = BIT(y,(n_bits-1)); |
| if( carry ) __STC; |
| else __CLC; |
| |
| |
| temp = *y; |
| temp = temp << (BITS_PER_EMUSHORT-n_bits); |
| |
| |
| *y = *y >> n_bits; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --y; |
| #else |
| ++y; |
| #endif |
| |
| i = np - 1; |
| while( i > 0 ) |
| { |
| tmp = *y; |
| *y = *y >> n_bits; |
| |
| tmp = tmp << (BITS_PER_EMUSHORT-n_bits); |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(y + 1) |= tmp; |
| #else |
| *(y - 1) |= tmp; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( *(y + 1) ) zero &= 0; |
| #else |
| if( *(y - 1) ) zero &= 0; |
| #endif |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --y; |
| #else |
| ++y; |
| #endif |
| --i; |
| } |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++y; |
| #else |
| --y; |
| #endif |
| |
| |
| if( n_parts == 0 ) |
| { |
| temp = temp << 1; |
| if( save_carry ) |
| SET_BIT( &temp, BITS_PER_EMUSHORT-n_bits ); |
| } |
| |
| if( n_parts ) |
| { |
| temp = temp << 1; |
| if( save_part_carry ) |
| SET_BIT( &temp, BITS_PER_EMUSHORT-n_bits ); |
| } |
| *y |= temp; |
| |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| save_zero &= zero; |
| if( save_zero ) __STZ; |
| else __CLZ; |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = c; |
| #else |
| y = c + np - 1; |
| #endif |
| if( *y & MASK_SIGN ) sign = 1; |
| else sign = 0; |
| |
| if( (!save_sign && sign) || (save_sign && !sign) ) __STO; |
| else __CLO; |
| |
| } |
| |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| void inot_8( __mpu_uint8_t *c, __mpu_uint8_t *a ) |
| { |
| *c = ~(*a); |
| } |
| |
| void inot_16( __mpu_uint16_t *c, __mpu_uint16_t *a ) |
| { |
| *c = ~(*a); |
| } |
| |
| void inot_32( __mpu_uint32_t *c, __mpu_uint32_t *a ) |
| { |
| *c = ~(*a); |
| } |
| |
| void inot_np( EMUSHORT *c, EMUSHORT *a, int np ) |
| { |
| EMUSHORT *x, *y; |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"inot_np (emushort)" ); |
| return; |
| } |
| |
| x = a; y = c; |
| |
| i = np; |
| while( i > 0 ) |
| { |
| *y = ~(*x); |
| ++x; ++y; --i; |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| void ineg_8( __mpu_uint8_t *c, __mpu_uint8_t *a ) |
| { |
| __mpu_uint8_t inc = 1; |
| |
| inot_8( c, a ); |
| iadd_8( c, c, &inc ); |
| } |
| |
| void ineg_16( __mpu_uint16_t *c, __mpu_uint16_t *a ) |
| { |
| __mpu_uint16_t inc = 1; |
| |
| inot_16( c, a ); |
| iadd_16( c, c, &inc ); |
| } |
| |
| void ineg_32( __mpu_uint32_t *c, __mpu_uint32_t *a ) |
| { |
| __mpu_uint32_t inc = 1; |
| |
| inot_32( c, a ); |
| iadd_32( c, c, &inc ); |
| } |
| |
| void ineg_np( EMUSHORT *c, EMUSHORT *a, int np ) |
| { |
| EMUSHORT *inc = (EMUSHORT *)EMUSHORT_C( 0 ); |
| |
| errno = 0; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"ineg_np (emushort)" ); |
| return; |
| } |
| |
| |
| inc = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) ); |
| if( !inc ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)inc, 0, np*SIZE_OF_EMUSHORT ); |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(inc + np - 1) = (EMUSHORT) 1; |
| #else |
| *inc = (EMUSHORT) 1; |
| #endif |
| |
| |
| inot_np( c, a, np ); |
| iadd_np( c, c, inc, np ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| void iand_8( __mpu_uint8_t *c, __mpu_uint8_t *a, __mpu_uint8_t *b ) |
| { |
| |
| __CLEAR_IFLAGS; |
| |
| *c = *a & *b; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x80 ) __STS; |
| |
| if( __MPARITY(*c) ) __STP; |
| } |
| |
| void iand_16( __mpu_uint16_t *c, __mpu_uint16_t *a, __mpu_uint16_t *b ) |
| { |
| |
| __CLEAR_IFLAGS; |
| |
| *c = *a & *b; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x8000 ) __STS; |
| |
| if( __MPARITY(*c) ) __STP; |
| } |
| |
| void iand_32( __mpu_uint32_t *c, __mpu_uint32_t *a, __mpu_uint32_t *b ) |
| { |
| |
| __CLEAR_IFLAGS; |
| |
| *c = *a & *b; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x80000000 ) __STS; |
| |
| if( __MPARITY(*c) ) __STP; |
| } |
| |
| void iand_np( EMUSHORT *c, EMUSHORT *a, EMUSHORT *b, int np ) |
| { |
| EMUSHORT *x, *y; |
| signed int zero = 1; |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"iand_np (emushort)" ); |
| return; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| y = b; |
| |
| i = 0; |
| |
| c[i] = *x & *y; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( c[i] & MASK_SIGN ) __STS; |
| #endif |
| |
| if( c[i] ) zero &= 0; |
| else zero &= 1; |
| |
| ++x; ++y; ++i; |
| |
| while( i < np ) |
| { |
| c[i] = *x & *y; |
| |
| if( c[i] ) zero &= 0; |
| else zero &= 1; |
| |
| ++x; ++y; |
| ++i; |
| } |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| --i; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 0 |
| if( c[i] & MASK_SIGN ) __STS; |
| #endif |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| void itest_8( __mpu_uint8_t *a, __mpu_uint8_t *b ) |
| { |
| __mpu_uint8_t c; |
| |
| |
| __CLEAR_IFLAGS; |
| |
| c = *a & *b; |
| |
| if( c == 0 ) __STZ; |
| if( c & 0x80 ) __STS; |
| |
| if( __MPARITY(c) ) __STP; |
| } |
| |
| void itest_16( __mpu_uint16_t *a, __mpu_uint16_t *b ) |
| { |
| __mpu_uint16_t c; |
| |
| |
| __CLEAR_IFLAGS; |
| |
| c = *a & *b; |
| |
| if( c == 0 ) __STZ; |
| if( c & 0x8000 ) __STS; |
| |
| if( __MPARITY(c) ) __STP; |
| } |
| |
| void itest_32( __mpu_uint32_t *a, __mpu_uint32_t *b ) |
| { |
| __mpu_uint32_t c; |
| |
| |
| __CLEAR_IFLAGS; |
| |
| c = *a & *b; |
| |
| if( c == 0 ) __STZ; |
| if( c & 0x80000000 ) __STS; |
| |
| if( __MPARITY(c) ) __STP; |
| } |
| |
| void itest_np( EMUSHORT *a, EMUSHORT *b, int np ) |
| { |
| EMUSHORT *x, *y, c; |
| signed int zero = 1; |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"itest_np (emushort)" ); |
| return; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| y = b; |
| |
| i = 0; |
| |
| c = *x & *y; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( c & MASK_SIGN ) __STS; |
| #endif |
| |
| if( c ) zero &= 0; |
| else zero &= 1; |
| |
| ++x; ++y; ++i; |
| |
| while( i < np ) |
| { |
| c = *x & *y; |
| |
| if( c ) zero &= 0; |
| else zero &= 1; |
| |
| ++x; ++y; |
| ++i; |
| } |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 0 |
| if( c & MASK_SIGN ) __STS; |
| #endif |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void icmp_8( __mpu_uint8_t *a, __mpu_uint8_t *b ) |
| { |
| __mpu_uint16_t rc, op1, op2; |
| __mpu_uint8_t c; |
| signed int carry, sign = 0; |
| |
| __CLEAR_IFLAGS; |
| |
| carry = __MFLAG(CF); |
| |
| |
| rc = ((__mpu_uint16_t) (*a) & 0x0f) - |
| ((__mpu_uint16_t) (*b) & 0x0f) - carry; |
| if( rc & 0x10 ) __STA; |
| |
| |
| rc = (__mpu_uint16_t) (*a) - |
| (__mpu_uint16_t) (*b) - carry; |
| if( rc & 0x100 ) __STC; |
| else __CLC; |
| |
| if( __MPARITY(rc) ) __STP; |
| |
| |
| op1 = (__mpu_uint16_t) (*a); |
| op2 = (__mpu_uint16_t) (*b); |
| if( op1 & 0x80 ) op1 |= 0x100; |
| if( op2 & 0x80 ) op2 |= 0x100; |
| |
| rc = op1 - op2 - carry; |
| if( rc & 0x100 ) carry = 1; |
| else carry = 0; |
| if( rc & 0x80 ) sign = 1; |
| |
| if((!carry && sign) || (carry && !sign)) __STO; |
| if( sign ) __STS; |
| else __CLS; |
| |
| c = (__mpu_uint8_t) rc; |
| if( c == 0 ) __STZ; |
| } |
| |
| |
| void icmp_16( __mpu_uint16_t *a, __mpu_uint16_t *b ) |
| { |
| __mpu_uint32_t rc, op1, op2; |
| __mpu_uint16_t c; |
| signed int carry, sign = 0; |
| |
| __CLEAR_IFLAGS; |
| |
| carry = __MFLAG(CF); |
| |
| |
| rc = ((__mpu_uint32_t) (*a) & 0x0f) - |
| ((__mpu_uint32_t) (*b) & 0x0f) - carry; |
| if( rc & 0x10 ) __STA; |
| |
| |
| rc = (__mpu_uint32_t) (*a) - |
| (__mpu_uint32_t) (*b) - carry; |
| if( rc & 0x10000 ) __STC; |
| else __CLC; |
| |
| if( __MPARITY(rc) ) __STP; |
| |
| |
| op1 = (__mpu_uint32_t) (*a); |
| op2 = (__mpu_uint32_t) (*b); |
| if( op1 & 0x8000 ) op1 |= 0x10000; |
| if( op2 & 0x8000 ) op2 |= 0x10000; |
| |
| rc = op1 - op2 - carry; |
| if( rc & 0x10000 ) carry = 1; |
| else carry = 0; |
| if( rc & 0x8000 ) sign = 1; |
| |
| if((!carry && sign) || (carry && !sign)) __STO; |
| if( sign ) __STS; |
| else __CLS; |
| |
| c = (__mpu_uint16_t) rc; |
| if( c == 0 ) __STZ; |
| } |
| |
| |
| void icmp_32( __mpu_uint32_t *a, __mpu_uint32_t *b ) |
| { |
| __mpu_uint64_t rc, op1, op2; |
| __mpu_uint32_t c; |
| signed int carry, sign = 0; |
| |
| __CLEAR_IFLAGS; |
| |
| carry = __MFLAG(CF); |
| |
| |
| rc = ((__mpu_uint64_t) (*a) & 0x0f) - |
| ((__mpu_uint64_t) (*b) & 0x0f) - carry; |
| if( rc & 0x10 ) __STA; |
| |
| |
| rc = (__mpu_uint64_t) (*a) - |
| (__mpu_uint64_t) (*b) - carry; |
| if( rc & 0x100000000 ) __STC; |
| else __CLC; |
| |
| |
| op1 = (__mpu_uint64_t) (*a); |
| op2 = (__mpu_uint64_t) (*b); |
| if( op1 & 0x80000000 ) op1 |= 0x100000000; |
| if( op2 & 0x80000000 ) op2 |= 0x100000000; |
| |
| rc = op1 - op2 - carry; |
| if( rc & 0x100000000 ) carry = 1; |
| else carry = 0; |
| if( rc & 0x80000000 ) sign = 1; |
| |
| if((!carry && sign) || (carry && !sign)) __STO; |
| if( sign ) __STS; |
| else __CLS; |
| |
| c = (__mpu_uint32_t) rc; |
| if( c == 0 ) __STZ; |
| } |
| |
| |
| void icmp_np( EMUSHORT *a, EMUSHORT *b, int np ) |
| { |
| EMULONG rc, op1, op2; |
| EMUSHORT *x, *y; |
| EMUSHORT c; |
| signed int carry, sign = 0, zero = 0; |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"icmp_np (emushort)" ); |
| return; |
| } |
| |
| __CLEAR_IFLAGS; |
| |
| carry = __MFLAG(CF); |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1; |
| y = b + np - 1; |
| i = np - 1; |
| #else |
| x = a; |
| y = b; |
| i = 0; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| while( i > 0 ) |
| #else |
| while( i < np - 1 ) |
| #endif |
| { |
| rc = (EMULONG) (*x) - |
| (EMULONG) (*y) - __MFLAG(CF); |
| if( rc & MASK_CARRY ) __STC; |
| else __CLC; |
| c = (EMUSHORT) rc; |
| if( c ) zero |= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; --y; --i; |
| #else |
| ++x; ++y; ++i; |
| #endif |
| } |
| |
| carry = __MFLAG(CF); |
| |
| |
| rc = (EMULONG) (*x) - |
| (EMULONG) (*y) - carry; |
| if( rc & MASK_CARRY ) __STC; |
| else __CLC; |
| |
| |
| op1 = (EMULONG) (*x); |
| op2 = (EMULONG) (*y); |
| if( op1 & MASK_SIGN ) op1 |= MASK_CARRY; |
| if( op2 & MASK_SIGN ) op2 |= MASK_CARRY; |
| |
| rc = op1 - op2 - carry; |
| if( rc & MASK_CARRY ) carry = 1; |
| else carry = 0; |
| if( rc & MASK_SIGN ) sign = 1; |
| |
| if((!carry && sign) || (carry && !sign)) __STO; |
| if( sign ) __STS; |
| else __CLS; |
| |
| c = (EMUSHORT) rc; |
| if( c ) zero |= 1; |
| zero ^= 1; |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| void ior_8( __mpu_uint8_t *c, __mpu_uint8_t *a, __mpu_uint8_t *b ) |
| { |
| |
| __CLEAR_IFLAGS; |
| |
| *c = *a | *b; |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x80 ) __STS; |
| } |
| |
| void ior_16( __mpu_uint16_t *c, __mpu_uint16_t *a, __mpu_uint16_t *b ) |
| { |
| |
| __CLEAR_IFLAGS; |
| |
| *c = *a | *b; |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x8000 ) __STS; |
| } |
| |
| void ior_32( __mpu_uint32_t *c, __mpu_uint32_t *a, __mpu_uint32_t *b ) |
| { |
| |
| __CLEAR_IFLAGS; |
| |
| *c = *a | *b; |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x80000000 ) __STS; |
| } |
| |
| void ior_np( EMUSHORT *c, EMUSHORT *a, EMUSHORT *b, int np ) |
| { |
| EMUSHORT *x, *y; |
| signed int zero = 1; |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"ior_np (emushort)" ); |
| return; |
| } |
| |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| y = b; |
| |
| i = 0; |
| |
| c[i] = *x | *y; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( c[i] & MASK_SIGN ) __STS; |
| #endif |
| |
| if( c[i] ) zero &= 0; |
| else zero &= 1; |
| |
| ++x; ++y; ++i; |
| |
| while( i < np ) |
| { |
| c[i] = *x | *y; |
| |
| if( c[i] ) zero &= 0; |
| else zero &= 1; |
| |
| ++x; ++y; ++i; |
| } |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| --i; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 0 |
| if( c[i] & MASK_SIGN ) __STS; |
| #endif |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| void ixor_8( __mpu_uint8_t *c, __mpu_uint8_t *a, __mpu_uint8_t *b ) |
| { |
| |
| __CLEAR_IFLAGS; |
| |
| *c = *a ^ *b; |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x80 ) __STS; |
| } |
| |
| void ixor_16( __mpu_uint16_t *c, __mpu_uint16_t *a, __mpu_uint16_t *b ) |
| { |
| |
| __CLEAR_IFLAGS; |
| |
| *c = *a ^ *b; |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x8000 ) __STS; |
| } |
| |
| void ixor_32( __mpu_uint32_t *c, __mpu_uint32_t *a, __mpu_uint32_t *b ) |
| { |
| |
| __CLEAR_IFLAGS; |
| |
| *c = *a ^ *b; |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x80000000 ) __STS; |
| } |
| |
| void ixor_np( EMUSHORT *c, EMUSHORT *a, EMUSHORT *b, int np ) |
| { |
| EMUSHORT *x, *y; |
| signed int zero = 1; |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"ior_np (emushort)" ); |
| return; |
| } |
| |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| y = b; |
| |
| i = 0; |
| |
| c[i] = *x ^ *y; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( c[i] & MASK_SIGN ) __STS; |
| #endif |
| |
| if( c[i] ) zero &= 0; |
| else zero &= 1; |
| |
| ++x; ++y; ++i; |
| |
| while( i < np ) |
| { |
| c[i] = *x ^ *y; |
| |
| if( c[i] ) zero &= 0; |
| else zero &= 1; |
| |
| ++x; ++y; ++i; |
| } |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| --i; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 0 |
| if( c[i] & MASK_SIGN ) __STS; |
| #endif |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| void iinc_8( __mpu_uint8_t *c, __mpu_uint8_t *a ) |
| { |
| __mpu_uint8_t inc = 1; |
| signed int save_carry; |
| |
| save_carry = __MFLAG(CF); |
| iadd_8( c, a, &inc ); |
| if( save_carry ) __STC; |
| else __CLC; |
| } |
| |
| void iinc_16( __mpu_uint16_t *c, __mpu_uint16_t *a ) |
| { |
| __mpu_uint16_t inc = 1; |
| signed int save_carry; |
| |
| save_carry = __MFLAG(CF); |
| iadd_16( c, a, &inc ); |
| if( save_carry ) __STC; |
| else __CLC; |
| } |
| |
| void iinc_32( __mpu_uint32_t *c, __mpu_uint32_t *a ) |
| { |
| __mpu_uint32_t inc = 1; |
| signed int save_carry; |
| |
| save_carry = __MFLAG(CF); |
| iadd_32( c, a, &inc ); |
| if( save_carry ) __STC; |
| else __CLC; |
| } |
| |
| void iinc_np( EMUSHORT *c, EMUSHORT *a, int np ) |
| { |
| EMUSHORT *inc = (EMUSHORT *)EMUSHORT_C( 0 ); |
| signed int save_carry; |
| |
| errno = 0; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"iinc_np (emushort)" ); |
| return; |
| } |
| |
| |
| inc = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) ); |
| if( !inc ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)inc, 0, np*SIZE_OF_EMUSHORT ); |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(inc + np - 1) = (EMUSHORT) 1; |
| #else |
| *inc = (EMUSHORT) 1; |
| #endif |
| |
| |
| save_carry = __MFLAG(CF); |
| iadd_np( c, a, inc, np ); |
| if( save_carry ) __STC; |
| else __CLC; |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| void idec_8( __mpu_uint8_t *c, __mpu_uint8_t *a ) |
| { |
| __mpu_uint8_t dec = 1; |
| signed int save_carry; |
| |
| save_carry = __MFLAG(CF); |
| isub_8( c, a, &dec ); |
| if( save_carry ) __STC; |
| else __CLC; |
| } |
| |
| void idec_16( __mpu_uint16_t *c, __mpu_uint16_t *a ) |
| { |
| __mpu_uint16_t dec = 1; |
| signed int save_carry; |
| |
| save_carry = __MFLAG(CF); |
| isub_16( c, a, &dec ); |
| if( save_carry ) __STC; |
| else __CLC; |
| } |
| |
| void idec_32( __mpu_uint32_t *c, __mpu_uint32_t *a ) |
| { |
| __mpu_uint32_t dec = 1; |
| signed int save_carry; |
| |
| save_carry = __MFLAG(CF); |
| isub_32( c, a, &dec ); |
| if( save_carry ) __STC; |
| else __CLC; |
| } |
| |
| void idec_np( EMUSHORT *c, EMUSHORT *a, int np ) |
| { |
| EMUSHORT *dec = (EMUSHORT *)EMUSHORT_C( 0 ); |
| signed int save_carry; |
| |
| errno = 0; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"idec_np (emushort)" ); |
| return; |
| } |
| |
| |
| dec = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) ); |
| if( !dec ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)dec, 0, np*SIZE_OF_EMUSHORT ); |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(dec + np - 1) = (EMUSHORT) 1; |
| #else |
| *dec = (EMUSHORT) 1; |
| #endif |
| |
| |
| save_carry = __MFLAG(CF); |
| isub_np( c, a, dec, np ); |
| if( save_carry ) __STC; |
| else __CLC; |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void icpy_8( __mpu_uint8_t *c, __mpu_uint8_t *a ) |
| { |
| |
| |
| __CLEAR_IFLAGS; |
| |
| *c = *a; |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x80 ) __STS; |
| |
| } |
| |
| void icpy_16( __mpu_uint16_t *c, __mpu_uint16_t *a ) |
| { |
| |
| |
| __CLEAR_IFLAGS; |
| |
| *c = *a; |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x8000 ) __STS; |
| |
| } |
| |
| void icpy_32( __mpu_uint32_t *c, __mpu_uint32_t *a ) |
| { |
| |
| |
| __CLEAR_IFLAGS; |
| |
| *c = *a; |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x80000000 ) __STS; |
| |
| } |
| |
| static void scpy_s2s_np( EMUSHORT *c, EMUSHORT *a, int np ) |
| { |
| EMUSHORT *x; |
| signed int zero = 1; |
| signed int i; |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| x = a; |
| i = 0; |
| |
| c[i] = *x; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( c[i] & MASK_SIGN ) __STS; |
| #endif |
| |
| if( c[i] ) zero &= 0; |
| else zero &= 1; |
| |
| ++x; ++i; |
| |
| while( i < np ) |
| { |
| c[i] = *x; |
| |
| if( c[i] ) zero &= 0; |
| else zero &= 1; |
| |
| ++x; ++i; |
| } |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| --i; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 0 |
| if( c[i] & MASK_SIGN ) __STS; |
| #endif |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| void icpy_s2l_8to16( __mpu_uint16_t *c, __mpu_uint8_t *a ) |
| { |
| |
| |
| __CLEAR_IFLAGS; |
| |
| *c = (__mpu_uint16_t)*a; |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| } |
| |
| void icpy_s2l_8to32( __mpu_uint32_t *c, __mpu_uint8_t *a ) |
| { |
| |
| |
| __CLEAR_IFLAGS; |
| |
| *c = (__mpu_uint32_t)*a; |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| } |
| |
| void icpy_s2l_8to_np( EMUSHORT *c, __mpu_uint8_t *a, int np ) |
| { |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"icpy_s2l_8to_np (to emushort)" ); |
| return; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| i = np - 1; |
| #else |
| i = 0; |
| #endif |
| |
| c[i] = (EMUSHORT)*a; |
| |
| if( c[i] == 0 ) __STZ; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --i; |
| while( i > 0 ) |
| { |
| c[i] = (EMUSHORT)0; |
| --i; |
| } |
| c[i] = (EMUSHORT)0; |
| #else |
| ++i; |
| while( i < np ) |
| { |
| c[i] = (EMUSHORT)0; |
| ++i; |
| } |
| #endif |
| } |
| |
| |
| |
| |
| void icpy_s2l_16to32( __mpu_uint32_t *c, __mpu_uint16_t *a ) |
| { |
| |
| |
| __CLEAR_IFLAGS; |
| |
| *c = (__mpu_uint32_t)*a; |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| } |
| |
| void icpy_s2l_16to_np( EMUSHORT *c, __mpu_uint16_t *a, int np ) |
| { |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"icpy_s2l_16to_np (to emushort)" ); |
| return; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| i = np - 1; |
| #else |
| i = 0; |
| #endif |
| |
| c[i] = (EMUSHORT)*a; |
| |
| if( c[i] == 0 ) __STZ; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --i; |
| while( i > 0 ) |
| { |
| c[i] = (EMUSHORT)0; |
| --i; |
| } |
| c[i] = (EMUSHORT)0; |
| #else |
| ++i; |
| while( i < np ) |
| { |
| c[i] = (EMUSHORT)0; |
| ++i; |
| } |
| #endif |
| } |
| |
| |
| |
| |
| #if BITS_PER_EMUSHORT > 32 |
| void icpy_s2l_32to_np( EMUSHORT *c, __mpu_uint32_t *a, int np ) |
| { |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"icpy_s2l_32to_np (to emushort)" ); |
| return; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| i = np - 1; |
| #else |
| i = 0; |
| #endif |
| |
| c[i] = (EMUSHORT)*a; |
| |
| if( c[i] == 0 ) __STZ; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --i; |
| while( i > 0 ) |
| { |
| c[i] = (EMUSHORT)0; |
| --i; |
| } |
| c[i] = (EMUSHORT)0; |
| #else |
| ++i; |
| while( i < np ) |
| { |
| c[i] = (EMUSHORT)0; |
| ++i; |
| } |
| #endif |
| } |
| #endif |
| |
| |
| |
| |
| static void scpy_s2l_np( EMUSHORT *c, EMUSHORT *a, int np_c, int np_a ) |
| { |
| EMUSHORT *x; |
| signed int zero = 1; |
| signed int i; |
| |
| if( np_c <= np_a || np_c < 1 || np_c > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"scpy_s2l_np (emushort to emushort)" ); |
| return; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np_a - 1; |
| i = np_c - 1; |
| #else |
| x = a; |
| i = 0; |
| #endif |
| |
| c[i] = *x; |
| |
| if( c[i] ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; --i; |
| |
| while( i >= (np_c - np_a) ) |
| { |
| c[i]= *x; |
| |
| if( c[i] ) zero &= 0; |
| else zero &= 1; |
| |
| --x; --i; |
| } |
| #else |
| ++x; ++i; |
| while( i < np_a ) |
| { |
| c[i]= *x; |
| |
| if( c[i] ) zero &= 0; |
| else zero &= 1; |
| |
| ++x; ++i; |
| } |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| while( i > 0 ) |
| { |
| c[i] = (EMUSHORT)0; |
| --i; |
| } |
| c[i] = (EMUSHORT)0; |
| #else |
| while( i < np_c ) |
| { |
| c[i] = (EMUSHORT)0; |
| ++i; |
| } |
| #endif |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| void icpy_l2s_16to8( __mpu_uint8_t *c, __mpu_uint16_t *a ) |
| { |
| __mpu_uint16_t x; |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| x = *a; |
| |
| x >>= 8; |
| if( x ) __STO; |
| |
| *c = (__mpu_uint8_t)*a; |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x80 ) __STS; |
| } |
| |
| void icpy_l2s_32to8( __mpu_uint8_t *c, __mpu_uint32_t *a ) |
| { |
| __mpu_uint32_t x; |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| x = *a; |
| |
| x >>= 8; |
| if( x ) __STO; |
| |
| *c = (__mpu_uint8_t)*a; |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x80 ) __STS; |
| } |
| |
| void icpy_l2s_np_to8( __mpu_uint8_t *c, EMUSHORT *a, int np ) |
| { |
| EMUSHORT y, *x; |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"icpy_l2s_np_to8 (from emushort)" ); |
| return; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1; |
| #else |
| x = a; |
| #endif |
| y = *x; |
| |
| y >>= 8; |
| if( y ) __STO; |
| |
| *c = (__mpu_uint8_t)*x; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; |
| #else |
| ++x; |
| #endif |
| i = np - 1; |
| while( i > 0 ) |
| { |
| if( *x ) __STO; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; |
| #else |
| ++x; |
| #endif |
| --i; |
| } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x80 ) __STS; |
| } |
| |
| |
| |
| |
| void icpy_l2s_32to16( __mpu_uint16_t *c, __mpu_uint32_t *a ) |
| { |
| __mpu_uint32_t x; |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| x = *a; |
| |
| x >>= 16; |
| if( x ) __STO; |
| |
| *c = (__mpu_uint16_t)*a; |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x8000 ) __STS; |
| } |
| |
| void icpy_l2s_np_to16( __mpu_uint16_t *c, EMUSHORT *a, int np ) |
| { |
| EMUSHORT y, *x; |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"icpy_l2s_np_to16 (from emushort)" ); |
| return; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1; |
| #else |
| x = a; |
| #endif |
| y = *x; |
| |
| y >>= 16; |
| if( y ) __STO; |
| |
| *c = (__mpu_uint16_t)*x; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; |
| #else |
| ++x; |
| #endif |
| i = np - 1; |
| while( i > 0 ) |
| { |
| if( *x ) __STO; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; |
| #else |
| ++x; |
| #endif |
| --i; |
| } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x8000 ) __STS; |
| } |
| |
| |
| |
| |
| #if BITS_PER_EMUSHORT > 32 |
| void icpy_l2s_np_to32( __mpu_uint32_t *c, EMUSHORT *a, int np ) |
| { |
| EMUSHORT y, *x; |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"icpy_l2s_np_to32 (from emushort)" ); |
| return; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1; |
| #else |
| x = a; |
| #endif |
| y = *x; |
| |
| y >>= 32; |
| if( y ) __STO; |
| |
| *c = (__mpu_uint32_t)*x; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; |
| #else |
| ++x; |
| #endif |
| i = np - 1; |
| while( i > 0 ) |
| { |
| if( *x ) __STO; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; |
| #else |
| ++x; |
| #endif |
| --i; |
| } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| if( *c & 0x80000000 ) __STS; |
| } |
| #endif |
| |
| |
| |
| |
| static void scpy_l2s_np( EMUSHORT *c, EMUSHORT *a, int np_c, int np_a ) |
| { |
| EMUSHORT *y, *x; |
| signed int zero = 1; |
| signed int i; |
| |
| if( np_a < np_c || np_a < 1 || np_a > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"scpy_l2s_np (emushort to emushort)" ); |
| return; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np_a - 1; |
| y = c + np_c - 1; |
| #else |
| x = a; |
| y = c; |
| #endif |
| |
| *y = *x; |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; --y; |
| #else |
| ++x; ++y; |
| #endif |
| i = 1; |
| while( i < np_c ) |
| { |
| *y = *x; |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; --y; |
| #else |
| ++x; ++y; |
| #endif |
| ++i; |
| } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++y; |
| #else |
| --y; |
| #endif |
| if( *y & MASK_SIGN ) __STS; |
| |
| while( i < np_a ) |
| { |
| if( *x ) __STO; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; |
| #else |
| ++x; |
| #endif |
| ++i; |
| } |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| } |
| |
| |
| |
| |
| void icpy_np( EMUSHORT *c, EMUSHORT *a, int np_c, int np_a ) |
| { |
| if( np_a < 1 || np_c < 1 || np_a > NP_MAX || np_c > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"icpy_np (emushort)" ); |
| return; |
| } |
| |
| if( np_c > np_a ) |
| { |
| scpy_s2l_np( c, a, np_c, np_a ); |
| return; |
| } |
| |
| if( np_c < np_a ) |
| { |
| scpy_l2s_np( c, a, np_c, np_a ); |
| return; |
| } |
| |
| if( np_c == np_a ) |
| { |
| scpy_s2s_np( c, a, np_a ); |
| return; |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void icvt_s2l_8to16( __mpu_uint16_t *c, __mpu_uint8_t *a ) |
| { |
| |
| |
| __CLEAR_IFLAGS; |
| |
| *c = (__mpu_uint16_t)*a; |
| |
| if( *a & 0x80 ) { *c |= 0xff00; __STS; } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| } |
| |
| void icvt_s2l_8to32( __mpu_uint32_t *c, __mpu_uint8_t *a ) |
| { |
| |
| |
| __CLEAR_IFLAGS; |
| |
| *c = (__mpu_uint32_t)*a; |
| |
| if( *a & 0x80 ) { *c |= 0xffffff00; __STS; } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| } |
| |
| void icvt_s2l_8to_np( EMUSHORT *c, __mpu_uint8_t *a, int np ) |
| { |
| EMUSHORT save_sign = 0; |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"icvt_s2l_8to_np (to emushort)" ); |
| return; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| i = np - 1; |
| #else |
| i = 0; |
| #endif |
| |
| c[i] = (EMUSHORT)*a; |
| |
| if( *a & 0x80 ) |
| { |
| save_sign = (EMUSHORT)MASK_ALL_BITS; |
| c[i] |= (save_sign << 8); |
| __STS; |
| } |
| |
| if( c[i] == 0 ) __STZ; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --i; |
| while( i > 0 ) |
| { |
| c[i] = save_sign; |
| --i; |
| } |
| c[i] = save_sign; |
| #else |
| ++i; |
| while( i < np ) |
| { |
| c[i] = save_sign; |
| ++i; |
| } |
| #endif |
| } |
| |
| |
| |
| |
| void icvt_s2l_16to32( __mpu_uint32_t *c, __mpu_uint16_t *a ) |
| { |
| |
| |
| __CLEAR_IFLAGS; |
| |
| *c = (__mpu_uint32_t)*a; |
| |
| if( *a & 0x8000 ) { *c |= 0xffff0000; __STS; } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| } |
| |
| void icvt_s2l_16to_np( EMUSHORT *c, __mpu_uint16_t *a, int np ) |
| { |
| EMUSHORT save_sign = 0; |
| signed int i; |
| |
| if( np == 0 ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"icvt_s2l_16to_np (to emushort)" ); |
| return; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| i = np - 1; |
| #else |
| i = 0; |
| #endif |
| |
| c[i] = (EMUSHORT)*a; |
| |
| if( *a & 0x8000 ) |
| { |
| save_sign = (EMUSHORT)MASK_ALL_BITS; |
| c[i] |= (save_sign << 16); |
| __STS; |
| } |
| |
| if( c[i] == 0 ) __STZ; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --i; |
| while( i > 0 ) |
| { |
| c[i] = save_sign; |
| --i; |
| } |
| c[i] = save_sign; |
| #else |
| ++i; |
| while( i < np ) |
| { |
| c[i] = save_sign; |
| ++i; |
| } |
| #endif |
| } |
| |
| #if BITS_PER_EMUSHORT > 32 |
| |
| |
| |
| void icvt_s2l_32to_np( EMUSHORT *c, __mpu_uint32_t *a, int np ) |
| { |
| EMUSHORT save_sign = 0; |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"icvt_s2l_32to_np (to emushort)" ); |
| return; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| i = np - 1; |
| #else |
| i = 0; |
| #endif |
| |
| c[i] = (EMUSHORT)*a; |
| |
| if( *a & 0x80000000 ) |
| { |
| save_sign = (EMUSHORT)MASK_ALL_BITS; |
| c[i] |= (save_sign << 32); |
| __STS; |
| } |
| |
| if( c[i] == 0 ) __STZ; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --i; |
| while( i > 0 ) |
| { |
| c[i] = save_sign; |
| --i; |
| } |
| c[i] = save_sign; |
| #else |
| ++i; |
| while( i < np ) |
| { |
| c[i] = save_sign; |
| ++i; |
| } |
| #endif |
| } |
| #endif |
| |
| |
| |
| |
| static void scvt_s2l_np( EMUSHORT *c, EMUSHORT *a, int np_c, int np_a ) |
| { |
| EMUSHORT *x, save_sign = 0; |
| signed int zero = 1; |
| signed int i; |
| |
| if( np_c <= np_a || np_c < 1 || np_c > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"scvt_s2l_np (emushort to emushort)" ); |
| return; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np_a - 1; |
| i = np_c - 1; |
| #else |
| x = a; |
| i = 0; |
| #endif |
| |
| c[i] = *x; |
| |
| if( c[i] ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; --i; |
| |
| while( i >= (np_c - np_a) ) |
| { |
| c[i]= *x; |
| |
| if( c[i] ) zero &= 0; |
| else zero &= 1; |
| |
| --x; --i; |
| } |
| #else |
| ++x; ++i; |
| while( i < np_a ) |
| { |
| c[i]= *x; |
| |
| if( c[i] ) zero &= 0; |
| else zero &= 1; |
| |
| ++x; ++i; |
| } |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++x; |
| #else |
| --x; |
| #endif |
| if( *x & MASK_SIGN ) |
| { |
| save_sign = (EMUSHORT)MASK_ALL_BITS; |
| __STS; |
| zero &= 0; |
| } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| while( i > 0 ) |
| { |
| c[i] = save_sign; |
| --i; |
| } |
| c[i] = save_sign; |
| #else |
| while( i < np_c ) |
| { |
| c[i] = save_sign; |
| ++i; |
| } |
| #endif |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| void icvt_l2s_16to8( __mpu_uint8_t *c, __mpu_uint16_t *a ) |
| { |
| __mpu_uint16_t x; |
| signed int sign = 0, save_sign = 0; |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| x = *a; |
| if( x & 0x8000 ) save_sign = 1; |
| if( x & 0x80 ) sign = 1; |
| |
| x &= 0xff00; |
| if( !(( save_sign && sign && (x == 0xff00)) || |
| (!save_sign && !sign && (x == 0)) |
| ) |
| ) __STO; |
| |
| *c = (__mpu_uint8_t)*a; |
| |
| if( save_sign ) *c |= 0x80; |
| else *c &= 0x7f; |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| if( *c == 0 ) __STZ; |
| } |
| |
| void icvt_l2s_32to8( __mpu_uint8_t *c, __mpu_uint32_t *a ) |
| { |
| __mpu_uint32_t x; |
| signed int sign = 0, save_sign = 0; |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| x = *a; |
| if( x & 0x80000000 ) save_sign = 1; |
| if( x & 0x80 ) sign = 1; |
| |
| x &= 0xffffff00; |
| if( !(( save_sign && sign && (x == 0xffffff00)) || |
| (!save_sign && !sign && (x == 0)) |
| ) |
| ) __STO; |
| |
| *c = (__mpu_uint8_t)*a; |
| |
| if( save_sign ) *c |= 0x80; |
| else *c &= 0x7f; |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| if( *c == 0 ) __STZ; |
| } |
| |
| void icvt_l2s_np_to8( __mpu_uint8_t *c, EMUSHORT *a, int np ) |
| { |
| EMUSHORT y, *x; |
| signed int sign = 0, save_sign = 0; |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"icvt_l2s_np_to8 (from emushort)" ); |
| return; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a; |
| #else |
| x = a + np - 1; |
| #endif |
| if( *x & MASK_SIGN ) save_sign = 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1; |
| #else |
| x = a; |
| #endif |
| y = *x; |
| if( y & 0x80 ) sign = 1; |
| |
| y &= ((EMUSHORT)MASK_ALL_BITS) << 8; |
| if( !(( save_sign && sign && |
| (y == (((EMUSHORT)MASK_ALL_BITS) << 8))) || |
| (!save_sign && !sign && (y == 0)) |
| ) |
| ) __STO; |
| |
| *c = (__mpu_uint8_t)*x; |
| |
| if( save_sign ) *c |= 0x80; |
| else *c &= 0x7f; |
| |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; |
| #else |
| ++x; |
| #endif |
| i = np - 1; |
| while( i > 0 ) |
| { |
| if( !(( save_sign && sign && |
| (*x == ((EMUSHORT)MASK_ALL_BITS))) || |
| (!save_sign && !sign && (*x == 0)) |
| ) |
| ) __STO; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; |
| #else |
| ++x; |
| #endif |
| --i; |
| } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| } |
| |
| |
| |
| |
| void icvt_l2s_32to16( __mpu_uint16_t *c, __mpu_uint32_t *a ) |
| { |
| __mpu_uint32_t x; |
| signed int sign = 0, save_sign = 0; |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| x = *a; |
| if( x & 0x80000000 ) save_sign = 1; |
| if( x & 0x8000 ) sign = 1; |
| |
| x &= 0xffff0000; |
| if( !(( save_sign && sign && (x == 0xffff0000)) || |
| (!save_sign && !sign && (x == 0)) |
| ) |
| ) __STO; |
| |
| *c = (__mpu_uint16_t)*a; |
| |
| if( save_sign ) *c |= 0x8000; |
| else *c &= 0x7fff; |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| if( *c == 0 ) __STZ; |
| } |
| |
| void icvt_l2s_np_to16( __mpu_uint16_t *c, EMUSHORT *a, int np ) |
| { |
| EMUSHORT y, *x; |
| signed int sign = 0, save_sign = 0; |
| signed int i; |
| |
| if( np == 0 ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"icvt_l2s_np_to16 (from emushort)" ); |
| return; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a; |
| #else |
| x = a + np - 1; |
| #endif |
| if( *x & MASK_SIGN ) save_sign = 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1; |
| #else |
| x = a; |
| #endif |
| y = *x; |
| if( y & 0x8000 ) sign = 1; |
| |
| y &= ((EMUSHORT)MASK_ALL_BITS) << 16; |
| if( !(( save_sign && sign && |
| (y == (((EMUSHORT)MASK_ALL_BITS) << 16))) || |
| (!save_sign && !sign && (y == 0)) |
| ) |
| ) __STO; |
| |
| *c = (__mpu_uint16_t)*x; |
| |
| if( save_sign ) *c |= 0x8000; |
| else *c &= 0x7fff; |
| |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; |
| #else |
| ++x; |
| #endif |
| i = np - 1; |
| while( i > 0 ) |
| { |
| if( !(( save_sign && sign && |
| (*x == ((EMUSHORT)MASK_ALL_BITS))) || |
| (!save_sign && !sign && (*x == 0)) |
| ) |
| ) __STO; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; |
| #else |
| ++x; |
| #endif |
| --i; |
| } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| } |
| |
| |
| |
| |
| #if BITS_PER_EMUSHORT > 32 |
| void icvt_l2s_np_to32( __mpu_uint32_t *c, EMUSHORT *a, int np ) |
| { |
| EMUSHORT y, *x; |
| signed int sign = 0, save_sign = 0; |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"icvt_l2s_np_to32 (from emushort)" ); |
| return; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a; |
| #else |
| x = a + np - 1; |
| #endif |
| if( *x & MASK_SIGN ) save_sign = 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np - 1; |
| #else |
| x = a; |
| #endif |
| y = *x; |
| if( y & 0x80000000 ) sign = 1; |
| |
| y &= ((EMUSHORT)MASK_ALL_BITS) << 32; |
| if( !(( save_sign && sign && |
| (y == (((EMUSHORT)MASK_ALL_BITS) << 32))) || |
| (!save_sign && !sign && (y == 0)) |
| ) |
| ) __STO; |
| |
| *c = (__mpu_uint32_t)*x; |
| |
| if( save_sign ) *c |= 0x80000000; |
| else *c &= 0x7fffffff; |
| |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; |
| #else |
| ++x; |
| #endif |
| i = np - 1; |
| while( i > 0 ) |
| { |
| if( !(( save_sign && sign && |
| (*x == ((EMUSHORT)MASK_ALL_BITS))) || |
| (!save_sign && !sign && (*x == 0)) |
| ) |
| ) __STO; |
| |
| #if MPU_WORD_ORDER_ENDIAN == 1 |
| --x; |
| #else |
| ++x; |
| #endif |
| --i; |
| } |
| |
| if( __MPARITY(*c) ) __STP; |
| |
| if( *c == 0 ) __STZ; |
| } |
| #endif |
| |
| |
| |
| |
| static void scvt_l2s_np( EMUSHORT *c, EMUSHORT *a, int np_c, int np_a ) |
| { |
| EMUSHORT *y, *x; |
| signed int sign = 0, save_sign = 0, zero = 1; |
| signed int i; |
| |
| if( np_a < np_c || np_a < 1 || np_a > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"scvt_l2s_np (emushort to emushort)" ); |
| return; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a; |
| #else |
| x = a + np_a - 1; |
| #endif |
| if( *x & MASK_SIGN ) save_sign = 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = a + np_a - 1; |
| y = c + np_c - 1; |
| #else |
| x = a; |
| y = c; |
| #endif |
| |
| *y = *x; |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 0 |
| ++x; ++y; |
| #endif |
| i = 1; |
| while( i < np_c ) |
| { |
| *y = *x; |
| |
| if( *y ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; --y; |
| #else |
| ++x; ++y; |
| #endif |
| ++i; |
| } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++x; |
| #else |
| --x; |
| #endif |
| if( *x & MASK_SIGN ) sign = 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++y; |
| #else |
| --y; |
| #endif |
| if( save_sign ) |
| { |
| *y |= ((EMUSHORT)MASK_ALL_BITS) << |
| (BITS_PER_EMUSHORT-1); |
| zero &= 0; |
| } |
| else |
| { |
| *y &= ((EMUSHORT)MASK_ALL_BITS) >> 1; |
| zero &= 1; |
| } |
| |
| if( save_sign ) __STS; |
| else __CLS; |
| |
| while( i < np_a ) |
| { |
| if( !(( save_sign && sign && |
| (*x == ((EMUSHORT)MASK_ALL_BITS))) || |
| (!save_sign && !sign && (*x == 0)) |
| ) |
| ) __STO; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --x; |
| #else |
| ++x; |
| #endif |
| ++i; |
| } |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| } |
| |
| |
| |
| |
| void icvt_np( EMUSHORT *c, EMUSHORT *a, int np_c, int np_a ) |
| { |
| if( np_a < 1 || np_c < 1 || np_a > NP_MAX || np_c > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"icvt_np (emushort)" ); |
| return; |
| } |
| |
| if( np_c > np_a ) |
| { |
| scvt_s2l_np( c, a, np_c, np_a ); |
| return; |
| } |
| |
| if( np_c < np_a ) |
| { |
| scvt_l2s_np( c, a, np_c, np_a ); |
| return; |
| } |
| |
| if( np_c == np_a ) |
| { |
| scpy_s2s_np( c, a, np_a ); |
| return; |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| void ixchg_8( __mpu_uint8_t *a, __mpu_uint8_t *b ) |
| { |
| __mpu_uint8_t xchg; |
| |
| xchg = *a; |
| *a = *b; |
| *b = xchg; |
| } |
| |
| void ixchg_16( __mpu_uint16_t *a, __mpu_uint16_t *b ) |
| { |
| __mpu_uint16_t xchg; |
| |
| xchg = *a; |
| *a = *b; |
| *b = xchg; |
| } |
| |
| void ixchg_32( __mpu_uint32_t *a, __mpu_uint32_t *b ) |
| { |
| __mpu_uint32_t xchg; |
| |
| xchg = *a; |
| *a = *b; |
| *b = xchg; |
| } |
| |
| void ixchg_np( EMUSHORT *a, EMUSHORT *b, int np ) |
| { |
| EMUSHORT xchg, *y, *x; |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"ixchg_np (emushort)" ); |
| return; |
| } |
| |
| x = a; |
| y = b; |
| i = np; |
| |
| while( i > 0 ) |
| { |
| xchg = *x; |
| *x = *y; |
| *y = xchg; |
| |
| ++x; ++y; |
| --i; |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void imul_8( __mpu_uint16_t *prod, __mpu_uint8_t *num, __mpu_uint8_t *mul ) |
| { |
| __mpu_uint16_t pcpy = 0; |
| signed int i, k, shifts = 0; |
| |
| icpy_s2l_8to16( &pcpy, num ); |
| |
| *prod = 0; |
| |
| k = BITS_PER_BYTE; |
| |
| for( i = 0; i < k; ++i ) |
| { |
| if( (*mul >> ((i)&(BITS_PER_BYTE-1)))&1 ) |
| { |
| ishln_16( &pcpy, &pcpy, shifts ); |
| iadd_16( prod, prod, &pcpy ); |
| |
| shifts = 1; |
| } |
| else ++shifts; |
| |
| } |
| |
| __CLA; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| if( *prod >> 8 ) __STR; |
| else __CLR; |
| } |
| |
| void imul_16( __mpu_uint32_t *prod, __mpu_uint16_t *num, __mpu_uint16_t *mul ) |
| { |
| __mpu_uint32_t pcpy = 0; |
| signed int i, k, shifts = 0; |
| |
| icpy_s2l_16to32( &pcpy, num ); |
| |
| *prod = 0; |
| |
| k = BITS_PER_TWO_BYTES; |
| |
| for( i = 0; i < k; ++i ) |
| { |
| if( (*mul >> ((i)&(BITS_PER_TWO_BYTES-1)))&1 ) |
| { |
| ishln_32( &pcpy, &pcpy, shifts ); |
| iadd_32( prod, prod, &pcpy ); |
| |
| shifts = 1; |
| } |
| else ++shifts; |
| |
| } |
| |
| __CLA; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| if( *prod >> 16 ) __STR; |
| else __CLR; |
| } |
| |
| #if BITS_PER_EMUSHORT > 32 |
| void imul_32( __mpu_uint64_t *prod, __mpu_uint32_t *num, __mpu_uint32_t *mul ) |
| { |
| __mpu_uint64_t pcpy = 0; |
| signed int i, k, shifts = 0; |
| |
| icpy_s2l_32to_np( (EMUSHORT *)(&pcpy), num, 1 ); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| *prod = 0; |
| |
| k = BITS_PER_FOUR_BYTES; |
| |
| for( i = 0; i < k; ++i ) |
| { |
| if( (*mul >> ((i)&(BITS_PER_FOUR_BYTES-1)))&1 ) |
| { |
| ishln_np( (EMUSHORT *)(&pcpy), |
| (EMUSHORT *)(&pcpy), shifts, |
| 1 ); |
| iadd_np( (EMUSHORT *)prod, |
| (EMUSHORT *)prod, |
| (EMUSHORT *)(&pcpy), |
| 1 ); |
| |
| shifts = 1; |
| } |
| else ++shifts; |
| |
| } |
| |
| __CLA; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| if( *prod >> 32 ) __STR; |
| else __CLR; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| } |
| #endif |
| |
| |
| |
| |
| |
| |
| |
| void ismul_8( __mpu_uint16_t *prod, __mpu_uint8_t *num, __mpu_uint8_t *mul ) |
| { |
| __mpu_uint16_t pcpy_num = 0, pcpy_mul = 0; |
| signed int sign_num = 0, sign_mul = 0; |
| signed int i, k, shifts = 0; |
| |
| if( *num & 0x80 ) sign_num = 1; |
| if( *mul & 0x80 ) sign_mul = 1; |
| |
| icvt_s2l_8to16( &pcpy_num, num ); |
| icvt_s2l_8to16( &pcpy_mul, mul ); |
| |
| *prod = 0; |
| |
| if( sign_num ) ineg_16( &pcpy_num, &pcpy_num ); |
| if( sign_mul ) ineg_16( &pcpy_mul, &pcpy_mul ); |
| |
| k = BITS_PER_BYTE; |
| |
| for( i = 0; i < k; ++i ) |
| { |
| if( (pcpy_mul >> ((i)&(BITS_PER_BYTE-1)))&1 ) |
| { |
| ishln_16( &pcpy_num, &pcpy_num, shifts ); |
| iadd_16( prod, prod, &pcpy_num ); |
| |
| shifts = 1; |
| } |
| else ++shifts; |
| |
| } |
| |
| |
| if( *prod >> 7 ) __STR; |
| else __CLR; |
| |
| if( sign_num ^ sign_mul ) ineg_16( prod, prod ); |
| |
| __CLA; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| } |
| |
| void ismul_16( __mpu_uint32_t *prod, __mpu_uint16_t *num, __mpu_uint16_t *mul ) |
| { |
| __mpu_uint32_t pcpy_num = 0, pcpy_mul = 0; |
| signed int sign_num = 0, sign_mul = 0; |
| signed int i, k, shifts = 0; |
| |
| if( *num & 0x8000 ) sign_num = 1; |
| if( *mul & 0x8000 ) sign_mul = 1; |
| |
| icvt_s2l_16to32( &pcpy_num, num ); |
| icvt_s2l_16to32( &pcpy_mul, mul ); |
| |
| *prod = 0; |
| |
| if( sign_num ) ineg_32( &pcpy_num, &pcpy_num ); |
| if( sign_mul ) ineg_32( &pcpy_mul, &pcpy_mul ); |
| |
| k = BITS_PER_TWO_BYTES; |
| |
| for( i = 0; i < k; ++i ) |
| { |
| if( (pcpy_mul >> ((i)&(BITS_PER_TWO_BYTES-1)))&1 ) |
| { |
| ishln_32( &pcpy_num, &pcpy_num, shifts ); |
| iadd_32( prod, prod, &pcpy_num ); |
| |
| shifts = 1; |
| } |
| else ++shifts; |
| |
| } |
| |
| |
| if( *prod >> 15 ) __STR; |
| else __CLR; |
| |
| if( sign_num ^ sign_mul ) ineg_32( prod, prod ); |
| |
| __CLA; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| } |
| |
| #if BITS_PER_EMUSHORT > 32 |
| void ismul_32( __mpu_uint64_t *prod, __mpu_uint32_t *num, __mpu_uint32_t *mul ) |
| { |
| __mpu_uint64_t pcpy_num = 0, pcpy_mul = 0; |
| signed int sign_num = 0, sign_mul = 0; |
| signed int i, k, shifts = 0; |
| |
| if( *num & 0x80000000 ) sign_num = 1; |
| if( *mul & 0x80000000 ) sign_mul = 1; |
| |
| icvt_s2l_32to_np( (EMUSHORT *)(&pcpy_num), num, 1 ); |
| icvt_s2l_32to_np( (EMUSHORT *)(&pcpy_mul), mul, 1 ); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| *prod = (__mpu_uint64_t)0; |
| |
| if( sign_num ) ineg_np( (EMUSHORT *)(&pcpy_num), |
| (EMUSHORT *)(&pcpy_num), 1 ); |
| if( sign_mul ) ineg_np( (EMUSHORT *)(&pcpy_mul), |
| (EMUSHORT *)(&pcpy_mul), 1 ); |
| |
| k = BITS_PER_FOUR_BYTES; |
| |
| for( i = 0; i < k; ++i ) |
| { |
| if( (pcpy_mul >> ((i)&(BITS_PER_FOUR_BYTES-1)))&1 ) |
| { |
| ishln_np( (EMUSHORT *)(&pcpy_num), |
| (EMUSHORT *)(&pcpy_num), |
| shifts, 1 ); |
| iadd_np( (EMUSHORT *)prod, |
| (EMUSHORT *)prod, |
| (EMUSHORT *)(&pcpy_num), |
| 1 ); |
| |
| shifts = 1; |
| } |
| else ++shifts; |
| |
| } |
| |
| |
| if( *prod >> 31 ) __STR; |
| else __CLR; |
| |
| if( sign_num ^ sign_mul ) |
| ineg_np( (EMUSHORT *)prod, (EMUSHORT *)prod, 1 ); |
| |
| __CLA; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| } |
| #endif |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void idiv_8( __mpu_uint8_t *quot, __mpu_uint8_t *rem, __mpu_uint8_t *num, __mpu_uint8_t *den ) |
| { |
| __mpu_uint8_t cpy_num = 0, cpy_den = 0, j; |
| signed int i, k; |
| int b, bnum, bden; |
| |
| cpy_num = *num; |
| cpy_den = *den; |
| |
| *quot = 0; |
| *rem = 0; |
| |
| b = BITS_PER_BYTE - 1; |
| while( !((cpy_num >> ((b)&(BITS_PER_BYTE-1)))&1) && |
| b != (-1) ) --b; |
| bnum = b; |
| |
| if( bnum == -1 ) |
| { |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; __CLP; |
| |
| return; |
| } |
| |
| b = BITS_PER_BYTE - 1; |
| while( !((cpy_den >> ((b)&(BITS_PER_BYTE-1)))&1) && |
| b != (-1) ) --b; |
| bden = b; |
| |
| if( bden == -1 ) |
| { |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| *rem = cpy_num; |
| if( *rem ) __STR; |
| else __CLR; |
| |
| *quot = 0xff; |
| |
| __STC; __STO; __STS; __STP; |
| |
| return; |
| } |
| |
| if( bnum < bden ) |
| { |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| *rem = cpy_num; |
| if( *rem ) __STR; |
| else __CLR; |
| |
| __STZ; __CLP; |
| |
| return; |
| } |
| |
| k = bnum - bden; |
| |
| ishln_8( &cpy_den, &cpy_den, k ); |
| |
| ++k; |
| |
| for( i = 0; i < k; ++i ) |
| { |
| icmp_8( &cpy_num, &cpy_den ); |
| if( !__MFLAG(SF) ) |
| { |
| isub_8( &cpy_num, &cpy_num, &cpy_den ); |
| j = 1; |
| } |
| else j = 0; |
| |
| ishl_8( quot, quot ); |
| *quot |= j; |
| |
| ishr_8( &cpy_den, &cpy_den ); |
| } |
| |
| if( __MPARITY(*quot) ) __STP; |
| else __CLP; |
| |
| if( *quot ) __CLZ; |
| else __STZ; |
| |
| if( *quot & 0x80 ) __STS; |
| else __CLS; |
| |
| if( __MFLAG(SF) ) __STO; |
| else __CLO; |
| |
| __CLA; |
| __CLC; |
| |
| __CLV; |
| |
| |
| *rem = cpy_num; |
| if( *rem ) __STR; |
| else __CLR; |
| } |
| |
| void idiv_16( __mpu_uint16_t *quot, __mpu_uint16_t *rem, __mpu_uint16_t *num, __mpu_uint16_t *den ) |
| { |
| __mpu_uint16_t cpy_num = 0, cpy_den = 0, j; |
| signed int i, k; |
| int b, bnum, bden; |
| |
| cpy_num = *num; |
| cpy_den = *den; |
| |
| *quot = 0; |
| *rem = 0; |
| |
| b = BITS_PER_TWO_BYTES - 1; |
| while( !((cpy_num >> ((b)&(BITS_PER_TWO_BYTES-1)))&1) && |
| b != (-1) ) --b; |
| bnum = b; |
| |
| if( bnum == -1 ) |
| { |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; __CLP; |
| |
| return; |
| } |
| |
| b = BITS_PER_TWO_BYTES - 1; |
| while( !((cpy_den >> ((b)&(BITS_PER_TWO_BYTES-1)))&1) && |
| b != (-1) ) --b; |
| bden = b; |
| |
| if( bden == -1 ) |
| { |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| *rem = cpy_num; |
| if( *rem ) __STR; |
| else __CLR; |
| |
| *quot = 0xffff; |
| |
| __STC; __STO; __STS; __STP; |
| |
| return; |
| } |
| |
| if( bnum < bden ) |
| { |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| *rem = cpy_num; |
| if( *rem ) __STR; |
| else __CLR; |
| |
| __STZ; __CLP; |
| |
| return; |
| } |
| |
| k = bnum - bden; |
| |
| ishln_16( &cpy_den, &cpy_den, k ); |
| |
| ++k; |
| |
| for( i = 0; i < k; ++i ) |
| { |
| icmp_16( &cpy_num, &cpy_den ); |
| if( !__MFLAG(SF) ) |
| { |
| isub_16( &cpy_num, &cpy_num, &cpy_den ); |
| j = 1; |
| } |
| else j = 0; |
| |
| ishl_16( quot, quot ); |
| *quot |= j; |
| |
| ishr_16( &cpy_den, &cpy_den ); |
| } |
| |
| if( __MPARITY(*quot) ) __STP; |
| else __CLP; |
| |
| if( *quot ) __CLZ; |
| else __STZ; |
| |
| if( *quot & 0x8000 ) __STS; |
| else __CLS; |
| |
| if( __MFLAG(SF) ) __STO; |
| else __CLO; |
| |
| __CLA; |
| __CLC; |
| |
| __CLV; |
| |
| |
| *rem = cpy_num; |
| if( *rem ) __STR; |
| else __CLR; |
| } |
| |
| #if BITS_PER_EMUSHORT > 32 |
| void idiv_32( __mpu_uint32_t *quot, __mpu_uint32_t *rem, __mpu_uint32_t *num, __mpu_uint32_t *den ) |
| { |
| __mpu_uint32_t cpy_num = 0, cpy_den = 0, j; |
| signed int i, k; |
| int b, bnum, bden; |
| |
| cpy_num = *num; |
| cpy_den = *den; |
| |
| *quot = 0; |
| *rem = 0; |
| |
| b = BITS_PER_FOUR_BYTES - 1; |
| while( !((cpy_num >> ((b)&(BITS_PER_FOUR_BYTES-1)))&1) && |
| b != (-1) ) --b; |
| bnum = b; |
| |
| if( bnum == -1 ) |
| { |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; __CLP; |
| |
| return; |
| } |
| |
| b = BITS_PER_FOUR_BYTES - 1; |
| while( !((cpy_den >> ((b)&(BITS_PER_FOUR_BYTES-1)))&1) && |
| b != (-1) ) --b; |
| bden = b; |
| |
| if( bden == -1 ) |
| { |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| *rem = cpy_num; |
| if( *rem ) __STR; |
| else __CLR; |
| |
| *quot = 0xffffffff; |
| |
| __STC; __STO; __STS; __STP; |
| |
| return; |
| } |
| |
| if( bnum < bden ) |
| { |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| *rem = cpy_num; |
| if( *rem ) __STR; |
| else __CLR; |
| |
| __STZ; __CLP; |
| |
| return; |
| } |
| |
| k = bnum - bden; |
| |
| ishln_32( &cpy_den, &cpy_den, k ); |
| |
| ++k; |
| |
| for( i = 0; i < k; ++i ) |
| { |
| icmp_32( &cpy_num, &cpy_den ); |
| if( !__MFLAG(SF) ) |
| { |
| isub_32( &cpy_num, &cpy_num, &cpy_den ); |
| j = 1; |
| } |
| else j = 0; |
| |
| ishl_32( quot, quot ); |
| *quot |= j; |
| |
| ishr_32( &cpy_den, &cpy_den ); |
| } |
| |
| if( __MPARITY(*quot) ) __STP; |
| else __CLP; |
| |
| if( *quot ) __CLZ; |
| else __STZ; |
| |
| if( *quot & 0x80000000 ) __STS; |
| else __CLS; |
| |
| if( __MFLAG(SF) ) __STO; |
| else __CLO; |
| |
| __CLA; |
| __CLC; |
| |
| __CLV; |
| |
| |
| *rem = cpy_num; |
| if( *rem ) __STR; |
| else __CLR; |
| } |
| #endif |
| |
| |
| |
| |
| |
| |
| |
| void isdiv_8( __mpu_uint8_t *quot, __mpu_uint8_t *rem, __mpu_uint8_t *num, __mpu_uint8_t *den ) |
| { |
| __mpu_uint8_t cpy_num = 0, cpy_den = 0, j = 0; |
| signed int sign_num = 0, sign_den = 0; |
| signed int i, k; |
| int b, bnum, bden; |
| |
| if( *num & 0x80 ) sign_num = 1; |
| if( *den & 0x80 ) sign_den = 1; |
| |
| cpy_num = *num; |
| cpy_den = *den; |
| |
| *quot = 0; |
| *rem = 0; |
| |
| if( sign_num ) ineg_8( &cpy_num, &cpy_num ); |
| if( sign_den ) ineg_8( &cpy_den, &cpy_den ); |
| |
| |
| b = BITS_PER_BYTE - 1; |
| while( !((cpy_num >> ((b)&(BITS_PER_BYTE-1)))&1) && |
| b != (-1) ) --b; |
| bnum = b; |
| |
| if( bnum == -1 ) |
| { |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; __CLP; |
| |
| return; |
| } |
| |
| b = BITS_PER_BYTE - 1; |
| while( !((cpy_den >> ((b)&(BITS_PER_BYTE-1)))&1) && |
| b != (-1) ) --b; |
| bden = b; |
| |
| if( bden == -1 ) |
| { |
| |
| |
| if( sign_num ) ineg_8( &cpy_num, &cpy_num ); |
| |
| *rem = cpy_num; |
| if( *rem ) __STR; |
| else __CLR; |
| |
| if( !sign_num ) j = 0xff; |
| *quot = j; |
| |
| if( !sign_num ) |
| { |
| *quot ^= 0x80; |
| __CLS; |
| } |
| else |
| { |
| *quot |= 0x80; |
| __STS; |
| } |
| |
| if( __MPARITY(*quot) ) __STP; |
| else __CLP; |
| |
| __CLA; |
| __STC; |
| __STO; |
| __CLZ; |
| __CLV; |
| |
| return; |
| } |
| |
| if( bnum < bden ) |
| { |
| |
| |
| *rem = cpy_num; |
| if( *rem ) __STR; |
| else __CLR; |
| |
| if( sign_num ^ sign_den ) ineg_8( rem, rem ); |
| |
| __CLA; |
| __CLC; |
| __CLO; |
| __CLS; |
| __STZ; |
| __CLV; |
| |
| __CLP; |
| |
| return; |
| } |
| |
| k = bnum - bden; |
| |
| ishln_8( &cpy_den, &cpy_den, k ); |
| |
| ++k; |
| |
| for( i = 0; i < k; ++i ) |
| { |
| icmp_8( &cpy_num, &cpy_den ); |
| if( !__MFLAG(SF) ) |
| { |
| isub_8( &cpy_num, &cpy_num, &cpy_den ); |
| j = 1; |
| } |
| else j = 0; |
| |
| ishl_8( quot, quot ); |
| *quot |= j; |
| |
| ishr_8( &cpy_den, &cpy_den ); |
| } |
| |
| |
| *rem = cpy_num; |
| if( *rem ) __STR; |
| else __CLR; |
| |
| if( sign_num ^ sign_den ) |
| { |
| ineg_8( rem, rem ); |
| ineg_8( quot, quot ); |
| |
| __CLA; |
| __CLC; |
| |
| if( __MFLAG(SF) == (sign_num ^ sign_den) ) |
| |
| __CLO; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| return; |
| } |
| |
| |
| if( __MPARITY(*quot) ) __STP; |
| else __CLP; |
| |
| if( *quot ) __CLZ; |
| else __STZ; |
| |
| if( *quot & 0x80 ) __STS; |
| else __CLS; |
| |
| if( __MFLAG(SF) ) __STO; |
| else __CLO; |
| |
| |
| |
| |
| __CLA; |
| __CLC; |
| |
| __CLV; |
| } |
| |
| void isdiv_16( __mpu_uint16_t *quot, __mpu_uint16_t *rem, __mpu_uint16_t *num, __mpu_uint16_t *den ) |
| { |
| __mpu_uint16_t cpy_num = 0, cpy_den = 0, j = 0; |
| signed int sign_num = 0, sign_den = 0; |
| signed int i, k; |
| int b, bnum, bden; |
| |
| if( *num & 0x8000 ) sign_num = 1; |
| if( *den & 0x8000 ) sign_den = 1; |
| |
| cpy_num = *num; |
| cpy_den = *den; |
| |
| *quot = 0; |
| *rem = 0; |
| |
| if( sign_num ) ineg_16( &cpy_num, &cpy_num ); |
| if( sign_den ) ineg_16( &cpy_den, &cpy_den ); |
| |
| b = BITS_PER_TWO_BYTES - 1; |
| while( !((cpy_num >> ((b)&(BITS_PER_TWO_BYTES-1)))&1) && |
| b != (-1) ) --b; |
| bnum = b; |
| |
| if( bnum == -1 ) |
| { |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; __CLP; |
| |
| return; |
| } |
| |
| b = BITS_PER_TWO_BYTES - 1; |
| while( !((cpy_den >> ((b)&(BITS_PER_TWO_BYTES-1)))&1) && |
| b != (-1) ) --b; |
| bden = b; |
| |
| if( bden == -1 ) |
| { |
| |
| |
| if( sign_num ) ineg_16( &cpy_num, &cpy_num ); |
| |
| *rem = cpy_num; |
| if( *rem ) __STR; |
| else __CLR; |
| |
| if( !sign_num ) j = 0xffff; |
| *quot = j; |
| |
| if( !sign_num ) |
| { |
| *quot ^= 0x8000; |
| __CLS; |
| } |
| else |
| { |
| *quot |= 0x8000; |
| __STS; |
| } |
| |
| if( __MPARITY(*quot) ) __STP; |
| else __CLP; |
| |
| __CLA; |
| __STC; |
| __STO; |
| __CLZ; |
| __CLV; |
| |
| return; |
| } |
| |
| if( bnum < bden ) |
| { |
| |
| |
| *rem = cpy_num; |
| if( *rem ) __STR; |
| else __CLR; |
| |
| if( sign_num ^ sign_den ) ineg_16( rem, rem ); |
| |
| __CLA; |
| __CLC; |
| __CLO; |
| __CLS; |
| __STZ; |
| __CLV; |
| |
| __CLP; |
| |
| return; |
| } |
| |
| k = bnum - bden; |
| |
| ishln_16( &cpy_den, &cpy_den, k ); |
| |
| ++k; |
| |
| for( i = 0; i < k; ++i ) |
| { |
| icmp_16( &cpy_num, &cpy_den ); |
| if( !__MFLAG(SF) ) |
| { |
| isub_16( &cpy_num, &cpy_num, &cpy_den ); |
| j = 1; |
| } |
| else j = 0; |
| |
| ishl_16( quot, quot ); |
| *quot |= j; |
| |
| ishr_16( &cpy_den, &cpy_den ); |
| } |
| |
| |
| *rem = cpy_num; |
| if( *rem ) __STR; |
| else __CLR; |
| |
| if( sign_num ^ sign_den ) |
| { |
| ineg_16( rem, rem ); |
| ineg_16( quot, quot ); |
| |
| __CLA; |
| __CLC; |
| |
| if( __MFLAG(SF) == (sign_num ^ sign_den) ) |
| |
| __CLO; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| return; |
| } |
| |
| |
| if( __MPARITY(*quot) ) __STP; |
| else __CLP; |
| |
| if( *quot ) __CLZ; |
| else __STZ; |
| |
| if( *quot & 0x8000 ) __STS; |
| else __CLS; |
| |
| if( __MFLAG(SF) ) __STO; |
| else __CLO; |
| |
| |
| |
| |
| __CLA; |
| __CLC; |
| |
| __CLV; |
| } |
| |
| #if BITS_PER_EMUSHORT > 32 |
| void isdiv_32( __mpu_uint32_t *quot, __mpu_uint32_t *rem, __mpu_uint32_t *num, __mpu_uint32_t *den ) |
| { |
| __mpu_uint32_t cpy_num = 0, cpy_den = 0, j = 0; |
| signed int sign_num = 0, sign_den = 0; |
| signed int i, k; |
| int b, bnum, bden; |
| |
| if( *num & 0x80000000 ) sign_num = 1; |
| if( *den & 0x80000000 ) sign_den = 1; |
| |
| cpy_num = *num; |
| cpy_den = *den; |
| |
| *quot = 0; |
| *rem = 0; |
| |
| if( sign_num ) ineg_32( &cpy_num, &cpy_num ); |
| if( sign_den ) ineg_32( &cpy_den, &cpy_den ); |
| |
| b = BITS_PER_FOUR_BYTES - 1; |
| while( !((cpy_num >> ((b)&(BITS_PER_FOUR_BYTES-1)))&1) && |
| b != (-1) ) --b; |
| bnum = b; |
| |
| if( bnum == -1 ) |
| { |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; __CLP; |
| |
| return; |
| } |
| |
| b = BITS_PER_FOUR_BYTES - 1; |
| while( !((cpy_den >> ((b)&(BITS_PER_FOUR_BYTES-1)))&1) && |
| b != (-1) ) --b; |
| bden = b; |
| |
| if( bden == -1 ) |
| { |
| |
| |
| if( sign_num ) ineg_32( &cpy_num, &cpy_num ); |
| |
| *rem = cpy_num; |
| if( *rem ) __STR; |
| else __CLR; |
| |
| if( !sign_num ) j = 0xffffffff; |
| *quot = j; |
| |
| if( !sign_num ) |
| { |
| *quot ^= 0x80000000; |
| __CLS; |
| } |
| else |
| { |
| *quot |= 0x80000000; |
| __STS; |
| } |
| |
| if( __MPARITY(*quot) ) __STP; |
| else __CLP; |
| |
| __CLA; |
| __STC; |
| __STO; |
| __CLZ; |
| __CLV; |
| |
| return; |
| } |
| |
| if( bnum < bden ) |
| { |
| |
| |
| *rem = cpy_num; |
| if( *rem ) __STR; |
| else __CLR; |
| |
| if( sign_num ^ sign_den ) ineg_32( rem, rem ); |
| |
| __CLA; |
| __CLC; |
| __CLO; |
| __CLS; |
| __STZ; |
| __CLV; |
| |
| __CLP; |
| |
| return; |
| } |
| |
| k = bnum - bden; |
| |
| ishln_32( &cpy_den, &cpy_den, k ); |
| |
| ++k; |
| |
| for( i = 0; i < k; ++i ) |
| { |
| icmp_32( &cpy_num, &cpy_den ); |
| if( !__MFLAG(SF) ) |
| { |
| isub_32( &cpy_num, &cpy_num, &cpy_den ); |
| j = 1; |
| } |
| else j = 0; |
| |
| ishl_32( quot, quot ); |
| *quot |= j; |
| |
| ishr_32( &cpy_den, &cpy_den ); |
| } |
| |
| |
| |
| *rem = cpy_num; |
| if( *rem ) __STR; |
| else __CLR; |
| |
| if( sign_num ^ sign_den ) |
| { |
| ineg_32( rem, rem ); |
| ineg_32( quot, quot ); |
| |
| __CLA; |
| __CLC; |
| |
| if( __MFLAG(SF) == (sign_num ^ sign_den) ) |
| |
| __CLO; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| return; |
| } |
| |
| |
| if( __MPARITY(*quot) ) __STP; |
| else __CLP; |
| |
| if( *quot ) __CLZ; |
| else __STZ; |
| |
| if( *quot & 0x80000000 ) __STS; |
| else __CLS; |
| |
| if( __MFLAG(SF) ) __STO; |
| else __CLO; |
| |
| |
| |
| |
| __CLA; |
| __CLC; |
| |
| __CLV; |
| } |
| #endif |
| |
| |
| #if 1 |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| static void iEMUSHORTm( EMUSHORT *prod, EMUSHORT *num, EMUSHORT mul, int np_prod, int np_num ) |
| |
| |
| |
| |
| |
| { |
| EMUSHORT *pp, *z; |
| EMULONG carry; |
| EMUSHORT *prd = EMUSHORT_C(0); |
| EMUSHORT *ps; |
| EMULONG a, m; |
| EMUSHORT i; |
| |
| if( np_prod < 2 || np_prod > NP_MAX || np_num < 1 || np_prod < np_num + 1 ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"iEMUSHORTm" ); |
| return; |
| } |
| |
| |
| prd = (EMUSHORT *)__mpu_sbrk( (int)(np_prod*SIZE_OF_EMUSHORT) ); |
| if( !prd ) |
| { |
| |
| return; |
| } |
| |
| |
| a = mul; |
| |
| |
| z = prd + np_prod - 1; |
| i = np_prod; |
| while( i > 0 ) |
| { |
| *z = (EMUSHORT)0; |
| --z; --i; |
| } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| |
| pp = &prd[np_prod - 1]; |
| |
| ps = &num[np_num - 1]; |
| #else |
| |
| pp = &prd[0]; |
| |
| ps = &num[0]; |
| #endif |
| |
| for( i = 0; i < np_num; ++i ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| m = (EMULONG) a * *ps--; |
| #else |
| m = (EMULONG) a * *ps++; |
| #endif |
| carry = (m & MASK_ALL_BITS) + *pp; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *pp-- = (EMUSHORT)carry; |
| #else |
| *pp++ = (EMUSHORT)carry; |
| #endif |
| carry = (carry >> BITS_PER_EMUSHORT) + |
| (m >> BITS_PER_EMUSHORT) + *pp; |
| *pp = (EMUSHORT)carry; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(pp-1) = (EMUSHORT)(carry >> BITS_PER_EMUSHORT); |
| #else |
| *(pp+1) = (EMUSHORT)(carry >> BITS_PER_EMUSHORT); |
| #endif |
| } |
| |
| for( i = 0; i < np_prod; ++i ) prod[i] = prd[i]; |
| |
| |
| __mpu_sbrk( -(int)(np_prod*SIZE_OF_EMUSHORT) ); |
| |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void imul_np( EMUSHORT *prod, EMUSHORT *num, EMUSHORT *mul, int np_prod, int np_num ) |
| { |
| EMUSHORT *z, *p, *pcpy = 0, *quot = 0; |
| signed int major = 0; |
| signed int i, shifts = 0; |
| |
| errno = 0; |
| |
| if( np_prod < 2 || np_prod > NP_MAX || np_num < 1 || np_prod < 2*np_num ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"imul_np (emushort)" ); |
| return; |
| } |
| |
| |
| quot = (EMUSHORT *)__mpu_sbrk( (int)(np_prod*SIZE_OF_EMUSHORT) ); |
| if( !quot ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)quot, 0, np_prod*SIZE_OF_EMUSHORT ); |
| |
| |
| |
| pcpy = (EMUSHORT *)__mpu_sbrk( (int)(np_prod*SIZE_OF_EMUSHORT) ); |
| if( !pcpy ) |
| { |
| |
| |
| __mpu_sbrk( -((int)(np_prod*SIZE_OF_EMUSHORT)) ); |
| |
| return; |
| } |
| scpy_s2l_np( pcpy, num, np_prod, np_num ); |
| |
| |
| z = prod + np_prod - 1; |
| i = np_prod; |
| while( i > 0 ) |
| { |
| *z = 0; |
| --z; --i; |
| } |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| p = mul + np_num - 1; |
| #else |
| p = mul; |
| #endif |
| |
| for( i = 0; i < np_num; ++i ) |
| { |
| if( *p == (EMUSHORT)0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --p; |
| #else |
| ++p; |
| #endif |
| } |
| else |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| iEMUSHORTm( prod, pcpy+np_num, *p--, np_prod, np_num ); |
| #else |
| iEMUSHORTm( prod, pcpy, *p++, np_prod, np_num ); |
| #endif |
| ishln_np( prod, prod, shifts*BITS_PER_EMUSHORT, np_prod ); |
| iadd_np( quot, quot, prod, np_prod ); |
| } |
| ++shifts; |
| |
| } |
| |
| |
| __mpu_sbrk( -((int)(np_prod*SIZE_OF_EMUSHORT)) ); |
| |
| |
| for( i = 0; i < np_prod; ++i ) prod[i] = quot[i]; |
| |
| |
| __mpu_sbrk( -((int)(np_prod*SIZE_OF_EMUSHORT)) ); |
| |
| |
| __CLA; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z = prod + np_num - 1; |
| #else |
| z = prod + np_num; |
| #endif |
| |
| i = np_num; |
| while( i > 0 ) |
| { |
| if( *z ) major |= 1; |
| else major |= 0; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --z; |
| #else |
| ++z; |
| #endif |
| --i; |
| } |
| |
| if( major ) __STR; |
| else __CLR; |
| } |
| |
| |
| void ismul_np( EMUSHORT *prod, EMUSHORT *num, EMUSHORT *mul, int np_prod, int np_num ) |
| { |
| EMUSHORT *z, *p; |
| EMUSHORT *pcpy_num = 0, *pcpy_mul = 0, *quot = 0; |
| signed int sign_num = 0, sign_mul = 0, major = 0; |
| signed int i, shifts = 0; |
| |
| errno = 0; |
| |
| if( np_prod < 2 || np_prod > NP_MAX || np_num < 1 || np_prod < 2*np_num ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"ismul_np (emushort)" ); |
| return; |
| } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| p = num; |
| #else |
| p = num + np_num - 1; |
| #endif |
| if( *p & MASK_SIGN ) sign_num = 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| p = mul; |
| #else |
| p = mul + np_num - 1; |
| #endif |
| if( *p & MASK_SIGN ) sign_mul = 1; |
| |
| |
| quot = (EMUSHORT *)__mpu_sbrk( (int)(np_prod*SIZE_OF_EMUSHORT) ); |
| if( !quot ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)quot, 0, np_prod*SIZE_OF_EMUSHORT ); |
| |
| |
| |
| pcpy_num = (EMUSHORT *)__mpu_sbrk( (int)(np_prod*SIZE_OF_EMUSHORT) ); |
| if( !pcpy_num ) |
| { |
| |
| |
| __mpu_sbrk( -((int)(np_prod*SIZE_OF_EMUSHORT)) ); |
| |
| return; |
| } |
| scvt_s2l_np( pcpy_num, num, np_prod, np_num ); |
| |
| |
| |
| pcpy_mul = (EMUSHORT *)__mpu_sbrk( (int)(np_prod*SIZE_OF_EMUSHORT) ); |
| if( !pcpy_mul ) |
| { |
| |
| |
| __mpu_sbrk( -(int)(np_prod*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -((int)(np_prod*SIZE_OF_EMUSHORT)) ); |
| |
| return; |
| } |
| scvt_s2l_np( pcpy_mul, mul, np_prod, np_num ); |
| |
| |
| z = prod + np_prod - 1; |
| i = np_prod; |
| while( i > 0 ) |
| { |
| *z = 0; |
| --z; --i; |
| } |
| |
| |
| if( sign_num ) ineg_np( pcpy_num, pcpy_num, np_prod ); |
| if( sign_mul ) ineg_np( pcpy_mul, pcpy_mul, np_prod ); |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| p = pcpy_mul + np_num - 1; |
| #else |
| p = pcpy_mul; |
| #endif |
| |
| for( i = 0; i < np_num; ++i ) |
| { |
| if( *p == (EMUSHORT)0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --p; |
| #else |
| ++p; |
| #endif |
| } |
| else |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| iEMUSHORTm( prod, pcpy_num, *p--, np_prod, np_num ); |
| #else |
| iEMUSHORTm( prod, pcpy_num, *p++, np_prod, np_num ); |
| #endif |
| ishln_np( prod, prod, shifts*BITS_PER_EMUSHORT, np_prod ); |
| iadd_np( quot, quot, prod, np_prod ); |
| } |
| ++shifts; |
| |
| } |
| |
| |
| __mpu_sbrk( -(int)(np_prod*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(np_prod*SIZE_OF_EMUSHORT) ); |
| |
| |
| for( i = 0; i < np_prod; ++i ) prod[i] = quot[i]; |
| |
| |
| __mpu_sbrk( -((int)(np_prod*SIZE_OF_EMUSHORT)) ); |
| |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z = prod + np_num; |
| #else |
| z = prod + np_num - 1; |
| #endif |
| |
| if( *z & MASK_SIGN ) major |= 1; |
| else major |= 0; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --z; |
| #else |
| ++z; |
| #endif |
| |
| i = np_num; |
| while( i > 0 ) |
| { |
| if( *z ) major |= 1; |
| else major |= 0; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --z; |
| #else |
| ++z; |
| #endif |
| --i; |
| } |
| |
| if( major ) __STR; |
| else __CLR; |
| |
| if( sign_num ^ sign_mul ) ineg_np( prod, prod, np_prod ); |
| |
| __CLA; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| } |
| |
| #else |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void imul_np( EMUSHORT *prod, EMUSHORT *num, EMUSHORT *mul, int np_prod, int np_num ) |
| { |
| EMUSHORT *z, *x, *y, *pcpy = 0; |
| signed int major = 0; |
| signed int i, k, shifts = 0; |
| |
| errno = 0; |
| |
| if( np_prod < 2 || np_prod > NP_MAX || np_num < 1 || np_prod < 2*np_num ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"imul_np (emushort)" ); |
| return; |
| } |
| |
| |
| pcpy = (EMUSHORT *)__mpu_sbrk( (int)(np_prod*SIZE_OF_EMUSHORT) ); |
| if( !pcpy ) |
| { |
| |
| return; |
| } |
| |
| scpy_s2l_np( pcpy, num, np_prod, np_num ); |
| |
| |
| z = prod + np_prod - 1; |
| i = np_prod; |
| while( i > 0 ) |
| { |
| *z = 0; |
| --z; --i; |
| } |
| ++z; |
| |
| x = pcpy; |
| y = mul; |
| |
| k = BITS_PER_EMUSHORT*np_num; |
| |
| for( i = 0; i < k; ++i ) |
| { |
| if( ORDER_BIT(y,i,np_num) ) |
| { |
| |
| |
| |
| |
| ishln_np( x, x, shifts, np_prod ); |
| iadd_np( z, z, x, np_prod ); |
| |
| shifts = 1; |
| } |
| else ++shifts; |
| |
| } |
| |
| |
| __mpu_sbrk( -((int)(np_prod*SIZE_OF_EMUSHORT)) ); |
| |
| |
| __CLA; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z = prod + np_num - 1; |
| #else |
| z = prod + np_num; |
| #endif |
| |
| i = np_num; |
| while( i > 0 ) |
| { |
| if( *z ) major |= 1; |
| else major |= 0; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --z; |
| #else |
| ++z; |
| #endif |
| --i; |
| } |
| |
| if( major ) __STR; |
| else __CLR; |
| } |
| |
| |
| void ismul_np( EMUSHORT *prod, EMUSHORT *num, EMUSHORT *mul, int np_prod, int np_num ) |
| { |
| EMUSHORT *z, *x, *y; |
| EMUSHORT *pcpy_num = 0, *pcpy_mul = 0; |
| signed int sign_num = 0, sign_mul = 0, major = 0; |
| signed int i, k, shifts = 0; |
| |
| errno = 0; |
| |
| if( np_prod < 2 || np_prod > NP_MAX || np_num < 1 || np_prod < 2*np_num ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"ismul_np (emushort)" ); |
| return; |
| } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = num; |
| #else |
| x = num + np_num - 1; |
| #endif |
| if( *x & MASK_SIGN ) sign_num = 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = mul; |
| #else |
| y = mul + np_num - 1; |
| #endif |
| if( *y & MASK_SIGN ) sign_mul = 1; |
| |
| |
| pcpy_num = (EMUSHORT *)__mpu_sbrk( (int)(np_prod*SIZE_OF_EMUSHORT) ); |
| if( !pcpy_num ) |
| { |
| |
| return; |
| } |
| scvt_s2l_np( pcpy_num, num, np_prod, np_num ); |
| |
| |
| |
| pcpy_mul = (EMUSHORT *)__mpu_sbrk( (int)(np_prod*SIZE_OF_EMUSHORT) ); |
| if( !pcpy_mul ) |
| { |
| |
| |
| __mpu_sbrk( -(int)(np_prod*SIZE_OF_EMUSHORT) ); |
| |
| return; |
| } |
| scvt_s2l_np( pcpy_mul, mul, np_prod, np_num ); |
| |
| |
| z = prod + np_prod - 1; |
| i = np_prod; |
| while( i > 0 ) |
| { |
| *z = 0; |
| --z; --i; |
| } |
| ++z; |
| |
| if( sign_num ) ineg_np( pcpy_num, pcpy_num, np_prod ); |
| if( sign_mul ) ineg_np( pcpy_mul, pcpy_mul, np_prod ); |
| |
| x = pcpy_num; |
| y = pcpy_mul; |
| |
| k = BITS_PER_EMUSHORT*np_num; |
| |
| for( i = 0; i < k; ++i ) |
| { |
| if( ORDER_BIT(y,i,np_prod) ) |
| { |
| |
| |
| |
| |
| ishln_np( x, x, shifts, np_prod ); |
| iadd_np( z, z, x, np_prod ); |
| |
| shifts = 1; |
| } |
| else ++shifts; |
| |
| } |
| |
| |
| __mpu_sbrk( -(int)(np_prod*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(np_prod*SIZE_OF_EMUSHORT) ); |
| |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z = prod + np_num; |
| #else |
| z = prod + np_num - 1; |
| #endif |
| |
| if( *z & MASK_SIGN ) major |= 1; |
| else major |= 0; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --z; |
| #else |
| ++z; |
| #endif |
| |
| i = np_num; |
| while( i > 0 ) |
| { |
| if( *z ) major |= 1; |
| else major |= 0; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --z; |
| #else |
| ++z; |
| #endif |
| --i; |
| } |
| |
| if( major ) __STR; |
| else __CLR; |
| |
| if( sign_num ^ sign_mul ) ineg_np( prod, prod, np_prod ); |
| |
| __CLA; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| } |
| |
| #endif |
| |
| |
| #if 1 |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #define BASE MASK_CARRY |
| |
| static void iSINGLE_EMUSHORTm( EMUSHORT *prod, EMUSHORT *num, EMUSHORT mul, int np_prod, int np_num ) |
| |
| |
| |
| |
| |
| { |
| EMUSHORT *prd = 0, *p, *n; |
| EMULONG carry = 0, tmp; |
| int i; |
| |
| if( np_prod < 2 || np_prod > NP_MAX || np_num < 1 || np_prod < np_num+1 ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"iSINGLE_EMUSHORTm" ); |
| return; |
| } |
| |
| |
| prd = (EMUSHORT *)__mpu_sbrk( (int)(np_prod*SIZE_OF_EMUSHORT) ); |
| if( !prd ) |
| { |
| |
| return; |
| } |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| p = prd; |
| #else |
| p = prd + np_prod - 1; |
| #endif |
| i = np_prod; |
| while( i > 0 ) |
| { |
| *p = 0; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++p; |
| #else |
| --p; |
| #endif |
| --i; |
| } |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --p; |
| #else |
| ++p; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| n = num + np_num - 1; |
| #else |
| n = num; |
| #endif |
| |
| for( i = 0; i < np_num; ++i ) |
| { |
| tmp = (EMULONG)*n * (EMULONG)mul + carry; |
| carry = tmp / BASE; |
| *p = (EMUSHORT)(tmp - carry * BASE); |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --p; --n; |
| #else |
| ++p; ++n; |
| #endif |
| } |
| |
| if( carry ) |
| { |
| *p = (EMUSHORT)carry; |
| } |
| |
| for( i = 0; i < np_prod; ++i ) prod[i] = prd[i]; |
| |
| |
| __mpu_sbrk( -(int)(np_prod*SIZE_OF_EMUSHORT) ); |
| |
| } |
| |
| static void iSINGLE_EMUSHORTd( EMUSHORT *quot, EMUSHORT *rem, EMUSHORT *num, EMUSHORT den, int np ) |
| |
| |
| |
| |
| |
| |
| |
| { |
| EMUSHORT *tquot = 0, *q, *n; |
| EMULONG r = 0, tmp = 0; |
| int i; |
| |
| if( !den ) return; |
| |
| if( np == 0 ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"iSINGLE_EMUSHORTd" ); |
| return; |
| } |
| |
| |
| tquot = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) ); |
| if( !tquot ) |
| { |
| |
| return; |
| } |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| q = tquot + np - 1; |
| #else |
| q = tquot; |
| #endif |
| i = np; |
| while( i > 0 ) |
| { |
| *q = 0; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --q; |
| #else |
| ++q; |
| #endif |
| --i; |
| } |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++q; |
| #else |
| --q; |
| #endif |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| n = num; |
| #else |
| n = num + np - 1; |
| #endif |
| |
| for( i = 0; i < np; ++i ) |
| { |
| tmp = r * BASE + (EMULONG)(*n); |
| *q = tmp / (EMULONG)den; |
| r = tmp - (EMULONG)(*q) * (EMULONG)den; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++n; ++q; |
| #else |
| --n; --q; |
| #endif |
| } |
| *rem = r; |
| |
| for( i = 0; i < np; ++i ) quot[i] = tquot[i]; |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void idiv_np( EMUSHORT *quot, EMUSHORT *rem, EMUSHORT *num, EMUSHORT *den, int np ) |
| { |
| EMUSHORT *z, *r, *x, *y, *p; |
| EMUSHORT *pcpy_num = 0, *pcpy_den = 0; |
| signed int remainder = 0, zero = 1; |
| int b, bnum, bden; |
| |
| EMUSHORT scale; |
| int i, j, k, m; |
| |
| errno = 0; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"idiv_np (emushort)" ); |
| return; |
| } |
| |
| |
| pcpy_num = (EMUSHORT *)__mpu_sbrk( (int)((np+1)*SIZE_OF_EMUSHORT) ); |
| if( !pcpy_num ) |
| { |
| |
| return; |
| } |
| scpy_s2l_np( pcpy_num, num, np+1, np ); |
| |
| |
| |
| pcpy_den = (EMUSHORT *)__mpu_sbrk( (int)((np+1)*SIZE_OF_EMUSHORT) ); |
| if( !pcpy_den ) |
| { |
| |
| |
| __mpu_sbrk( -(int)((np+1)*SIZE_OF_EMUSHORT) ); |
| |
| return; |
| } |
| scpy_s2l_np( pcpy_den, den, np+1, np ); |
| |
| |
| z = quot + np - 1; |
| i = np; |
| while( i > 0 ) |
| { |
| *z = 0; |
| --z; --i; |
| } |
| ++z; |
| |
| r = rem + np - 1; |
| i = np; |
| while( i > 0 ) |
| { |
| *r = 0; |
| --r; --i; |
| } |
| ++r; |
| |
| x = pcpy_num; |
| y = pcpy_den; |
| |
| |
| |
| |
| b = np - 1; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| while( x[np-b] == 0 && b != (-1) ) --b; |
| #else |
| while( x[b] == 0 && b != (-1) ) --b; |
| #endif |
| bnum = b; |
| |
| if( bnum == -1 ) |
| { |
| |
| |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; |
| |
| |
| __mpu_sbrk( -(int)((np+1)*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)((np+1)*SIZE_OF_EMUSHORT) ); |
| |
| |
| return; |
| } |
| |
| |
| |
| |
| b = np - 1; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| while( y[np-b] == 0 && b != (-1) ) --b; |
| #else |
| while( y[b] == 0 && b != (-1) ) --b; |
| #endif |
| bden = b; |
| |
| if( bden == -1 ) |
| { |
| |
| |
| |
| |
| i = np; |
| while( i > 0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *r = *(x+1); |
| #else |
| *r = *x; |
| #endif |
| |
| if( *r ) remainder |= 1; |
| |
| ++x; ++r; |
| --i; |
| } |
| |
| |
| i = np; |
| while( i > 0 ) |
| { |
| *z = MASK_ALL_BITS; |
| ++z; --i; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| if( remainder ) __STR; |
| else __CLR; |
| |
| __STC; __STO; __STS; |
| |
| |
| |
| __mpu_sbrk( -(int)((np+1)*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)((np+1)*SIZE_OF_EMUSHORT) ); |
| |
| |
| return; |
| } |
| |
| if( bden == 0 ) |
| { |
| |
| |
| |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| iSINGLE_EMUSHORTd( z, &r[np-1], x+1, y[np], np ); |
| #else |
| iSINGLE_EMUSHORTd( z, &r[0], x, y[0], np ); |
| #endif |
| |
| goto check_flags_and_stop; |
| } |
| |
| if( bnum < bden ) |
| { |
| |
| |
| |
| |
| i = np; |
| while( i > 0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *r = *(x+1); |
| #else |
| *r = *x; |
| #endif |
| |
| if( *r ) remainder |= 1; |
| |
| ++x; ++r; |
| --i; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| if( remainder ) __STR; |
| else __CLR; |
| |
| __STZ; |
| |
| |
| __mpu_sbrk( -(int)((np+1)*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)((np+1)*SIZE_OF_EMUSHORT) ); |
| |
| |
| return; |
| } |
| |
| m = bnum - bden; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| scale = BASE / (y[np-bden] + 1); |
| #else |
| scale = BASE / (y[bden] + 1); |
| #endif |
| if( scale > 1 ) |
| { |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| iSINGLE_EMUSHORTm( x, x+1, scale, np + 1, np ); |
| iSINGLE_EMUSHORTm( y, y+1, scale, np + 1, np ); |
| #else |
| iSINGLE_EMUSHORTm( x, x, scale, np + 1, np ); |
| iSINGLE_EMUSHORTm( y, y, scale, np + 1, np ); |
| #endif |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| for( k = m, j = bden + k; k >= 0; --k, --j ) |
| { |
| EMULONG guess, rm; |
| EMULONG borrow, carry; |
| EMULONG tmp, tmp1, tmp2; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| guess = ((EMULONG)x[np-j-1] * BASE + (EMULONG)x[np-j]) / (EMULONG)y[np-bden]; |
| rm = ((EMULONG)x[np-j-1] * BASE + (EMULONG)x[np-j]) % (EMULONG)y[np-bden]; |
| #else |
| guess = ((EMULONG)x[j+1] * BASE + (EMULONG)x[j]) / (EMULONG)y[bden]; |
| rm = ((EMULONG)x[j+1] * BASE + (EMULONG)x[j]) % (EMULONG)y[bden]; |
| #endif |
| |
| |
| |
| |
| while( rm < BASE ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| tmp2 = (EMULONG)y[np-bden+1] * guess; |
| tmp1 = rm * BASE + (EMULONG)x[np-j+1]; |
| #else |
| tmp2 = (EMULONG)y[bden-1] * guess; |
| tmp1 = rm * BASE + (EMULONG)x[j-1]; |
| #endif |
| if( (tmp2 > tmp1) || (guess == BASE) ) |
| { |
| --guess; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| rm += (EMULONG)y[np-bden]; |
| #else |
| rm += (EMULONG)y[bden]; |
| #endif |
| } |
| else |
| break; |
| } |
| |
| |
| |
| |
| |
| |
| carry = 0; borrow = 0; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| p = &x[np-k]; |
| #else |
| p = x + k; |
| #endif |
| |
| |
| for( i = 0; i <= bden; ++i ) |
| { |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| tmp1 = (EMULONG)y[np-i] * guess + carry; |
| #else |
| tmp1 = (EMULONG)y[i] * guess + carry; |
| #endif |
| carry = tmp1 / BASE; |
| tmp1 -= carry * BASE; |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| tmp2 = (EMULONG)p[-i] - tmp1 - borrow; |
| #else |
| tmp2 = (EMULONG)p[i] - tmp1 - borrow; |
| #endif |
| if( (tmp2 >> BITS_PER_EMUSHORT) & MASK_SIGN ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| p[-i] = tmp2 + BASE; |
| #else |
| p[i] = tmp2 + BASE; |
| #endif |
| borrow = 1; |
| } |
| else |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| p[-i] = tmp2; |
| #else |
| p[i] = tmp2; |
| #endif |
| borrow = 0; |
| } |
| } |
| |
| |
| |
| |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| tmp2 = (EMULONG)p[-i] - carry - borrow; |
| #else |
| tmp2 = (EMULONG)p[i] - carry - borrow; |
| #endif |
| if( (tmp2 >> BITS_PER_EMUSHORT) & MASK_SIGN ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| p[-i] = tmp2 + BASE; |
| #else |
| p[i] = tmp2 + BASE; |
| #endif |
| borrow = 1; |
| } |
| else |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| p[-i] = tmp2; |
| #else |
| p[i] = tmp2; |
| #endif |
| borrow = 0; |
| } |
| |
| |
| if( borrow == 0 ) |
| { |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z[np-1-k] = guess; |
| #else |
| z[k] = guess; |
| #endif |
| } |
| else |
| { |
| |
| |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z[np-1-k] = guess - 1; |
| #else |
| z[k] = guess - 1; |
| #endif |
| |
| |
| carry = 0; |
| for( i = 0; i <= bden; ++i ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| tmp = (EMULONG)p[-i] + (EMULONG)y[np-i] + carry; |
| #else |
| tmp = (EMULONG)p[i] + (EMULONG)y[i] + carry; |
| #endif |
| if( tmp >= BASE ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| p[-i] = tmp - BASE; |
| #else |
| p[i] = tmp - BASE; |
| #endif |
| carry = 1; |
| } |
| else |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| p[-i] = tmp; |
| #else |
| p[i] = tmp; |
| #endif |
| carry = 0; |
| } |
| } |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| p[-i] = (EMULONG)p[-i] + carry - BASE; |
| #else |
| p[i] = (EMULONG)p[i] + carry - BASE; |
| #endif |
| } |
| |
| } |
| |
| |
| |
| |
| |
| |
| |
| if( scale > 1 ) |
| { |
| EMUSHORT junk; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| |
| iSINGLE_EMUSHORTd( rem, &junk, x+1, scale, np ); |
| #else |
| |
| iSINGLE_EMUSHORTd( rem, &junk, x, scale, np ); |
| #endif |
| } |
| else |
| { |
| for( i = 0; i < np; ++i ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| rem[i] = x[i+1]; |
| #else |
| rem[i] = x[i]; |
| #endif |
| } |
| } |
| |
| |
| |
| |
| check_flags_and_stop: |
| |
| |
| |
| |
| __CLP; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| |
| if( *z & MASK_SIGN ) __STS; |
| #else |
| |
| if( z[np-1] & MASK_SIGN ) __STS; |
| #endif |
| else __CLS; |
| |
| i = np; |
| while( i > 0 ) |
| { |
| if( *z ) zero &= 0; |
| else zero &= 1; |
| |
| ++z; --i; |
| } |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| if( __MFLAG(SF) ) __STO; |
| else __CLO; |
| |
| __CLA; |
| __CLC; |
| __CLV; |
| |
| |
| i = np; |
| while( i > 0 ) |
| { |
| if( *r ) remainder |= 1; |
| ++r; --i; |
| } |
| |
| if( remainder ) __STR; |
| else __CLR; |
| |
| |
| __mpu_sbrk( -(int)((np+1)*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)((np+1)*SIZE_OF_EMUSHORT) ); |
| |
| |
| } |
| |
| void isdiv_np( EMUSHORT *quot, EMUSHORT *rem, EMUSHORT *num, EMUSHORT *den, int np ) |
| { |
| EMUSHORT *z, *r, *x, *y, *p, sj = 0; |
| EMUSHORT *pcpy_num = 0, *pcpy_den = 0; |
| signed int sign_num = 0, sign_den = 0; |
| signed int remainder = 0, zero = 1; |
| int b, bnum, bden; |
| |
| EMUSHORT scale; |
| int i, j, k, m; |
| |
| errno = 0; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"isdiv_np (emushort)" ); |
| return; |
| } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = num; |
| #else |
| x = num + np - 1; |
| #endif |
| if( *x & MASK_SIGN ) sign_num = 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = den; |
| #else |
| y = den + np - 1; |
| #endif |
| if( *y & MASK_SIGN ) sign_den = 1; |
| |
| |
| pcpy_num = (EMUSHORT *)__mpu_sbrk( (int)((np+1)*SIZE_OF_EMUSHORT) ); |
| if( !pcpy_num ) |
| { |
| |
| return; |
| } |
| scvt_s2l_np( pcpy_num, num, np+1, np ); |
| |
| |
| |
| pcpy_den = (EMUSHORT *)__mpu_sbrk( (int)((np+1)*SIZE_OF_EMUSHORT) ); |
| if( !pcpy_den ) |
| { |
| |
| |
| __mpu_sbrk( -(int)((np+1)*SIZE_OF_EMUSHORT) ); |
| |
| return; |
| } |
| scvt_s2l_np( pcpy_den, den, np+1, np ); |
| |
| |
| if( sign_num ) ineg_np( pcpy_num, pcpy_num, np+1 ); |
| if( sign_den ) ineg_np( pcpy_den, pcpy_den, np+1 ); |
| |
| z = quot + np - 1; |
| i = np; |
| while( i > 0 ) |
| { |
| *z = 0; |
| --z; --i; |
| } |
| ++z; |
| |
| r = rem + np - 1; |
| i = np; |
| while( i > 0 ) |
| { |
| *r = 0; |
| --r; --i; |
| } |
| ++r; |
| |
| x = pcpy_num; |
| y = pcpy_den; |
| |
| |
| |
| |
| b = np - 1; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| while( x[np-b] == 0 && b != (-1) ) --b; |
| #else |
| while( x[b] == 0 && b != (-1) ) --b; |
| #endif |
| bnum = b; |
| |
| if( bnum == -1 ) |
| { |
| |
| |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; |
| |
| |
| __mpu_sbrk( -(int)((np+1)*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)((np+1)*SIZE_OF_EMUSHORT) ); |
| |
| |
| return; |
| } |
| |
| |
| |
| |
| b = np - 1; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| while( y[np-b] == 0 && b != (-1) ) --b; |
| #else |
| while( y[b] == 0 && b != (-1) ) --b; |
| #endif |
| bden = b; |
| |
| if( bden == -1 ) |
| { |
| |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| if( sign_num ) ineg_np( pcpy_num, pcpy_num, np+1 ); |
| |
| |
| i = np; |
| while( i > 0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *r = *(x+1); |
| #else |
| *r = *x; |
| #endif |
| |
| if( *r ) remainder |= 1; |
| |
| ++x; ++r; |
| --i; |
| } |
| |
| if( !sign_num ) sj = MASK_ALL_BITS; |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z = z + np - 1; |
| #endif |
| |
| i = np; |
| while( i > 0 ) |
| { |
| *z = sj; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --z; |
| #else |
| ++z; |
| #endif |
| --i; |
| } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++z; |
| #else |
| --z; |
| #endif |
| if( !sign_num ) |
| { |
| *z ^= MASK_SIGN; |
| __CLS; |
| } |
| else |
| { |
| *z |= MASK_SIGN; |
| __STS; |
| } |
| |
| if( remainder ) __STR; |
| else __CLR; |
| |
| __STC; __STO; |
| |
| |
| __mpu_sbrk( -(int)((np+1)*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)((np+1)*SIZE_OF_EMUSHORT) ); |
| |
| |
| return; |
| } |
| |
| if( bden == 0 ) |
| { |
| |
| |
| |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| iSINGLE_EMUSHORTd( z, &r[np-1], x+1, y[np], np ); |
| #else |
| iSINGLE_EMUSHORTd( z, &r[0], x, y[0], np ); |
| #endif |
| |
| goto check_flags_and_stop; |
| } |
| |
| if( bnum < bden ) |
| { |
| |
| |
| x = pcpy_num; |
| |
| i = np; |
| while( i > 0 ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *r = *(x+1); |
| #else |
| *r = *x; |
| #endif |
| |
| if( *r ) remainder |= 1; |
| |
| ++x; ++r; |
| --i; |
| } |
| |
| if( sign_num ^ sign_den ) ineg_np( rem, rem, np ); |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| if( remainder ) __STR; |
| else __CLR; |
| |
| __STZ; |
| |
| |
| __mpu_sbrk( -(int)((np+1)*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)((np+1)*SIZE_OF_EMUSHORT) ); |
| |
| |
| return; |
| } |
| |
| m = bnum - bden; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| scale = BASE / (y[np-bden] + 1); |
| #else |
| scale = BASE / (y[bden] + 1); |
| #endif |
| if( scale > 1 ) |
| { |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| iSINGLE_EMUSHORTm( x, x+1, scale, np + 1, np ); |
| iSINGLE_EMUSHORTm( y, y+1, scale, np + 1, np ); |
| #else |
| iSINGLE_EMUSHORTm( x, x, scale, np + 1, np ); |
| iSINGLE_EMUSHORTm( y, y, scale, np + 1, np ); |
| #endif |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| for( k = m, j = bden + k; k >= 0; --k, --j ) |
| { |
| EMULONG guess, rm; |
| EMULONG borrow, carry; |
| EMULONG tmp, tmp1, tmp2; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| guess = ((EMULONG)x[np-j-1] * BASE + (EMULONG)x[np-j]) / (EMULONG)y[np-bden]; |
| rm = ((EMULONG)x[np-j-1] * BASE + (EMULONG)x[np-j]) % (EMULONG)y[np-bden]; |
| #else |
| guess = ((EMULONG)x[j+1] * BASE + (EMULONG)x[j]) / (EMULONG)y[bden]; |
| rm = ((EMULONG)x[j+1] * BASE + (EMULONG)x[j]) % (EMULONG)y[bden]; |
| #endif |
| |
| |
| |
| |
| while( rm < BASE ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| tmp2 = (EMULONG)y[np-bden+1] * guess; |
| tmp1 = rm * BASE + (EMULONG)x[np-j+1]; |
| #else |
| tmp2 = (EMULONG)y[bden-1] * guess; |
| tmp1 = rm * BASE + (EMULONG)x[j-1]; |
| #endif |
| if( (tmp2 > tmp1) || (guess == BASE) ) |
| { |
| --guess; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| rm += (EMULONG)y[np-bden]; |
| #else |
| rm += (EMULONG)y[bden]; |
| #endif |
| } |
| else |
| break; |
| } |
| |
| |
| |
| |
| |
| |
| carry = 0; borrow = 0; |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| p = &x[np-k]; |
| #else |
| p = x + k; |
| #endif |
| |
| |
| for( i = 0; i <= bden; ++i ) |
| { |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| tmp1 = (EMULONG)y[np-i] * guess + carry; |
| #else |
| tmp1 = (EMULONG)y[i] * guess + carry; |
| #endif |
| carry = tmp1 / BASE; |
| tmp1 -= carry * BASE; |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| tmp2 = (EMULONG)p[-i] - tmp1 - borrow; |
| #else |
| tmp2 = (EMULONG)p[i] - tmp1 - borrow; |
| #endif |
| if( (tmp2 >> BITS_PER_EMUSHORT) & MASK_SIGN ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| p[-i] = tmp2 + BASE; |
| #else |
| p[i] = tmp2 + BASE; |
| #endif |
| borrow = 1; |
| } |
| else |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| p[-i] = tmp2; |
| #else |
| p[i] = tmp2; |
| #endif |
| borrow = 0; |
| } |
| } |
| |
| |
| |
| |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| tmp2 = (EMULONG)p[-i] - carry - borrow; |
| #else |
| tmp2 = (EMULONG)p[i] - carry - borrow; |
| #endif |
| if( (tmp2 >> BITS_PER_EMUSHORT) & MASK_SIGN ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| p[-i] = tmp2 + BASE; |
| #else |
| p[i] = tmp2 + BASE; |
| #endif |
| borrow = 1; |
| } |
| else |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| p[-i] = tmp2; |
| #else |
| p[i] = tmp2; |
| #endif |
| borrow = 0; |
| } |
| |
| |
| if( borrow == 0 ) |
| { |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z[np-1-k] = guess; |
| #else |
| z[k] = guess; |
| #endif |
| } |
| else |
| { |
| |
| |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z[np-1-k] = guess - 1; |
| #else |
| z[k] = guess - 1; |
| #endif |
| |
| |
| carry = 0; |
| for( i = 0; i <= bden; ++i ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| tmp = (EMULONG)p[-i] + (EMULONG)y[np-i] + carry; |
| #else |
| tmp = (EMULONG)p[i] + (EMULONG)y[i] + carry; |
| #endif |
| if( tmp >= BASE ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| p[-i] = tmp - BASE; |
| #else |
| p[i] = tmp - BASE; |
| #endif |
| carry = 1; |
| } |
| else |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| p[-i] = tmp; |
| #else |
| p[i] = tmp; |
| #endif |
| carry = 0; |
| } |
| } |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| p[-i] = (EMULONG)p[-i] + carry - BASE; |
| #else |
| p[i] = (EMULONG)p[i] + carry - BASE; |
| #endif |
| } |
| |
| } |
| |
| |
| |
| |
| |
| |
| |
| if( scale > 1 ) |
| { |
| EMUSHORT junk; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| |
| iSINGLE_EMUSHORTd( rem, &junk, x+1, scale, np ); |
| #else |
| |
| iSINGLE_EMUSHORTd( rem, &junk, x, scale, np ); |
| #endif |
| } |
| else |
| { |
| for( i = 0; i < np; ++i ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| rem[i] = x[i+1]; |
| #else |
| rem[i] = x[i]; |
| #endif |
| } |
| } |
| |
| |
| |
| |
| check_flags_and_stop: |
| |
| |
| i = np; |
| while( i > 0 ) |
| { |
| if( *r ) remainder |= 1; |
| ++r; --i; |
| } |
| |
| if( remainder ) __STR; |
| else __CLR; |
| |
| if( sign_num ^ sign_den ) |
| { |
| ineg_np( rem, rem, np ); |
| ineg_np( quot, quot, np ); |
| |
| __CLA; |
| __CLC; |
| |
| if( __MFLAG(SF) == (sign_num ^ sign_den) ) |
| |
| __CLO; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| __mpu_sbrk( -(int)((np+1)*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)((np+1)*SIZE_OF_EMUSHORT) ); |
| |
| |
| return; |
| } |
| |
| |
| |
| |
| __CLP; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| |
| if( *z & MASK_SIGN ) __STS; |
| #else |
| |
| if( z[np-1] & MASK_SIGN ) __STS; |
| #endif |
| else __CLS; |
| |
| i = np; |
| while( i > 0 ) |
| { |
| if( *z ) zero &= 0; |
| else zero &= 1; |
| |
| ++z; --i; |
| } |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| if( __MFLAG(SF) ) __STO; |
| else __CLO; |
| |
| |
| |
| |
| __CLA; |
| __CLC; |
| __CLV; |
| |
| |
| __mpu_sbrk( -(int)((np+1)*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)((np+1)*SIZE_OF_EMUSHORT) ); |
| |
| |
| } |
| |
| #undef BASE |
| |
| #else |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void idiv_np( EMUSHORT *quot, EMUSHORT *rem, EMUSHORT *num, EMUSHORT *den, int np ) |
| { |
| EMUSHORT *z, *r, *x, *y, j; |
| EMUSHORT *pcpy_num = 0, *pcpy_den = 0; |
| signed int remainder = 0, zero = 1; |
| signed int i, k; |
| int b, bnum, bden; |
| |
| errno = 0; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"idiv_np (emushort)" ); |
| return; |
| } |
| |
| |
| pcpy_num = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) ); |
| if( !pcpy_num ) |
| { |
| |
| return; |
| } |
| scpy_s2s_np( pcpy_num, num, np ); |
| |
| |
| |
| pcpy_den = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) ); |
| if( !pcpy_den ) |
| { |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| return; |
| } |
| scpy_s2s_np( pcpy_den, den, np ); |
| |
| |
| z = quot + np - 1; |
| i = np; |
| while( i > 0 ) |
| { |
| *z = 0; |
| --z; --i; |
| } |
| ++z; |
| |
| r = rem + np - 1; |
| i = np; |
| while( i > 0 ) |
| { |
| *r = 0; |
| --r; --i; |
| } |
| ++r; |
| |
| x = pcpy_num; |
| y = pcpy_den; |
| |
| b = np * BITS_PER_EMUSHORT - 1; |
| while( !ORDER_BIT(x,b,np) && b != (-1) ) --b; |
| bnum = b; |
| |
| if( bnum == -1 ) |
| { |
| |
| |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| return; |
| } |
| |
| b = np * BITS_PER_EMUSHORT - 1; |
| while( !ORDER_BIT(y,b,np) && b != (-1) ) --b; |
| bden = b; |
| |
| if( bden == -1 ) |
| { |
| |
| |
| |
| |
| i = np; |
| while( i > 0 ) |
| { |
| *r = *x; |
| |
| if( *r ) remainder |= 1; |
| |
| ++x; ++r; |
| --i; |
| } |
| |
| |
| i = np; |
| while( i > 0 ) |
| { |
| *z = MASK_ALL_BITS; |
| ++z; --i; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| if( remainder ) __STR; |
| else __CLR; |
| |
| __STC; __STO; __STS; |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| return; |
| } |
| |
| if( bnum < bden ) |
| { |
| |
| |
| |
| |
| i = np; |
| while( i > 0 ) |
| { |
| *r = *x; |
| |
| if( *r ) remainder |= 1; |
| |
| ++x; ++r; |
| --i; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| if( remainder ) __STR; |
| else __CLR; |
| |
| __STZ; |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| return; |
| } |
| |
| k = bnum - bden; |
| |
| ishln_np( y, y, k, np ); |
| |
| ++k; |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z = z + np - 1; |
| #endif |
| for( i = 0; i < k; ++i ) |
| { |
| icmp_np( x, y, np ); |
| if( !__MFLAG(SF) ) |
| { |
| isub_np( x, x, y, np ); |
| j = 1; |
| } |
| else j = 0; |
| |
| ishl_np( quot, quot, np ); |
| *z |= j; |
| |
| ishr_np( y, y, np ); |
| } |
| |
| |
| |
| |
| |
| i = np; |
| while( i > 0 ) |
| { |
| if( *z ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --z; |
| #else |
| ++z; |
| #endif |
| --i; |
| } |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++z; |
| #else |
| --z; |
| #endif |
| |
| if( *z & MASK_SIGN ) __STS; |
| else __CLS; |
| |
| if( __MFLAG(SF) ) __STO; |
| else __CLO; |
| |
| __CLA; |
| __CLC; |
| __CLV; |
| |
| |
| |
| i = np; |
| while( i > 0 ) |
| { |
| *r = *x; |
| |
| if( *r ) remainder |= 1; |
| |
| ++x; ++r; |
| --i; |
| } |
| |
| if( remainder ) __STR; |
| else __CLR; |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| } |
| |
| void isdiv_np( EMUSHORT *quot, EMUSHORT *rem, EMUSHORT *num, EMUSHORT *den, int np ) |
| { |
| EMUSHORT *z, *r, *x, *y, j = 0; |
| EMUSHORT *pcpy_num = 0, *pcpy_den = 0; |
| signed int sign_num = 0, sign_den = 0; |
| signed int remainder = 0, zero = 1; |
| signed int i, k; |
| int b, bnum, bden; |
| |
| errno = 0; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"isdiv_np (emushort)" ); |
| return; |
| } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = num; |
| #else |
| x = num + np - 1; |
| #endif |
| if( *x & MASK_SIGN ) sign_num = 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| y = den; |
| #else |
| y = den + np - 1; |
| #endif |
| if( *y & MASK_SIGN ) sign_den = 1; |
| |
| |
| pcpy_num = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) ); |
| if( !pcpy_num ) |
| { |
| |
| return; |
| } |
| scpy_s2s_np( pcpy_num, num, np ); |
| |
| |
| |
| pcpy_den = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) ); |
| if( !pcpy_den ) |
| { |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| return; |
| } |
| scpy_s2s_np( pcpy_den, den, np ); |
| |
| |
| if( sign_num ) ineg_np( pcpy_num, pcpy_num, np ); |
| if( sign_den ) ineg_np( pcpy_den, pcpy_den, np ); |
| |
| z = quot + np - 1; |
| i = np; |
| while( i > 0 ) |
| { |
| *z = 0; |
| --z; --i; |
| } |
| ++z; |
| |
| r = rem + np - 1; |
| i = np; |
| while( i > 0 ) |
| { |
| *r = 0; |
| --r; --i; |
| } |
| ++r; |
| |
| x = pcpy_num; |
| y = pcpy_den; |
| |
| b = np * BITS_PER_EMUSHORT - 1; |
| while( !ORDER_BIT(x,b,np) && b != (-1) ) --b; |
| bnum = b; |
| |
| if( bnum == -1 ) |
| { |
| |
| |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| return; |
| } |
| |
| b = np * BITS_PER_EMUSHORT - 1; |
| while( !ORDER_BIT(y,b,np) && b != (-1) ) --b; |
| bden = b; |
| |
| if( bden == -1 ) |
| { |
| |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| if( sign_num ) ineg_np( pcpy_num, pcpy_num, np ); |
| |
| |
| i = np; |
| while( i > 0 ) |
| { |
| *r = *x; |
| |
| if( *r ) remainder |= 1; |
| |
| ++x; ++r; |
| --i; |
| } |
| |
| if( !sign_num ) j = MASK_ALL_BITS; |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z = z + np - 1; |
| #endif |
| |
| i = np; |
| while( i > 0 ) |
| { |
| *z = j; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --z; |
| #else |
| ++z; |
| #endif |
| --i; |
| } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++z; |
| #else |
| --z; |
| #endif |
| if( !sign_num ) |
| { |
| *z ^= MASK_SIGN; |
| __CLS; |
| } |
| else |
| { |
| *z |= MASK_SIGN; |
| __STS; |
| } |
| |
| if( remainder ) __STR; |
| else __CLR; |
| |
| __STC; __STO; |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| return; |
| } |
| |
| if( bnum < bden ) |
| { |
| |
| |
| x = pcpy_num; |
| |
| i = np; |
| while( i > 0 ) |
| { |
| *r = *x; |
| |
| if( *r ) remainder |= 1; |
| |
| ++x; ++r; |
| --i; |
| } |
| |
| if( sign_num ^ sign_den ) ineg_np( rem, rem, np ); |
| |
| |
| |
| __CLEAR_IFLAGS; |
| |
| if( remainder ) __STR; |
| else __CLR; |
| |
| __STZ; |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| return; |
| } |
| |
| k = bnum - bden; |
| |
| ishln_np( y, y, k, np ); |
| |
| ++k; |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z = z + np - 1; |
| #endif |
| |
| for( i = 0; i < k; ++i ) |
| { |
| icmp_np( x, y, np ); |
| if( !__MFLAG(SF) ) |
| { |
| isub_np( x, x, y, np ); |
| j = 1; |
| } |
| else j = 0; |
| |
| ishl_np( quot, quot, np ); |
| *z |= j; |
| |
| ishr_np( y, y, np ); |
| } |
| |
| |
| |
| |
| |
| i = np; |
| while( i > 0 ) |
| { |
| *r = *x; |
| |
| if( *r ) remainder |= 1; |
| |
| ++x; ++r; |
| --i; |
| } |
| |
| if( remainder ) __STR; |
| else __CLR; |
| |
| if( sign_num ^ sign_den ) |
| { |
| ineg_np( rem, rem, np ); |
| ineg_np( quot, quot, np ); |
| |
| __CLA; |
| __CLC; |
| |
| if( __MFLAG(SF) == (sign_num ^ sign_den) ) |
| |
| __CLO; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| return; |
| } |
| |
| |
| |
| __CLP; |
| |
| i = np; |
| while( i > 0 ) |
| { |
| if( *z ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --z; |
| #else |
| ++z; |
| #endif |
| --i; |
| } |
| |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++z; |
| #else |
| --z; |
| #endif |
| if( *z & MASK_SIGN ) __STS; |
| else __CLS; |
| |
| if( __MFLAG(SF) ) __STO; |
| else __CLO; |
| |
| |
| |
| |
| __CLA; |
| __CLC; |
| __CLV; |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| } |
| |
| #endif |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #define _IS_SPACE_(c) ( (c) == NEWLINE || \ |
| (c) == CR || \ |
| (c) == SP || \ |
| (c) == HT || \ |
| (c) == VT ) |
| |
| #define _IS_DIGIT_(c) (((c) >= '0')&&((c) <= '9')) |
| |
| #define _IS_XDIGIT_(c) ( (((c) >= '0')&&((c) <= '9')) || \ |
| (((c) >= 'A')&&((c) <= 'F')) || \ |
| (((c) >= 'a')&&((c) <= 'f')) ) |
| |
| static int hexval( int c ) |
| { |
| if( c >= '0' && c <= '9' ) return ( c - '0' ); |
| if( c >= 'A' && c <= 'F' ) return ( c - 'A' + 10 ); |
| if( c >= 'a' && c <= 'f' ) return ( c - 'a' + 10 ); |
| |
| return( -1 ); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| static void satoi8_10( __mpu_uint8_t *c, __mpu_char8_t *str ) |
| { |
| __mpu_uint8_t b, weight = 10; |
| __mpu_uint16_t tmp = 0, mul = 1; |
| __mpu_char8_t *ptr; |
| signed int save_RF; |
| signed int i = 0; |
| |
| __CLV; |
| |
| save_RF = __MFLAG(RF); |
| |
| ptr = str; |
| |
| while( _IS_DIGIT_(*ptr) ) { ++ptr; ++i; } |
| --ptr; |
| |
| *c = 0; |
| |
| while( i > 0 ) |
| { |
| b = (__mpu_uint8_t) *ptr; |
| b -= '0'; |
| |
| icpy_s2l_8to16( (__mpu_uint16_t *)&tmp, &b ); |
| imul_8( (__mpu_uint16_t *)&tmp, (__mpu_uint8_t *)&tmp, (__mpu_uint8_t *)&mul ); |
| |
| if( !__MFLAG(RF) ) |
| { |
| iadd_8( c, c, (__mpu_uint8_t *)&tmp ); |
| |
| if( __MFLAG(CF) ) |
| { |
| |
| __STO; |
| |
| |
| if( __MPARITY(*c) ) __STP; |
| else __CLP; |
| |
| __CLA; |
| __CLC; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| |
| return; |
| } |
| } |
| else |
| { |
| |
| __STO; |
| |
| |
| if( __MPARITY(*c) ) __STP; |
| else __CLP; |
| |
| if( *c ) __CLZ; |
| else __STZ; |
| |
| if( *c & 0x80 ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| |
| return; |
| } |
| |
| imul_8( (__mpu_uint16_t *)&mul, (__mpu_uint8_t *)&mul, &weight ); |
| |
| --i; |
| --ptr; |
| |
| if( i && __MFLAG(RF) ) |
| { |
| |
| __STO; |
| |
| |
| if( __MPARITY(*c) ) __STP; |
| else __CLP; |
| |
| if( *c ) __CLZ; |
| else __STZ; |
| |
| if( *c & 0x80 ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| |
| return; |
| } |
| |
| } |
| |
| |
| if( __MPARITY(*c) ) __STP; |
| else __CLP; |
| |
| if( *c ) __CLZ; |
| else __STZ; |
| |
| if( *c & 0x80 ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| __CLO; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| } |
| |
| static void satoi8_16( __mpu_uint8_t *c, __mpu_char8_t *str ) |
| { |
| __mpu_uint8_t b; |
| __mpu_char8_t *ptr; |
| signed int i = 0; |
| signed int k = 0; |
| |
| __CLV; |
| |
| ptr = str; |
| |
| while( *ptr == '0' ) ++ptr; |
| |
| while( _IS_XDIGIT_(*ptr) ) { ++ptr; ++i; } |
| --ptr; |
| |
| *c = 0; |
| |
| __CLO; |
| if( i > 2 ) |
| { |
| __STO; |
| i = 2; |
| } |
| |
| while( i > 0 ) |
| { |
| b = (__mpu_uint8_t) *ptr; |
| b = (__mpu_uint8_t) hexval( b ); |
| |
| *c |= b << (k*4); |
| |
| --i; --ptr; ++k; |
| |
| } |
| |
| |
| if( __MPARITY(*c) ) __STP; |
| else __CLP; |
| |
| if( *c ) __CLZ; |
| else __STZ; |
| |
| if( *c & 0x80 ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| } |
| |
| static void satoi8_8( __mpu_uint8_t *c, __mpu_char8_t *str ) |
| { |
| __mpu_uint8_t b; |
| __mpu_char8_t *ptr; |
| signed int i = 0; |
| signed int k = 0; |
| |
| __CLV; |
| |
| ptr = str; |
| |
| while( *ptr == '0' ) ++ptr; |
| |
| while( *ptr >= '0' && *ptr <= '7' ) { ++ptr; ++i; } |
| --ptr; |
| |
| *c = 0; |
| |
| __CLO; |
| if( i >= 3 ) |
| { |
| b = (__mpu_uint8_t) *(ptr - 2); |
| b -= '0'; |
| |
| if( b > 3 || i > 3 ) |
| { |
| __STO; |
| } |
| i = 3; |
| } |
| |
| while( i > 0 ) |
| { |
| b = (__mpu_uint8_t) *ptr; |
| b -= '0'; |
| |
| *c |= b << (k*3); |
| |
| --i; --ptr; ++k; |
| |
| } |
| |
| |
| if( __MPARITY(*c) ) __STP; |
| else __CLP; |
| |
| if( *c ) __CLZ; |
| else __STZ; |
| |
| if( *c & 0x80 ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| } |
| |
| static void satoi8_2( __mpu_uint8_t *c, __mpu_char8_t *str ) |
| { |
| __mpu_uint8_t b; |
| __mpu_char8_t *ptr; |
| signed int i = 0; |
| signed int k = 0; |
| |
| __CLV; |
| |
| ptr = str; |
| |
| while( *ptr == '0' ) ++ptr; |
| |
| while( *ptr == '0' || *ptr == '1' ) { ++ptr; ++i; } |
| --ptr; |
| |
| *c = 0; |
| |
| __CLO; |
| if( i > BITS_PER_BYTE ) |
| { |
| __STO; |
| i = BITS_PER_BYTE; |
| } |
| |
| while( i > 0 ) |
| { |
| b = (__mpu_uint8_t) *ptr; |
| b -= '0'; |
| |
| *c |= b << (k); |
| |
| --i; --ptr; ++k; |
| |
| } |
| |
| |
| if( __MPARITY(*c) ) __STP; |
| else __CLP; |
| |
| if( *c ) __CLZ; |
| else __STZ; |
| |
| if( *c & 0x80 ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| } |
| |
| |
| |
| |
| |
| void iatoi_8( __mpu_uint8_t *c, __mpu_char8_t *str ) |
| { |
| signed int sign = 0, save_RF; |
| __mpu_char8_t *ptr; |
| |
| __CLV; |
| |
| save_RF = __MFLAG(RF); |
| |
| ptr = str; |
| |
| while( _IS_SPACE_(*ptr) ) ++ptr; |
| if( *ptr == '-' || *ptr == '+' ) |
| { |
| if( *ptr == '-' ) sign = 1; |
| ++ptr; |
| } |
| while( _IS_SPACE_(*ptr) ) ++ptr; |
| |
| if( !_IS_DIGIT_( *ptr ) ) |
| { |
| |
| __integer_invalid_number( (__mpu_char8_t *)"iatoi_8" ); |
| |
| *c = 0; |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; __CLP; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| |
| return; |
| } |
| |
| if( *ptr == '0' ) |
| { |
| ++ptr; |
| switch( *ptr ) |
| { |
| case 'b': |
| case 'B': |
| ++ptr; |
| |
| satoi8_2( c, ptr ); |
| return; |
| break; |
| |
| case 'x': |
| case 'X': |
| ++ptr; |
| |
| satoi8_16( c, ptr ); |
| return; |
| break; |
| |
| default: |
| |
| if( !_IS_DIGIT_(*ptr) ) |
| { |
| *c = 0; |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; __CLP; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| } |
| else |
| { |
| satoi8_8( c, ptr ); |
| } |
| return; |
| break; |
| |
| } |
| } |
| else |
| { |
| satoi8_10( c, ptr ); |
| if( __MFLAG(OF) ) return; |
| |
| if( sign ) ineg_8( c, c ); |
| if( sign == __MFLAG(SF) ) __CLO; |
| else __STO; |
| |
| __CLA; |
| __CLC; |
| |
| return; |
| } |
| } |
| |
| |
| void iatoui_8( __mpu_uint8_t *c, __mpu_char8_t *str ) |
| { |
| signed int save_RF; |
| __mpu_char8_t *ptr; |
| |
| __CLV; |
| |
| save_RF = __MFLAG(RF); |
| |
| ptr = str; |
| |
| while( _IS_SPACE_(*ptr) ) ++ptr; |
| if( *ptr == '-' || *ptr == '+' ) ++ptr; |
| while( _IS_SPACE_(*ptr) ) ++ptr; |
| |
| if( !_IS_DIGIT_( *ptr ) ) |
| { |
| |
| __integer_invalid_number( (__mpu_char8_t *)"iatoui_8" ); |
| |
| *c = 0; |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; __CLP; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| |
| return; |
| } |
| |
| if( *ptr == '0' ) |
| { |
| ++ptr; |
| switch( *ptr ) |
| { |
| case 'b': |
| case 'B': |
| ++ptr; |
| |
| satoi8_2( c, ptr ); |
| return; |
| break; |
| |
| case 'x': |
| case 'X': |
| ++ptr; |
| |
| satoi8_16( c, ptr ); |
| return; |
| break; |
| |
| default: |
| |
| if( !_IS_DIGIT_(*ptr) ) |
| { |
| *c = 0; |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; __CLP; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| } |
| else |
| { |
| satoi8_8( c, ptr ); |
| } |
| return; |
| break; |
| |
| } |
| } |
| else |
| { |
| satoi8_10( c, ptr ); |
| return; |
| } |
| } |
| |
| |
| |
| |
| static void satoi16_10( __mpu_uint16_t *c, __mpu_char8_t *str ) |
| { |
| __mpu_uint16_t b, weight = 10; |
| __mpu_uint32_t tmp = 0, mul = 1; |
| __mpu_char8_t *ptr; |
| signed int save_RF; |
| signed int i = 0; |
| |
| __CLV; |
| |
| save_RF = __MFLAG(RF); |
| |
| ptr = str; |
| |
| while( _IS_DIGIT_(*ptr) ) { ++ptr; ++i; } |
| --ptr; |
| |
| *c = 0; |
| |
| while( i > 0 ) |
| { |
| b = (__mpu_uint16_t) *ptr; |
| b -= '0'; |
| |
| icpy_s2l_16to32( &tmp, &b ); |
| imul_16( &tmp, (__mpu_uint16_t *)&tmp, (__mpu_uint16_t *)&mul ); |
| |
| if( !__MFLAG(RF) ) |
| { |
| iadd_16( c, c, (__mpu_uint16_t *)&tmp ); |
| |
| if( __MFLAG(CF) ) |
| { |
| |
| __STO; |
| |
| |
| if( __MPARITY(*c) ) __STP; |
| else __CLP; |
| |
| __CLA; |
| __CLC; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| |
| return; |
| } |
| |
| } |
| else |
| { |
| |
| __STO; |
| |
| |
| if( __MPARITY(*c) ) __STP; |
| else __CLP; |
| |
| if( *c ) __CLZ; |
| else __STZ; |
| |
| if( *c & 0x8000 ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| |
| return; |
| } |
| |
| imul_16( &mul, (__mpu_uint16_t *)&mul, &weight ); |
| |
| --i; |
| --ptr; |
| |
| if( i && __MFLAG(RF) ) |
| { |
| |
| __STO; |
| |
| |
| if( __MPARITY(*c) ) __STP; |
| else __CLP; |
| |
| if( *c ) __CLZ; |
| else __STZ; |
| |
| if( *c & 0x8000 ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| |
| return; |
| } |
| |
| } |
| |
| |
| if( __MPARITY(*c) ) __STP; |
| else __CLP; |
| |
| if( *c ) __CLZ; |
| else __STZ; |
| |
| if( *c & 0x8000 ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| __CLO; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| } |
| |
| static void satoi16_16( __mpu_uint16_t *c, __mpu_char8_t *str ) |
| { |
| __mpu_uint16_t b; |
| __mpu_char8_t *ptr; |
| signed int i = 0; |
| signed int k = 0; |
| |
| __CLV; |
| |
| ptr = str; |
| |
| while( *ptr == '0' ) ++ptr; |
| |
| while( _IS_XDIGIT_(*ptr) ) { ++ptr; ++i; } |
| --ptr; |
| |
| *c = 0; |
| |
| __CLO; |
| if( i > 4 ) |
| { |
| __STO; |
| i = 4; |
| } |
| |
| while( i > 0 ) |
| { |
| b = (__mpu_uint16_t) *ptr; |
| b = (__mpu_uint16_t) hexval( b ); |
| |
| *c |= b << (k*4); |
| |
| --i; --ptr; ++k; |
| |
| } |
| |
| |
| if( __MPARITY(*c) ) __STP; |
| else __CLP; |
| |
| if( *c ) __CLZ; |
| else __STZ; |
| |
| if( *c & 0x8000 ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| } |
| |
| static void satoi16_8( __mpu_uint16_t *c, __mpu_char8_t *str ) |
| { |
| __mpu_uint16_t b; |
| __mpu_char8_t *ptr; |
| signed int i = 0; |
| signed int k = 0; |
| |
| __CLV; |
| |
| ptr = str; |
| |
| while( *ptr == '0' ) ++ptr; |
| |
| while( *ptr >= '0' && *ptr <= '7' ) { ++ptr; ++i; } |
| --ptr; |
| |
| *c = 0; |
| |
| __CLO; |
| if( i >= 6 ) |
| { |
| b = (__mpu_uint16_t) *(ptr - 5); |
| b -= '0'; |
| |
| if( b > 1 || i > 6 ) |
| { |
| __STO; |
| } |
| i = 6; |
| } |
| |
| while( i > 0 ) |
| { |
| b = (__mpu_uint16_t) *ptr; |
| b -= '0'; |
| |
| *c |= b << (k*3); |
| |
| --i; |
| --ptr; |
| ++k; |
| |
| } |
| |
| |
| if( __MPARITY(*c) ) __STP; |
| else __CLP; |
| |
| if( *c ) __CLZ; |
| else __STZ; |
| |
| if( *c & 0x8000 ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| } |
| |
| static void satoi16_2( __mpu_uint16_t *c, __mpu_char8_t *str ) |
| { |
| __mpu_uint16_t b; |
| __mpu_char8_t *ptr; |
| signed int i = 0; |
| signed int k = 0; |
| |
| __CLV; |
| |
| ptr = str; |
| |
| while( *ptr == '0' ) ++ptr; |
| |
| while( *ptr == '0' || *ptr == '1' ) { ++ptr; ++i; } |
| --ptr; |
| |
| *c = 0; |
| |
| __CLO; |
| if( i > BITS_PER_TWO_BYTES ) |
| { |
| __STO; |
| i = BITS_PER_TWO_BYTES; |
| } |
| |
| while( i > 0 ) |
| { |
| b = (__mpu_uint16_t) *ptr; |
| b -= '0'; |
| |
| *c |= b << (k); |
| |
| --i; |
| --ptr; |
| ++k; |
| |
| } |
| |
| |
| if( __MPARITY(*c) ) __STP; |
| else __CLP; |
| |
| if( *c ) __CLZ; |
| else __STZ; |
| |
| if( *c & 0x8000 ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| } |
| |
| |
| |
| |
| |
| void iatoi_16( __mpu_uint16_t *c, __mpu_char8_t *str ) |
| { |
| signed int sign = 0, save_RF; |
| __mpu_char8_t *ptr; |
| |
| __CLV; |
| |
| save_RF = __MFLAG(RF); |
| |
| ptr = str; |
| |
| while( _IS_SPACE_(*ptr) ) ++ptr; |
| if( *ptr == '-' || *ptr == '+' ) |
| { |
| if( *ptr == '-' ) sign = 1; |
| ++ptr; |
| } |
| while( _IS_SPACE_(*ptr) ) ++ptr; |
| |
| if( !_IS_DIGIT_( *ptr ) ) |
| { |
| |
| __integer_invalid_number( (__mpu_char8_t *)"iatoi_16" ); |
| |
| *c = 0; |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; __CLP; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| |
| return; |
| } |
| |
| if( *ptr == '0' ) |
| { |
| ++ptr; |
| switch( *ptr ) |
| { |
| case 'b': |
| case 'B': |
| ++ptr; |
| |
| satoi16_2( c, ptr ); |
| return; |
| break; |
| |
| case 'x': |
| case 'X': |
| ++ptr; |
| |
| satoi16_16( c, ptr ); |
| return; |
| break; |
| |
| default: |
| |
| if( !_IS_DIGIT_(*ptr) ) |
| { |
| *c = 0; |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; __CLP; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| } |
| else |
| { |
| satoi16_8( c, ptr ); |
| } |
| return; |
| break; |
| |
| } |
| } |
| else |
| { |
| satoi16_10( c, ptr ); |
| if( __MFLAG(OF) ) return; |
| |
| if( sign ) ineg_16( c, c ); |
| if( sign == __MFLAG(SF) ) __CLO; |
| else __STO; |
| |
| __CLA; |
| __CLC; |
| |
| return; |
| } |
| } |
| |
| |
| |
| void iatoui_16( __mpu_uint16_t *c, __mpu_char8_t *str ) |
| { |
| signed int save_RF; |
| __mpu_char8_t *ptr; |
| |
| __CLV; |
| |
| save_RF = __MFLAG(RF); |
| |
| ptr = str; |
| |
| while( _IS_SPACE_(*ptr) ) ++ptr; |
| if( *ptr == '-' || *ptr == '+' ) ++ptr; |
| while( _IS_SPACE_(*ptr) ) ++ptr; |
| |
| if( !_IS_DIGIT_( *ptr ) ) |
| { |
| |
| __integer_invalid_number( (__mpu_char8_t *)"iatoui_16" ); |
| |
| *c = 0; |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; __CLP; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| |
| return; |
| } |
| |
| if( *ptr == '0' ) |
| { |
| ++ptr; |
| switch( *ptr ) |
| { |
| case 'b': |
| case 'B': |
| ++ptr; |
| |
| satoi16_2( c, ptr ); |
| return; |
| break; |
| |
| case 'x': |
| case 'X': |
| ++ptr; |
| |
| satoi16_16( c, ptr ); |
| return; |
| break; |
| |
| default: |
| |
| if( !_IS_DIGIT_(*ptr) ) |
| { |
| *c = 0; |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; __CLP; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| } |
| else |
| { |
| satoi16_8( c, ptr ); |
| } |
| return; |
| break; |
| |
| } |
| } |
| else |
| { |
| satoi16_10( c, ptr ); |
| return; |
| } |
| } |
| |
| |
| #define BITS_PER_EIGHT_BYTES 64 |
| |
| #if BITS_PER_EMUSHORT > 32 |
| |
| |
| |
| static void satoi32_10( __mpu_uint32_t *c, __mpu_char8_t *str ) |
| { |
| __mpu_uint32_t b, weight = 10; |
| __mpu_uint64_t tmp = 0, mul = 1; |
| __mpu_char8_t *ptr; |
| signed int save_RF; |
| signed int i = 0; |
| |
| __CLV; |
| |
| save_RF = __MFLAG(RF); |
| |
| ptr = str; |
| |
| while( _IS_DIGIT_(*ptr) ) { ++ptr; ++i; } |
| --ptr; |
| |
| *c = 0; |
| |
| while( i > 0 ) |
| { |
| b = (__mpu_uint32_t) *ptr; |
| b -= '0'; |
| |
| icpy_s2l_32to_np( (EMUSHORT *)&tmp, &b, BITS_PER_EIGHT_BYTES/ |
| BITS_PER_EMUSHORT ); |
| imul_32( &tmp, (__mpu_uint32_t *)&tmp, (__mpu_uint32_t *)&mul ); |
| |
| if( !__MFLAG(RF) ) |
| { |
| iadd_32( c, c, (__mpu_uint32_t *)&tmp ); |
| |
| if( __MFLAG(CF) ) |
| { |
| |
| __STO; |
| |
| |
| if( __MPARITY(*c) ) __STP; |
| else __CLP; |
| |
| __CLA; |
| __CLC; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| |
| return; |
| } |
| |
| } |
| else |
| { |
| |
| __STO; |
| |
| |
| if( __MPARITY(*c) ) __STP; |
| else __CLP; |
| |
| if( *c ) __CLZ; |
| else __STZ; |
| |
| if( *c & 0x80000000 ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| |
| return; |
| } |
| |
| imul_32( &mul, (__mpu_uint32_t *)&mul, &weight ); |
| |
| --i; |
| --ptr; |
| |
| if( i && __iflag_major_rem ) |
| { |
| |
| __STO; |
| |
| |
| if( __MPARITY(*c) ) __STP; |
| else __CLP; |
| |
| if( *c ) __CLZ; |
| else __STZ; |
| |
| if( *c & 0x80000000 ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| |
| return; |
| } |
| |
| } |
| |
| |
| if( __MPARITY(*c) ) __STP; |
| else __CLP; |
| |
| if( *c ) __CLZ; |
| else __STZ; |
| |
| if( *c & 0x80000000 ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| __CLO; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| } |
| |
| static void satoi32_16( __mpu_uint32_t *c, __mpu_char8_t *str ) |
| { |
| __mpu_uint32_t b; |
| __mpu_char8_t *ptr; |
| signed int i = 0; |
| signed int k = 0; |
| |
| __CLV; |
| |
| ptr = str; |
| |
| while( *ptr == '0' ) ++ptr; |
| |
| while( _IS_XDIGIT_(*ptr) ) { ++ptr; ++i; } |
| --ptr; |
| |
| *c = 0; |
| |
| __CLO; |
| if( i > 8 ) |
| { |
| __STO; |
| i = 8; |
| } |
| |
| while( i > 0 ) |
| { |
| b = (__mpu_uint32_t) *ptr; |
| b = (__mpu_uint32_t) hexval( b ); |
| |
| *c |= b << (k*4); |
| |
| --i; --ptr; ++k; |
| |
| } |
| |
| |
| if( __MPARITY(*c) ) __STP; |
| else __CLP; |
| |
| if( *c ) __CLZ; |
| else __STZ; |
| |
| if( *c & 0x80000000 ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| } |
| |
| static void satoi32_8( __mpu_uint32_t *c, __mpu_char8_t *str ) |
| { |
| __mpu_uint32_t b; |
| __mpu_char8_t *ptr; |
| signed int i = 0; |
| signed int k = 0; |
| |
| __CLV; |
| |
| ptr = str; |
| |
| while( *ptr == '0' ) ++ptr; |
| |
| while( *ptr >= '0' && *ptr <= '7' ) { ++ptr; ++i; } |
| --ptr; |
| |
| *c = 0; |
| |
| __CLO; |
| if( i >= 11 ) |
| { |
| b = *(ptr - 10); |
| b -= '0'; |
| |
| if( b > 3 || i > 11 ) |
| { |
| __STO; |
| } |
| i = 11; |
| } |
| |
| while( i > 0 ) |
| { |
| b = (__mpu_uint32_t) *ptr; |
| b -= '0'; |
| |
| *c |= b << (k*3); |
| |
| --i; --ptr; ++k; |
| |
| } |
| |
| |
| if( __MPARITY(*c) ) __STP; |
| else __CLP; |
| |
| if( *c ) __CLZ; |
| else __STZ; |
| |
| if( *c & 0x80000000 ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| } |
| |
| static void satoi32_2( __mpu_uint32_t *c, __mpu_char8_t *str ) |
| { |
| __mpu_uint32_t b; |
| __mpu_char8_t *ptr; |
| signed int i = 0; |
| signed int k = 0; |
| |
| __CLV; |
| |
| ptr = str; |
| |
| while( *ptr == '0' ) ++ptr; |
| |
| while( *ptr == '0' || *ptr == '1' ) { ++ptr; ++i; } |
| --ptr; |
| |
| *c = 0; |
| |
| __CLO; |
| if( i > BITS_PER_FOUR_BYTES ) |
| { |
| __STO; |
| i = BITS_PER_FOUR_BYTES; |
| } |
| |
| while( i > 0 ) |
| { |
| b = (__mpu_uint32_t) *ptr; |
| b -= '0'; |
| |
| *c |= b << (k); |
| |
| --i; --ptr; ++k; |
| |
| } |
| |
| |
| if( __MPARITY(*c) ) __STP; |
| else __CLP; |
| |
| if( *c ) __CLZ; |
| else __STZ; |
| |
| if( *c & 0x80000000 ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| } |
| |
| |
| |
| |
| |
| void iatoi_32( __mpu_uint32_t *c, __mpu_char8_t *str ) |
| { |
| signed int sign = 0, save_RF; |
| __mpu_char8_t *ptr; |
| |
| __CLV; |
| |
| save_RF = __MFLAG(RF); |
| |
| ptr = str; |
| |
| while( _IS_SPACE_(*ptr) ) ++ptr; |
| if( *ptr == '-' || *ptr == '+' ) |
| { |
| if( *ptr == '-' ) sign = 1; |
| ++ptr; |
| } |
| while( _IS_SPACE_(*ptr) ) ++ptr; |
| |
| if( !_IS_DIGIT_( *ptr ) ) |
| { |
| |
| __integer_invalid_number( (__mpu_char8_t *)"iatoi_32" ); |
| |
| *c = 0; |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; __CLP; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| |
| return; |
| } |
| |
| if( *ptr == '0' ) |
| { |
| ++ptr; |
| switch( *ptr ) |
| { |
| case 'b': |
| case 'B': |
| ++ptr; |
| |
| satoi32_2( c, ptr ); |
| return; |
| break; |
| |
| case 'x': |
| case 'X': |
| ++ptr; |
| |
| satoi32_16( c, ptr ); |
| return; |
| break; |
| |
| default: |
| |
| if( !_IS_DIGIT_(*ptr) ) |
| { |
| *c = 0; |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; __CLP; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| } |
| else |
| { |
| satoi32_8( c, ptr ); |
| } |
| return; |
| break; |
| |
| } |
| } |
| else |
| { |
| satoi32_10( c, ptr ); |
| if( __MFLAG(OF) ) return; |
| |
| if( sign ) ineg_32( c, c ); |
| if( sign == __MFLAG(SF) ) __CLO; |
| else __STO; |
| |
| __CLA; |
| __CLC; |
| |
| return; |
| } |
| } |
| |
| |
| |
| void iatoui_32( __mpu_uint32_t *c, __mpu_char8_t *str ) |
| { |
| signed int save_RF; |
| __mpu_char8_t *ptr; |
| |
| __CLV; |
| |
| save_RF = __MFLAG(RF); |
| |
| ptr = str; |
| |
| while( _IS_SPACE_(*ptr) ) ++ptr; |
| if( *ptr == '-' || *ptr == '+' ) ++ptr; |
| while( _IS_SPACE_(*ptr) ) ++ptr; |
| |
| if( !_IS_DIGIT_( *ptr ) ) |
| { |
| |
| __integer_invalid_number( (__mpu_char8_t *)"iatoui_32" ); |
| |
| *c = 0; |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; __CLP; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| |
| return; |
| } |
| |
| if( *ptr == '0' ) |
| { |
| ++ptr; |
| switch( *ptr ) |
| { |
| case 'b': |
| case 'B': |
| ++ptr; |
| |
| satoi32_2( c, ptr ); |
| return; |
| break; |
| |
| case 'x': |
| case 'X': |
| ++ptr; |
| |
| satoi32_16( c, ptr ); |
| return; |
| break; |
| |
| default: |
| |
| if( !_IS_DIGIT_(*ptr) ) |
| { |
| *c = 0; |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; __CLP; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| } |
| else |
| { |
| satoi32_8( c, ptr ); |
| } |
| return; |
| break; |
| |
| } |
| } |
| else |
| { |
| satoi32_10( c, ptr ); |
| return; |
| } |
| } |
| |
| #endif |
| |
| |
| |
| |
| |
| static void satoi_np_10( EMUSHORT *c, __mpu_char8_t *str, int np ) |
| { |
| EMUSHORT b, *z, *weight=0, *tmp=0, *mul=0; |
| __mpu_char8_t *ptr; |
| signed int save_RF, zero = 1; |
| signed int n, i = 0; |
| |
| errno = 0; |
| |
| __CLV; |
| |
| |
| weight = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) ); |
| if( !weight ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)weight, 0, np*SIZE_OF_EMUSHORT ); |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(weight+np-1) = (EMUSHORT) 10; |
| #else |
| *weight = (EMUSHORT) 10; |
| #endif |
| |
| |
| |
| mul = (EMUSHORT *)__mpu_sbrk( (int)(2*np*SIZE_OF_EMUSHORT) ); |
| if( !mul ) |
| { |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| return; |
| } |
| (void)memset( (void *)mul, 0, 2*np*SIZE_OF_EMUSHORT ); |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(mul+2*np-1) = (EMUSHORT) 1; |
| #else |
| *mul = (EMUSHORT) 1; |
| #endif |
| |
| |
| |
| tmp = (EMUSHORT *)__mpu_sbrk( (int)(2*np*SIZE_OF_EMUSHORT) ); |
| if( !tmp ) |
| { |
| |
| |
| __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| return; |
| } |
| (void)memset( (void *)tmp, 0, 2*np*SIZE_OF_EMUSHORT ); |
| |
| |
| |
| save_RF = __MFLAG(RF); |
| |
| ptr = str; |
| |
| while( _IS_DIGIT_(*ptr) ) { ++ptr; ++i; } |
| --ptr; |
| |
| z = c + np - 1; |
| n = np; |
| while( n > 0 ) |
| { |
| *z = 0; |
| --z; --n; |
| } |
| ++z; |
| |
| while( i > 0 ) |
| { |
| b = (EMUSHORT) *ptr; |
| b -= '0'; |
| |
| |
| scpy_s2l_np( (EMUSHORT *)tmp, &b, np*2, 1 ); |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| imul_np( tmp, tmp+np, mul+np, np*2, np ); |
| #else |
| imul_np( tmp, tmp, mul, np*2, np ); |
| #endif |
| if( !__MFLAG(RF) ) |
| { |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| iadd_np( z, z, tmp+np, np ); |
| #else |
| iadd_np( z, z, tmp, np ); |
| #endif |
| |
| if( __MFLAG(CF) ) |
| { |
| |
| __STO; |
| |
| |
| __CLA; |
| __CLC; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| |
| |
| |
| |
| __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| return; |
| } |
| |
| } |
| else |
| { |
| |
| __STO; |
| |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z = z + np - 1; |
| #endif |
| |
| n = np; |
| while( n > 0 ) |
| { |
| if( *z ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --z; |
| #else |
| ++z; |
| #endif |
| --n; |
| } |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++z; |
| #else |
| --z; |
| #endif |
| if( *z & MASK_SIGN ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| |
| |
| __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| return; |
| } |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| imul_np( mul, mul+np, weight, np*2, np ); |
| #else |
| imul_np( mul, mul, weight, np*2, np ); |
| #endif |
| |
| --i; |
| --ptr; |
| |
| if( i && __MFLAG(RF) ) |
| { |
| |
| __STO; |
| |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z = z + np - 1; |
| #endif |
| |
| n = np; |
| while( n > 0 ) |
| { |
| if( *z ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --z; |
| #else |
| ++z; |
| #endif |
| --n; |
| } |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++z; |
| #else |
| --z; |
| #endif |
| if( *z & MASK_SIGN ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| |
| |
| __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| return; |
| } |
| |
| } |
| |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z = z + np - 1; |
| #endif |
| |
| n = np; |
| while( n > 0 ) |
| { |
| if( *z ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --z; |
| #else |
| ++z; |
| #endif |
| --n; |
| } |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++z; |
| #else |
| --z; |
| #endif |
| if( *z & MASK_SIGN ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| __CLO; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| |
| |
| __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| } |
| |
| static void satoi_np_16( EMUSHORT *c, __mpu_char8_t *str, int np ) |
| { |
| EMUSHORT b, *z; |
| __mpu_char8_t *ptr; |
| signed int zero = 1; |
| signed int n, i = 0; |
| signed int k = 0; |
| |
| __CLV; |
| |
| ptr = str; |
| |
| while( *ptr == '0' ) ++ptr; |
| |
| while( _IS_XDIGIT_(*ptr) ) { ++ptr; ++i; } |
| --ptr; |
| |
| z = c + np - 1; |
| n = np; |
| while( n > 0 ) |
| { |
| *z = 0; |
| --z; --n; |
| } |
| ++z; |
| |
| __CLO; |
| if( i > BITS_PER_EMUSHORT*np/4 ) |
| { |
| __STO; |
| i = BITS_PER_EMUSHORT*np/4; |
| } |
| |
| while( i > 0 ) |
| { |
| b = (EMUSHORT) *ptr; |
| b = (EMUSHORT) hexval( b ); |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z[(np-1) - N_PARTS(k*4)] |= b << (N_BITS(k*4)); |
| #else |
| z[N_PARTS(k*4)] |= b << (N_BITS(k*4)); |
| #endif |
| |
| --i; --ptr; ++k; |
| |
| } |
| |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z = z + np - 1; |
| #endif |
| |
| n = np; |
| while( n > 0 ) |
| { |
| if( *z ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --z; |
| #else |
| ++z; |
| #endif |
| --n; |
| } |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++z; |
| #else |
| --z; |
| #endif |
| if( *z & MASK_SIGN ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| } |
| |
| static void satoi_np_8( EMUSHORT *c, __mpu_char8_t *str, int np ) |
| { |
| EMUSHORT b, *z; |
| __mpu_char8_t *ptr; |
| signed int zero = 1; |
| signed int n, i = 0; |
| signed int k = 0; |
| |
| __CLV; |
| |
| ptr = str; |
| |
| while( *ptr == '0' ) ++ptr; |
| |
| while( *ptr >= '0' && *ptr <= '7' ) { ++ptr; ++i; } |
| --ptr; |
| |
| z = c + np - 1; |
| n = np; |
| while( n > 0 ) |
| { |
| *z = 0; |
| --z; --n; |
| } |
| ++z; |
| |
| __CLO; |
| if( i >= BITS_PER_EMUSHORT*np/3+1 ) |
| { |
| b = (EMUSHORT) *(ptr - BITS_PER_EMUSHORT*np/3); |
| b -= '0'; |
| |
| if( b > ((BITS_PER_EMUSHORT*np%3) | 1) || |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| i > (BITS_PER_EMUSHORT*np/3 + 1) ) |
| { |
| __STO; |
| } |
| i = BITS_PER_EMUSHORT*np/3+1; |
| } |
| |
| while( i > 0 ) |
| { |
| b = (EMUSHORT) *ptr; |
| b -= '0'; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z[(np-1) - N_PARTS(k*3)] |= b << (N_BITS(k*3)); |
| #else |
| z[N_PARTS(k*3)] |= b << (N_BITS(k*3)); |
| #endif |
| |
| |
| if( k ) |
| { |
| if( !(k%(BITS_PER_EMUSHORT*(N_PARTS(k*3)+1)/3)) ) |
| { |
| |
| |
| |
| |
| |
| |
| if( !(N_PARTS(k*3) == np - 1) ) |
| { |
| |
| |
| |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z[(np-1) - N_PARTS(k*3)-1] |= |
| b >> ((BITS_PER_EMUSHORT*(N_PARTS(k*3)+1))%3); |
| #else |
| z[N_PARTS(k*3)+1] |= |
| b >> ((BITS_PER_EMUSHORT*(N_PARTS(k*3)+1))%3); |
| #endif |
| } |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| --i; --ptr; ++k; |
| |
| } |
| |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z = z + np - 1; |
| #endif |
| |
| n = np; |
| while( n > 0 ) |
| { |
| if( *z ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --z; |
| #else |
| ++z; |
| #endif |
| --n; |
| } |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++z; |
| #else |
| --z; |
| #endif |
| if( *z & MASK_SIGN ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| } |
| |
| static void satoi_np_2( EMUSHORT *c, __mpu_char8_t *str, int np ) |
| { |
| EMUSHORT b, *z; |
| __mpu_char8_t *ptr; |
| signed int zero = 1; |
| signed int n, i = 0; |
| signed int k = 0; |
| |
| __CLV; |
| |
| ptr = str; |
| |
| while( *ptr == '0' ) ++ptr; |
| |
| while( *ptr == '0' || *ptr == '1' ) { ++ptr; ++i; } |
| --ptr; |
| |
| z = c + np - 1; |
| n = np; |
| while( n > 0 ) |
| { |
| *z = 0; |
| --z; --n; |
| } |
| ++z; |
| |
| __CLO; |
| if( i > BITS_PER_EMUSHORT*np ) |
| { |
| __STO; |
| i = BITS_PER_EMUSHORT*np; |
| } |
| |
| while( i > 0 ) |
| { |
| b = (EMUSHORT) *ptr; |
| b -= '0'; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z[(np-1) - N_PARTS(k)] |= b << (N_BITS(k)); |
| #else |
| z[N_PARTS(k)] |= b << (N_BITS(k)); |
| #endif |
| |
| --i; --ptr; ++k; |
| |
| } |
| |
| |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| z = z + np - 1; |
| #endif |
| |
| n = np; |
| while( n > 0 ) |
| { |
| if( *z ) zero &= 0; |
| else zero &= 1; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| --z; |
| #else |
| ++z; |
| #endif |
| --n; |
| } |
| if( zero ) __STZ; |
| else __CLZ; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| ++z; |
| #else |
| --z; |
| #endif |
| if( *z & MASK_SIGN ) __STS; |
| else __CLS; |
| |
| __CLA; |
| __CLC; |
| } |
| |
| |
| |
| |
| void iatoi_np( EMUSHORT *c, __mpu_char8_t *str, int np ) |
| { |
| EMUSHORT *z; |
| signed int sign = 0, save_RF; |
| __mpu_char8_t *ptr; |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"iatoi_np (emushort)" ); |
| return; |
| } |
| |
| __CLV; |
| |
| save_RF = __MFLAG(RF); |
| |
| ptr = str; |
| |
| while( _IS_SPACE_(*ptr) ) ++ptr; |
| if( *ptr == '-' || *ptr == '+' ) |
| { |
| if( *ptr == '-' ) sign = 1; |
| ++ptr; |
| } |
| while( _IS_SPACE_(*ptr) ) ++ptr; |
| |
| if( !_IS_DIGIT_( *ptr ) ) |
| { |
| |
| __integer_invalid_number( (__mpu_char8_t *)"iatoi_np (emushort)" ); |
| |
| z = c + np - 1; |
| i = np; |
| while( i > 0 ) |
| { |
| *z = 0; |
| --z; --i; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| |
| return; |
| } |
| |
| if( *ptr == '0' ) |
| { |
| ++ptr; |
| switch( *ptr ) |
| { |
| case 'b': |
| case 'B': |
| ++ptr; |
| |
| satoi_np_2( c, ptr, np ); |
| return; |
| break; |
| |
| case 'x': |
| case 'X': |
| ++ptr; |
| |
| satoi_np_16( c, ptr, np ); |
| return; |
| break; |
| |
| default: |
| |
| if( !_IS_DIGIT_(*ptr) ) |
| { |
| z = c + np - 1; |
| i = np; |
| while( i > 0 ) |
| { |
| *z = 0; |
| --z; --i; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| } |
| else |
| { |
| satoi_np_8( c, ptr, np ); |
| } |
| return; |
| break; |
| |
| } |
| } |
| else |
| { |
| satoi_np_10( c, ptr, np ); |
| if( __MFLAG(OF) ) return; |
| |
| if( sign ) ineg_np( c, c, np ); |
| if( sign == __MFLAG(SF) ) __CLO; |
| else __STO; |
| |
| __CLA; |
| __CLC; |
| |
| return; |
| } |
| } |
| |
| void iatoui_np( EMUSHORT *c, __mpu_char8_t *str, int np ) |
| { |
| EMUSHORT *z; |
| __mpu_char8_t *ptr; |
| signed int save_RF; |
| signed int i; |
| |
| if( np < 1 || np > NP_MAX ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"iatoui_np (emushort)" ); |
| return; |
| } |
| |
| __CLV; |
| |
| save_RF = __MFLAG(RF); |
| |
| ptr = str; |
| |
| while( _IS_SPACE_(*ptr) ) ++ptr; |
| if( *ptr == '-' || *ptr == '+' ) ++ptr; |
| while( _IS_SPACE_(*ptr) ) ++ptr; |
| |
| if( !_IS_DIGIT_( *ptr ) ) |
| { |
| |
| __integer_invalid_number( (__mpu_char8_t *)"iatoui_np (emushort)" ); |
| |
| z = c + np - 1; |
| i = np; |
| while( i > 0 ) |
| { |
| *z = 0; |
| --z; --i; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| |
| return; |
| } |
| |
| if( *ptr == '0' ) |
| { |
| ++ptr; |
| switch( *ptr ) |
| { |
| case 'b': |
| case 'B': |
| ++ptr; |
| |
| satoi_np_2( c, ptr, np ); |
| return; |
| break; |
| |
| case 'x': |
| case 'X': |
| ++ptr; |
| |
| satoi_np_16( c, ptr, np ); |
| return; |
| break; |
| |
| default: |
| |
| if( !_IS_DIGIT_(*ptr) ) |
| { |
| z = c + np - 1; |
| i = np; |
| while( i > 0 ) |
| { |
| *z = 0; |
| --z; --i; |
| } |
| |
| |
| |
| __CLEAR_IFLAGS; |
| __STZ; |
| |
| if( save_RF ) __STR; |
| else __CLR; |
| } |
| else |
| { |
| satoi_np_8( c, ptr, np ); |
| } |
| return; |
| break; |
| |
| } |
| } |
| else |
| { |
| satoi_np_10( c, ptr, np ); |
| return; |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| static int hexdigit( int c, int uf ) |
| { |
| if( c >= 0 && c <= 9 ) return( '0' + c ); |
| if( c >= 10 && c <= 15 ) |
| { |
| if( uf ) return( 'A' + c - 10 ); |
| else return( 'a' + c - 10 ); |
| } |
| return( -1 ); |
| } |
| |
| |
| |
| |
| |
| |
| static void sitoa8_10( __mpu_char8_t *str, __mpu_uint8_t *a, int sign ) |
| { |
| __mpu_uint8_t b, x, weight = 10; |
| __mpu_char8_t *s = 0, *ptr; |
| __mpu_uint32_t flags; |
| |
| int size = (int)((BITS_PER_BYTE+3)*sizeof( __mpu_char8_t )); |
| |
| __CLV; |
| |
| flags = __MPU_FLAGS; |
| |
| s = (__mpu_char8_t *)__mpu_sbrk( size ); |
| if( !s ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)s, 0, (size_t)size ); |
| |
| ptr = s + BITS_PER_BYTE + 1; |
| |
| b = *a; |
| |
| if( b == 0 ) |
| { |
| *ptr = '0'; |
| } |
| else |
| { |
| do |
| { |
| idiv_8( &b, &x, &b, &weight ); |
| |
| *ptr = 0x30 | x; |
| --ptr; |
| |
| } while( b ); |
| *ptr = '0'; |
| |
| if( sign ) *ptr = '-'; |
| else ++ptr; |
| |
| } |
| strncpy( (char *)str, (const char *)ptr, (size_t)size ); |
| |
| |
| if( s ) |
| __mpu_sbrk( -size ); |
| |
| |
| __MPU_FLAGS = flags; |
| } |
| |
| |
| |
| |
| |
| |
| static void sitoa8_16( __mpu_char8_t *str, __mpu_uint8_t *a, int uf ) |
| { |
| __mpu_uint8_t b, x, mask = 15; |
| __mpu_char8_t *s = 0, *ptr; |
| int i; |
| |
| int size = (int)((BITS_PER_BYTE+3)*sizeof( __mpu_char8_t )); |
| |
| __CLV; |
| |
| s = (__mpu_char8_t *)__mpu_sbrk( size ); |
| if( !s ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)s, 0, (size_t)size ); |
| |
| ptr = s + BITS_PER_BYTE + 1; |
| |
| b = *a; |
| |
| if( b == 0 ) |
| { |
| *ptr = '0'; --ptr; |
| } |
| else |
| { |
| i = 0; |
| while( i < BITS_PER_BYTE / 4 ) |
| { |
| x = (b >> (i*4)) & mask; |
| x = (__mpu_uint8_t)hexdigit( x, uf ); |
| |
| *ptr = x; |
| --ptr; |
| ++i; |
| } |
| ++ptr; |
| while( *ptr == '0' ) ++ptr; |
| --ptr; |
| |
| } |
| |
| if( uf ) *ptr = 'X'; |
| else *ptr = 'x'; |
| --ptr; |
| *ptr = '0'; |
| |
| strncpy( (char *)str, (const char *)ptr, (size_t)size ); |
| |
| |
| if( s ) |
| __mpu_sbrk( -size ); |
| |
| } |
| |
| |
| |
| |
| |
| static void sitoa8_8( __mpu_char8_t *str, __mpu_uint8_t *a ) |
| { |
| __mpu_uint8_t b, x, mask = 7; |
| __mpu_char8_t *s = 0, *ptr; |
| int i; |
| |
| int size = (int)((BITS_PER_BYTE+3)*sizeof( __mpu_char8_t )); |
| |
| __CLV; |
| |
| s = (__mpu_char8_t *)__mpu_sbrk( size ); |
| if( !s ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)s, 0, (size_t)size ); |
| |
| ptr = s + BITS_PER_BYTE + 1; |
| |
| b = *a; |
| |
| if( b == 0 ) |
| { |
| *ptr = '0'; |
| --ptr; |
| } |
| else |
| { |
| i = 0; |
| while( i < BITS_PER_BYTE / 3 + 1 ) |
| { |
| x = (b >> (i*3)) & mask; |
| |
| *ptr = 0x30 | x; |
| --ptr; |
| ++i; |
| } |
| |
| } |
| |
| *ptr = '0'; |
| |
| while( *ptr == '0' ) ++ptr; |
| --ptr; |
| |
| strncpy( (char *)str, (const char *)ptr, (size_t)size ); |
| |
| |
| if( s ) |
| __mpu_sbrk( -size ); |
| |
| } |
| |
| |
| |
| |
| |
| |
| static void sitoa8_2( __mpu_char8_t *str, __mpu_uint8_t *a, int uf ) |
| { |
| __mpu_uint8_t b, x, mask = 1; |
| __mpu_char8_t *s = 0, *ptr; |
| int i; |
| |
| int size = (int)((BITS_PER_BYTE+3)*sizeof( __mpu_char8_t )); |
| |
| __CLV; |
| |
| s = (__mpu_char8_t *)__mpu_sbrk( size ); |
| if( !s ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)s, 0, (size_t)size ); |
| |
| ptr = s + BITS_PER_BYTE + 1; |
| |
| b = *a; |
| |
| if( b == 0 ) |
| { |
| *ptr = '0'; |
| --ptr; |
| } |
| else |
| { |
| i = 0; |
| while( i < BITS_PER_BYTE ) |
| { |
| x = (b >> (i)) & mask; |
| |
| if( x ) *ptr = '1'; |
| else *ptr = '0'; |
| |
| --ptr; |
| ++i; |
| } |
| ++ptr; |
| while( *ptr == '0' ) ++ptr; |
| --ptr; |
| |
| } |
| |
| if( uf ) *ptr = 'B'; |
| else *ptr = 'b'; |
| --ptr; |
| *ptr = '0'; |
| |
| strncpy( (char *)str, (const char *)ptr, (size_t)size ); |
| |
| |
| if( s ) |
| __mpu_sbrk( -size ); |
| |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void iitoa_8( __mpu_char8_t *str, __mpu_uint8_t *a, int radix, int uf ) |
| { |
| __mpu_uint8_t b; |
| int sign = 0; |
| __mpu_uint32_t flags; |
| |
| __CLV; |
| |
| flags = __MPU_FLAGS; |
| |
| switch( radix ) |
| { |
| case 2: |
| sitoa8_2( str, a, uf ); |
| break; |
| |
| case 8: |
| sitoa8_8( str, a ); |
| break; |
| |
| case 10: |
| { |
| b = *a; |
| |
| if( b & 0x80 ) |
| { |
| sign = 1; |
| ineg_8( &b, &b ); |
| } |
| sitoa8_10( str, &b, sign ); |
| break; |
| } |
| |
| case 16: |
| sitoa8_16( str, a, uf ); |
| break; |
| |
| default: |
| |
| __integer_invalid_radix( (__mpu_char8_t *)"iitoa_8" ); |
| |
| *str = NUL; |
| break; |
| |
| } |
| |
| __MPU_FLAGS = flags; |
| } |
| |
| void iuitoa_8( __mpu_char8_t *str, __mpu_uint8_t *a, int radix, int uf ) |
| { |
| switch( radix ) |
| { |
| case 2: |
| sitoa8_2( str, a, uf ); |
| break; |
| case 8: |
| sitoa8_8( str, a ); |
| break; |
| case 10: |
| sitoa8_10( str, a, 0 ); |
| break; |
| case 16: |
| sitoa8_16( str, a, uf ); |
| break; |
| default: |
| |
| __integer_invalid_radix( (__mpu_char8_t *)"iuitoa_8" ); |
| |
| *str = NUL; |
| break; |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| static void sitoa16_10( __mpu_char8_t *str, __mpu_uint16_t *a, int sign ) |
| { |
| __mpu_uint16_t b, x, weight = 10; |
| __mpu_char8_t *s = 0, *ptr; |
| __mpu_uint32_t flags; |
| |
| int size = (int)((BITS_PER_TWO_BYTES+3)*sizeof( __mpu_char8_t )); |
| |
| __CLV; |
| |
| flags = __MPU_FLAGS; |
| |
| s = (__mpu_char8_t *)__mpu_sbrk( size ); |
| if( !s ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)s, 0, (size_t)size ); |
| |
| ptr = s + BITS_PER_TWO_BYTES + 1; |
| |
| b = *a; |
| |
| if( b == 0 ) |
| { |
| *ptr = '0'; |
| } |
| else |
| { |
| do |
| { |
| idiv_16( &b, &x, &b, &weight ); |
| |
| *ptr = 0x30 | (__mpu_uint8_t)x; |
| --ptr; |
| |
| } while( b ); |
| *ptr = '0'; |
| |
| if( sign ) *ptr = '-'; |
| else ++ptr; |
| |
| } |
| strncpy( (char *)str, (const char *)ptr, (size_t)size ); |
| |
| |
| if( s ) |
| __mpu_sbrk( -size ); |
| |
| |
| __MPU_FLAGS = flags; |
| } |
| |
| |
| |
| |
| |
| |
| static void sitoa16_16( __mpu_char8_t *str, __mpu_uint16_t *a, int uf ) |
| { |
| __mpu_uint16_t b, x, mask = 15; |
| __mpu_char8_t *s = 0, *ptr; |
| int i; |
| |
| int size = (int)((BITS_PER_TWO_BYTES+3)*sizeof( __mpu_char8_t )); |
| |
| __CLV; |
| |
| s = (__mpu_char8_t *)__mpu_sbrk( size ); |
| if( !s ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)s, 0, (size_t)size ); |
| |
| ptr = s + BITS_PER_TWO_BYTES + 1; |
| |
| b = *a; |
| |
| if( b == 0 ) |
| { |
| *ptr = '0'; |
| --ptr; |
| } |
| else |
| { |
| i = 0; |
| while( i < BITS_PER_TWO_BYTES / 4 ) |
| { |
| x = (b >> (i*4)) & mask; |
| x = (__mpu_uint16_t)hexdigit( x, uf ); |
| |
| *ptr = (__mpu_uint8_t)x; |
| --ptr; |
| ++i; |
| } |
| ++ptr; |
| while( *ptr == '0' ) ++ptr; |
| --ptr; |
| |
| } |
| |
| if( uf ) *ptr = 'X'; |
| else *ptr = 'x'; |
| --ptr; |
| *ptr = '0'; |
| |
| strncpy( (char *)str, (const char *)ptr, (size_t)size ); |
| |
| |
| if( s ) |
| __mpu_sbrk( -size ); |
| |
| } |
| |
| |
| |
| |
| |
| static void sitoa16_8( __mpu_char8_t *str, __mpu_uint16_t *a ) |
| { |
| __mpu_uint16_t b, x, mask = 7; |
| __mpu_char8_t *s = 0, *ptr; |
| int i; |
| |
| int size = (int)((BITS_PER_TWO_BYTES+3)*sizeof( __mpu_char8_t )); |
| |
| __CLV; |
| |
| s = (__mpu_char8_t *)__mpu_sbrk( size ); |
| if( !s ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)s, 0, (size_t)size ); |
| |
| ptr = s + BITS_PER_TWO_BYTES + 1; |
| |
| b = *a; |
| |
| if( b == 0 ) |
| { |
| *ptr = '0'; |
| --ptr; |
| } |
| else |
| { |
| i = 0; |
| while( i < BITS_PER_TWO_BYTES / 3 + 1 ) |
| { |
| x = (b >> (i*3)) & mask; |
| |
| *ptr = 0x30 | (__mpu_uint8_t)x; |
| --ptr; |
| ++i; |
| } |
| |
| } |
| |
| *ptr = '0'; |
| |
| while( *ptr == '0' ) ++ptr; |
| --ptr; |
| |
| strncpy( (char *)str, (const char *)ptr, (size_t)size ); |
| |
| |
| if( s ) |
| __mpu_sbrk( -size ); |
| |
| } |
| |
| |
| |
| |
| |
| |
| static void sitoa16_2( __mpu_char8_t *str, __mpu_uint16_t *a, int uf ) |
| { |
| __mpu_uint16_t b, x, mask = 1; |
| __mpu_char8_t *s = 0, *ptr; |
| int i; |
| |
| int size = (int)((BITS_PER_TWO_BYTES+3)*sizeof( __mpu_char8_t )); |
| |
| __CLV; |
| |
| s = (__mpu_char8_t *)__mpu_sbrk( size ); |
| if( !s ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)s, 0, (size_t)size ); |
| |
| ptr = s + BITS_PER_TWO_BYTES + 1; |
| |
| b = *a; |
| |
| if( b == 0 ) |
| { |
| *ptr = '0'; --ptr; |
| } |
| else |
| { |
| i = 0; |
| while( i < BITS_PER_TWO_BYTES ) |
| { |
| x = (b >> (i)) & mask; |
| |
| if( x ) *ptr = '1'; |
| else *ptr = '0'; |
| |
| --ptr; |
| ++i; |
| } |
| ++ptr; |
| while( *ptr == '0' ) ++ptr; |
| --ptr; |
| |
| } |
| |
| if( uf ) *ptr = 'B'; |
| else *ptr = 'b'; |
| --ptr; |
| *ptr = '0'; |
| |
| strncpy( (char *)str, (const char *)ptr, (size_t)size ); |
| |
| |
| if( s ) |
| __mpu_sbrk( -size ); |
| |
| } |
| |
| |
| |
| |
| void iitoa_16( __mpu_char8_t *str, __mpu_uint16_t *a, int radix, int uf ) |
| { |
| __mpu_uint16_t b; |
| int sign = 0; |
| __mpu_uint32_t flags; |
| |
| __CLV; |
| |
| flags = __MPU_FLAGS; |
| |
| switch( radix ) |
| { |
| case 2: |
| sitoa16_2( str, a, uf ); |
| break; |
| |
| case 8: |
| sitoa16_8( str, a ); |
| break; |
| |
| case 10: |
| { |
| b = *a; |
| |
| if( b & 0x8000 ) |
| { |
| sign = 1; |
| ineg_16( &b, &b ); |
| } |
| sitoa16_10( str, &b, sign ); |
| break; |
| } |
| |
| case 16: |
| sitoa16_16( str, a, uf ); |
| break; |
| |
| default: |
| |
| __integer_invalid_radix( (__mpu_char8_t *)"iitoa_16" ); |
| |
| *str = NUL; |
| break; |
| } |
| __MPU_FLAGS = flags; |
| } |
| |
| void iuitoa_16( __mpu_char8_t *str, __mpu_uint16_t *a, int radix, int uf ) |
| { |
| switch( radix ) |
| { |
| case 2: |
| sitoa16_2( str, a, uf ); |
| break; |
| case 8: |
| sitoa16_8( str, a ); |
| break; |
| case 10: |
| sitoa16_10( str, a, 0 ); |
| break; |
| case 16: |
| sitoa16_16( str, a, uf ); |
| break; |
| default: |
| |
| __integer_invalid_radix( (__mpu_char8_t *)"iuitoa_16" ); |
| |
| *str = NUL; |
| break; |
| } |
| } |
| |
| |
| #if BITS_PER_EMUSHORT > 32 |
| |
| |
| |
| static void sitoa32_10( __mpu_char8_t *str, __mpu_uint32_t *a, int sign ) |
| { |
| __mpu_uint32_t b, x, weight = 10; |
| __mpu_char8_t *s = 0, *ptr; |
| __mpu_uint32_t flags; |
| |
| int size = (int)((BITS_PER_FOUR_BYTES+3)*sizeof( __mpu_char8_t )); |
| |
| __CLV; |
| |
| flags = __MPU_FLAGS; |
| |
| s = (__mpu_char8_t *)__mpu_sbrk( size ); |
| if( !s ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)s, 0, (size_t)size ); |
| |
| ptr = s + BITS_PER_FOUR_BYTES + 1; |
| |
| b = *a; |
| |
| if( b == 0 ) |
| { |
| *ptr = '0'; |
| } |
| else |
| { |
| do |
| { |
| idiv_32( &b, &x, &b, &weight ); |
| |
| *ptr = 0x30 | (__mpu_uint8_t)x; |
| --ptr; |
| |
| } while( b ); |
| *ptr = '0'; |
| |
| if( sign ) *ptr = '-'; |
| else ++ptr; |
| |
| } |
| strncpy( (char *)str, (const char *)ptr, (size_t)size ); |
| |
| |
| if( s ) |
| __mpu_sbrk( -size ); |
| |
| |
| __MPU_FLAGS = flags; |
| } |
| |
| static void sitoa32_16( __mpu_char8_t *str, __mpu_uint32_t *a, int uf ) |
| { |
| __mpu_uint32_t b, x, mask = 15; |
| __mpu_char8_t *s = 0, *ptr; |
| int i; |
| |
| int size = (int)((BITS_PER_FOUR_BYTES+3)*sizeof( __mpu_char8_t )); |
| |
| s = (__mpu_char8_t *)__mpu_sbrk( size ); |
| if( !s ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)s, 0, (size_t)size ); |
| |
| ptr = s + BITS_PER_FOUR_BYTES + 1; |
| |
| b = *a; |
| |
| if( b == 0 ) |
| { |
| *ptr = '0'; |
| --ptr; |
| } |
| else |
| { |
| i = 0; |
| while( i < BITS_PER_FOUR_BYTES / 4 ) |
| { |
| x = (b >> (i*4)) & mask; |
| x = (__mpu_uint32_t)hexdigit( x, uf ); |
| |
| *ptr = (__mpu_uint8_t)x; |
| --ptr; |
| ++i; |
| } |
| ++ptr; |
| while( *ptr == '0' ) ++ptr; |
| --ptr; |
| |
| } |
| |
| if( uf ) *ptr = 'X'; |
| else *ptr = 'x'; |
| --ptr; |
| *ptr = '0'; |
| |
| strncpy( (char *)str, (const char *)ptr, (size_t)size ); |
| |
| |
| if( s ) |
| __mpu_sbrk( -size ); |
| |
| } |
| |
| static void sitoa32_8( __mpu_char8_t *str, __mpu_uint32_t *a ) |
| { |
| __mpu_uint32_t b, x, mask = 7; |
| __mpu_char8_t *s = 0, *ptr; |
| int i; |
| |
| int size = (int)((BITS_PER_FOUR_BYTES+3)*sizeof( __mpu_char8_t )); |
| |
| s = (__mpu_char8_t *)__mpu_sbrk( size ); |
| if( !s ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)s, 0, (size_t)size ); |
| |
| ptr = s + BITS_PER_FOUR_BYTES + 1; |
| |
| b = *a; |
| |
| if( b == 0 ) |
| { |
| *ptr = '0'; |
| --ptr; |
| } |
| else |
| { |
| i = 0; |
| while( i < BITS_PER_FOUR_BYTES / 3 + 1 ) |
| { |
| x = (b >> (i*3)) & mask; |
| |
| *ptr = 0x30 | (__mpu_uint8_t)x; |
| --ptr; |
| ++i; |
| } |
| |
| } |
| |
| *ptr = '0'; |
| |
| while( *ptr == '0' ) ++ptr; |
| --ptr; |
| |
| strncpy( (char *)str, (const char *)ptr, (size_t)size ); |
| |
| |
| if( s ) |
| __mpu_sbrk( -size ); |
| |
| } |
| |
| static void sitoa32_2( __mpu_char8_t *str, __mpu_uint32_t *a, int uf ) |
| { |
| __mpu_uint32_t b, x, mask = 1; |
| __mpu_char8_t *s = 0, *ptr; |
| int i; |
| |
| int size = (int)((BITS_PER_FOUR_BYTES+3)*sizeof( __mpu_char8_t )); |
| |
| s = (__mpu_char8_t *)__mpu_sbrk( size ); |
| if( !s ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)s, 0, (size_t)size ); |
| |
| ptr = s + BITS_PER_FOUR_BYTES + 1; |
| |
| b = *a; |
| |
| if( b == 0 ) |
| { |
| *ptr = '0'; --ptr; |
| } |
| else |
| { |
| i = 0; |
| while( i < BITS_PER_FOUR_BYTES ) |
| { |
| x = (b >> (i)) & mask; |
| |
| if( x ) *ptr = '1'; |
| else *ptr = '0'; |
| |
| --ptr; |
| ++i; |
| } |
| ++ptr; |
| while( *ptr == '0' ) ++ptr; |
| --ptr; |
| |
| } |
| |
| if( uf ) *ptr = 'B'; |
| else *ptr = 'b'; |
| --ptr; |
| *ptr = '0'; |
| |
| strncpy( (char *)str, (const char *)ptr, (size_t)size ); |
| |
| |
| if( s ) |
| __mpu_sbrk( -size ); |
| |
| } |
| |
| |
| |
| |
| void iitoa_32( __mpu_char8_t *str, __mpu_uint32_t *a, int radix, int uf ) |
| { |
| __mpu_uint32_t b; |
| int sign = 0; |
| __mpu_uint32_t flags; |
| |
| __CLV; |
| |
| flags = __MPU_FLAGS; |
| |
| switch( radix ) |
| { |
| case 2: |
| sitoa32_2( str, a, uf ); |
| break; |
| |
| case 8: |
| sitoa32_8( str, a ); |
| break; |
| |
| case 10: |
| { |
| b = *a; |
| |
| if( b & 0x80000000 ) |
| { |
| sign = 1; |
| ineg_32( &b, &b ); |
| } |
| sitoa32_10( str, &b, sign ); |
| break; |
| } |
| |
| case 16: |
| sitoa32_16( str, a, uf ); |
| break; |
| |
| default: |
| |
| __integer_invalid_radix( (__mpu_char8_t *)"iitoa_32" ); |
| |
| *str = NUL; |
| break; |
| |
| } |
| |
| __MPU_FLAGS = flags; |
| } |
| |
| void iuitoa_32( __mpu_char8_t *str, __mpu_uint32_t *a, int radix, int uf ) |
| { |
| switch( radix ) |
| { |
| case 2: |
| sitoa32_2( str, a, uf ); |
| break; |
| case 8: |
| sitoa32_8( str, a ); |
| break; |
| case 10: |
| sitoa32_10( str, a, 0 ); |
| break; |
| case 16: |
| sitoa32_16( str, a, uf ); |
| break; |
| default: |
| |
| __integer_invalid_radix( (__mpu_char8_t *)"iuitoa_32" ); |
| |
| *str = NUL; |
| break; |
| } |
| } |
| #endif |
| |
| |
| |
| |
| |
| static void sitoa_np_10( __mpu_char8_t *str, EMUSHORT *a, int sign, int np ) |
| { |
| EMUSHORT *b = 0, *x = 0, *weight = 0; |
| __mpu_char8_t *s = 0, *ptr; |
| __mpu_uint8_t y; |
| __mpu_uint32_t flags; |
| |
| int size = (int)((BITS_PER_EMUSHORT*np+3)*sizeof( __mpu_char8_t )); |
| |
| errno = 0; |
| |
| __CLV; |
| |
| flags = __MPU_FLAGS; |
| |
| |
| weight = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) ); |
| if( !weight ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)weight, 0, np*SIZE_OF_EMUSHORT ); |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(weight + np - 1) = (EMUSHORT)10; |
| #else |
| *weight = (EMUSHORT)10; |
| #endif |
| |
| |
| |
| x = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) ); |
| if( !x ) |
| { |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| return; |
| } |
| (void)memset( (void*)x, 0, np*SIZE_OF_EMUSHORT ); |
| |
| |
| |
| |
| b = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) ); |
| if( !b ) |
| { |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| return; |
| } |
| (void)memset( (void *)b, 0, np*SIZE_OF_EMUSHORT ); |
| |
| |
| |
| s = (__mpu_char8_t *)__mpu_sbrk( size ); |
| if( !s ) |
| { |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| return; |
| } |
| (void)memset( (void *)s, 0, (size_t)size ); |
| |
| ptr = s + BITS_PER_EMUSHORT*np + 1; |
| |
| scpy_s2s_np( b, a, np ); |
| |
| icmp_np( b, x, np ); |
| if( __MFLAG(ZF) ) |
| { |
| *ptr = '0'; |
| } |
| else |
| { |
| do |
| { |
| idiv_np( b, x, b, weight, np ); |
| |
| icpy_l2s_np_to8( &y, x, np ); |
| |
| *ptr = 0x30 | y; |
| --ptr; |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(weight + np - 1) = (EMUSHORT)0; |
| #else |
| *weight = (EMUSHORT)0; |
| #endif |
| icmp_np( b, weight, np ); |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| *(weight + np - 1) = (EMUSHORT)10; |
| #else |
| *weight = (EMUSHORT)10; |
| #endif |
| |
| } while( !__MFLAG(ZF) ); |
| *ptr = '0'; |
| |
| if( sign ) *ptr = '-'; |
| else ++ptr; |
| |
| } |
| strncpy( (char *)str, (const char *)ptr, (size_t)size ); |
| |
| |
| if( s ) __mpu_sbrk( -size ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __MPU_FLAGS = flags; |
| } |
| |
| static void sitoa_np_16( __mpu_char8_t *str, EMUSHORT *a, int uf, int np ) |
| { |
| EMUSHORT *b = 0, x, mask = 15; |
| __mpu_char8_t *s = 0, *ptr; |
| int i; |
| __mpu_uint32_t flags; |
| |
| int size = (int)((BITS_PER_EMUSHORT*np+3)*sizeof( __mpu_char8_t )); |
| |
| errno = 0; |
| |
| __CLV; |
| |
| flags = __MPU_FLAGS; |
| |
| |
| b = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) ); |
| if( !b ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)b, 0, np*SIZE_OF_EMUSHORT ); |
| |
| |
| |
| s = (__mpu_char8_t *)__mpu_sbrk( size ); |
| if( !s ) |
| { |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| return; |
| } |
| (void)memset( (void *)s, 0, (size_t)size ); |
| |
| ptr = s + BITS_PER_EMUSHORT*np + 1; |
| |
| icmp_np( a, b, np ); |
| if( __MFLAG(ZF) ) |
| { |
| *ptr = '0'; |
| --ptr; |
| } |
| else |
| { |
| i = 0; |
| while( i < BITS_PER_EMUSHORT*np / 4 ) |
| { |
| ishrn_np( b, a, (i*4), np ); |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = *(b+np-1) & mask; |
| #else |
| x = *b & mask; |
| #endif |
| x = (EMUSHORT)hexdigit( x, uf ); |
| |
| *ptr = (__mpu_uint8_t)x; |
| --ptr; |
| ++i; |
| } |
| ++ptr; |
| while( *ptr == '0' ) ++ptr; |
| --ptr; |
| |
| } |
| |
| if( uf ) *ptr = 'X'; |
| else *ptr = 'x'; |
| --ptr; |
| *ptr = '0'; |
| |
| strncpy( (char *)str, (const char *)ptr, (size_t)size ); |
| |
| |
| if( s ) __mpu_sbrk( -size ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __MPU_FLAGS = flags; |
| } |
| |
| static void sitoa_np_8( __mpu_char8_t *str, EMUSHORT *a, int np ) |
| { |
| EMUSHORT *b = 0, x, mask = 7; |
| __mpu_char8_t *s = 0, *ptr; |
| int i; |
| __mpu_uint32_t flags; |
| |
| int size = (int)((BITS_PER_EMUSHORT*np+3)*sizeof( __mpu_char8_t )); |
| |
| errno = 0; |
| |
| __CLV; |
| |
| flags = __MPU_FLAGS; |
| |
| |
| b = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) ); |
| if( !b ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)b, 0, np*SIZE_OF_EMUSHORT ); |
| |
| |
| |
| s = (__mpu_char8_t *)__mpu_sbrk( size ); |
| if( !s ) |
| { |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| return; |
| } |
| (void)memset( (void *)s, 0, (size_t)size ); |
| |
| ptr = s + BITS_PER_EMUSHORT*np + 1; |
| |
| icmp_np( a, b, np ); |
| if( __MFLAG(ZF) ) |
| { |
| *ptr = '0'; |
| --ptr; |
| } |
| else |
| { |
| i = 0; |
| while( i < BITS_PER_EMUSHORT*np / 3 + 1 ) |
| { |
| ishrn_np( b, a, (i*3), np ); |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = *(b+np-1) & mask; |
| #else |
| x = *b & mask; |
| #endif |
| |
| *ptr = 0x30 | (__mpu_uint8_t)x; |
| --ptr; |
| ++i; |
| } |
| |
| } |
| |
| *ptr = '0'; |
| |
| while( *ptr == '0' ) ++ptr; |
| --ptr; |
| |
| strncpy( (char *)str, (const char *)ptr, (size_t)size ); |
| |
| |
| if( s ) __mpu_sbrk( -size ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __MPU_FLAGS = flags; |
| } |
| |
| static void sitoa_np_2( __mpu_char8_t *str, EMUSHORT *a, int uf, int np ) |
| { |
| EMUSHORT *b = 0, x, mask = 1; |
| __mpu_char8_t *s = 0, *ptr; |
| int i; |
| __mpu_uint32_t flags; |
| |
| int size = (int)((BITS_PER_EMUSHORT*np+3)*sizeof( __mpu_char8_t )); |
| |
| errno = 0; |
| |
| __CLV; |
| |
| flags = __MPU_FLAGS; |
| |
| |
| b = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) ); |
| if( !b ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)b, 0, np*SIZE_OF_EMUSHORT ); |
| |
| |
| |
| s = (__mpu_char8_t *)__mpu_sbrk( size ); |
| if( !s ) |
| { |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| return; |
| } |
| (void)memset( (void *)s, 0, (size_t)size ); |
| |
| ptr = s + BITS_PER_EMUSHORT*np + 1; |
| |
| icmp_np( a, b, np ); |
| if( __MFLAG(ZF) ) |
| { |
| *ptr = '0'; |
| --ptr; |
| } |
| else |
| { |
| i = 0; |
| while( i < BITS_PER_EMUSHORT*np ) |
| { |
| ishrn_np( b, a, (i), np ); |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| x = *(b+np-1) & mask; |
| #else |
| x = *b & mask; |
| #endif |
| |
| if( x ) *ptr = '1'; |
| else *ptr = '0'; |
| |
| --ptr; |
| ++i; |
| } |
| ++ptr; |
| while( *ptr == '0' ) ++ptr; |
| --ptr; |
| |
| } |
| |
| if( uf ) *ptr = 'B'; |
| else *ptr = 'b'; |
| --ptr; |
| *ptr = '0'; |
| |
| strncpy( (char *)str, (const char *)ptr, (size_t)size ); |
| |
| |
| if( s ) __mpu_sbrk( -size ); |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __MPU_FLAGS = flags; |
| } |
| |
| |
| |
| |
| void iitoa_np( __mpu_char8_t *str, EMUSHORT *a, int radix, int uf, int np ) |
| { |
| EMUSHORT *b = 0; |
| int sign = 0; |
| __mpu_uint32_t flags; |
| |
| errno = 0; |
| |
| if( np == 0 ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"iitoa_np" ); |
| return; |
| } |
| |
| __CLV; |
| |
| flags = __MPU_FLAGS; |
| |
| |
| b = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) ); |
| if( !b ) |
| { |
| |
| return; |
| } |
| (void)memset( (void *)b, 0, np*SIZE_OF_EMUSHORT ); |
| |
| |
| |
| switch( radix ) |
| { |
| case 2: |
| sitoa_np_2( str, a, uf, np ); |
| break; |
| |
| case 8: |
| sitoa_np_8( str, a, np ); |
| break; |
| |
| case 10: |
| { |
| scpy_s2s_np( b, a, np ); |
| |
| #if MPU_WORD_ORDER_BIG_ENDIAN == 1 |
| if( *(b) & MASK_SIGN ) |
| #else |
| if( *(b+np-1) & MASK_SIGN ) |
| #endif |
| { |
| sign = 1; |
| ineg_np( b, b, np ); |
| } |
| sitoa_np_10( str, b, sign, np ); |
| break; |
| } |
| |
| case 16: |
| sitoa_np_16( str, a, uf, np ); |
| break; |
| |
| default: |
| |
| __integer_invalid_radix( (__mpu_char8_t *)"iitoa_np" ); |
| |
| *str = NUL; |
| break; |
| |
| } |
| |
| |
| __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) ); |
| |
| |
| __MPU_FLAGS = flags; |
| } |
| |
| void iuitoa_np( __mpu_char8_t *str, EMUSHORT *a, int radix, int uf, int np ) |
| { |
| if( np == 0 ) |
| { |
| |
| __integer_invalid_size( (__mpu_char8_t *)"iuitoa_np" ); |
| return; |
| } |
| |
| __CLV; |
| |
| switch( radix ) |
| { |
| case 2: |
| sitoa_np_2( str, a, uf, np ); |
| break; |
| case 8: |
| sitoa_np_8( str, a, np ); |
| break; |
| case 10: |
| sitoa_np_10( str, a, 0, np ); |
| break; |
| case 16: |
| sitoa_np_16( str, a, uf, np ); |
| break; |
| default: |
| |
| __integer_invalid_radix( (__mpu_char8_t *)"iuitoa_np" ); |
| |
| *str = NUL; |
| break; |
| |
| } |
| } |
| |
| |
| |
| |
| |
| __mpu_hidden_decl(iadd_8); |
| __mpu_hidden_decl(iadc_8); |
| __mpu_hidden_decl(isub_8); |
| __mpu_hidden_decl(isbb_8); |
| |
| __mpu_hidden_decl(iadd_16); |
| __mpu_hidden_decl(iadc_16); |
| __mpu_hidden_decl(isub_16); |
| __mpu_hidden_decl(isbb_16); |
| |
| __mpu_hidden_decl(iadd_32); |
| __mpu_hidden_decl(iadc_32); |
| __mpu_hidden_decl(isub_32); |
| __mpu_hidden_decl(isbb_32); |
| |
| __mpu_hidden_decl(iadd_np); |
| __mpu_hidden_decl(iadc_np); |
| __mpu_hidden_decl(isub_np); |
| __mpu_hidden_decl(isbb_np); |
| |
| |
| __mpu_hidden_decl(ishl_8); |
| __mpu_hidden_decl(ishr_8); |
| __mpu_hidden_decl(isal_8); |
| __mpu_hidden_decl(isar_8); |
| |
| __mpu_hidden_decl(ishl_16); |
| __mpu_hidden_decl(ishr_16); |
| __mpu_hidden_decl(isal_16); |
| __mpu_hidden_decl(isar_16); |
| |
| __mpu_hidden_decl(ishl_32); |
| __mpu_hidden_decl(ishr_32); |
| __mpu_hidden_decl(isal_32); |
| __mpu_hidden_decl(isar_32); |
| |
| __mpu_hidden_decl(ishl_np); |
| __mpu_hidden_decl(ishr_np); |
| __mpu_hidden_decl(isal_np); |
| __mpu_hidden_decl(isar_np); |
| |
| |
| __mpu_hidden_decl(irol_8); |
| __mpu_hidden_decl(iror_8); |
| __mpu_hidden_decl(ircl_8); |
| __mpu_hidden_decl(ircr_8); |
| |
| __mpu_hidden_decl(irol_16); |
| __mpu_hidden_decl(iror_16); |
| __mpu_hidden_decl(ircl_16); |
| __mpu_hidden_decl(ircr_16); |
| |
| __mpu_hidden_decl(irol_32); |
| __mpu_hidden_decl(iror_32); |
| __mpu_hidden_decl(ircl_32); |
| __mpu_hidden_decl(ircr_32); |
| |
| __mpu_hidden_decl(irol_np); |
| __mpu_hidden_decl(iror_np); |
| __mpu_hidden_decl(ircl_np); |
| __mpu_hidden_decl(ircr_np); |
| |
| |
| __mpu_hidden_decl(ishln_8); |
| __mpu_hidden_decl(ishrn_8); |
| __mpu_hidden_decl(isaln_8); |
| __mpu_hidden_decl(isarn_8); |
| |
| __mpu_hidden_decl(ishln_16); |
| __mpu_hidden_decl(ishrn_16); |
| __mpu_hidden_decl(isaln_16); |
| __mpu_hidden_decl(isarn_16); |
| |
| __mpu_hidden_decl(ishln_32); |
| __mpu_hidden_decl(ishrn_32); |
| __mpu_hidden_decl(isaln_32); |
| __mpu_hidden_decl(isarn_32); |
| |
| __mpu_hidden_decl(ishln_np); |
| __mpu_hidden_decl(ishrn_np); |
| __mpu_hidden_decl(isaln_np); |
| __mpu_hidden_decl(isarn_np); |
| |
| |
| __mpu_hidden_decl(iroln_8); |
| __mpu_hidden_decl(irorn_8); |
| __mpu_hidden_decl(ircln_8); |
| __mpu_hidden_decl(ircrn_8); |
| |
| __mpu_hidden_decl(iroln_16); |
| __mpu_hidden_decl(irorn_16); |
| __mpu_hidden_decl(ircln_16); |
| __mpu_hidden_decl(ircrn_16); |
| |
| __mpu_hidden_decl(iroln_32); |
| __mpu_hidden_decl(irorn_32); |
| __mpu_hidden_decl(ircln_32); |
| __mpu_hidden_decl(ircrn_32); |
| |
| __mpu_hidden_decl(iroln_np); |
| __mpu_hidden_decl(irorn_np); |
| __mpu_hidden_decl(ircln_np); |
| __mpu_hidden_decl(ircrn_np); |
| |
| |
| __mpu_hidden_decl(inot_8); |
| __mpu_hidden_decl(inot_16); |
| __mpu_hidden_decl(inot_32); |
| __mpu_hidden_decl(inot_np); |
| |
| __mpu_hidden_decl(ineg_8); |
| __mpu_hidden_decl(ineg_16); |
| __mpu_hidden_decl(ineg_32); |
| __mpu_hidden_decl(ineg_np); |
| |
| __mpu_hidden_decl(iand_8); |
| __mpu_hidden_decl(iand_16); |
| __mpu_hidden_decl(iand_32); |
| __mpu_hidden_decl(iand_np); |
| |
| __mpu_hidden_decl(itest_8); |
| __mpu_hidden_decl(itest_16); |
| __mpu_hidden_decl(itest_32); |
| __mpu_hidden_decl(itest_np); |
| |
| __mpu_hidden_decl(icmp_8); |
| __mpu_hidden_decl(icmp_16); |
| __mpu_hidden_decl(icmp_32); |
| __mpu_hidden_decl(icmp_np); |
| |
| __mpu_hidden_decl(ior_8); |
| __mpu_hidden_decl(ior_16); |
| __mpu_hidden_decl(ior_32); |
| __mpu_hidden_decl(ior_np); |
| |
| __mpu_hidden_decl(ixor_8); |
| __mpu_hidden_decl(ixor_16); |
| __mpu_hidden_decl(ixor_32); |
| __mpu_hidden_decl(ixor_np); |
| |
| __mpu_hidden_decl(iinc_8); |
| __mpu_hidden_decl(iinc_16); |
| __mpu_hidden_decl(iinc_32); |
| __mpu_hidden_decl(iinc_np); |
| |
| __mpu_hidden_decl(idec_8); |
| __mpu_hidden_decl(idec_16); |
| __mpu_hidden_decl(idec_32); |
| __mpu_hidden_decl(idec_np); |
| |
| __mpu_hidden_decl(icpy_8); |
| __mpu_hidden_decl(icpy_16); |
| __mpu_hidden_decl(icpy_32); |
| |
| __mpu_hidden_decl(icpy_s2l_8to16); |
| __mpu_hidden_decl(icpy_s2l_8to32); |
| __mpu_hidden_decl(icpy_s2l_8to_np); |
| |
| __mpu_hidden_decl(icpy_s2l_16to32); |
| __mpu_hidden_decl(icpy_s2l_16to_np); |
| |
| #if BITS_PER_EMUSHORT > 32 |
| __mpu_hidden_decl(icpy_s2l_32to_np); |
| #endif |
| |
| __mpu_hidden_decl(icpy_l2s_16to8); |
| __mpu_hidden_decl(icpy_l2s_32to8); |
| __mpu_hidden_decl(icpy_l2s_np_to8); |
| |
| __mpu_hidden_decl(icpy_l2s_32to16); |
| __mpu_hidden_decl(icpy_l2s_np_to16); |
| |
| #if BITS_PER_EMUSHORT > 32 |
| __mpu_hidden_decl(icpy_l2s_np_to32); |
| #endif |
| |
| __mpu_hidden_decl(icpy_np); |
| |
| |
| __mpu_hidden_decl(icvt_s2l_8to16); |
| __mpu_hidden_decl(icvt_s2l_8to32); |
| __mpu_hidden_decl(icvt_s2l_8to_np); |
| |
| __mpu_hidden_decl(icvt_s2l_16to32); |
| __mpu_hidden_decl(icvt_s2l_16to_np); |
| |
| #if BITS_PER_EMUSHORT > 32 |
| __mpu_hidden_decl(icvt_s2l_32to_np); |
| #endif |
| |
| __mpu_hidden_decl(icvt_l2s_16to8); |
| __mpu_hidden_decl(icvt_l2s_32to8); |
| __mpu_hidden_decl(icvt_l2s_np_to8); |
| |
| __mpu_hidden_decl(icvt_l2s_32to16); |
| __mpu_hidden_decl(icvt_l2s_np_to16); |
| #if BITS_PER_EMUSHORT > 32 |
| __mpu_hidden_decl(icvt_l2s_np_to32); |
| #endif |
| |
| __mpu_hidden_decl(icvt_np); |
| |
| |
| __mpu_hidden_decl(ixchg_8); |
| __mpu_hidden_decl(ixchg_16); |
| __mpu_hidden_decl(ixchg_32); |
| __mpu_hidden_decl(ixchg_np); |
| |
| |
| __mpu_hidden_decl(imul_8); |
| __mpu_hidden_decl(imul_16); |
| #if BITS_PER_EMUSHORT > 32 |
| __mpu_hidden_decl(imul_32); |
| #endif |
| |
| __mpu_hidden_decl(ismul_8); |
| __mpu_hidden_decl(ismul_16); |
| #if BITS_PER_EMUSHORT > 32 |
| __mpu_hidden_decl(ismul_32); |
| #endif |
| |
| |
| __mpu_hidden_decl(idiv_8); |
| __mpu_hidden_decl(idiv_16); |
| #if BITS_PER_EMUSHORT > 32 |
| __mpu_hidden_decl(idiv_32); |
| #endif |
| |
| __mpu_hidden_decl(isdiv_8); |
| __mpu_hidden_decl(isdiv_16); |
| #if BITS_PER_EMUSHORT > 32 |
| __mpu_hidden_decl(isdiv_32); |
| #endif |
| |
| |
| __mpu_hidden_decl(imul_np); |
| __mpu_hidden_decl(ismul_np); |
| |
| __mpu_hidden_decl(idiv_np); |
| __mpu_hidden_decl(isdiv_np); |
| |
| |
| |
| __mpu_hidden_decl(iatoi_8); |
| __mpu_hidden_decl(iatoui_8); |
| |
| __mpu_hidden_decl(iatoi_16); |
| __mpu_hidden_decl(iatoui_16); |
| |
| #if BITS_PER_EMUSHORT > 32 |
| __mpu_hidden_decl(iatoi_32); |
| __mpu_hidden_decl(iatoui_32); |
| #endif |
| |
| __mpu_hidden_decl(iatoi_np); |
| __mpu_hidden_decl(iatoui_np); |
| |
| |
| __mpu_hidden_decl(iitoa_8); |
| __mpu_hidden_decl(iuitoa_8); |
| |
| __mpu_hidden_decl(iitoa_16); |
| __mpu_hidden_decl(iuitoa_16); |
| |
| #if BITS_PER_EMUSHORT > 32 |
| __mpu_hidden_decl(iitoa_32); |
| __mpu_hidden_decl(iuitoa_32); |
| #endif |
| |
| __mpu_hidden_decl(iitoa_np); |
| __mpu_hidden_decl(iuitoa_np); |
| |
| |
| |
| |
| |
| |