Skip to content

Commit

Permalink
Another Sync with atlas-dev (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
kathlenemagnus authored Nov 25, 2024
1 parent b62fe90 commit 25e173f
Show file tree
Hide file tree
Showing 193 changed files with 3,210 additions and 4,761 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ arch/rv64/**
spike
.vscode/**
mavis_json
riscv-tests
64 changes: 64 additions & 0 deletions MergeInstHandlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import os, sys, re, subprocess

if len(sys.argv) > 1:
os.chdir(os.path.abspath(sys.argv[1]))

result = subprocess.run(['git', 'status', '--porcelain', '|', 'grep "M "'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if result.returncode == 0 and result.stdout:
raise RuntimeError('Cannot have uncommitted changes in this directory: {}'.format(os.getcwd()))

ext = os.path.basename(os.getcwd())
rv_insts_cpp = 'Rv{}Insts.cpp'.format(ext)
pattern = r"ActionGroup\* Rv{}Insts::".format(ext)

headers = set()
headers.add('#include "core/ActionGroup.hpp"\n')
headers.add('#include "include/ActionTags.hpp"\n')
for filename in os.listdir(os.getcwd()):
if filename.endswith(".cpp") and filename != rv_insts_cpp:
with open(filename, 'r') as fin:
for line in fin.readlines():
if line.find('#include') == 0:
headers.add(line)

lines = list(headers)
lines = sorted(lines, key=len, reverse=True)
lines.append('')

with open(rv_insts_cpp, 'r') as fin:
transfer = False
for line in fin.readlines():
if line.find('namespace atlas') == 0:
transfer = True
elif line.find('// namespace atlas') != -1:
break

if transfer:
lines.append(line)

lines = [''.join(lines)]
lines.append('')

for filename in os.listdir(os.getcwd()):
if filename.endswith(".cpp") and filename != rv_insts_cpp:
lines.append('')
with open(filename, 'r') as fin:
transfer = False
for line in fin.readlines():
if re.search(pattern, line):
transfer = True
elif line.find('// namespace atlas') != -1:
break

if transfer:
lines.append(line.rstrip('\n'))

lines.append('')
lines.append('} // namespace atlas')

with open(rv_insts_cpp, 'w') as fout:
fout.write('\n'.join(lines))

for filename in os.listdir(os.getcwd()):
if filename.endswith('.cpp') and filename != rv_insts_cpp:
os.remove(filename)
1 change: 0 additions & 1 deletion core/inst_handlers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ target_link_libraries(atlasinsts
rvzicsr
rvzifencei
)
add_dependencies(atlasinsts AutogenArchFiles)
59 changes: 59 additions & 0 deletions core/inst_handlers/inst_helpers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#pragma once

#include <stdint.h>

typedef int64_t sreg_t;
typedef uint64_t reg_t;
#define xlen 64

template <typename T> inline sreg_t sext32(T x) { return (sreg_t)(int32_t)(x); }

template <typename T> inline reg_t zext32(T x) { return (reg_t)(uint32_t)(x); }

template <typename T> inline sreg_t sext(T x, uint32_t pos)
{
return (((sreg_t)(x) << (64 - (pos))) >> (64 - (pos)));
}

template <typename T> inline reg_t zext(T x, uint32_t pos)
{
return (((reg_t)(x) << (64 - (pos))) >> (64 - (pos)));
}

template <typename T> inline sreg_t sext_xlen(T x) { return sext(x, xlen); }

template <typename T> inline reg_t zext_xlen(T x) { return zext(x, xlen); }

inline uint64_t mulhu(uint64_t a, uint64_t b)
{
uint64_t t;
uint32_t y1, y2, y3;
uint64_t a0 = (uint32_t)a, a1 = a >> 32;
uint64_t b0 = (uint32_t)b, b1 = b >> 32;

t = a1 * b0 + ((a0 * b0) >> 32);
y1 = t;
y2 = t >> 32;

t = a0 * b1 + y1;

t = a1 * b1 + y2 + (t >> 32);
y2 = t;
y3 = t >> 32;

return ((uint64_t)y3 << 32) | y2;
}

inline int64_t mulhsu(int64_t a, uint64_t b)
{
int negate = a < 0;
uint64_t res = mulhu(a < 0 ? -a : a, b);
return negate ? ~res + (a * b == 0) : res;
}

inline int64_t mulh(int64_t a, int64_t b)
{
int negate = (a < 0) != (b < 0);
uint64_t res = mulhu(a < 0 ? -a : a, b < 0 ? -b : b);
return negate ? ~res + ((uint64_t)a * (uint64_t)b == 0) : res;
}
25 changes: 2 additions & 23 deletions core/inst_handlers/rv64/a/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
project(Atlas)

file(GLOB SOURCES "${CMAKE_CURRENT_LIST_DIR}/*.cpp")
add_library(rva
OBJECT
RvaInsts.cpp
amoadd_d.cpp
amoadd_w.cpp
amoand_d.cpp
amoand_w.cpp
amomax_d.cpp
amomax_w.cpp
amomaxu_d.cpp
amomaxu_w.cpp
amomin_d.cpp
amomin_w.cpp
amominu_d.cpp
amominu_w.cpp
amoor_d.cpp
amoor_w.cpp
amoswap_d.cpp
amoswap_w.cpp
amoxor_d.cpp
amoxor_w.cpp
lr_d.cpp
lr_w.cpp
sc_d.cpp
sc_w.cpp
${SOURCES}
)
Loading

0 comments on commit 25e173f

Please sign in to comment.