add.c File Reference

#include <stdio.h>
#include <assert.h>
#include "private.h"
#include "gsm.h"
#include "proto.h"

Include dependency graph for add.c:

Go to the source code of this file.

Defines

#define saturate(x)   ((x) < MIN_WORD ? MIN_WORD : (x) > MAX_WORD ? MAX_WORD: (x))

Functions

word gsm_norm P1 ((a), longword a)
word gsm_abs P1 ((a), word a)
word gsm_div P2 ((num, denum), word num, word denum)
word gsm_asl P2 ((a, n), word a, int n)
longword gsm_L_asl P2 ((a, n), longword a, int n)
longword gsm_L_add P2 ((a, b), longword a, longword b)
word gsm_add P2 ((a, b), word a, word b)

Variables

static unsigned char const bitoff [256]


Define Documentation

#define saturate (  )     ((x) < MIN_WORD ? MIN_WORD : (x) > MAX_WORD ? MAX_WORD: (x))

Definition at line 20 of file add.c.

Referenced by block4(), g722_encode(), and P2().


Function Documentation

word gsm_norm P1 ( (a ,
longword  a 
)

Definition at line 117 of file add.c.

00132                          : L_norm_var1 = L_var1 << norm( L_var1 );
00133  *
00134  * (That's 'ffs', only from the left, not the right..)
00135  */
00136 {
00137    assert(a != 0);
00138 
00139    if (a < 0) {
00140       if (a <= -1073741824) return 0;
00141       a = ~a;
00142    }
00143 
00144    return    a & 0xffff0000 
00145       ? ( a & 0xff000000
00146         ?  -1 + bitoff[ 0xFF & (a >> 24) ]
00147         :   7 + bitoff[ 0xFF & (a >> 16) ] )
00148       : ( a & 0xff00
00149         ?  15 + bitoff[ 0xFF & (a >> 8) ]
00150         :  23 + bitoff[ 0xFF & a ] );
00151 }

word gsm_abs P1 ( (a ,
word  a 
)

Definition at line 51 of file add.c.

References MAX_WORD, and MIN_WORD.

00052 {
00053    return a < 0 ? (a == MIN_WORD ? MAX_WORD : -a) : a;
00054 }

word gsm_div P2 ( (num, denum)  ,
word  num,
word  denum 
)

Definition at line 206 of file add.c.

00207 {
00208    longword L_num   = num;
00209    longword L_denum = denum;
00210    word     div   = 0;
00211    int      k  = 15;
00212 
00213    /* The parameter num sometimes becomes zero.
00214     * Although this is explicitly guarded against in 4.2.5,
00215     * we assume that the result should then be zero as well.
00216     */
00217 
00218    /* assert(num != 0); */
00219 
00220    assert(num >= 0 && denum >= num);
00221    if (num == 0)
00222        return 0;
00223 
00224    while (k--) {
00225       div   <<= 1;
00226       L_num <<= 1;
00227 
00228       if (L_num >= L_denum) {
00229          L_num -= L_denum;
00230          div++;
00231       }
00232    }
00233 
00234    return div;
00235 }

word gsm_asr P2 ( (a, n)  ,
word  a,
int  n 
)

Definition at line 161 of file add.c.

00162 {
00163    if (n >= 16) return 0;
00164    if (n <= -16) return -(a < 0);
00165    if (n < 0) return gsm_asr(a, -n);
00166    return a << n;
00167 }

longword gsm_L_asr P2 ( (a, n)  ,
longword  a,
int  n 
)

Definition at line 153 of file add.c.

00154 {
00155    if (n >= 32) return 0;
00156    if (n <= -32) return -(a < 0);
00157    if (n < 0) return gsm_L_asr(a, -n);
00158    return a << n;
00159 }

longword gsm_L_sub P2 ( (a, b ,
longword  a,
longword  b 
)

Definition at line 62 of file add.c.

References MAX_LONGWORD, and MIN_LONGWORD.

00063 {
00064    if (a < 0) {
00065       if (b >= 0) return a + b;
00066       else {
00067          ulongword A = (ulongword)-(a + 1) + (ulongword)-(b + 1);
00068          return A >= MAX_LONGWORD ? MIN_LONGWORD :-(longword)A-2;
00069       }
00070    }
00071    else if (b <= 0) return a + b;
00072    else {
00073       ulongword A = (ulongword)a + (ulongword)b;
00074       return A > MAX_LONGWORD ? MAX_LONGWORD : A;
00075    }
00076 }

longword gsm_L_mult P2 ( (a, b ,
word  a,
word  b 
)

Definition at line 23 of file add.c.

References saturate.

00024 {
00025    longword sum = (longword)a + (longword)b;
00026    return (word)saturate(sum);
00027 }


Variable Documentation

unsigned char const bitoff[256] [static]

Definition at line 98 of file add.c.


Generated on Thu Apr 16 06:28:09 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6