Skip to content

Implementation of uint8At: added, senders of byteAt: replaced with uint8At: #967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: pharo-12
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/pharovm/common/sqMemoryAccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ typedef unsigned long long usqIntptr_t;
static inline char *pointerForOop(usqInt oop) { return sqMemoryBase + oop; }
static inline sqInt oopForPointer(void *ptr) { return (sqInt)(ptr - sqMemoryBase); }
# endif
static inline sqInt byteAt(sqInt oop) { return byteAtPointer(pointerForOop(oop)); }
static inline sqInt uint8At(sqInt oop) { return byteAtPointer(pointerForOop(oop)); }
static inline sqInt byteAtput(sqInt oop, int val) { return byteAtPointerput(pointerForOop(oop), val); }
static inline sqInt shortAt(sqInt oop) { return shortAtPointer(pointerForOop(oop)); }
static inline sqInt shortAtput(sqInt oop, int val) { return shortAtPointerput(pointerForOop(oop), val); }
Expand Down Expand Up @@ -239,7 +239,7 @@ typedef unsigned long long usqIntptr_t;
# define oopForPointer(ptr) ((sqInt)(((char *)(ptr)) - (sqMemoryBase)))
# define atPointerArg(oop) sqMemoryBase + (usqInt)(oop)
# endif
# define byteAt(oop) byteAtPointer(atPointerArg(oop))
# define uint8At(oop) byteAtPointer(atPointerArg(oop))
# define byteAtput(oop,val) byteAtPointerput(atPointerArg(oop), val)
# define shortAt(oop) shortAtPointer(atPointerArg(oop))
# define shortAtput(oop,val) shortAtPointerput(atPointerArg(oop), val)
Expand Down
9 changes: 9 additions & 0 deletions smalltalksrc/Melchor/VMClass.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,15 @@ VMClass >> uint64AtPointer: pointer put: value [

]

{ #category : 'memory access' }
VMClass >> uint8At: pointer [
"This gets implemented by Macros in C, where its types will also be checked.
pointer is a raw address, and the result is an 32 bit integer."
<doNotGenerate>

^memoryManager readIntegerAt: pointer size: 1 signed: false
]

{ #category : 'memory access' }
VMClass >> uint8AtPointer: pointer [
"This gets implemented by Macros in C, where its types will also be checked.
Expand Down
6 changes: 3 additions & 3 deletions smalltalksrc/VMMaker/CoInterpreter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2815,7 +2815,7 @@ CoInterpreter >> getCurrentBytecode [

^((stackPages couldBeFramePointer: framePointer)
and: [(self isMachineCodeFrame: framePointer) not])
ifTrue: [objectMemory byteAt: instructionPointer]
ifTrue: [objectMemory uint8At: instructionPointer]
ifFalse: [-1]
]

Expand Down Expand Up @@ -3112,7 +3112,7 @@ CoInterpreter >> iframeBackwardBranchByte: theFP [
"See encodeFrameFieldHasContext:numArgs: and ifBackwardsCheckForEvents:"
<inline: true>
<var: #theFP type: #'char *'>
^stackPages byteAt: theFP + (VMBIGENDIAN ifTrue: [FoxIFrameFlags + objectMemory wordSize - 1] ifFalse: [FoxIFrameFlags])
^stackPages uint8At: theFP + (VMBIGENDIAN ifTrue: [FoxIFrameFlags + objectMemory wordSize - 1] ifFalse: [FoxIFrameFlags])
]

{ #category : 'frame access' }
Expand Down Expand Up @@ -3794,7 +3794,7 @@ CoInterpreter >> mnuCompilationBreak: selectorOop point: selectorLength [
breakSelectorLength negated = selectorLength ifTrue:
[i := breakSelectorLength negated.
[i > 0] whileTrue:
[(objectMemory byteAt: selectorOop + i + objectMemory baseHeaderSize - 1) = (breakSelector at: i) asInteger
[(objectMemory uint8At: selectorOop + i + objectMemory baseHeaderSize - 1) = (breakSelector at: i) asInteger
ifTrue: [(i := i - 1) = 0 ifTrue:
[self mnuCompilationBreakpointFor: selectorOop]]
ifFalse: [i := 0]]]
Expand Down
42 changes: 21 additions & 21 deletions smalltalksrc/VMMaker/CogIA32Compiler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3610,7 +3610,7 @@ CogIA32Compiler >> instructionSizeAt: pc [
"Answer the instruction size at pc. This is very far from a full decode.
It only has to cope with the instructions generated in a block dispatch."
| op |
op := objectMemory byteAt: pc.
op := objectMemory uint8At: pc.
^op caseOf:
{ [16r0F] -> [self twoByteInstructionSizeAt: pc].
[16r3D] -> [5]. "cmp EAX,imm32"
Expand Down Expand Up @@ -3647,18 +3647,18 @@ CogIA32Compiler >> isBigEndian [
{ #category : 'testing' }
CogIA32Compiler >> isCallPrecedingReturnPC: mcpc [
"Assuming mcpc is a send return pc answer if the instruction before it is a call (not a CallFull)."
^(objectMemory byteAt: mcpc - 5) = 16rE8
^(objectMemory uint8At: mcpc - 5) = 16rE8
]

{ #category : 'disassembly' }
CogIA32Compiler >> isJumpAt: pc [
| op |
op := objectMemory byteAt: pc.
op := objectMemory uint8At: pc.
^ (op between: 16r70 and: 16r7F) "short conditional jumps"
or: [op = 16rE9 "long unconditional jump"
or: [op = 16rEB "short unconditional jump"
or: [op = 16r0F "long conditional jumps"
and: [(objectMemory byteAt: pc + 1) between: 16r80 and: 16r8F]]]]
and: [(objectMemory uint8At: pc + 1) between: 16r80 and: 16r8F]]]]
]

{ #category : 'testing' }
Expand Down Expand Up @@ -3721,14 +3721,14 @@ CogIA32Compiler >> jumpTargetPCAt: pc [
size := self instructionSizeAt: pc.
size = 2
ifTrue:
[byte := objectMemory byteAt: pc + 1.
[byte := objectMemory uint8At: pc + 1.
offset := (byte bitAnd: 16r80) = 0 ifTrue: [byte] ifFalse: [byte - 256]]
ifFalse:
[byte := objectMemory byteAt: pc + size - 1.
[byte := objectMemory uint8At: pc + size - 1.
offset := (byte bitAnd: 16r80) = 0 ifTrue: [byte] ifFalse: [byte - 256].
offset := offset << 8 + (objectMemory byteAt: pc + size - 2).
offset := offset << 8 + (objectMemory byteAt: pc + size - 3).
offset := offset << 8 + (objectMemory byteAt: pc + size - 4)].
offset := offset << 8 + (objectMemory uint8At: pc + size - 2).
offset := offset << 8 + (objectMemory uint8At: pc + size - 3).
offset := offset << 8 + (objectMemory uint8At: pc + size - 4)].
^pc + size + offset
]

Expand All @@ -3744,10 +3744,10 @@ CogIA32Compiler >> leafCallStackPointerDelta [
{ #category : 'inline cacheing' }
CogIA32Compiler >> literalBeforeFollowingAddress: followingAddress [
"Answer the literal embedded in the instruction immediately preceding followingAddress."
^ ((objectMemory byteAt: followingAddress - 1) << 24)
+ ((objectMemory byteAt: followingAddress - 2) << 16)
+ ((objectMemory byteAt: followingAddress - 3) << 8)
+ (objectMemory byteAt: followingAddress - 4)
^ ((objectMemory uint8At: followingAddress - 1) << 24)
+ ((objectMemory uint8At: followingAddress - 2) << 16)
+ ((objectMemory uint8At: followingAddress - 3) << 8)
+ (objectMemory uint8At: followingAddress - 4)
]

{ #category : 'inline cacheing' }
Expand Down Expand Up @@ -3854,10 +3854,10 @@ CogIA32Compiler >> prepareStackToCallCFunctionInSmalltalkStack: numberOfArgument
CogIA32Compiler >> relocateCallBeforeReturnPC: retpc by: delta [
| distance |
delta ~= 0 ifTrue:
[distance := ((objectMemory byteAt: retpc - 1) << 24)
+ ((objectMemory byteAt: retpc - 2) << 16)
+ ((objectMemory byteAt: retpc - 3) << 8)
+ (objectMemory byteAt: retpc - 4).
[distance := ((objectMemory uint8At: retpc - 1) << 24)
+ ((objectMemory uint8At: retpc - 2) << 16)
+ ((objectMemory uint8At: retpc - 3) << 8)
+ (objectMemory uint8At: retpc - 4).
distance := distance + delta.
objectMemory
byteAt: retpc - 1 put: (distance >> 24 bitAnd: 16rFF);
Expand Down Expand Up @@ -4023,7 +4023,7 @@ CogIA32Compiler >> shiftSetsConditionCodesFor: aConditionalJumpOpcode [
{ #category : 'disassembly' }
CogIA32Compiler >> sizeHasModrm: op at: pc [
| modrm mod ro rm |
modrm := objectMemory byteAt: pc + 1.
modrm := objectMemory uint8At: pc + 1.
mod := modrm >> 6.
ro := modrm >> 3 bitAnd: 7.
rm := modrm bitAnd: 7.
Expand All @@ -4044,7 +4044,7 @@ CogIA32Compiler >> sizeHasModrm: op at: pc [
CogIA32Compiler >> sizeImmediateGroup1: op at: pc [
"see [1] p A-7, p A-13"
| modrm mod ro rm |
modrm := objectMemory byteAt: pc + 1.
modrm := objectMemory uint8At: pc + 1.
mod := modrm >> 6.
ro := modrm >> 3 bitAnd: 7.
rm := modrm bitAnd: 7.
Expand Down Expand Up @@ -4162,14 +4162,14 @@ CogIA32Compiler >> storeLiteral: literal beforeFollowingAddress: followingAddres
{ #category : 'disassembly' }
CogIA32Compiler >> twoByteInstructionSizeAt: pc [
| op |
op := objectMemory byteAt: pc + 1.
op := objectMemory uint8At: pc + 1.
^(op bitAnd: 16rF0) caseOf:
{ [16r80] -> [6 "long conditional jumps"] }
]

{ #category : 'accessing' }
CogIA32Compiler >> unsignedShortAt: byteAddress [
^(objectMemory byteAt: byteAddress) + ((objectMemory byteAt: byteAddress + 1) bitShift: 8)
^(objectMemory uint8At: byteAddress) + ((objectMemory uint8At: byteAddress + 1) bitShift: 8)
]

{ #category : 'inline cacheing' }
Expand Down
8 changes: 4 additions & 4 deletions smalltalksrc/VMMaker/CogInLineLiteralsARMCompiler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ CogInLineLiteralsARMCompiler >> cogit: aCogit [
{ #category : 'testing' }
CogInLineLiteralsARMCompiler >> extract32BitOperandFrom4InstructionsPreceding: addr [
<inline: true>
^(objectMemory byteAt: addr -4)
+ ((objectMemory byteAt: addr - 8) << 8)
+ ((objectMemory byteAt: addr - 12) << 16)
+ ((objectMemory byteAt: addr - 16) << 24)
^(objectMemory uint8At: addr -4)
+ ((objectMemory uint8At: addr - 8) << 8)
+ ((objectMemory uint8At: addr - 12) << 16)
+ ((objectMemory uint8At: addr - 16) << 24)
]

{ #category : 'accessing' }
Expand Down
4 changes: 2 additions & 2 deletions smalltalksrc/VMMaker/CogInLineLiteralsX64Compiler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ CogInLineLiteralsX64Compiler >> literalBeforeFollowingAddress: followingAddress
a (self mod: ModReg RM: rX RO: rY) ending the ArithCwR sequence, which is at least 16rC0."

| lastByte base |
lastByte := objectMemory byteAt: followingAddress - 1.
lastByte := objectMemory uint8At: followingAddress - 1.
base := followingAddress - (lastByte = 16r90
ifTrue: [ "MoveCwR" 9 ]
ifFalse: [
Expand Down Expand Up @@ -284,7 +284,7 @@ CogInLineLiteralsX64Compiler >> storeLiteral: literal beforeFollowingAddress: fo
nop following the literal load in MoveCwR, a 16r50 + reg ending the PushCw sequence, and
a (self mod: ModReg RM: rX RO: rY) ending the CmpCwR sequence, which is at least 16rC0."
| lastByte base |
lastByte := objectMemory byteAt: followingAddress - 1.
lastByte := objectMemory uint8At: followingAddress - 1.
base := followingAddress - (lastByte <= 16r90
ifTrue:
[lastByte = 16r90
Expand Down
11 changes: 2 additions & 9 deletions smalltalksrc/VMMaker/CogVMSimulator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,6 @@ CogVMSimulator >> breakCount [
^breakCount
]

{ #category : 'memory access' }
CogVMSimulator >> byteAt: byteAddress [
"This is really only for the C library simulations memcpy:_:_: et al in VMClass.
Use objectMemory byteAt: directly where possible."
^objectMemory byteAt: byteAddress
]

{ #category : 'memory access' }
CogVMSimulator >> byteAt: byteAddress put: byte [
^objectMemory byteAt: byteAddress put: byte
Expand Down Expand Up @@ -572,7 +565,7 @@ CogVMSimulator >> expectSends: anArray [

{ #category : 'interpreter shell' }
CogVMSimulator >> fetchByte [
^objectMemory byteAt: (instructionPointer := instructionPointer + 1)
^objectMemory uint8At: (instructionPointer := instructionPointer + 1)
]

{ #category : 'interpreter access' }
Expand Down Expand Up @@ -687,7 +680,7 @@ CogVMSimulator >> imageNamePut: p Length: sz [
1 to: sz do: [ :i |
newName
at: i
put: (Character value: (objectMemory byteAt: p + i - 1)) ].
put: (Character value: (objectMemory uint8At: p + i - 1)) ].
imageName := newName
]

Expand Down
Loading