We planned to upgrade GitLab and Mattermost to the latest version this Friday morning (early). You may experience some downtime!

Verified Commit d545b2ce authored by Camil Staps's avatar Camil Staps 🚀

Add instructions for the BtoAC and RtoAC present in normal RTSs

parent b423481f
Pipeline #20933 passed with stages
in 14 minutes and 3 seconds
......@@ -191,6 +191,23 @@ intp = new Uint8Array(intp);
expR: Math.exp,
lnR: Math.log,
log10R: Math.log10,
RtoAC: function (dest, v) {
v=Number(0+v).toLocaleString(
['en-US'],
{
useGrouping: false,
maximumSignificantDigits: 15,
}
);
membuffer[dest/4]=6*8+2; // __STRING__
membuffer[dest/4+1]=0;
membuffer[dest/4+2]=v.length;
membuffer[dest/4+3]=0;
var arr=new Uint8Array(membuffer.buffer, dest+16);
for (var i=0; i<v.length; i++)
arr[i]=v.charCodeAt(i);
return dest+16+(((v.length+7)>>3)<<3);
},
}
}
);
......
......@@ -533,10 +533,12 @@ const char *instruction_type (BC_WORD i) {
case Cupdate_r3b: return "n";
case Cupdate_b: return "nn";
case CxorI: return "";
case CBtoAC: return "";
case CCtoAC: return "";
case CItoAC: return "";
case CItoC: return "";
case CItoR: return "";
case CRtoAC: return "";
case CRtoI: return "";
case Cswap_a1: return "";
case Cswap_a2: return "";
......
......@@ -519,10 +519,12 @@ enum {
INSTRUCTION(update_r34)
INSTRUCTION(update_r3b)
INSTRUCTION(xorI)
INSTRUCTION(BtoAC)
INSTRUCTION(CtoAC)
INSTRUCTION(ItoAC)
INSTRUCTION(ItoC)
INSTRUCTION(ItoR)
INSTRUCTION(RtoAC)
INSTRUCTION(RtoI)
INSTRUCTION(jmp_ap1)
INSTRUCTION(jsr_ap1)
......
......@@ -827,16 +827,17 @@ static char *specialized_jsr_labels[] = {
/* 3*/ "sliceAC",
/* 4*/ "ItoAC",
/* 5*/ "BtoAC",
/* 6*/ "print__string__",
/* 7*/ "openF",
/* 8*/ "stdioF",
/* 9*/ "closeF",
/*10*/ "readLineF",
/*11*/ "endF",
/*12*/ "writeFI",
/*13*/ "writeFS",
/*14*/ "writeFC",
/*15*/ "openSF"
/* 6*/ "RtoAC",
/* 7*/ "print__string__",
/* 8*/ "openF",
/* 9*/ "stdioF",
/*10*/ "closeF",
/*11*/ "readLineF",
/*12*/ "endF",
/*13*/ "writeFI",
/*14*/ "writeFS",
/*15*/ "writeFC",
/*16*/ "openSF"
};
static int get_specialized_jsr_label_n(char label_name[]) {
......@@ -857,7 +858,9 @@ void add_specialized_jsr_instruction(unsigned int n) {
case 2: add_instruction(CcatAC); return;
case 3: add_instruction(CsliceAC); return;
case 4: add_instruction(CItoAC); return;
case 6: add_instruction(Cprint_string); return;
case 5: add_instruction(CBtoAC); return;
case 6: add_instruction(CRtoAC); return;
case 7: add_instruction(Cprint_string); return;
default:
if (n < sizeof(specialized_jsr_labels)/sizeof(char*)) {
fprintf(stderr,"Warning: jsr %s is not supported by the interpreter\n",specialized_jsr_labels[n]);
......
......@@ -27,4 +27,4 @@ typedef int64_t CleanInt;
#define BCGEN_INSTRUCTION_TABLE_SIZE 512
#define ABC_MAGIC_NUMBER 0x2a434241
#define ABC_VERSION 4
#define ABC_VERSION 5
[42,42,0,0.420000016689301,4.19999980926514,1,42.5400466918945,3.5,0,3.5,-1,0,1,3.5,0,-3.5,1,0,0,1,1,-1,3.62021970748901,1.57079637050629,0,0.785398185253143,5]
([42,42,0,0.420000016689301,4.19999980926514,1,42.5400466918945,3.5,0,3.5,-1,0,1,3.5,0,-3.5,1,0,0,1,1,-1,3.62021970748901,1.57079637050629,0,0.785398185253143,5],"37.4199981689453")
halt at 4
202 524086 524288
216 524072 524288
[42,42,0,0.42,4.2,1,42.540042248726,3.5,0,3.5,-1,0,1,3.5,0,-3.5,1,0,0,1,1,-1,3.62021856711158,1.5707963267949,0,0.785398163397448,5]
([42,42,0,0.42,4.2,1,42.540042248726,3.5,0,3.5,-1,0,1,3.5,0,-3.5,1,0,0,1,1,-1,3.62021856711158,1.5707963267949,0,0.785398163397448,5],"37.42")
halt at 4
202 261942 262144
213 261931 262144
module reals
import StdReal
import StdReal, StdString
Start =
(
[ 5.5 + 36.5
, 64.5 - 22.5
, zero
......@@ -31,5 +32,7 @@ Start =
, atan 1.0
, toReal (entier 5.5)
]
, toString 37.42
)
pi :== 3.14159265359
......@@ -15,6 +15,7 @@ instr_unimplemented :: !Target -> Target
instr_halt :: !Target -> Target
instr_divLU :: !Target -> Target
instr_mulUUL :: !Target -> Target
instr_RtoAC :: !Target -> Target
lit_word :: !Int -> Expr TWord
lit_char :: !Char -> Expr TChar
......@@ -77,6 +78,7 @@ tanR :: !(Expr TReal) -> Expr TReal
ItoR :: !(Expr TInt) -> Expr TReal
RtoI :: !(Expr TReal) -> Expr TInt
if_i64_or_i32 :: !(Target -> Target) !(Target -> Target) !Target -> Target
if_i64_or_i32_expr :: !(Expr t) !(Expr t) -> Expr t
if_expr :: !(Expr TWord) !(Expr t) !(Expr t) -> Expr t
......
......@@ -165,6 +165,23 @@ instr_mulUUL t = foldl (flip append) t
, "}"
]
instr_RtoAC :: !Target -> Target
instr_RtoAC t = foldl (flip append) t
[ "{"
, "char r[20];"
, "int n=sprintf(r,\"%.15g\",*((BC_REAL*)bsp)+0.0);"
, "NEED_HEAP(2+((n+IF_INT_64_OR_32(7,3))>>IF_INT_64_OR_32(3,2)));"
, "hp[0]=(BC_WORD)&__STRING__+2;"
, "hp[1]=n;"
, "memcpy(&hp[2],r,n);"
, "pc+=1;"
, "bsp+=1;"
, "asp[1]=(BC_WORD)hp;"
, "asp+=1;"
, "hp+=2+((n+IF_INT_64_OR_32(7,3))>>IF_INT_64_OR_32(3,2));"
, "}"
]
lit_word :: !Int -> Expr TWord
lit_word i = toString i
......@@ -292,6 +309,9 @@ ItoR e = "(BC_REAL)("+-+e+-+")"
RtoI :: !(Expr TReal) -> Expr TInt
RtoI e = "(BC_WORD_S)("+-+e+-+")"
if_i64_or_i32 :: !(Target -> Target) !(Target -> Target) !Target -> Target
if_i64_or_i32 i64 i32 t = append "#endif" (i32 (append "#else" (i64 (append "#if WORD_WIDTH==64" t))))
if_i64_or_i32_expr :: !(Expr t) !(Expr t) -> Expr t
if_i64_or_i32_expr a b = "IF_INT_64_OR_32("+-+a+-+","+-+b+-+")"
......
......@@ -15,6 +15,7 @@ instr_unimplemented :: !Target -> Target
instr_halt :: !Target -> Target
instr_divLU :: !Target -> Target
instr_mulUUL :: !Target -> Target
instr_RtoAC :: !Target -> Target
lit_word :: !Int -> Expr TWord
lit_char :: !Char -> Expr TChar
......@@ -77,6 +78,7 @@ tanR :: !(Expr TReal) -> Expr TReal
ItoR :: !(Expr TInt) -> Expr TReal
RtoI :: !(Expr TReal) -> Expr TInt
if_i64_or_i32 :: !(Target -> Target) !(Target -> Target) !Target -> Target
if_i64_or_i32_expr :: !(Expr t) !(Expr t) -> Expr t
if_expr :: !(Expr TWord) !(Expr t) !(Expr t) -> Expr t | typename t
......
......@@ -316,6 +316,7 @@ where
, "(func $clean_expR (import \"clean\" \"expR\") (param f64) (result f64))"
, "(func $clean_lnR (import \"clean\" \"lnR\") (param f64) (result f64))"
, "(func $clean_log10R (import \"clean\" \"log10R\") (param f64) (result f64))"
, "(func $clean_RtoAC (import \"clean\" \"RtoAC\") (param i32 f64) (result i32))"
, if debug_instructions "(func $clean_debug_instr (import \"clean\" \"debug_instr\") (param i32 i32))" ""
// For illegal instructions, first the handler is called with arguments (pc,instr,asp,bsp,csp,hp,hp_free).
// If the result is zero, clean_illegal_instr is called with (pc,instr) and interpretation stops.
......@@ -401,6 +402,15 @@ instr_divLU t = instr_unimplemented t // TODO
instr_mulUUL :: !Target -> Target
instr_mulUUL t = instr_unimplemented t // TODO
instr_RtoAC :: !Target -> Target
instr_RtoAC t = foldl (flip append) (ensure_hp 3 t) // TODO how many blocks are needed depends on the value
[ "(i64.store offset=8 (i32.wrap_i64 (global.get $asp)) (global.get $hp))"
, "(global.set $hp (i64.extend_i32_u (call $clean_RtoAC (i32.wrap_i64 (global.get $hp)) (f64.reinterpret_i64 (i64.load (i32.wrap_i64 (global.get $bsp)))))))"
, "(global.set $pc (i64.add (global.get $pc) (i64.const 8)))"
, "(global.set $asp (i64.add (global.get $asp) (i64.const 8)))"
, "(global.set $bsp (i64.add (global.get $bsp) (i64.const 8)))"
]
lit_word :: !Int -> Expr TWord
lit_word i = Ei64_const i
......@@ -528,6 +538,9 @@ ItoR e = Ef64_convert_i64_s e
RtoI :: !(Expr TReal) -> Expr TInt
RtoI e = Ei64_trunc_f64_s e
if_i64_or_i32 :: !(Target -> Target) !(Target -> Target) !Target -> Target
if_i64_or_i32 i64 _ t = i64 t
if_i64_or_i32_expr :: !(Expr t) !(Expr t) -> Expr t
if_i64_or_i32_expr a _ = a
......
......@@ -2969,6 +2969,34 @@ all_instructions opts t = bootstrap $ collect_instructions opts $ map (\i -> i t
, instr "xorI" (Just 0) $
B @ 1 .= xorI (B @ 0) (B @ 1) :.
shrink_b 1
, instr "BtoAC" (Just 0) $
if_then_else (B @ 0 ==. lit_word 0) (
if_i64_or_i32 (
ensure_hp 3 :.
Hp @ 0 .= STRING__ptr + lit_word 2 :.
Hp @ 1 .= lit_word 5 :.
Hp @ 2 .= lit_word 0x65736c6146 :. // False
A @ 1 .= to_word Hp :.
advance_ptr Hp 3
) (
ensure_hp 4 :.
Hp @ 0 .= STRING__ptr + lit_word 2 :.
Hp @ 1 .= lit_word 5 :.
Hp @ 2 .= lit_word 0x736c6146 :. // Fals
Hp @ 3 .= lit_word 0x65 :. // e
A @ 1 .= to_word Hp :.
advance_ptr Hp 4
)
) [] (else (
ensure_hp 3 :.
Hp @ 0 .= STRING__ptr + lit_word 2 :.
Hp @ 1 .= lit_word 4 :.
Hp @ 2 .= lit_word 0x65757254 :. // True
A @ 1 .= to_word Hp :.
advance_ptr Hp 3
)) :.
grow_a 1 :.
shrink_b 1
, instr "CtoAC" (Just 0) $
ensure_hp 3 :.
Hp @ 0 .= STRING__ptr + lit_word 2 :.
......@@ -3022,6 +3050,7 @@ all_instructions opts t = bootstrap $ collect_instructions opts $ map (\i -> i t
, instr "ItoR" (Just 0) $
new_local TReal (ItoR (to_int (B @ 0))) \r ->
B @ 0 .= to_word r
, instr "RtoAC" Nothing instr_RtoAC
, instr "RtoI" (Just 0) $
new_local TReal (to_real (B @ 0)) \r ->
B @ 0 .= to_word (RtoI r)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment