Floating point constants and the first FP test routine.

This commit is contained in:
Chad Kersey 2013-10-06 02:57:52 -04:00
parent 7b6e49ad4d
commit 89e66d64f2
3 changed files with 57 additions and 6 deletions

View file

@ -94,7 +94,9 @@ static uint64_t readParenExpression(const string &s, const map<string, Word> &d,
exit(1); exit(1);
} }
int lexerBits;
Obj *AsmReader::read(std::istream &input) { Obj *AsmReader::read(std::istream &input) {
lexerBits = wordSize;
FlexLexer *f = new yyFlexLexer(&input); FlexLexer *f = new yyFlexLexer(&input);
Obj *o = new Obj(); Obj *o = new Obj();
std::vector<Chunk>::reverse_iterator cur; std::vector<Chunk>::reverse_iterator cur;

View file

@ -14,15 +14,24 @@
#include <iostream> #include <iostream>
#include "include/asm-tokens.h" #include "include/asm-tokens.h"
#include "include/harpfloat.h"
extern int lexerBits;
static int64_t read_number(const char *s) { static int64_t read_number(const char *s) {
long long u;
while (!isdigit(*s) && *s != '-' && *s != '+') s++; while (!isdigit(*s) && *s != '-' && *s != '+') s++;
sscanf(s, "%lli", &u); if (strchr(s, 'f') || strchr(s, '.')) {
return u; double d;
sscanf(s, "%f", &d);
return Harp::Word_u(Harp::Float(d, lexerBits));
} else {
long long u;
sscanf(s, "%lli", &u);
return u;
}
} }
static std::string label_name(const char *cs) { static std::string label_name(const char *cs) {
return std::string(cs, strlen(cs)-1); return std::string(cs, strlen(cs)-1);
} }
@ -40,8 +49,9 @@ using namespace HarpTools;
sym [A-Za-z_.][A-Za-z0-9_.]* sym [A-Za-z_.][A-Za-z0-9_.]*
decnum [1-9][0-9]* decnum [1-9][0-9]*
hexnum 0x[0-9a-f]+ hexnum 0x[0-9a-f]+
octnum 0[0-9]* octnum 0[0-7]*
num [+-]?({decnum}|{hexnum}|{octnum}) floatnum ([0-9]+f|[0-9]*\.[0-9]+)
num [+-]?({decnum}|{hexnum}|{octnum}|{floatnum})
space [ \t]* space [ \t]*
peoperator ("+"|"-"|"*"|"/"|"%"|"&"|"|"|"^"|"<<"|">>") peoperator ("+"|"-"|"*"|"/"|"%"|"&"|"|"|"^"|"<<"|">>")
parenexp "("({num}|{sym}|{peoperator}|{space}|"("|")")+")" parenexp "("({num}|{sym}|{peoperator}|{space}|"("|")")+")"
@ -52,7 +62,7 @@ endl \r?\n
/* Ignore comments but keep line count consistent. */ /* Ignore comments but keep line count consistent. */
for (const char *c = YYText(); *c; c++) if (*c == '\n') yyline++; for (const char *c = YYText(); *c; c++) if (*c == '\n') yyline++;
} }
to
<INITIAL>\.def { BEGIN DEFARGS; return ASM_T_DIR_DEF; } <INITIAL>\.def { BEGIN DEFARGS; return ASM_T_DIR_DEF; }
<INITIAL>\.perm { BEGIN PERMARGS; return ASM_T_DIR_PERM; } <INITIAL>\.perm { BEGIN PERMARGS; return ASM_T_DIR_PERM; }
<INITIAL>\.byte { BEGIN WORDARGS; return ASM_T_DIR_BYTE; } <INITIAL>\.byte { BEGIN WORDARGS; return ASM_T_DIR_BYTE; }

39
src/test/dotprod.s Normal file
View file

@ -0,0 +1,39 @@
/*******************************************************************************
HARPtools by Chad D. Kersey, Summer 2011
********************************************************************************
Sample HARP assmebly program.
*******************************************************************************/
/* sieve of eratosthanes: Find some primes. */
.def SIZE 0x1000
.align 4096
.perm x
.entry
.global
entry: /* . . . */
trap;
/* Return in r0 dot product of vectors of real values pointed to by r0 and r1,
length in r2 */
dotprod: ldi %r3, #0;
dploop: ld %r4, %r0, #0;
ld %r5, %r1, #0;
subi %r2, %r2, #1;
addi %r0, %r0, __WORD;
addi %r1, %r1, __WORD;
rtop @p0, %r2;
fadd %r4, %r4, %r5;
fadd %r3, %r3, %r4;
@p0 ? jmpi dploop;
.perm rw
array_a: .word 1.0 2.0 3.0 0.5 1.0 1.5 0.33 0.67 1.0 1.33
array_b: .word 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
.global
array: .space 0x1000 /* SIZE words of space. */