ref: 4f2ba23c15b6f2eda24ca6d25c9361bbe2bb024e
parent: ce5ada585dc6ec662e607a0f88934adb52cb9976
author: rrt <rrt>
date: Wed Dec 6 22:34:03 EST 2006
Remove unused long gsm_L_* arithmetic functions. Remove SASR compile-time constant, which was hardwired; instead, define a right shift that is a) correct (unlike the old version of gsm_asr, at least) and b) will work with either a logical or an arithmetic right shift on signed types (use the one I wrote for Beetle).
--- a/src/libgsm/Makefile.am
+++ b/src/libgsm/Makefile.am
@@ -1,8 +1,5 @@
man_MANS = gsm.3 gsm_option.3
-# Define SASR if >> is a signed on signed types (-1 >> 1 == -1)
-SASR = -DSASR
-
AM_CFLAGS = $(SASR)
lib_LIBRARIES = libgsm.a
--- a/src/libgsm/Makefile.in
+++ b/src/libgsm/Makefile.in
@@ -164,9 +164,6 @@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
man_MANS = gsm.3 gsm_option.3
-
-# Define SASR if >> is a signed on signed types (-1 >> 1 == -1)
-SASR = -DSASR
AM_CFLAGS = $(SASR)
lib_LIBRARIES = libgsm.a
libgsm_a_SOURCES = add.c code.c decode.c long_term.c lpc.c preprocess.c \
--- a/src/libgsm/add.c
+++ b/src/libgsm/add.c
@@ -50,48 +50,6 @@
return a < 0 ? (a == MIN_WORD ? MAX_WORD : -a) : a;
}
-longword gsm_L_mult (word a, word b)
-{
- assert( a != MIN_WORD || b != MIN_WORD );
- return ((longword)a * (longword)b) << 1;
-}
-
-longword gsm_L_add (longword a, longword b)
-{
- if (a < 0) {
- if (b >= 0) return a + b;
- else {
- ulongword A = (ulongword)-(a + 1) + (ulongword)-(b + 1);
- return A >= MAX_LONGWORD ? MIN_LONGWORD :-(longword)A-2;
- }
- }
- else if (b <= 0) return a + b;
- else {
- ulongword A = (ulongword)a + (ulongword)b;
- return A > MAX_LONGWORD ? MAX_LONGWORD : A;
- }
-}
-
-longword gsm_L_sub (longword a, longword b)
-{
- if (a >= 0) {
- if (b >= 0) return a - b;
- else {
- /* a>=0, b<0 */
-
- ulongword A = (ulongword)a + -(b + 1);
- return A >= MAX_LONGWORD ? MAX_LONGWORD : (A + 1);
- }
- }
- else if (b <= 0) return a - b;
- else {
- /* a<0, b>0 */
-
- ulongword A = (ulongword)-(a + 1) + b;
- return A >= MAX_LONGWORD ? MIN_LONGWORD : -(longword)A - 1;
- }
-}
-
static unsigned char const bitoff[ 256 ] = {
8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
@@ -147,14 +105,6 @@
: 23 + bitoff[ 0xFF & a ] );
}
-longword gsm_L_asl (longword a, int n)
-{
- if (n >= 32) return 0;
- if (n <= -32) return -(a < 0);
- if (n < 0) return gsm_L_asr(a, -n);
- return a << n;
-}
-
word gsm_asl (word a, int n)
{
if (n >= 16) return 0;
@@ -163,32 +113,12 @@
return a << n;
}
-longword gsm_L_asr (longword a, int n)
-{
- if (n >= 32) return -(a < 0);
- if (n <= -32) return 0;
- if (n < 0) return a << -n;
-
-# ifdef SASR
- return a >> n;
-# else
- if (a >= 0) return a >> n;
- else return -(longword)( -(ulongword)a >> n );
-# endif
-}
-
word gsm_asr (word a, int n)
{
if (n >= 16) return -(a < 0);
if (n <= -16) return 0;
if (n < 0) return a << -n;
-
-# ifdef SASR
- return a >> n;
-# else
- if (a >= 0) return a >> n;
- else return -(word)( -(uword)a >> n );
-# endif
+ return SASR(a, n);
}
/*
--- a/src/libgsm/private.h
+++ b/src/libgsm/private.h
@@ -44,36 +44,26 @@
#define MIN_LONGWORD (-2147483647 - 1)
#define MAX_LONGWORD 2147483647
-#ifdef SASR /* flag: >> is a signed arithmetic shift right */
-#undef SASR
-#define SASR(x, by) ((x) >> (by))
-#else
-#define SASR(x, by) ((x) >= 0 ? (x) >> (by) : (~(-((x) + 1) >> (by))))
-#endif /* SASR */
+#define SASR(x, by) (((x) >> (by)) | (-((x) < 0) << (by)))
/*
* Prototypes from add.c
*/
extern word gsm_mult (word a, word b);
-extern longword gsm_L_mult (word a, word b);
extern word gsm_mult_r (word a, word b);
extern word gsm_div (word num, word denum);
extern word gsm_add ( word a, word b );
-extern longword gsm_L_add ( longword a, longword b );
extern word gsm_sub (word a, word b);
-extern longword gsm_L_sub (longword a, longword b);
extern word gsm_abs (word a);
extern word gsm_norm ( longword a );
-extern longword gsm_L_asl (longword a, int n);
extern word gsm_asl (word a, int n);
-extern longword gsm_L_asr (longword a, int n);
extern word gsm_asr (word a, int n);
/*