Nicolas Cellier uploaded a new version of VMMaker to project VM Maker: http://source.squeak.org/VMMaker/VMMaker.oscog-nice.2548.mcz ==================== Summary ==================== Name: VMMaker.oscog-nice.2548 Author: nice Time: 5 September 2019, 11:45:21.497902 am UUID: 7e9a5859-39bb-054c-9e30-ecb8fab97761 Ancestors: VMMaker.oscog-nice.2547 Provide a more simulator friendly primitiveHighBit. If the simulator can fake a '__GNUC__' defined, or '_MSC_VER', , then it should be able to emulate the primitive behavior. Eliot, I hope it helps... =============== Diff against VMMaker.oscog-nice.2547 =============== Item was changed: ----- Method: InterpreterPrimitives>>primitiveHighBit (in category 'arithmetic integer primitives') ----- primitiveHighBit | integerReceiverOop leadingZeroCount highestBitZeroBased | integerReceiverOop := self stackTop. "Convert the receiver Oop to use a single tag bit" self numSmallIntegerTagBits > 1 ifTrue: [integerReceiverOop := (integerReceiverOop >>> (self numSmallIntegerTagBits-1) bitOr: 1)]. self cppIf: #'__GNUC__' defined ifTrue: ["Note: in gcc, result is undefined if input is zero (for compatibility with BSR fallback when no CLZ instruction available). but input is never zero because we pass the oop with tag bits set, so we are safe" objectMemory wordSize = 4 ifTrue: [leadingZeroCount := self __builtin_clz: integerReceiverOop] ifFalse: [leadingZeroCount := self __builtin_clzll: integerReceiverOop]. leadingZeroCount = 0 ifTrue: ["highBit is not defined for negative Integer" self primitiveFail] ifFalse: ["Nice bit trick: 1-based high-bit is (32 - clz) - 1 to account for tag bit. This is like two-complement - clz - 1 on 5 bits, or in other words a bit-invert operation clz ^16r1F" + self pop: 1 thenPushInteger: (leadingZeroCount bitXor: (BytesPerWord * 8 - 1))]. + ^self]. + self cppIf: #'__GNUC__' defined not & (#'_MSC_VER' defined | #'__ICC' defined) + ifTrue: + ["In MSVC, _lzcnt and _lzcnt64 builtins do not fallback to BSR when not supported by CPU + Instead of messing with __cpuid() we always use the BSR intrinsic" + + "Trick: we test the oop sign rather than the integerValue. Assume oop are signed (so far, they are, sqInt are signed)" + integerReceiverOop < 0 ifTrue: [self primitiveFail] ifFalse: [ + "Setting this variable is useless, but VMMaker will generate it at a worse place" + highestBitZeroBased := 0. + "We do not even test the return value, because integerReceiverOop is never zero" + self cCode: [objectMemory wordSize = 4 - self pop: 1 thenPushInteger: (leadingZeroCount bitXor: (BytesPerWord * 8 - 1))]] - ifFalse: [self cppIf: #'_MSC_VER' defined - ifTrue: - ["In MSVC, _lzcnt and _lzcnt64 builtins do not fallback to BSR when not supported by CPU - Instead of messing with __cpuid() we always use the BSR intrinsic" - - "Trick: we test the oop sign rather than the integerValue. Assume oop are signed (so far, they are, sqInt are signed)" - integerReceiverOop < 0 ifTrue: [self primitiveFail] ifFalse: [ - "Setting this variable is useless, but VMMaker will generate it at a worse place" - highestBitZeroBased := 0. - "We do not even test the return value, because integerReceiverOop is never zero" - objectMemory wordSize = 4 ifTrue: [self _BitScanReverse: highestBitZeroBased address _: integerReceiverOop] + ifFalse: [self _BitScanReverse64: highestBitZeroBased address _: integerReceiverOop]] + inSmalltalk: [highestBitZeroBased := integerReceiverOop highBit - 1]. + "thanks to the tag bit, the +1 operation for getting 1-based rank is not necessary" + self pop: 1 thenPushInteger: highestBitZeroBased]. + ^self]. + self cppIf: #'__GNUC__' defined not & #'_MSC_VER' defined not & #'__ICC' defined not + ifTrue: + ["not gcc/clang, nor MSVC/ICC, you have to implement if your compiler provide useful builtins" + self primitiveFail].! - ifFalse: [self _BitScanReverse64: highestBitZeroBased address _: integerReceiverOop]. - "thanks to the tag bit, the +1 operation for getting 1-based rank is not necessary" - self pop: 1 thenPushInteger: highestBitZeroBased]] - ifFalse: - ["not gcc/clang, nor MSVC, you have to implement if your compiler provide useful builtins" - self primitiveFail]].! Item was changed: ----- Method: VMBasicConstants class>>namesDefinedAtCompileTime (in category 'C translation') ----- namesDefinedAtCompileTime "Answer the set of names for variables that should be defined at compile time. Some of these get default values during simulation, and hence get defaulted in the various initializeMiscConstants methods. But that they have values should /not/ cause the code generator to do dead code elimination based on their default values. In particular, methods marked with <option: ANameDefinedAtCompileTime> will be emitted within #if defined(ANameDefinedAtCompileTime)...#endif." ^#( VMBIGENDIAN IMMUTABILITY STACKVM COGVM COGMTVM SPURVM PharoVM "Pharo vs Squeak" TerfVM "Terf vs Squeak" EnforceAccessControl "Newspeak" CheckRememberedInTrampoline "IMMUTABILITY" LLDB "As of lldb-370.0.42 Swift-3.1, passing funciton parameters to printOopsSuchThat fails with Internal error [IRForTarget]: Couldn't rewrite one of the arguments of a function call. Turning off link time optimization with -fno-lto has no effect. hence we define some debugging functions as being <option: LLDB>" "processor related" __ARM_ARCH__ __arm__ __arm32__ ARM32 __arm64__ ARM64 _M_I386 _X86_ i386 i486 i586 i686 __i386__ __386__ X86 I386 x86_64 __amd64 __x86_64 __amd64__ __x86_64__ _M_AMD64 _M_X64 + "Compiler brand related" + __GNUC__ + _MSC_VER + __ICC + "os related" ACORN - __GNUC__ __linux__ __MINGW32__ __OpenBSD__ __osf__ UNIX WIN32 _WIN32 _WIN32_WCE WIN64 _WIN64 _WIN64_WCE)! Item was added: + ----- Method: VMClass>>__builtin_clz: (in category 'C library simulation') ----- + __builtin_clz: anInteger + <doNotGenerate> + anInteger < 0 ifTrue: [^0]. + ^32 - anInteger highBit! Item was added: + ----- Method: VMClass>>__builtin_clzll: (in category 'C library simulation') ----- + __builtin_clzll: anInteger + <doNotGenerate> + anInteger < 0 ifTrue: [^0]. + ^64 - anInteger highBitOfMagnitude! |
Free forum by Nabble | Edit this page |