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

Atomic extension #126

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
d96aa80
ignore build files
giancarlopernudisegura May 14, 2021
e846a9d
lr.w and sc.w syntax support
giancarlopernudisegura May 14, 2021
7363378
fix sc.w instructions
giancarlopernudisegura May 15, 2021
fd13240
ReserveTable for 2 processors with shared memory
Sivachow May 25, 2021
2514a83
macOS .DS_Store
Sivachow May 25, 2021
fcac477
ReserveTable for 2 processors with shared memory
Sivachow May 25, 2021
7a12061
Merge branch 'ReservationTable' of https://github.com/giancarlopernud…
Sivachow May 25, 2021
e9022e0
Reserve Table
Sivachow May 25, 2021
e81c253
General Reserve Table
Sivachow May 27, 2021
d37dcf5
General Reserve Table 27 May
Sivachow May 27, 2021
7ea28ab
reservation table and tables
giancarlopernudisegura May 28, 2021
31a24b6
Commit
Sivachow May 28, 2021
37680f5
Small change
Sivachow May 28, 2021
815f798
basic tool
giancarlopernudisegura May 28, 2021
f555edb
28 May
Sivachow May 28, 2021
b5d07df
Merge branch 'ReservationTable' of https://github.com/giancarlopernud…
Sivachow May 28, 2021
c8bdb74
28 May
Sivachow May 28, 2021
a6000a0
integrate reservation table with lr.w and sc.w
giancarlopernudisegura May 28, 2021
f2911f9
show reservation table and help
giancarlopernudisegura May 29, 2021
af791d7
fix duplication of first cell
giancarlopernudisegura May 29, 2021
2d3e687
add table headers
giancarlopernudisegura May 29, 2021
9de9f2e
unreserve selection
giancarlopernudisegura May 29, 2021
735c061
Moved Clear to button area
Sivachow May 29, 2021
a4183fe
Modified Clear Selected
Sivachow May 29, 2021
92cefca
May 29
Sivachow May 29, 2021
d60dfb5
Reserve Table Layout
Sivachow May 29, 2021
56deb61
Reserve Table Tool
Sivachow May 29, 2021
87d0808
Changed 'Processor' to Hart'
Sivachow May 31, 2021
60d1341
change hart in help window to lowercase
giancarlopernudisegura Jun 1, 2021
22c1477
add atomic instructions example
giancarlopernudisegura Jun 2, 2021
21ef508
redefine all atomic instructions to be R type
giancarlopernudisegura Jun 2, 2021
ba9fd8e
parent AMO class
giancarlopernudisegura Jun 2, 2021
7a66fa1
Fixing the glue before clearselect
Sivachow Jun 3, 2021
ce33c92
Merge branch 'master' of https://github.com/giancarlopernudisegura/rars
Sivachow Jun 3, 2021
888a561
unreserve address on regular store
giancarlopernudisegura Jun 6, 2021
1cf1ea4
implement rest of 32-bit atomic instructions
giancarlopernudisegura Jun 6, 2021
8b0ce6e
Added To GUI
Sivachow Jun 7, 2021
3a5ab65
atomic 64-bit support
giancarlopernudisegura Jun 7, 2021
665ec73
GUI for Harts
Sivachow Jun 8, 2021
4fd92f5
Added the GUI for Harts
Sivachow Jun 8, 2021
58c3f05
Bug fix for Window GUI
Sivachow Jun 9, 2021
30d37fd
Merge branch 'TheThirdOne:master' into master
giancarlopernudisegura Jun 9, 2021
4875de9
categorize atomic instructions in statistics tool
giancarlopernudisegura Jun 9, 2021
095b715
update getInstructionCategory description for instruction support
giancarlopernudisegura Jun 9, 2021
9cf6d0a
add mhartid csr
giancarlopernudisegura Jun 9, 2021
a72d74e
sc.w/d returns unspecified failiure
giancarlopernudisegura Jun 9, 2021
d3c92b3
Moving the Harts to Globals
Sivachow Jun 10, 2021
9970c10
Merge branch 'master' of https://github.com/giancarlopernudisegura/rars
Sivachow Jun 10, 2021
0e17170
Documentation
Sivachow Jun 10, 2021
0cc3815
add rv32a unit tests
giancarlopernudisegura Jun 11, 2021
895bfb7
Fixed bugs for more than One Hart
Sivachow Jun 11, 2021
988346a
add rv64a unit tests
giancarlopernudisegura Jun 11, 2021
fc77595
All Harts work alike
Sivachow Jun 16, 2021
35cda76
fix sc on 64-bit mode
giancarlopernudisegura Jun 18, 2021
f703297
rename atomic example
giancarlopernudisegura Jun 18, 2021
66ef861
disable multithreading code for PR
giancarlopernudisegura Jul 16, 2021
c83a9ed
disable extra harts on reservation table tool
giancarlopernudisegura Jul 16, 2021
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ out
.classpath
.project
examples/riscv

# RARS build
build/
rars.jar

# macOS
.DS_Store
15 changes: 15 additions & 0 deletions examples/atomic_increment.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.globl main
.data
num:
.word 0x12345678

.text
main:
la t0, num
retry:
lr.w t1, (t0)
# increment by 1
addi t1, t1, 1
sc.w t2, t1, (t0)
# if save fails; retry operations again
bne zero, t2, retry
Binary file added src/images/Shared.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion src/rars/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import rars.assembler.SymbolTable;
import rars.riscv.hardware.Memory;
import rars.riscv.hardware.ReservationTables;
import rars.riscv.InstructionSet;
import rars.riscv.SyscallNumberOverride;
import rars.util.PropertiesFile;
Expand Down Expand Up @@ -68,6 +69,10 @@ public class Globals {
* Simulated memory component.
**/
public static Memory memory;
/**
* Simulated reservation tables component.
**/
public static ReservationTables reservationTables;
/**
* Lock variable used at head of synchronized block to guard memory and registers
**/
Expand Down Expand Up @@ -140,6 +145,11 @@ public class Globals {

public static boolean runSpeedPanelExists = false;

private static int harts = 1;

public static int getHarts() {
return harts;
}
private static String getCopyrightYears() {
return "2003-2019";
}
Expand All @@ -166,7 +176,8 @@ public static Settings getSettings() {

public static void initialize(boolean gui) {
if (!initialized) {
memory = Memory.getInstance(); //clients can use Memory.getInstance instead of Globals.memory
memory = Memory.getInstance(); //clients can use Memory.getInstance instead of Globals.memory
reservationTables = new ReservationTables(harts);
symbolTable = new SymbolTable("global");
settings = new Settings(gui);
instructionSet = new InstructionSet();
Expand Down
1 change: 1 addition & 0 deletions src/rars/api/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ private ErrorList assemble(ArrayList<RISCVprogram> programs) throws AssemblyExce
*/
public void setup(ArrayList<String> args, String STDIN){
RegisterFile.resetRegisters();
Globals.reservationTables.reset();
FloatingPointRegisterFile.resetRegisters();
ControlAndStatusRegisterFile.resetRegisters();
InterruptController.reset();
Expand Down
2 changes: 1 addition & 1 deletion src/rars/riscv/BasicInstructionFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ public enum BasicInstructionFormat {
S_FORMAT, // 2 src registers + small immediate
B_FORMAT, // 2 src registers + small immediate shifted left
U_FORMAT, // 1 dst register + large immediate
J_FORMAT // 1 dst register + large immediate for jumping
J_FORMAT, // 1 dst register + large immediate for jumping
}
4 changes: 3 additions & 1 deletion src/rars/riscv/hardware/ControlAndStatusRegisterFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ public class ControlAndStatusRegisterFile {
null, // cycleh
null, // timeh
null, // instreth
null, // mhartid
};
tmp[1] = new LinkedRegister("fflags", 0x001, tmp[3], 0x1F);
tmp[2] = new LinkedRegister("frm", 0x002, tmp[3], 0xE0);

tmp[14] = new LinkedRegister("cycleh", 0xC80,tmp[11], 0xFFFFFFFF_00000000L);
tmp[15] = new LinkedRegister("timeh", 0xC81, tmp[12],0xFFFFFFFF_00000000L);
tmp[16] = new LinkedRegister("instreth",0xC82, tmp[13],0xFFFFFFFF_00000000L);
tmp[16] = new LinkedRegister("instreth", 0xC82, tmp[13], 0xFFFFFFFF_00000000L);
tmp[17] = new ReadOnlyRegister("mhartid", 0xF10, 0);
instance = new RegisterBlock('_', tmp); // prefix not used
}

Expand Down
108 changes: 108 additions & 0 deletions src/rars/riscv/hardware/ReservationTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package rars.riscv.hardware;

import java.util.ArrayList;
import java.util.function.Predicate;

/*
Copyright (c) 2021, Siva Chowdeswar Nandipati & Giancarlo Pernudi Segura.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject
to the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

(MIT license, http://www.opensource.org/licenses/mit-license.html)
*/

public class ReservationTable {
private ArrayList<ReservationTableEntry> table;
public final static int capacity = 8;
private final static int doubleAlignMask = ~0x7;

public enum bitWidth {
word,
doubleWord
}

protected class ReservationTableEntry {
protected Integer address;
protected bitWidth width;

public ReservationTableEntry(Integer address, bitWidth width) {
this.address = address;
this.width = width;
}

public boolean equals(Object o) {
ReservationTableEntry other = (ReservationTableEntry) o;
return address.equals(other.address) && width.equals(other.width);
}
}

public ReservationTable() {
table = new ArrayList<ReservationTableEntry>();
}

public void reserveAddress(int address, bitWidth width) {
ReservationTableEntry newEntry = new ReservationTableEntry(address, width);
if(table.contains(newEntry))
return;
if (table.size() == capacity)
table.remove(0);
table.add(newEntry);
}

public void unreserveAddress(int address, bitWidth width) {
Predicate<ReservationTableEntry> filter = entry ->
(entry.address == address && entry.width == width)
|| ((address & doubleAlignMask) == entry.address && entry.width == bitWidth.doubleWord);
table.removeIf(filter);
}

public boolean contains(int address, bitWidth width) {
for (ReservationTableEntry entry : table) {
if ((entry.address == address && entry.width == width)
|| ((address & doubleAlignMask) == entry.address && entry.width == bitWidth.doubleWord))
return true;
}
return false;
}

public Integer[] getAddresses() {
Integer[] addresses = new Integer[capacity];
for (int i = 0; i < capacity; i++) {
try {
addresses[i] = this.table.get(i).address;
} catch (IndexOutOfBoundsException e) {
addresses[i] = 0;
}
}
return addresses;
}

public bitWidth[] getWidths() {
bitWidth[] addresses = new bitWidth[capacity];
for (int i = 0; i < capacity; i++) {
try {
addresses[i] = this.table.get(i).width;
} catch (IndexOutOfBoundsException e) {
addresses[i] = null;
}
}
return addresses;
}
}
129 changes: 129 additions & 0 deletions src/rars/riscv/hardware/ReservationTables.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package rars.riscv.hardware;

import java.util.Collection;
import java.util.Observable;
import java.util.Observer;
import java.util.Vector;

import rars.SimulationException;
import rars.riscv.hardware.ReservationTable.bitWidth;

/*
Copyright (c) 2021, Siva Chowdeswar Nandipati & Giancarlo Pernudi Segura.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject
to the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

(MIT license, http://www.opensource.org/licenses/mit-license.html)
*/

public class ReservationTables extends Observable {
private ReservationTable[] reservationTables;
public int harts;
private Collection<ReservationTablesObservable> observables = new Vector<>();

public ReservationTables(int harts) {
this.harts = harts;
reset();
}

public void reset() {
reservationTables = new ReservationTable[harts];
for (int i = 0; i < reservationTables.length; i++) {
reservationTables[i] = new ReservationTable();
}
}

public void reserveAddress(int hart, int address, bitWidth width) throws AddressErrorException {
int modulo = width == bitWidth.doubleWord ? 8 : 4;
if (address % modulo != 0) {
throw new AddressErrorException("Reservation address not aligned to word boundary ", SimulationException.LOAD_ADDRESS_MISALIGNED, address);
}
reservationTables[hart].reserveAddress(address, width);
}

public boolean unreserveAddress(int hart, int address, bitWidth width) throws AddressErrorException {
int modulo = width == bitWidth.doubleWord ? 8 : 4;
if (address % modulo != 0) {
throw new AddressErrorException("Reservation address not aligned to word boundary ", SimulationException.STORE_ADDRESS_MISALIGNED, address);
}
if (reservationTables[hart].contains(address, width)) {
for (ReservationTable reservationTable : reservationTables) {
reservationTable.unreserveAddress(address, width);
}
return true;
}
return false;
}

public String[][] getAllAddressesAsStrings() {
String[][] all = new String[ReservationTable.capacity][harts * 2];
char width = '0';
for (int i = 0; i < ReservationTable.capacity; i++) {
for (int j = 0; j < harts; j++) {
Integer[] addresses = reservationTables[j].getAddresses();
ReservationTable.bitWidth[] widths = reservationTables[j].getWidths();
if (widths[i] == ReservationTable.bitWidth.word) {
width = 'w';
} else if (widths[i] == ReservationTable.bitWidth.doubleWord) {
width = 'd';
} else {
width = ' ';
}
all[i][j * 2] = String.format("0x%08x", addresses[i]);
all[i][j * 2 + 1] = String.format("%c", width);
}
}
return all;
}

public void addObserver(Observer obs) {
observables.add(new ReservationTablesObservable(obs));
}

/**
* Remove specified reservation tables observer
*
* @param obs Observer to be removed
*/
public void deleteObserver(Observer obs) {
for (ReservationTablesObservable o : observables) {
o.deleteObserver(obs);
}
}

/**
* Remove all reservation tables observers
*/
public void deleteObservers() {
// just drop the collection
observables = new Vector<>();
}

private class ReservationTablesObservable extends Observable {
public ReservationTablesObservable(Observer obs) {
this.addObserver(obs);
}

public void notifyObserver(MemoryAccessNotice notice) {
this.setChanged();
this.notifyObservers(notice);
}
}
}
39 changes: 39 additions & 0 deletions src/rars/riscv/instructions/AMOADDD.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package rars.riscv.instructions;

/*
Copyright (c) 2021, Giancarlo Pernudi Segura

Developed by Giancarlo Pernudi Segura at the University of Alberta ([email protected])

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject
to the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

(MIT license, http://www.opensource.org/licenses/mit-license.html)
*/

public class AMOADDD extends AtomicMemoryOperation {
public AMOADDD() {
super("amoadd.d t0, t1, (t2)", "Loads value at t2 and places it into t0, adds value t1 and t0 (new), and saves at memory location t2.", "00000", true);
}

@Override
protected long binaryOperation(long value1, long value2) {
return value1 + value2;
}
}
Loading