; ************* PME_COUNT:  BUCKET COUNT INCREMENT ROUTINE ******************
;
;
; This routine accepts a Program Counter value and increments the reference
; count in the corresponding Bucket Record.  There are two entry points to
; the routine: PME_COUNTER which provides a CALL linkage and PME_COUNT which
; uses a JSB linkage.  PME_COUNTER simply extracts the passed PC value and then
; calls PME_COUNT to do the actual bucket incrementation.
;
;
;		Written by Bert Beander, March, 1979.



	.TITLE	PMECOUNT Performance Measurement and Evaluation
	.IDENT	/V01-01/

	.LIBRARY "PMEDEFS.MLB"

	PMEDEFS				; Define all Bucket File tags

	.PSECT	PME_CODE,EXE,NOWRT,LONG,PIC


; ******************** PME_COUNTER: THE CALL LINKAGE ************************
;
;
; This subroutine is called as follows (from Fortran):
;
;			CALL PME_COUNTER(PCVAL)
;
; where PCVAL is the Program Counter value to be tallied.
;
	.ENTRY	PME_COUNTER,^M<R2>	; CALL entry point

	MOVL	@4(AP),R0		; R0 = the Program Counter value
	JSB	PME_COUNT		; Tally it in the proper bucket
	RET				; Return


; ******************** PME_COUNT: TALLY THE PC VALUE ************************
;
;
; This subroutine accepts a Program Counter value in register R0 and increments
; the corresponding Bucket Record counter by one.  The routine is called with a
; JSB linkage and destroys registers R1 and R2.
;
;
; Determine whether the PC value is in the address range of the current Bucket
; Group, and if so, index into the corresponding index table to get at the
; proper Bucket Record.
;
PME_COUNT::				; Bucket counting routine entry point
	MOVL	PME_GRPADDR,R2		; R2 = addr of first Bucket Group Record
10$:	CMPL	R0,GRPLOWBND(R2)	; Is the PC address in R0 in the address
	BLSSU	40$			;      range of this Bucket Group?  If
	CMPL	R0,GRPHIBND(R2)		;      not, go to 40$.
	BGTRU	40$			;
	SUBL3	GRPLOWBND(R2),R0,R1	; Compute index table pointer in R1
	DIVL2	BUCKETSIZE(R2),R1	;
	ADDL3	@ABSTBLPTR(R2)[R1],PME_BASE,R1	; R1 = pointer to the first
					;	    Bucket Record on chain


; If the PC value is in the address range of this bucket, increment the count
; and return.
;
20$:	CMPL	R0,BKTLOWBND(R1)	; Is the PC address in R0 in the address
	BLSSU	30$			;      range of this Bucket Record?  If
	CMPL	R0,BKTHIBND(R1)		;      not, go to 30$
	BGTRU	30$			;
	INCL	COUNT(R1)		; Yes, in range--increment the count
	RSB				; Return to the caller


; The PC value is not in this bucket--link to the next Bucket Record on the
; chain and try it.
;
30$:	TSTL	FLINK(R1)		; Is there a next bucket to link to?
	BEQL	40$			; If not (end of chain), go to 40$
	ADDL3	FLINK(R1),PME_BASE,R1	; There is--link to that Bucket Record
	BRB	20$			;      and take a look at it


; The PC address is not in the current bucket group--go on to the next bucket
; group and try it.  If there are no more Bucket Group Records, increment the
; default counter and return to the caller.
;
40$:	ADDL2	#GRPRECSIZ,R2		; Advance R2 to the next Bucket Group Record
	TSTL	BUCKETSIZE(R2)		; Is the bucketsize zero for this group?
	BNEQ	10$			; If not, it's a valid group record
					; If yes, no more Bucket Group Records
	INCL	@PME_DEFCNTR		; Increment the default counter
	RSB				; Return

	.END
