Shop OBEX P1 Docs P2 Docs Learn Events
Prop2 FPGA files!!! - Updated 2 June 2018 - Final Version 32i - Page 60 — Parallax Forums

Prop2 FPGA files!!! - Updated 2 June 2018 - Final Version 32i

15758606263160

Comments

  • ozpropdev wrote: »
    David Betz wrote: »
    Cluso99 wrote: »
    Has anyone used ALTI/ALTR/ALTD/ALTS or seen a recent writeup of these instructions?
    I think the ALTx instructions will likely be generated automatically by compilers or assemblers and not be coded directly.
    Do you mean AUGS & AUGD?

    Oops, just kidding about ALTx. Sorry. I guess I don't know what those do. As you guessed, I had them confused with AUGx.

  • RaymanRayman Posts: 14,652
    The SETx instructions make self-modifying code a lot easier...
  • Rayman wrote: »
    The SETx instructions make self-modifying code a lot easier...
    And here I'd been hoping we would get away from self-modifying code with P2. :-(

  • evanhevanh Posts: 15,920
    I would expect compilers to make regular use of the ALTx instructions. Although, my one attempt to get my head around them resulted in confusion about their capabilities, so I'm no expert.
  • I've found ALTx very useful as a simple way to implement a poor man's "conditional compile".
    It works nicely as a indirect register mechanism too. :)
  • Cluso99Cluso99 Posts: 18,069
    Thanks Brian.
    ALTS now working with hubexec :)
  • David Betz wrote: »
    Rayman wrote: »
    The SETx instructions make self-modifying code a lot easier...
    And here I'd been hoping we would get away from self-modifying code with P2. :-(
    Someone complained about this comment. However, aren't the SETx instructions redundant now that we have the ALTx instructions?

  • RaymanRayman Posts: 14,652
    I was using the SETx instructions to configure an assembly subroutine before calling it.

    Don't think you can do that with ALTx...
  • SETx changes the value in cog memory. ALTx changes the value in the instruction pipeline. So they are slightly different.
  • Dave Hein wrote: »
    SETx changes the value in cog memory. ALTx changes the value in the instruction pipeline. So they are slightly different.
    Yes, I understand that. I think the ALTx instructions were added when it was realized that you couldn't use SETx in hubexec mode. However, it seems like ALTx could handle everything that SETx could in a slightly different way. I guess I've always been nervous about self-modifying code and I'm glad ALTx provides a way to avoid that if you choose.

  • Rayman wrote: »
    I was using the SETx instructions to configure an assembly subroutine before calling it.

    Don't think you can do that with ALTx...
    Interesting. I suppose that is a rather unusual way to pass parameters to a non-recursive subroutine. It would have to be in COG memory though, right? Or will SETx work to hub memory if you use AUGD to provide a full hub address?

  • RaymanRayman Posts: 14,652
    Now that I think about it, I suppose I could have used some registers for the parameters and then used ALTx instructions inside the routine to set them.

    But, I think the SETx is more direct and maybe saves register space...
  • Rayman wrote: »
    Now that I think about it, I suppose I could have used some registers for the parameters and then used ALTx instructions inside the routine to set them.

    But, I think the SETx is more direct and maybe saves register space...
    ALTx has to be used every time you execute the "modified" instruction so I guess SETx would generate faster code if the modified instruction was in a loop.

  • RaymanRayman Posts: 14,652
    BTW: I think one or two instructions have to be after your SETx and when you use it. ALTx doesn't have that restriction...
  • SETx requires 2 spacer instructions.
  • kwinnkwinn Posts: 8,697
    David Betz wrote: »
    Rayman wrote: »
    The SETx instructions make self-modifying code a lot easier...
    And here I'd been hoping we would get away from self-modifying code with P2. :-(

    And I am hoping for the opposite. On rare occasions self modifying code makes things so much easier.
  • kwinn wrote: »
    David Betz wrote: »
    Rayman wrote: »
    The SETx instructions make self-modifying code a lot easier...
    And here I'd been hoping we would get away from self-modifying code with P2. :-(

    And I am hoping for the opposite. On rare occasions self modifying code makes things so much easier.
    I'm sure you'll get your wish. :-)

  • Cluso99Cluso99 Posts: 18,069
    FWFW SETS/SETD/SETI only requires 2 spacer instructions if they modify a following instruction.

    Note if you are only using SETS/SETD/SETI to set/modify a register, then spacer instructions are not required.
  • Cluso99Cluso99 Posts: 18,069
    Another amazing instruction(s)...
                    alts	lmm_w, ##_TABLE_CCCC		'\ set next S to offset+table addrs
                    mov	lmm_p, #0-0			'/
    
    Of course this expands into AUGS + ALTS + MOV instructions by the compiler.

    BTW Don't forget the "#" in the mov xxxx,#0 instruction!!!
  • Cluso99Cluso99 Posts: 18,069
    Does anyone know the format for forcing relative or direct addressing for JMP/CALL/CALLA/CALLB ?
    eg JMP #@$1000 ?
  • Cluso99 wrote: »
    Does anyone know the format for forcing relative or direct addressing for JMP/CALL/CALLA/CALLB ?
    eg JMP #@$1000 ?

    Pnut default is relative.
    Use #\ to force absolute address.
  • cgraceycgracey Posts: 14,155
    Cluso99 wrote: »
    Another amazing instruction(s)...
                    alts	lmm_w, ##_TABLE_CCCC		'\ set next S to offset+table addrs
                    mov	lmm_p, #0-0			'/
    
    Of course this expands into AUGS + ALTS + MOV instructions by the compiler.

    BTW Don't forget the "#" in the mov xxxx,#0 instruction!!!

    I've added a section to the documentation about this. ALTR/ALTD/ALTS are useful for indirect cog register reading, not hub reading. I'm going to complete that section now.
  • cgraceycgracey Posts: 14,155
    There's a new section in the documentation called "REGISTER INDIRECTION" that covers the ALTI/ALTR/ALTD/ALTS and SETI/SETD/SETS instructions. It took me a bit to relearn everything ALTI does.

    The ALTx instructions pretty much antiquate the need for self-modifying code.

    The SETI/SETD/SETS instructions can be used for self-modifying code, but are really useful for setting up ALTI behavior.
  • cgraceycgracey Posts: 14,155
    edited 2016-07-09 11:48
    I think I've got the SHA-256/HMAC rewritten from Prop2-Hot, so that the boot ROM can do signed loader verification.

    There was one snippet of code that translated in kind of a surprising way:
    		setd	i,#w			'save opad key
    		setr	i,#opad_key
    		rep	@.r,#16
    		alti	i,#%111_111_000
    		xor	0,opad			'xor bytes with opad ($5C)
    

    This picks up 16 longs in cog RAM, starting at 'w', XOR's them with 'opad' ($5C5C5C5C), then writes them starting at 'opad_key'. It uses the ALTI instruction to indirect and increment pointers for both the D register ('w') and result register ('opad key').
  • cgracey wrote: »
    I think I've got the SHA-256/HMAC rewritten from Prop2-Hot, so that the boot ROM can do signed loader verification.

    There was one snippet of code that translated in kind of a surprising way:
    		setd	i,#w			'save opad key
    		setr	i,#opad_key
    		rep	@.r,#16
    		alti	i,#%111_111_000
    		xor	0,opad			'xor bytes with opad ($5C)
    

    This picks up 16 longs in cog RAM, starting at 'w', XOR's them with 'opad' ($5C5C5C5C), then writes them starting at 'opad_key'. It uses the ALTI instruction to indirect and increment pointers for both the D register ('w') and result register ('opad key').

    Your documentation states SETI, not SETR. Personally, I think SETR is more appropriate.
  • evanhevanh Posts: 15,920
    True, "Instruction" technically is the entire long-word.
  • R = result
    S = source
    D = destination
    I = instruction
  • evanhevanh Posts: 15,920
    edited 2016-07-09 14:44
    Hmm, so, R is obviously not correct either. SETO, for opcode, then? That clearly separates it from ALTI too then, which is a good thing IMHO.
  • SETR is a new instruction not supported by Pnut yet.
  • evanhevanh Posts: 15,920
    edited 2016-07-09 14:57
    In addition to SETI?

    SETR can't affect the result register like ALTR does. It can only fiddle bit fields of stored RAM.
Sign In or Register to comment.