Skip to content

Commit

Permalink
3.1: minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dcamarmas committed Sep 9, 2022
1 parent edb1436 commit 1ea2909
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 810 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"arch_conf": [
{
"name": "Name",
"value": "RISC-V"
"value": "RISC-V (RV32IMFD)"
},
{
"name": "Bits",
Expand Down Expand Up @@ -3085,7 +3085,7 @@
"stopbit": 0
}
],
"definition": "var val = capi_split_double(ft, 1);\n capi_mem_write(base+off, val, 'w');\n val = capi_split_double(ft, 0);\n capi_mem_write(base+off+4, val, 'w');",
"definition": "var val = capi_split_double(ft, 0);\n capi_mem_write(base+off, val, 'w');\n val = capi_split_double(ft, 1);\n capi_mem_write(base+off+4, val, 'w');",
"separated": [
false,
true,
Expand Down Expand Up @@ -5755,7 +5755,7 @@
"stopbit": 7
}
],
"definition": " var isnotalign = capi_bad_align(rs1+inm, 'd');\n if (isnotalign) { capi_raise('The memory must be align'); }\n var val1 = capi_mem_read(rs1+inm, 'w');\n var val2 = capi_mem_read(rs1+inm+4, 'w');\n var buf = new ArrayBuffer(8);\n var arr = (new Uint32Array(buf));\n arr[0] = val1;\n arr[1] = val2;\n rd = (new Float64Array(buf))[0];\n",
"definition": " var isnotalign = capi_bad_align(rs1+inm, 'd');\n if (isnotalign) { capi_raise('The memory must be align'); }\n var val1 = capi_mem_read(rs1+inm, 'w');\n var val2 = capi_mem_read(rs1+inm+4, 'w');\n var buf = new ArrayBuffer(8);\n var arr = (new Uint32Array(buf));\n arr[1] = val1;\n arr[0] = val2;\n rd = (new Float64Array(buf))[0];\n",
"separated": [
false,
false,
Expand Down
2 changes: 1 addition & 1 deletion architecture/available_arch.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"name": "RISC-V",
"name": "RISC-V (RV32IMFD)",
"img": "./images/risc-v_logo.png",
"alt": "RISC-V",
"id": "select_confRISV",
Expand Down
4 changes: 2 additions & 2 deletions examples/example_set.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{
"name": "RISC-V Examples",
"id": "default",
"architecture":"RISC-V",
"architecture":"RISC-V (RV32IMFD)",
"url":"examples/RISCV/list.json",
"description": "RISC-V examples"
},
Expand All @@ -23,7 +23,7 @@
{
"name": "RISC-V from UC3M-AG",
"id": "uc3m-ec-ag",
"architecture":"RISC-V",
"architecture":"RISC-V (RV32IMFD)",
"url":"examples/ag-uc3m-ec/list.json",
"description": "RISC-V examples for Aula Global at UC3M"
}
Expand Down
24 changes: 22 additions & 2 deletions js/creator_compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,30 @@ function assembly_compiler()
data_address = parseInt(architecture.memory_layout[2].value);
stack_address = parseInt(architecture.memory_layout[4].value);

architecture.components[1].elements[29].value = bi_intToBigInt(stack_address,10) ;
for (var i = 0; i < architecture.components.length; i++)
{
for (var j = 0; j < architecture.components[i].elements.length; j++)
{
if (architecture.components[i].elements[j].properties.includes("pointer"))
{
if (architecture.components[i].elements[j].properties.includes("code"))
{
architecture.components[i].elements[j].value = bi_intToBigInt(address,10) ;
architecture.components[i].elements[j].default_value = bi_intToBigInt(address,10) ;
}
if (architecture.components[i].elements[j].properties.includes("stack"))
{
architecture.components[i].elements[j].value = bi_intToBigInt(stack_address,10) ;
architecture.components[i].elements[j].default_value = bi_intToBigInt(stack_address,10) ;
}
}
}
}

/*architecture.components[1].elements[29].value = bi_intToBigInt(stack_address,10) ;
architecture.components[0].elements[0].value = bi_intToBigInt(address,10) ;
architecture.components[1].elements[29].default_value = bi_intToBigInt(stack_address,10) ;
architecture.components[0].elements[0].default_value = bi_intToBigInt(address,10) ;
architecture.components[0].elements[0].default_value = bi_intToBigInt(address,10) ;*/

/*Reset stats*/
totalStats = 0;
Expand Down
190 changes: 97 additions & 93 deletions js/creator_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,25 @@

function hex2char8 ( hexvalue )
{
var num_char = ((hexvalue.toString().length))/2;
var exponent = 0;
var pos = 0;
var num_char = ((hexvalue.toString().length))/2;
var exponent = 0;
var pos = 0;

var valuec = [] ;
var valuec = [] ;

for (var i = 0; i < num_char; i++) {
var auxHex = hexvalue.substring(pos, pos+2);
valuec[i] = String.fromCharCode(parseInt(auxHex, 16));
pos = pos + 2;
}
for (var i = 0; i < num_char; i++) {
var auxHex = hexvalue.substring(pos, pos+2);
valuec[i] = String.fromCharCode(parseInt(auxHex, 16));
pos = pos + 2;
}

var characters = '';
var characters = '';

for (var i = 0; i < valuec.length; i++){
characters = characters + valuec[i] + ' ';
}
for (var i = 0; i < valuec.length; i++){
characters = characters + valuec[i] + ' ';
}

return characters;
return characters;
}

function hex2float ( hexvalue )
Expand All @@ -103,6 +103,10 @@
return valuef ;*/
var value = hexvalue.split('x');
if (typeof value[1] != "undefined" && value[1].length > 8) {
value[1] = value[1].substring(0, 8);
}

var value_bit = '';

for (var i = 0; i < value[1].length; i++){
Expand All @@ -120,32 +124,32 @@

function uint_to_float32 ( value )
{
var buf = new ArrayBuffer(4) ;
(new Uint32Array(buf))[0] = value ;
return (new Float32Array(buf))[0] ;
var buf = new ArrayBuffer(4) ;
(new Uint32Array(buf))[0] = value ;
return (new Float32Array(buf))[0] ;
}

function float32_to_uint ( value )
{
var buf = new ArrayBuffer(4) ;
(new Float32Array(buf))[0] = value ;
return (new Uint32Array(buf))[0];
var buf = new ArrayBuffer(4) ;
(new Float32Array(buf))[0] = value ;
return (new Uint32Array(buf))[0];
}

function uint_to_float64 ( value0, value1 )
{
var buf = new ArrayBuffer(8) ;
var arr = new Uint32Array(buf) ;
arr[0] = value0 ;
arr[1] = value1 ;
return (new Float64Array(buf))[0] ;
var buf = new ArrayBuffer(8) ;
var arr = new Uint32Array(buf) ;
arr[0] = value0 ;
arr[1] = value1 ;
return (new Float64Array(buf))[0] ;
}

function float64_to_uint ( value )
{
var buf = new ArrayBuffer(8) ;
(new Float64Array(buf))[0] = value ;
return (new Uint32Array(buf)) ;
var buf = new ArrayBuffer(8) ;
(new Float64Array(buf))[0] = value ;
return (new Uint32Array(buf)) ;
}

function float2bin ( number )
Expand All @@ -157,104 +161,104 @@

for (i = 0; i < 4; i++)
{
var bits = dv.getUint8(i).toString(2);
if (bits.length < 8) {
bits = new Array(8 - bits.length).fill('0').join("") + bits;
}
result += bits;
var bits = dv.getUint8(i).toString(2);
if (bits.length < 8) {
bits = new Array(8 - bits.length).fill('0').join("") + bits;
}
result += bits;
}
return result;
}

function double2bin ( number )
{
var i, result = "";
var dv = new DataView(new ArrayBuffer(8));
var i, result = "";
var dv = new DataView(new ArrayBuffer(8));

dv.setFloat64(0, number, false);
dv.setFloat64(0, number, false);

for (i = 0; i < 8; i++)
{
var bits = dv.getUint8(i).toString(2);
if (bits.length < 8) {
bits = new Array(8 - bits.length).fill('0').join("") + bits;
}
result += bits;
for (i = 0; i < 8; i++)
{
var bits = dv.getUint8(i).toString(2);
if (bits.length < 8) {
bits = new Array(8 - bits.length).fill('0').join("") + bits;
}
return result;
result += bits;
}
return result;
}

function bin2hex ( s )
{
var i, k, part, accum, ret = '';
var i, k, part, accum, ret = '';

for (i = s.length-1; i >= 3; i -= 4)
{
part = s.substr(i+1-4, 4);
accum = 0;
for (k = 0; k < 4; k += 1)
for (i = s.length-1; i >= 3; i -= 4)
{
if (part[k] !== '0' && part[k] !== '1') {
return { valid: false };
}
accum = accum * 2 + parseInt(part[k], 10);
}
if (accum >= 10) {
ret = String.fromCharCode(accum - 10 + 'A'.charCodeAt(0)) + ret;
}
else {
ret = String(accum) + ret;
}
part = s.substr(i+1-4, 4);
accum = 0;
for (k = 0; k < 4; k += 1)
{
if (part[k] !== '0' && part[k] !== '1') {
return { valid: false };
}
accum = accum * 2 + parseInt(part[k], 10);
}
if (accum >= 10) {
ret = String.fromCharCode(accum - 10 + 'A'.charCodeAt(0)) + ret;
}
else {
ret = String(accum) + ret;
}
}

if (i >= 0)
{
accum = 0;
for (k = 0; k <= i; k += 1)
if (i >= 0)
{
if (s[k] !== '0' && s[k] !== '1') {
return { valid: false };
}
accum = accum * 2 + parseInt(s[k], 10);
}
ret = String(accum) + ret;
accum = 0;
for (k = 0; k <= i; k += 1)
{
if (s[k] !== '0' && s[k] !== '1') {
return { valid: false };
}
accum = accum * 2 + parseInt(s[k], 10);
}
ret = String(accum) + ret;
}

return ret;
return ret;
}

function hex2double ( hexvalue )
{
var value = hexvalue.split('x');
var value_bit = '';
var value = hexvalue.split('x');
var value_bit = '';

for (var i=0; i<value[1].length; i++)
{
var aux = value[1].charAt(i);
aux = (parseInt(aux, 16)).toString(2).padStart(4, "0");
value_bit = value_bit + aux;
}
for (var i=0; i<value[1].length; i++)
{
var aux = value[1].charAt(i);
aux = (parseInt(aux, 16)).toString(2).padStart(4, "0");
value_bit = value_bit + aux;
}

value_bit = value_bit.padStart(64, "0");
value_bit = value_bit.padStart(64, "0");

var buffer = new ArrayBuffer(8);
new Uint8Array( buffer ).set( value_bit.match(/.{8}/g).map(binaryStringToInt ));
return new DataView( buffer ).getFloat64(0, false);
var buffer = new ArrayBuffer(8);
new Uint8Array( buffer ).set( value_bit.match(/.{8}/g).map(binaryStringToInt ));
return new DataView( buffer ).getFloat64(0, false);
}

function float2int_v2 ( value )
{
return parseInt(float2bin(value),2);
return parseInt(float2bin(value),2);
}

function double2int_v2 ( value )
{
return parseInt(double2bin(value),2);
return parseInt(double2bin(value),2);
}

function int2float_v2 ( value )
{
return hex2float("0x" + bin2hex(value.toString(2)));
return hex2float("0x" + bin2hex(value.toString(2)));
}

function full_print ( value, bin_value, add_dot_zero )
Expand Down Expand Up @@ -286,13 +290,13 @@

function clean_string( value, prefix )
{
var value2 = value.replace(/[&\/\\#,+()$~%.'":*?<>{}]/g, '_');
var value2 = value.replace(/[&\/\\#,+()$~%.'":*?<>{}]/g, '_');

re = new RegExp("^[0-9]+$");
if (value2.search(re) != -1 && prefix != "undefined") {
value2 = prefix + value2;
}
re = new RegExp("^[0-9]+$");
if (value2.search(re) != -1 && prefix != "undefined") {
value2 = prefix + value2;
}

return value2;
return value2;
}

Loading

0 comments on commit 1ea2909

Please sign in to comment.