endianess
This commit is contained in:
parent
5634163eab
commit
62a798d4f0
9 changed files with 86 additions and 48 deletions
5
Makefile
5
Makefile
|
@ -4,8 +4,7 @@
|
|||
#
|
||||
# $ tar zxf eigenmath-linux.tar.gz
|
||||
#
|
||||
# 2. Compile it. (For Power PC and other big endian machines, first add -DMAC
|
||||
# to CFLAGS below.)
|
||||
# 2. Compile it.
|
||||
#
|
||||
# $ cd eigenmath
|
||||
# $ make
|
||||
|
@ -32,8 +31,6 @@
|
|||
# CXX and CXXFLAGS are used by make's implicit rule for compiling C++ files.
|
||||
# divby1billion() in mstr.c doesn't work with -O2
|
||||
CXXFLAGS = -Wall -Wuninitialized -O -DLINUX
|
||||
# For big endian machines add -DMAC
|
||||
#CXXFLAGS = -Wall -Wuninitialized -O -DLINUX -DMAC
|
||||
|
||||
objects = madd.o mmul.o mprime.o mgcd.o mpow.o mroot.o mcmp.o mstr.o mscan.o mmodpow.o \
|
||||
qadd.o qsub.o qmul.o qdiv.o qpow.o \
|
||||
|
|
2
data.cpp
2
data.cpp
|
@ -27,4 +27,4 @@ int conjugating;
|
|||
int verbosing;
|
||||
int floating;
|
||||
int esc_flag;
|
||||
|
||||
int little_endian;
|
||||
|
|
1
defs.h
1
defs.h
|
@ -316,6 +316,7 @@ extern int floating;
|
|||
extern int primetab[MAXPRIMETAB];
|
||||
extern int esc_flag;
|
||||
extern int mtotal;
|
||||
extern int little_endian;
|
||||
extern char logbuf[];
|
||||
extern char program_buf[];
|
||||
extern U *nil;
|
||||
|
|
5
init.cpp
5
init.cpp
|
@ -10,6 +10,11 @@ init(void)
|
|||
if (nil)
|
||||
return; // already initted
|
||||
|
||||
// endianess
|
||||
|
||||
little_endian = 1;
|
||||
little_endian = *((unsigned char *) &little_endian);
|
||||
|
||||
nsym = USR_SYMBOLS;
|
||||
|
||||
nil = symtab + NIL;
|
||||
|
|
31
integral.cpp
31
integral.cpp
|
@ -1731,3 +1731,34 @@ test_integral(void)
|
|||
{
|
||||
test(__FILE__, s, sizeof s / sizeof (char *));
|
||||
}
|
||||
|
||||
int
|
||||
compare_them(const void *a, const void *b)
|
||||
{
|
||||
return cmp_expr(((U **) a)[0], ((U **) b)[0]);
|
||||
}
|
||||
|
||||
void
|
||||
make_integral_code(void)
|
||||
{
|
||||
int i, h, n;
|
||||
scan_integrals();
|
||||
p1 = table_of_integrals;
|
||||
h = tos;
|
||||
while (iscons(p1)) {
|
||||
p2 = caar(p1);
|
||||
// printline(p2);
|
||||
if (iscons(p2))
|
||||
push(car(p2));
|
||||
else
|
||||
push(p2);
|
||||
p1 = cdr(p1);
|
||||
}
|
||||
|
||||
n = tos - h;
|
||||
|
||||
qsort(stack + h, n, sizeof (U *), compare_them);
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
printline(stack[i]);
|
||||
}
|
||||
|
|
45
mmul.cpp
45
mmul.cpp
|
@ -108,13 +108,14 @@ mdiv(unsigned int *a, unsigned int *b)
|
|||
|
||||
/* estimate the partial quotient */
|
||||
|
||||
#ifndef MAC
|
||||
((unsigned int *) &jj)[0] = x[alen - i - 1];
|
||||
((unsigned int *) &jj)[1] = x[alen - i - 0];
|
||||
#else
|
||||
((unsigned int *) &jj)[1] = x[alen - i - 1];
|
||||
((unsigned int *) &jj)[0] = x[alen - i - 0];
|
||||
#endif
|
||||
if (little_endian) {
|
||||
((unsigned int *) &jj)[0] = x[alen - i - 1];
|
||||
((unsigned int *) &jj)[1] = x[alen - i - 0];
|
||||
} else {
|
||||
((unsigned int *) &jj)[1] = x[alen - i - 1];
|
||||
((unsigned int *) &jj)[0] = x[alen - i - 0];
|
||||
}
|
||||
|
||||
c = (unsigned int) (jj / kk);
|
||||
|
||||
if (c == 0) {
|
||||
|
@ -239,13 +240,14 @@ mmod(unsigned int *a, unsigned int *b)
|
|||
|
||||
/* estimate the partial quotient */
|
||||
|
||||
#ifndef MAC
|
||||
((unsigned int *) &jj)[0] = x[alen - i - 1];
|
||||
((unsigned int *) &jj)[1] = x[alen - i - 0];
|
||||
#else
|
||||
((unsigned int *) &jj)[1] = x[alen - i - 1];
|
||||
((unsigned int *) &jj)[0] = x[alen - i - 0];
|
||||
#endif
|
||||
if (little_endian) {
|
||||
((unsigned int *) &jj)[0] = x[alen - i - 1];
|
||||
((unsigned int *) &jj)[1] = x[alen - i - 0];
|
||||
} else {
|
||||
((unsigned int *) &jj)[1] = x[alen - i - 1];
|
||||
((unsigned int *) &jj)[0] = x[alen - i - 0];
|
||||
}
|
||||
|
||||
c = (int) (jj / kk);
|
||||
|
||||
if (c == 0) {
|
||||
|
@ -333,13 +335,14 @@ mdivrem(unsigned int **q, unsigned int **r, unsigned int *a, unsigned int *b)
|
|||
|
||||
/* estimate the partial quotient */
|
||||
|
||||
#ifndef MAC
|
||||
((unsigned int *) &jj)[0] = x[alen - i - 1];
|
||||
((unsigned int *) &jj)[1] = x[alen - i - 0];
|
||||
#else
|
||||
((unsigned int *) &jj)[1] = x[alen - i - 1];
|
||||
((unsigned int *) &jj)[0] = x[alen - i - 0];
|
||||
#endif
|
||||
if (little_endian) {
|
||||
((unsigned int *) &jj)[0] = x[alen - i - 1];
|
||||
((unsigned int *) &jj)[1] = x[alen - i - 0];
|
||||
} else {
|
||||
((unsigned int *) &jj)[1] = x[alen - i - 1];
|
||||
((unsigned int *) &jj)[0] = x[alen - i - 0];
|
||||
}
|
||||
|
||||
c = (int) (jj / kk);
|
||||
|
||||
if (c == 0) {
|
||||
|
|
24
mstr.cpp
24
mstr.cpp
|
@ -79,13 +79,14 @@ divby1billion(unsigned int *a)
|
|||
|
||||
for (i = MLENGTH(a) - 1; i >= 0; i--) {
|
||||
|
||||
#ifndef MAC
|
||||
((unsigned int *) &kk)[1] = ((unsigned int *) &kk)[0];
|
||||
((unsigned int *) &kk)[0] = a[i];
|
||||
#else
|
||||
((unsigned int *) &kk)[0] = ((unsigned int *) &kk)[1];
|
||||
((unsigned int *) &kk)[1] = a[i];
|
||||
#endif
|
||||
if (little_endian) {
|
||||
((unsigned int *) &kk)[1] = ((unsigned int *) &kk)[0];
|
||||
((unsigned int *) &kk)[0] = a[i];
|
||||
} else {
|
||||
((unsigned int *) &kk)[0] = ((unsigned int *) &kk)[1];
|
||||
((unsigned int *) &kk)[1] = a[i];
|
||||
}
|
||||
|
||||
a[i] = (int) (kk / 1000000000);
|
||||
|
||||
kk -= (unsigned long long) 1000000000 * a[i];
|
||||
|
@ -99,9 +100,8 @@ divby1billion(unsigned int *a)
|
|||
|
||||
MLENGTH(a) = i + 1;
|
||||
|
||||
#ifndef MAC
|
||||
return ((unsigned int *) &kk)[0];
|
||||
#else
|
||||
return ((unsigned int *) &kk)[1];
|
||||
#endif
|
||||
if (little_endian)
|
||||
return ((unsigned int *) &kk)[0];
|
||||
else
|
||||
return ((unsigned int *) &kk)[1];
|
||||
}
|
||||
|
|
|
@ -359,6 +359,7 @@ void eval_integral(void);
|
|||
void eval_integral(void);
|
||||
void integral(void);
|
||||
void test_integral(void);
|
||||
void make_integral_code(void);
|
||||
|
||||
// inv.cpp
|
||||
void inv(void);
|
||||
|
@ -634,6 +635,8 @@ void test_roots(void);
|
|||
// run.cpp
|
||||
void stop(char *str);
|
||||
void run(char *s);
|
||||
int dash_dash_command(char *s);
|
||||
void check_stack(void);
|
||||
void echo_input(char *s);
|
||||
void print_mem_info(void);
|
||||
|
||||
|
|
18
run.cpp
18
run.cpp
|
@ -1,17 +1,11 @@
|
|||
#include "stdafx.h"
|
||||
#include "defs.h"
|
||||
|
||||
extern int scan(char *);
|
||||
extern void setup(void);
|
||||
extern void init(void);
|
||||
extern void selftest(void);
|
||||
extern void cmdisplay(U *);
|
||||
void make_integral_code(void);
|
||||
|
||||
extern int symbol_level;
|
||||
extern int test_flag;
|
||||
extern U *varlist;
|
||||
static void check_stack(void);
|
||||
void print_mem_info(void);
|
||||
static int dash_dash_command(char *);
|
||||
jmp_buf stop_return;
|
||||
static char *errstr;
|
||||
static char buf[100];
|
||||
|
@ -109,7 +103,7 @@ run(char *s)
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
int
|
||||
dash_dash_command(char *s)
|
||||
{
|
||||
if (strncmp(s, "--mem", 5) == 0) {
|
||||
|
@ -125,10 +119,14 @@ dash_dash_command(char *s)
|
|||
selftest();
|
||||
return 1;
|
||||
}
|
||||
if (strncmp(s, "--mic", 3) == 0) {
|
||||
make_integral_code();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
check_stack(void)
|
||||
{
|
||||
if (tos != 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue