Math Processor Unit Library

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

16 Commits   0 Branches   2 Tags

/***************************************************************
  __ST_LOGTABLE.C

       This file contains source code of functions for
       LOGTABLE constants operations.

       PART OF : MPU - library .

       USAGE   : Internal only .

       NOTE    : NONE .

       Copyright (C) 2000 - 2024  by Andrew V.Kosteltsev.
       All Rights Reserved.
 ***************************************************************/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <errno.h>   /* errno(3)  */
#include <string.h>  /* strcpy(3) */
#include <strings.h> /* bzero(3)  */
#include <stdlib.h>

#include <libmpu.h>
#include <mpu-context.h>

#include <mpu-emutype.h>
#include <mpu-integer.h>
#include <mpu-real.h>
#include <mpu-floatp.h>

#include <mpu-char.h>
#include <mpu-symbols.h>

#include <mpu-math-errno.h>
#include <mpu-mtherr.h>


/***************************************************************
  Кодировка имен файлов:

  Трехзначное десятичное число, представляющее количество
  128-и битных слов, из которых состоят вещественные числа
  размещенные в массивах:

    размер чисел в битах  кодировка
    --------------------  ---------
                     128  001
                     256  002
                     512  004
                    1024  008
                    2048  016
                    4096  032
                    8192  064
                   16384  128
                   32768  256
                   65536  512 (это предел);

    ПРИМЕРЫ:
    -------
      ei_logtable_001_emu32lsb.dfn -   128-бит,
      ei_logtable_512_emu32lsb.dfn - 65536-бит.

 ***************************************************************/

#if MPU_MATH_FN_LIMIT >= 128
#if MPU_WORD_ORDER_BIG_ENDIAN == 0
#include <math/logtable/emu00128/ei_logtable_001_emu32lsb.dfn>
#else
#include <math/logtable/emu00128/ei_logtable_001_emu32msb.dfn>
#endif
#endif /* MPU_MATH_FN_LIMIT >= 128 */

#if MPU_MATH_FN_LIMIT >= 256
#if MPU_WORD_ORDER_BIG_ENDIAN == 0
#include <math/logtable/emu00256/ei_logtable_002_emu32lsb.dfn>
#else
#include <math/logtable/emu00256/ei_logtable_002_emu32msb.dfn>
#endif
#endif /* MPU_MATH_FN_LIMIT >= 256 */

#if MPU_MATH_FN_LIMIT >= 512
#if MPU_WORD_ORDER_BIG_ENDIAN == 0
#include <math/logtable/emu00512/ei_logtable_004_emu32lsb.dfn>
#else
#include <math/logtable/emu00512/ei_logtable_004_emu32msb.dfn>
#endif
#endif /* MPU_MATH_FN_LIMIT >= 512 */

#if MPU_MATH_FN_LIMIT >= 1024
#if MPU_WORD_ORDER_BIG_ENDIAN == 0
#include <math/logtable/emu01024/ei_logtable_008_emu32lsb.dfn>
#else
#include <math/logtable/emu01024/ei_logtable_008_emu32msb.dfn>
#endif
#endif /* MPU_MATH_FN_LIMIT >= 1024 */

#if MPU_MATH_FN_LIMIT >= 2048
#if MPU_WORD_ORDER_BIG_ENDIAN == 0
#include <math/logtable/emu02048/ei_logtable_016_emu32lsb.dfn>
#else
#include <math/logtable/emu02048/ei_logtable_016_emu32msb.dfn>
#endif
#endif /* MPU_MATH_FN_LIMIT >= 2048 */

#if MPU_MATH_FN_LIMIT >= 4096
#if MPU_WORD_ORDER_BIG_ENDIAN == 0
#include <math/logtable/emu04096/ei_logtable_032_emu32lsb.dfn>
#else
#include <math/logtable/emu04096/ei_logtable_032_emu32msb.dfn>
#endif
#endif /* MPU_MATH_FN_LIMIT >= 4096 */

#if MPU_MATH_FN_LIMIT >= 8192
#if MPU_WORD_ORDER_BIG_ENDIAN == 0
#include <math/logtable/emu08192/ei_logtable_064_emu32lsb.dfn>
#else
#include <math/logtable/emu08192/ei_logtable_064_emu32msb.dfn>
#endif
#endif /* MPU_MATH_FN_LIMIT >= 8192 */

#if MPU_MATH_FN_LIMIT >= 16384
#if MPU_WORD_ORDER_BIG_ENDIAN == 0
#include <math/logtable/emu16384/ei_logtable_128_emu32lsb.dfn>
#else
#include <math/logtable/emu16384/ei_logtable_128_emu32msb.dfn>
#endif
#endif /* MPU_MATH_FN_LIMIT >= 16384 */

#if MPU_MATH_FN_LIMIT >= 32768
#if MPU_WORD_ORDER_BIG_ENDIAN == 0
#include <math/logtable/emu32768/ei_logtable_256_emu32lsb.dfn>
#else
#include <math/logtable/emu32768/ei_logtable_256_emu32msb.dfn>
#endif
#endif /* MPU_MATH_FN_LIMIT >= 32768 */

#if MPU_MATH_FN_LIMIT >= 65536
#if MPU_WORD_ORDER_BIG_ENDIAN == 0
#include <math/logtable/emu65536/ei_logtable_512_emu32lsb.dfn>
#else
#include <math/logtable/emu65536/ei_logtable_512_emu32msb.dfn>
#endif
#endif /* MPU_MATH_FN_LIMIT >= 65536 */


int _get_n_log_table( int nb )
{
  int  rc = 0;

  if( nb < NBR_32 || nb > MPU_MATH_FN_LIMIT )
  {
    /* error: Invalid size of operand(s) */
    __real_error_no = __R_ESIZE__;
    __STIND; /* Set REAL ind-produsing operation Flag */
    return( rc );
  }

  switch( nb )
  {
#if MPU_MATH_FN_LIMIT >= 128
    case NBR_32   :
    case NBR_64   :
    case NBR_128  :
      rc = N_LOG_TABLE128;
      break;
#endif /* MPU_MATH_FN_LIMIT >= 128 */
#if MPU_MATH_FN_LIMIT >= 256
    case NBR_256  :
      rc = N_LOG_TABLE256;
      break;
#endif /* MPU_MATH_FN_LIMIT >= 256 */
#if MPU_MATH_FN_LIMIT >= 512
    case NBR_512  :
      rc = N_LOG_TABLE512;
      break;
#endif /* MPU_MATH_FN_LIMIT >= 512 */
#if MPU_MATH_FN_LIMIT >= 1024
    case NBR_1024 :
      rc = N_LOG_TABLE1024;
      break;
#endif /* MPU_MATH_FN_LIMIT >= 1024 */
#if MPU_MATH_FN_LIMIT >= 2048
    case NBR_2048 :
      rc = N_LOG_TABLE2048;
      break;
#endif /* MPU_MATH_FN_LIMIT >= 2048 */
#if MPU_MATH_FN_LIMIT >= 4096
    case NBR_4096 :
      rc = N_LOG_TABLE4096;
      break;
#endif /* MPU_MATH_FN_LIMIT >= 4096 */
#if MPU_MATH_FN_LIMIT >= 8192
    case NBR_8192 :
      rc = N_LOG_TABLE8192;
      break;
#endif /* MPU_MATH_FN_LIMIT >= 8192 */
#if MPU_MATH_FN_LIMIT >= 16384
    case NBR_16384:
      rc = N_LOG_TABLE16384;
      break;
#endif /* MPU_MATH_FN_LIMIT >= 16384 */

    default:
    {
      /* error: Invalid size of operand(s) */
      __real_error_no = __R_ESIZE__;
      __STIND; /* Set REAL ind-produsing operation Flag */
      break;
    }

  } /* End of switch( nb ) */

  return( rc );

} /* End of _get_n_log_table() */


EMUSHORT *_get_logF_head_ptr( int nb )
{
  EMUSHORT *rc = (EMUSHORT *)NULL;

  if( nb < NBR_32 || nb > MPU_MATH_FN_LIMIT )
  {
    /* error: Invalid size of operand(s) */
    __real_error_no = __R_ESIZE__;
    __STIND; /* Set REAL ind-produsing operation Flag */
    return( rc );
  }

  switch( nb )
  {
#if MPU_MATH_FN_LIMIT >= 128
    case NBR_32   :
    case NBR_64   :
    case NBR_128  :
      rc = (EMUSHORT *)&_ei_logF_head_128_[0][0];
      break;
#endif /* MPU_MATH_FN_LIMIT >= 128 */
#if MPU_MATH_FN_LIMIT >= 256
    case NBR_256  :
      rc = (EMUSHORT *)&_ei_logF_head_256_[0][0];
      break;
#endif /* MPU_MATH_FN_LIMIT >= 256 */
#if MPU_MATH_FN_LIMIT >= 512
    case NBR_512  :
      rc = (EMUSHORT *)&_ei_logF_head_512_[0][0];
      break;
#endif /* MPU_MATH_FN_LIMIT >= 512 */
#if MPU_MATH_FN_LIMIT >= 1024
    case NBR_1024 :
      rc = (EMUSHORT *)&_ei_logF_head_1024_[0][0];
      break;
#endif /* MPU_MATH_FN_LIMIT >= 1024 */
#if MPU_MATH_FN_LIMIT >= 2048
    case NBR_2048 :
      rc = (EMUSHORT *)&_ei_logF_head_2048_[0][0];
      break;
#endif /* MPU_MATH_FN_LIMIT >= 2048 */
#if MPU_MATH_FN_LIMIT >= 4096
    case NBR_4096 :
      rc = (EMUSHORT *)&_ei_logF_head_4096_[0][0];
      break;
#endif /* MPU_MATH_FN_LIMIT >= 4096 */
#if MPU_MATH_FN_LIMIT >= 8192
    case NBR_8192 :
      rc = (EMUSHORT *)&_ei_logF_head_8192_[0][0];
      break;
#endif /* MPU_MATH_FN_LIMIT >= 8192 */
#if MPU_MATH_FN_LIMIT >= 16384
    case NBR_16384:
      rc = (EMUSHORT *)&_ei_logF_head_16384_[0][0];
      break;
#endif /* MPU_MATH_FN_LIMIT >= 16384 */

    default:
    {
      /* error: Invalid size of operand(s) */
      __real_error_no = __R_ESIZE__;
      __STIND; /* Set REAL ind-produsing operation Flag */
      break;
    }

  } /* End of switch( nb ) */

  return( rc );

} /* End of _get_logF_head_ptr() */


EMUSHORT *_get_logF_tail_ptr( int nb )
{
  EMUSHORT *rc = (EMUSHORT *)NULL;

  if( nb < NBR_32 || nb > MPU_MATH_FN_LIMIT )
  {
    /* error: Invalid size of operand(s) */
    __real_error_no = __R_ESIZE__;
    __STIND; /* Set REAL ind-produsing operation Flag */
    return( rc );
  }

  switch( nb )
  {
#if MPU_MATH_FN_LIMIT >= 128
    case NBR_32   :
    case NBR_64   :
    case NBR_128  :
      rc = (EMUSHORT *)&_ei_logF_tail_128_[0][0];
      break;
#endif /* MPU_MATH_FN_LIMIT >= 128 */
#if MPU_MATH_FN_LIMIT >= 256
    case NBR_256  :
      rc = (EMUSHORT *)&_ei_logF_tail_256_[0][0];
      break;
#endif /* MPU_MATH_FN_LIMIT >= 256 */
#if MPU_MATH_FN_LIMIT >= 512
    case NBR_512  :
      rc = (EMUSHORT *)&_ei_logF_tail_512_[0][0];
      break;
#endif /* MPU_MATH_FN_LIMIT >= 512 */
#if MPU_MATH_FN_LIMIT >= 1024
    case NBR_1024 :
      rc = (EMUSHORT *)&_ei_logF_tail_1024_[0][0];
      break;
#endif /* MPU_MATH_FN_LIMIT >= 1024 */
#if MPU_MATH_FN_LIMIT >= 2048
    case NBR_2048 :
      rc = (EMUSHORT *)&_ei_logF_tail_2048_[0][0];
      break;
#endif /* MPU_MATH_FN_LIMIT >= 2048 */
#if MPU_MATH_FN_LIMIT >= 4096
    case NBR_4096 :
      rc = (EMUSHORT *)&_ei_logF_tail_4096_[0][0];
      break;
#endif /* MPU_MATH_FN_LIMIT >= 4096 */
#if MPU_MATH_FN_LIMIT >= 8192
    case NBR_8192 :
      rc = (EMUSHORT *)&_ei_logF_tail_8192_[0][0];
      break;
#endif /* MPU_MATH_FN_LIMIT >= 8192 */
#if MPU_MATH_FN_LIMIT >= 16384
    case NBR_16384:
      rc = (EMUSHORT *)&_ei_logF_tail_16384_[0][0];
      break;
#endif /* MPU_MATH_FN_LIMIT >= 16384 */

    default:
    {
      /* error: Invalid size of operand(s) */
      __real_error_no = __R_ESIZE__;
      __STIND; /* Set REAL ind-produsing operation Flag */
      break;
    }

  } /* End of switch( nb ) */

  return( rc );

} /* End of _get_logF_tail_ptr() */


/***************************************************************
  Hide internal symbols:
 ***************************************************************/

__mpu_hidden_decl(_get_n_log_table);
__mpu_hidden_decl(_get_logF_head_ptr);
__mpu_hidden_decl(_get_logF_tail_ptr);


/*
  End of hide internal symbols.
 ***************************************************************/