Re: [coldfire-gnu-discuss] trapf opcode
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [coldfire-gnu-discuss] trapf opcode



Nathan Sidwell wrote:
Paul McConkey wrote:

So the assembler supports trapf, which is fine, but are you likely to
support the CF syntax below in future? If so, will you deprecate or
remove the support for trapf?
CFPRM rev.3 p 4-83 Assembler syntax: TPF PC + 2 -> PC
                     TPF.W    PC + 4 -> PC
                     TPF.L    PC + 6 -> PC

oh joy. trapf is the cpu32 instruction name, coldfire appears to have selected a different name for the same encoding.

We won't remove trapf, but will probably accept 'tpf' as an alternative.

nathan


The TRAPcc instruction in the cpu32 was a bit more general, and could trap to vector 7 on a given condition code (the same as for branches). The Coldfire does not really implement these instructions (vector 7 is "reserved"). However, TRAPF, which never actually traps, is still there as it is useful as a sort of "skip next instruction" instruction. I guess they renamed it to stop people expecting TRAPZ and all the other TRAPcc instructions.

The ColdFire manual gives an idea of how the TPF.W and TPF.L instructions can be as "bra.b +2" and "bra.b +4" alternatives, taking 1 clock cycle instead of 2. This could perhaps be implemented as a peephole optimisation after initial code generation. Of course, it would work better if gcc generated better code for something like:

extern unsigned long int a, b, z;
void test(void) {
	if (a == b) {
		z = 3;
	} else {
		z = 1;
	};
}

Today it generates:

  37               	test:
  38 0000 4E56 0000 		link.w %fp,#0
  39 0004 2039 0000 		move.l b,%d0	| b,
  39      0000
  40 000a B0B9 0000 		cmp.l a.l,%d0	| a,
  40      0000
  41 0010 670A      		jbeq .L7	|
  42 0012 7001      		moveq #1,%d0	|,
  43 0014 23C0 0000 		move.l %d0,z	|, z
  43      0000
  44 001a 6008      		jbra .L5	|
  45               	.L7:
  46 001c 7003      		moveq #3,%d0	|,
  47 001e 23C0 0000 		move.l %d0,z	|, z
  47      0000
  48               	.L5:
  49 0024 4E5E      		unlk %fp
  50 0026 4E75      		rts


If that were optimised to shorter code with the duplicate "move.l %d, z" moved to after .L5:

test:
	link.w %fp, #0
	move.l b, %d0
	cmp.l a.l, %d0
	jbeq .L7
	moveq #1, %d0
	jbra .L5
.L7:
	moveq #3, %d0
.L5:
	move.l %d0, z
	unlk %fp
	rts


Then the TPF.W instruction could be used instead of the jbra instruction, saving a clock cycle. On the more advanced Coldfire cores with more pipelining, the TPF instruction may save even more than a branch.

mvh.,

David