Skip to content

Commit

Permalink
initial Aarch64 support
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jun 3, 2024
1 parent 91fa7e2 commit 4acce51
Show file tree
Hide file tree
Showing 18 changed files with 2,738 additions and 27 deletions.
3 changes: 3 additions & 0 deletions compiler/src/.dscanner.ini
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ unused_variable_check="-dmd.backend.aarray,\
-dmd.backend.cgelem,\
-dmd.backend.cgobj,\
-dmd.backend.cgsched,\
-dmd.backend.arm.cod2,\
-dmd.backend.arm.cod3,\
-dmd.backend.arm.disasmarm,\
-dmd.backend.x86.cgxmm,\
-dmd.backend.x86.cod1,\
-dmd.backend.x86.cod2,\
Expand Down
1 change: 1 addition & 0 deletions compiler/src/build.d
Original file line number Diff line number Diff line change
Expand Up @@ -1623,6 +1623,7 @@ auto sourceFiles()
x86/cod3.d cv8.d dcgcv.d pdata.d util2.d var.d backconfig.d drtlsym.d dwarfeh.d ptrntab.d
dvarstats.d dwarfdbginf.d cgen.d goh.d barray.d cgcse.d elpicpie.d
machobj.d elfobj.d mscoffobj.d filespec.d cgobj.d aarray.d disasm86.d
arm/cod2.d arm/cod3.d arm/disasmarm.d
"
),
};
Expand Down
160 changes: 160 additions & 0 deletions compiler/src/dmd/backend/arm/cod2.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/**
* Code generation 2
*
* Includes:
* - math operators (+ - * / %) and functions (abs, cos, sqrt)
* - 'string' functions (strlen, memcpy, memset)
* - pointers (address of / dereference)
* - struct assign, constructor, destructor
*
* Compiler implementation of the
* $(LINK2 https://www.dlang.org, D programming language).
*
* Copyright: Copyright (C) 1984-1998 by Symantec
* Copyright (C) 2000-2024 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/backend/arm/cod2.d, backend/cod2.d)
* Documentation: https://dlang.org/phobos/dmd_backend_arm_cod2.html
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/backend/arm/cod2.d
*/

module dmd.backend.arm.cod2;

import core.stdc.stdio;
import core.stdc.stdlib;
import core.stdc.string;

import dmd.backend.cc;
import dmd.backend.cdef;
import dmd.backend.code;
import dmd.backend.x86.code_x86;
import dmd.backend.codebuilder;
import dmd.backend.mem;
import dmd.backend.el;
import dmd.backend.global;
import dmd.backend.oper;
import dmd.backend.ty;
import dmd.backend.type;
import dmd.backend.x86.xmm;


nothrow:
@safe:

import dmd.backend.cg : segfl, stackfl;

__gshared int cdcmp_flag;

import dmd.backend.divcoeff : choose_multiplier, udiv_coefficients;

/*****************************
* Handle operators which are more or less orthogonal
* OPadd, OPmin, OPand, OPor, OPxor
*/

@trusted
void cdorth(ref CGstate cg, ref CodeBuilder cdb,elem *e,regm_t *pretregs)
{
//printf("cdorth(e = %p, *pretregs = %s)\n",e,regm_str(*pretregs));

elem* e1 = e.E1;
elem* e2 = e.E2;
if (*pretregs == 0) // if don't want result

Check warning on line 63 in compiler/src/dmd/backend/arm/cod2.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod2.d#L61-L63

Added lines #L61 - L63 were not covered by tests
{
codelem(cg,cdb,e1,pretregs,false); // eval left leaf
*pretregs = 0; // in case they got set
codelem(cg,cdb,e2,pretregs,false);
return;

Check warning on line 68 in compiler/src/dmd/backend/arm/cod2.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod2.d#L65-L68

Added lines #L65 - L68 were not covered by tests
}

const ty = tybasic(e.Ety);
const ty1 = tybasic(e1.Ety);
const ty2 = tybasic(e2.Ety);
const sz = _tysize[ty];

Check warning on line 74 in compiler/src/dmd/backend/arm/cod2.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod2.d#L71-L74

Added lines #L71 - L74 were not covered by tests

if (tyfloating(ty1))

Check warning on line 76 in compiler/src/dmd/backend/arm/cod2.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod2.d#L76

Added line #L76 was not covered by tests
{
assert(0);
}

regm_t posregs = cg.allregs;

Check warning on line 81 in compiler/src/dmd/backend/arm/cod2.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod2.d#L81

Added line #L81 was not covered by tests

regm_t retregs1 = posregs;

Check warning on line 83 in compiler/src/dmd/backend/arm/cod2.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod2.d#L83

Added line #L83 was not covered by tests

codelem(cg, cdb, e1, &retregs1, false);
regm_t retregs2 = cg.allregs & ~retregs1;
scodelem(cg, cdb, e2, &retregs2, retregs1, false);

Check warning on line 87 in compiler/src/dmd/backend/arm/cod2.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod2.d#L85-L87

Added lines #L85 - L87 were not covered by tests

regm_t retregs = *pretregs & cg.allregs;
if (retregs == 0) /* if no return regs speced */

Check warning on line 90 in compiler/src/dmd/backend/arm/cod2.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod2.d#L89-L90

Added lines #L89 - L90 were not covered by tests
/* (like if wanted flags only) */
retregs = ALLREGS & posregs; // give us some
reg_t Rd = allocreg(cdb, retregs, ty);

Check warning on line 93 in compiler/src/dmd/backend/arm/cod2.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod2.d#L92-L93

Added lines #L92 - L93 were not covered by tests

reg_t Rn = findreg(retregs1);
reg_t Rm = findreg(retregs2);

Check warning on line 96 in compiler/src/dmd/backend/arm/cod2.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod2.d#L95-L96

Added lines #L95 - L96 were not covered by tests

uint sf = sz == 8;
uint op = 0;
uint S = (*pretregs & mPSW) != 0;
uint opcode = 0xB;
uint opt = 0;
uint option = tyToExtend(ty);
uint imm3 = 0;
switch (e.Eoper)

Check warning on line 105 in compiler/src/dmd/backend/arm/cod2.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod2.d#L98-L105

Added lines #L98 - L105 were not covered by tests
{
case OPadd: op = 0; break;
case OPmin: op = 1; break;

Check warning on line 108 in compiler/src/dmd/backend/arm/cod2.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod2.d#L107-L108

Added lines #L107 - L108 were not covered by tests
default:
assert(0);
}
uint ins = (sf << 31) |

Check warning on line 112 in compiler/src/dmd/backend/arm/cod2.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod2.d#L112

Added line #L112 was not covered by tests
(op << 30) |
(0xB << 24) |
(opt << 22) |
(1 << 21) |
(Rm << 16) |
(option << 13) |
(imm3 << 10) |
(Rn << 5) |
Rd;
cdb.gen1(ins);

Check warning on line 122 in compiler/src/dmd/backend/arm/cod2.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod2.d#L122

Added line #L122 was not covered by tests

fixresult(cdb,e,mask(Rd),*pretregs);

Check warning on line 124 in compiler/src/dmd/backend/arm/cod2.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod2.d#L124

Added line #L124 was not covered by tests
}

/*************************************************
* Convert from ty to <extend> type according to table:
<extend>
0 UXTB
1 UXTH
2 UXTW
3 LSL|UXTX
4 SXTB
5 SXTH
6 SXTW
7 SXTX
* Params:
* ty = basic ty
* Output:
* <extend>
*/
uint tyToExtend(tym_t ty)
{
assert(tyintegral(ty));
uint extend;
uint sz = tysize(ty);
switch (sz)

Check warning on line 148 in compiler/src/dmd/backend/arm/cod2.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod2.d#L145-L148

Added lines #L145 - L148 were not covered by tests
{
case 1: extend = 0; break;
case 2: extend = 1; break;
case 4: extend = 2; break;
case 8: extend = 3; break;

Check warning on line 153 in compiler/src/dmd/backend/arm/cod2.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod2.d#L150-L153

Added lines #L150 - L153 were not covered by tests
default:
assert(0);
}
if (!tyuns(ty))
extend |= 4;
return extend;

Check warning on line 159 in compiler/src/dmd/backend/arm/cod2.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/arm/cod2.d#L157-L159

Added lines #L157 - L159 were not covered by tests
}
Loading

0 comments on commit 4acce51

Please sign in to comment.