Skip to content

Commit

Permalink
make X86 a positive affirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed May 30, 2024
1 parent 1dae282 commit 5913811
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 8 deletions.
2 changes: 2 additions & 0 deletions compiler/src/dmd/dmdparams.d
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,14 @@ void setTargetBuildDefaults(ref Target target)
target.osMajor = defaultTargetOSMajor();
target.cpu = CPU.baseline;
target.isX86_64 = (size_t.sizeof == 8);
target.isX86 = !target.isX86_64;
}

void setTriple(ref Target target, const ref Triple triple) @safe
{
target.cpu = triple.cpu;
target.isX86_64 = triple.isX86_64;
target.isX86 = !target.isX86_64;
target.isLP64 = triple.isLP64;
target.os = triple.os;
target.osMajor = triple.osMajor;
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dmd/frontend.d
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ void initDMD(

target.os = defaultTargetOS();
target.isX86_64 = (size_t.sizeof == 8);
target.isX86 = !target.isX86_64;
target._init(global.params);
Type._init();
Id.initialize();
Expand Down
5 changes: 4 additions & 1 deletion compiler/src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -7542,6 +7542,7 @@ struct Target final
_d_dynamicArray< const char > architectureName;
CPU cpu;
bool isX86_64;
bool isX86;
bool isLP64;
_d_dynamicArray< const char > obj_ext;
_d_dynamicArray< const char > lib_ext;
Expand Down Expand Up @@ -7613,6 +7614,7 @@ struct Target final
objc(),
architectureName(),
isX86_64(),
isX86(),
isLP64(),
obj_ext(),
lib_ext(),
Expand All @@ -7625,7 +7627,7 @@ struct Target final
params()
{
}
Target(OS os, uint8_t osMajor = 0u, uint8_t ptrsize = 0u, uint8_t realsize = 0u, uint8_t realpad = 0u, uint8_t realalignsize = 0u, uint8_t classinfosize = 0u, uint64_t maxStaticDataSize = 0LLU, TargetC c = TargetC(), TargetCPP cpp = TargetCPP(), TargetObjC objc = TargetObjC(), _d_dynamicArray< const char > architectureName = {}, CPU cpu = (CPU)0u, bool isX86_64 = false, bool isLP64 = false, _d_dynamicArray< const char > obj_ext = {}, _d_dynamicArray< const char > lib_ext = {}, _d_dynamicArray< const char > dll_ext = {}, bool run_noext = false, FPTypeProperties<float > FloatProperties = FPTypeProperties<float >(), FPTypeProperties<double > DoubleProperties = FPTypeProperties<double >(), FPTypeProperties<_d_real > RealProperties = FPTypeProperties<_d_real >(), Type* tvalist = nullptr, const Param* params = nullptr) :
Target(OS os, uint8_t osMajor = 0u, uint8_t ptrsize = 0u, uint8_t realsize = 0u, uint8_t realpad = 0u, uint8_t realalignsize = 0u, uint8_t classinfosize = 0u, uint64_t maxStaticDataSize = 0LLU, TargetC c = TargetC(), TargetCPP cpp = TargetCPP(), TargetObjC objc = TargetObjC(), _d_dynamicArray< const char > architectureName = {}, CPU cpu = (CPU)0u, bool isX86_64 = false, bool isX86 = false, bool isLP64 = false, _d_dynamicArray< const char > obj_ext = {}, _d_dynamicArray< const char > lib_ext = {}, _d_dynamicArray< const char > dll_ext = {}, bool run_noext = false, FPTypeProperties<float > FloatProperties = FPTypeProperties<float >(), FPTypeProperties<double > DoubleProperties = FPTypeProperties<double >(), FPTypeProperties<_d_real > RealProperties = FPTypeProperties<_d_real >(), Type* tvalist = nullptr, const Param* params = nullptr) :
os(os),
osMajor(osMajor),
ptrsize(ptrsize),
Expand All @@ -7640,6 +7642,7 @@ struct Target final
architectureName(architectureName),
cpu(cpu),
isX86_64(isX86_64),
isX86(isX86),
isLP64(isLP64),
obj_ext(obj_ext),
lib_ext(lib_ext),
Expand Down
3 changes: 3 additions & 0 deletions compiler/src/dmd/mars.d
Original file line number Diff line number Diff line change
Expand Up @@ -883,14 +883,17 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param
}
else if (arg == "-m32") // https://dlang.org/dmd.html#switch-m32
{
target.isX86 = true;
target.isX86_64 = false;
}
else if (arg == "-m64") // https://dlang.org/dmd.html#switch-m64
{
target.isX86 = false;
target.isX86_64 = true;
}
else if (arg == "-m32mscoff") // https://dlang.org/dmd.html#switch-m32mscoff
{
target.isX86 = true;
target.isX86_64 = false;
}
else if (startsWith(p + 1, "mscrtlib="))
Expand Down
27 changes: 20 additions & 7 deletions compiler/src/dmd/target.d
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

module dmd.target;

import core.stdc.stdio;

import dmd.astenums : CHECKENABLE;
import dmd.globals : Param;

Expand Down Expand Up @@ -348,6 +350,7 @@ extern (C++) struct Target
const(char)[] architectureName;
CPU cpu; // CPU instruction set to target
bool isX86_64; // generate 64 bit code for x86_64; true by default for 64 bit dmd
bool isX86; // generate 32 bit Intel x86 code
bool isLP64; // pointers are 64 bits

// Environmental
Expand Down Expand Up @@ -403,6 +406,7 @@ extern (C++) struct Target
extern (C++) void _init(ref const Param params)
{
// isX86_64 and cpu are initialized in parseCommandLine
isX86 = !isX86_64;

this.params = &params;

Expand Down Expand Up @@ -460,10 +464,12 @@ extern (C++) struct Target
}
}

assert(isX86 != isX86_64);
c.initialize(params, this);
cpp.initialize(params, this);
objc.initialize(params, this);

assert(isX86 != isX86_64);
if (isX86_64)
architectureName = "X86_64";
else
Expand Down Expand Up @@ -1039,7 +1045,7 @@ extern (C++) struct Target
if (tns.ty != TY.Tstruct)
{
L2:
if (os == Target.OS.linux && tf.linkage != LINK.d && !isX86_64)
if (os == Target.OS.linux && tf.linkage != LINK.d && isX86)
{
// 32 bit C/C++ structs always on stack
}
Expand All @@ -1066,12 +1072,12 @@ extern (C++) struct Target
if (auto ts = tns.isTypeStruct())
{
auto sd = ts.sym;
if (os == Target.OS.linux && tf.linkage != LINK.d && !isX86_64)
if (os == Target.OS.linux && tf.linkage != LINK.d && isX86)
{
//printf(" 2 true\n");
return true; // 32 bit C/C++ structs always on stack
}
if (os == Target.OS.Windows && tf.linkage == LINK.cpp && !isX86_64 &&
if (os == Target.OS.Windows && tf.linkage == LINK.cpp && isX86 &&
sd.isPOD() && sd.ctor)
{
// win32 returns otherwise POD structs with ctors via memory
Expand Down Expand Up @@ -1119,7 +1125,7 @@ extern (C++) struct Target
return true;
}
else if (os == Target.OS.Windows &&
!isX86_64 &&
isX86 &&
tf.linkage == LINK.cpp &&
tf.isfloating())
{
Expand Down Expand Up @@ -1278,7 +1284,7 @@ extern (C++) struct Target
*/
extern (C++) bool libraryObjectMonitors(FuncDeclaration fd, Statement fbody)
{
if (!isX86_64 && os == Target.OS.Windows && !fd.isStatic() && !fbody.usesEH() && !params.trace)
if (isX86 && os == Target.OS.Windows && !fd.isStatic() && !fbody.usesEH() && !params.trace)
{
/* The back end uses the "jmonitor" hack for syncing;
* no need to do the sync in the library.
Expand Down Expand Up @@ -1309,7 +1315,7 @@ extern (C++) struct Target
*/
extern (D) bool isXmmSupported() @safe
{
return isX86_64 || os == Target.OS.OSX;
return isX86_64 || (isX86 && os == Target.OS.OSX);
}

/**
Expand All @@ -1329,7 +1335,13 @@ extern (C++) struct Target
*/
extern (D) uint stackAlign() @safe
{
return isXmmSupported() ? 16 : (isX86_64 ? 8 : 4);
assert(isX86_64 != isX86);
uint sz = isXmmSupported() ? 16 :
isX86_64 ? 8 :
isX86 ? 4 : 0;
assert(sz);
assert(sz == (isXmmSupported() ? 16 : (isX86_64 ? 8 : 4)));
return sz;
}
}

Expand Down Expand Up @@ -1482,6 +1494,7 @@ struct TargetCPP
else
assert(0);
// C++ and D ABI incompatible on all (?) x86 32-bit platforms
assert(target.isX86 == !target.isX86_64);
wrapDtorInExternD = !target.isX86_64;
}

Expand Down
1 change: 1 addition & 0 deletions compiler/src/dmd/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ struct Target
DString architectureName; // name of the platform architecture (e.g. X86_64)
CPU cpu; // CPU instruction set to target
d_bool isX86_64; // generate 64 bit code for x86_64; true by default for 64 bit dmd
d_bool isX86; // generate 32 bit Intel x86 code
d_bool isLP64; // pointers are 64 bits

// Environmental
Expand Down

0 comments on commit 5913811

Please sign in to comment.