More detail about new AVR instructions LAC, LAS, LAT and XCH
Asked Answered
P

2

11

Looking at the AVR instruction set there are four instructions added in 2010

LAC load and clear
LAS load and set
LAT load and toggle
XCH load and exchange
  1. Does anyone know what chips have these instructions

  2. What tools support these instructions

  3. More information on what they do

    (Z) <- Rd v (Z), Rd <- (Z)

does that imply that Rd and (Z) get the same value or does Rd get the pre-modified value of what was pointed to by Z?

Paigepaik answered 17/1, 2012 at 20:27 Comment(6)
It does eXCHange Rd and the value pointed to by Z, obviously.Kong
Some forums suggest they're probably avaliable on the XMEGA series of AVR microcontrollers only.Kong
not obvious yet, the xmega docs do not show the instruction in the list. the most recent had its last update before the instruction set manual had these added.Paigepaik
XCH is obvious the other three LAx are not necessarily. Unlike other instructions these dont have much information, appear to have been inserted in a quick, "dont forget to document these" kind of way rather than taking the time to make them complete and consistent with the rest of the manual.Paigepaik
Hm.. someone should test them on the real hardware so we know what they do.Kong
I have this xmega sparkfun.com/products/9546 and it took a bit to rig up a pdi programmer but I have that going and it appears as if this xmega does not support these instructions. I tried las, lac and xch and neither the Z register, the location pointed to by Z nor the rd register in the instruction are modified. It doesnt hang or otherwise get upset about an undefined instruction it seems to just be flywheeling though it like a nop.Paigepaik
I
4

These are probably not around in current (as of initial question) chips, but all have a common theme - atomic memory operations. Their purpose is typically for synchronisation between threads, and their inclusion at an instruction set level probably indicates that Atmel are planning to launch a multi-core AVR chip. Since they're specified now tool vendors can add them to assemblers already, but they won't make a big deal of that until chips have the instructions. (Edit: As it turns out, the other core is the USB peripheral, not a CPU. Thanks to avakar for that information.)

The behaviour, as I read it from the Atmel AVR 8-bit Instruction Set Manual:

LAC - Load and Clear, loads memory contents *Z into register Rd while simultaneously clearing bits in *Z that were set in Rd.

LAS - Load And Set simultaneously sets bits in a memory location that were set in a register, and loads the register with the prior contents of the memory location. Very useful for single-bit mutexes, for instance.

LAT - Load And Toggle; like LAS, but instead of bitwise or, it uses bitwise xor, thus toggling bits.

XCH - Exchange; simply exchanges memory and register contents.

All of them are RAM access instructions (07/2014 reference states they take two cycles), which combine operations so they could also make code that needs RAM faster than it currently is.

Inaugural answered 25/1, 2012 at 14:6 Comment(6)
these avr docs I have been combing through lately, both for my instruction set simulator and for programming the xmega via pdi, are loaded with typos and other mistakes. I assume the lac is missing ",Rd <- (Z)" at the end of the definition. It became a curiosity when I was making an instruction set simulator.Paigepaik
multi-core AVR? That would be super-awesome.Kong
I'm afraid the instructions were not added for another CPU core, but rather for the USB peripheral, which uses SRAM to store endpoint control/status registers. The instructions are missing in the early A and D models, but are present in AU and newer ones.Outmaneuver
Even ignoring true multi-thread, these instructions are also useful to avoid races with interrupt handlers. Often you end up doing something like CLI; MOV; CBI/SBI; STI when now you could avoid that and use a single LAC or LAS instruction.Sunil
Do you have a link to the instruction reference that documents these instructions?Softhearted
Link added in answer.Inaugural
Z
0

Small but important detail to emphasize: the LAS, LAC and LAT instructions work when Z points to "real" SRAM only. That is not (memory mapped) registers etc. So, in fact, these are useful either for your own (OS) data or XMega USB module, no other peripherals and modules.

It is a pity (as it would be really handy for manipulating PMIC.CTRL flags for example), but it really does not work. Tested. It looks like that LAS, LAC and LAT has the same effect as XCH (exchange between Rd and (Z) but no bit twiddling) when applied on memory mapped registers.

Zacatecas answered 20/1, 2017 at 20:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.