Skip to content

Commit 561cc3d

Browse files
committed
Added some of the upcoming v51 Spin2 float functions
1 parent da8dea1 commit 561cc3d

File tree

6 files changed

+97
-28
lines changed

6 files changed

+97
-28
lines changed

Changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Version 7.1.0
33
- Reverted _rx* functions to no longer use 28 bit internal buffer; this is less resilient to P2 side timing changes, but better if PC timing is uncertain
44
- Added new Spin2 @\"string" for strings with embedded C-style escapes
55
- Added DITTO to duplicate code/data in Spin2 assembly
6+
- Added some of the upcoming Spin2 v51 float functions
67
- Many internal changes to support DITTO and future assembly work
78
- Updated -gbrk debug code (thanks Ada)
89
- Use cluster size for stat() st_blksize on FAT32

frontends/lexer.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#define VT '\013'
2525

26-
#define MAX_PNUT_VERSION 50 /* maximum PNut version we understand */
26+
#define MAX_PNUT_VERSION 51 /* maximum PNut version we understand */
2727

2828
int allow_type_names = 1;
2929

@@ -2494,7 +2494,14 @@ struct reservedword_soft {
24942494

24952495
/* v50 keywords */
24962496
{ "ditto", SP_DITTO, 50, 0 },
2497-
2497+
2498+
/* v51 keywords */
2499+
{ "log2", SP_LOG2, 51, 0 },
2500+
{ "exp2", SP_EXP2, 51, 0 },
2501+
{ "log10", SP_LOG10, 51, 0 },
2502+
{ "exp10", SP_EXP10, 51, 0 },
2503+
{ "ln", SP_LOG, 51, 0 },
2504+
{ "exp", SP_EXP, 51, 0 },
24982505
};
24992506

25002507
struct reservedword basic_keywords[] = {

frontends/spin/spin.y

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,13 @@ SpinDeclareStruct(AST *ident, AST *defs)
557557
%token SP_CONDITIONAL_SEP ": after ?"
558558
%token SP_REPEAT_SEP ": after repeat"
559559

560+
%token SP_LOG2 "LOG2"
561+
%token SP_EXP2 "EXP2"
562+
%token SP_LOG10 "LOG10"
563+
%token SP_EXP10 "EXP10"
564+
%token SP_LOG "LN"
565+
%token SP_EXP "EXP"
566+
560567
%token SP_FADD "+."
561568
%token SP_FSUB "-."
562569
%token SP_FMUL "*."
@@ -2457,6 +2464,48 @@ funccall:
24572464
params);
24582465
$$ = call;
24592466
}
2467+
| SP_LOG2 '(' expr ')'
2468+
{
2469+
AST *arg1 = $3;
2470+
AST *ident = AstIdentifier("__builtin_log2f");
2471+
2472+
$$ = MakeFunccall(ident, arg1, NULL);
2473+
}
2474+
| SP_EXP2 '(' expr ')'
2475+
{
2476+
AST *arg1 = $3;
2477+
AST *ident = AstIdentifier("__builtin_exp2f");
2478+
2479+
$$ = MakeFunccall(ident, arg1, NULL);
2480+
}
2481+
| SP_LOG10 '(' expr ')'
2482+
{
2483+
AST *arg1 = $3;
2484+
AST *ident = AstIdentifier("__builtin_log10f");
2485+
2486+
$$ = MakeFunccall(ident, arg1, NULL);
2487+
}
2488+
| SP_EXP10 '(' expr ')'
2489+
{
2490+
AST *arg1 = $3;
2491+
AST *ident = AstIdentifier("__builtin_exp10f");
2492+
2493+
$$ = MakeFunccall(ident, arg1, NULL);
2494+
}
2495+
| SP_LOG '(' expr ')'
2496+
{
2497+
AST *arg1 = $3;
2498+
AST *ident = AstIdentifier("__builtin_logf");
2499+
2500+
$$ = MakeFunccall(ident, arg1, NULL);
2501+
}
2502+
| SP_EXP '(' expr ')'
2503+
{
2504+
AST *arg1 = $3;
2505+
AST *ident = AstIdentifier("__builtin_expf");
2506+
2507+
$$ = MakeFunccall(ident, arg1, NULL);
2508+
}
24602509
;
24612510

24622511

include/libsys/powers.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ float __builtin_expf(float x)
311311
return __builtin_powf(CONST_E, x);
312312
}
313313

314+
float __builtin_exp10f(float x)
315+
{
316+
return __builtin_powf(10.0, x);
317+
}
318+
314319
float __builtin_logf(float x)
315320
{
316321
return __builtin_logbase(CONST_E, x);
@@ -320,3 +325,4 @@ float __builtin_log10f(float x)
320325
{
321326
return __builtin_logbase(10.0, x);
322327
}
328+

sys/float.spin

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ pri file "libsys/s_ldexpf.c" __builtin_ldexpf(x = float, n=long) : r=float
396396
pri file "libsys/s_modf.c" __builtin_modff(x = float, p) : r=float
397397
pri file "libsys/powers.c" __builtin_expf(x = float) : r=float
398398
pri file "libsys/powers.c" __builtin_exp2f(x = float) : r=float
399+
pri file "libsys/powers.c" __builtin_exp10f(x = float) : r=float
399400
pri file "libsys/powers.c" __builtin_logf(x = float) : r=float
400401
pri file "libsys/powers.c" __builtin_log2f(x = float) : r=float
401402
pri file "libsys/powers.c" __builtin_log10f(x = float) : r=float

sys/float.spin.h

Lines changed: 31 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)