History

arm64: Implement TOK_NEG for floats natively

Aleksi Hannula committed 9 months ago

Commit c39eaf11 parent 1cb0a3d4 files · +44 −1Browse files

Unified · Split

4 files
  1. arm64-gen.c +31 −0
  2. lib/lib-arm64.c +11 −0
  3. tccgen.c +1 −1
  4. tcctok.h +1 −0
arm64-gen.c+31−0
@@ -1849,6 +1849,37 @@ ST_FUNC void gen_opf(int op) · 1848 unmodified lines
18491849 {
18501850 uint32_t x, a, b, dbl;
18511851
1852+ if (op == TOK_NEG) {
1853+ switch (vtop[0].type.t & VT_BTYPE) {
1854+ case VT_LDOUBLE:
1855+ vpush_helper_func(TOK___negtf2);
1856+ vrott(2);
1857+ gfunc_call(1);
1858+ vpushi(0);
1859+ vtop->type.t = VT_LDOUBLE;
1860+ vtop->r = REG_FRET;
1861+ break;
1862+
1863+ case VT_FLOAT:
1864+ case VT_DOUBLE:
1865+ gv(RC_FLOAT);
1866+ dbl = vtop[0].type.t == VT_DOUBLE;
1867+
1868+ a = fltr(vtop[0].r);
1869+ vtop--;
1870+ x = get_reg(RC_FLOAT);
1871+ vtop++;
1872+ vtop[0].r = x;
1873+ x = fltr(x);
1874+
1875+ o(0x1e214000 | dbl << 22 | x | a << 5);
1876+ break;
1877+ default:
1878+ assert(0);
1879+ }
1880+ return;
1881+ }
1882+
18521883 if (vtop[0].type.t == VT_LDOUBLE) {
18531884 CType type = vtop[0].type;
18541885 int func = 0;
lib/lib-arm64.c+11−0
@@ -373,6 +373,17 @@ long double __divtf3(long double fa, long double fb) · 372 unmodified lines
373373 return f3_round(x_sgn, x_exp, x);
374374 }
375375
376+long double __negtf2(long double f)
377+{
378+ u128_t a;
379+
380+ memcpy(&a, &f, 16);
381+ a.x1 ^= 1UL << 63;
382+ memcpy(&f, &a, 16);
383+
384+ return f;
385+}
386+
376387 long double __extendsftf2(float f)
377388 {
378389 long double fx;
tccgen.c+1−1
@@ -2504,7 +2504,7 @@ static void gen_opic(int op) · 2503 unmodified lines
25042504 }
25052505 }
25062506
2507−#if defined TCC_TARGET_X86_64 || defined TCC_TARGET_I386
2507+#if defined TCC_TARGET_X86_64 || defined TCC_TARGET_I386 || defined TCC_TARGET_ARM64
25082508 # define gen_negf gen_opf
25092509 #elif defined TCC_TARGET_ARM
25102510 void gen_negf(int op)
tcctok.h+1−0
@@ -316,6 +316,7 @@ · 315 unmodified lines
316316 DEF(TOK___extenddftf2, "__extenddftf2")
317317 DEF(TOK___trunctfsf2, "__trunctfsf2")
318318 DEF(TOK___trunctfdf2, "__trunctfdf2")
319+ DEF(TOK___negtf2, "__negtf2")
319320 DEF(TOK___fixtfsi, "__fixtfsi")
320321 DEF(TOK___fixtfdi, "__fixtfdi")
321322 DEF(TOK___fixunstfsi, "__fixunstfsi")

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t