Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rv64f): Add single precision floating point extension #45

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added h/form/fdouble.h
Empty file.
5 changes: 5 additions & 0 deletions h/form/fsingle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once
#include "form/instructions.h"

extern const struct formation rv32f[];
extern const struct formation rv64f[];
2 changes: 2 additions & 0 deletions h/form/generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#define OP_LUI 0x37
#define OP_AUIPC 0x17
#define OP_AMO 0x2F
#define OP_LOADF 0x13
#define OP_STOREF 0x33

#define END_FORMATION \
{ \
Expand Down
1 change: 1 addition & 0 deletions h/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ arg_parser parse_al;
arg_parser parse_as;
arg_parser parse_csr;
arg_parser parse_csri;
arg_parser parse_fltype;

int parse_asm(const char *, struct sectionpos);
Empty file added src/form/fdouble.c
Empty file.
10 changes: 10 additions & 0 deletions src/form/fsingle.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

#include "form/fsingle.h"

#include "form/generic.h"
#include "parse.h"

const struct formation rv32f[] = {
{ "FLW", &form_itype, &parse_fltype, { 4, OP_LOADF, 0x2, 0 } },
END_FORMATION
};
2 changes: 0 additions & 2 deletions src/form/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ struct bytecode form_stype(const char *name, struct idata instruction,
struct bytecode form_btype(const char *name, struct idata instruction,
struct args args, size_t position)
{
(void)position;
logger(DEBUG, no_error, "Generating B type instruction %s", name);

if (args.sym->type != SYMBOL_LABEL)
Expand Down Expand Up @@ -166,7 +165,6 @@ struct bytecode form_utype(const char *name, struct idata instruction,
struct bytecode form_jtype(const char *name, struct idata instruction,
struct args args, size_t position)
{
(void)position;
logger(DEBUG, no_error, "Generating J type instruction %s", name);

int32_t offset = calc_symbol_offset(args.sym, position);
Expand Down
8 changes: 4 additions & 4 deletions src/generation.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ size_t getl(char **lineptr, size_t *n, FILE *stream)
return (size_t)(p - bufptr - 1);
}

void parse_file(FILE *ifp, FILE *ofp)
void parse_file(FILE *input, FILE *output)
{
char *line = NULL;
size_t linesize = 0;
size_t nread;

linenumber = 0;

fseek(ifp, 0L, SEEK_SET);
fseek(input, 0L, SEEK_SET);

while ((nread = getl(&line, &linesize, ifp)) != (size_t)-1) {
while ((nread = getl(&line, &linesize, input)) != (size_t)-1) {
linenumber++;
logger(DEBUG, no_error, "Parsing line \"%s\"", line);
if (parse_line(line, get_outputpos()))
Expand All @@ -94,7 +94,7 @@ void parse_file(FILE *ifp, FILE *ofp)
fill_strtab();
fill_symtab();

flush_output(ofp);
flush_output(output);

free_output();
free_instructions();
Expand Down
54 changes: 30 additions & 24 deletions src/registers.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,24 +386,23 @@ const struct {
{ "dscratch1", 0x7B3 },
};

/* TODO: implement w/ float extension */
const char *float_reg_abi_map[] = { 0 };

size_t get_register_id(const char *reg)
{
logger(DEBUG, no_error, "Searching for register (%s)", reg);

/* limit the number of possible characters in the register */
int l = 0;
while (reg[l] && reg[l] != ' ')
l++;
if (l > 4)
return (size_t)-1;
logger(DEBUG, no_error, "Searching for register %s", reg);

if (*reg == 'x') {
size_t r = (size_t)atol(reg + 1);
if (r >= 32)
char *endptr;
size_t r = strtol(reg + 1, &endptr, 10);
if (*endptr) {
logger(ERROR, error_instruction_other,
"Expected end of register but got %s", endptr);
return (size_t)-1;
}
if (r >= 32) {
logger(ERROR, error_instruction_other,
"Maximum register is x31 but got %s", reg);
return (size_t)-1;
}
return r;
}

Expand All @@ -415,24 +414,31 @@ size_t get_register_id(const char *reg)
if (!strcmp(reg, "fp"))
return 8;

logger(INFO, no_error, "unknown register (%s)", reg);
logger(ERROR, no_error, "unknown register %s", reg);

return (size_t)-1;
}

size_t get_float_register_id(const char *reg)
{
if (*reg != 'f')
if (*reg != 'f') {
logger(ERROR, error_instruction_other,
"Expected floating point register but got %s", reg);
return (size_t)-1;

if (reg[1] >= '0' && reg[1] <= '9')
return (size_t)atoi(reg + 1);

for (size_t i = 0; i < ARRAY_LENGTH(float_reg_abi_map); i++)
if (!strcmp(reg, float_reg_abi_map[i]))
return i;

return (size_t)-1;
}
char *endptr;
size_t r = strtol(reg + 1, &endptr, 10);
if (*endptr) {
logger(ERROR, error_instruction_other,
"Expected end of register but got %s", endptr);
return (size_t)-1;
}
if (r >= 32) {
logger(ERROR, error_instruction_other,
"Maximum register is f31 but got %s", reg);
return (size_t)-1;
}
return r;
}

int get_immediate(const char *imm, size_t *res)
Expand Down
Loading