-
-
Notifications
You must be signed in to change notification settings - Fork 621
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91fa7e2
commit 4acce51
Showing
18 changed files
with
2,738 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
codelem(cg,cdb,e1,pretregs,false); // eval left leaf | ||
*pretregs = 0; // in case they got set | ||
codelem(cg,cdb,e2,pretregs,false); | ||
return; | ||
} | ||
|
||
const ty = tybasic(e.Ety); | ||
const ty1 = tybasic(e1.Ety); | ||
const ty2 = tybasic(e2.Ety); | ||
const sz = _tysize[ty]; | ||
|
||
if (tyfloating(ty1)) | ||
{ | ||
assert(0); | ||
} | ||
|
||
regm_t posregs = cg.allregs; | ||
|
||
regm_t retregs1 = posregs; | ||
|
||
codelem(cg, cdb, e1, &retregs1, false); | ||
regm_t retregs2 = cg.allregs & ~retregs1; | ||
scodelem(cg, cdb, e2, &retregs2, retregs1, false); | ||
|
||
regm_t retregs = *pretregs & cg.allregs; | ||
if (retregs == 0) /* if no return regs speced */ | ||
/* (like if wanted flags only) */ | ||
retregs = ALLREGS & posregs; // give us some | ||
reg_t Rd = allocreg(cdb, retregs, ty); | ||
|
||
reg_t Rn = findreg(retregs1); | ||
reg_t Rm = findreg(retregs2); | ||
|
||
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) | ||
{ | ||
case OPadd: op = 0; break; | ||
case OPmin: op = 1; break; | ||
default: | ||
assert(0); | ||
} | ||
uint ins = (sf << 31) | | ||
(op << 30) | | ||
(0xB << 24) | | ||
(opt << 22) | | ||
(1 << 21) | | ||
(Rm << 16) | | ||
(option << 13) | | ||
(imm3 << 10) | | ||
(Rn << 5) | | ||
Rd; | ||
cdb.gen1(ins); | ||
|
||
fixresult(cdb,e,mask(Rd),*pretregs); | ||
} | ||
|
||
/************************************************* | ||
* 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) | ||
{ | ||
case 1: extend = 0; break; | ||
case 2: extend = 1; break; | ||
case 4: extend = 2; break; | ||
case 8: extend = 3; break; | ||
default: | ||
assert(0); | ||
} | ||
if (!tyuns(ty)) | ||
extend |= 4; | ||
return extend; | ||
} |
Oops, something went wrong.