Hi,

I have a problem with defining the behaviour of data alignment, and aligning the corresponding labels, in my run-time assembler SoftWire. An example will make the problem clear immediately:

label L1:
dd 01234567h

SoftWire has always had the 'feature' that all data is aligned to its natural boundary. So the above code is internally translated and equivalent to:

label L1:
align 4
dd 01234567h

The problem is of course that the alignment most likely will insert nop instructions, so L1 doesn't point to the constant 01234567h any more.

Now, I have two ways to solve this 'automatically', and one way to give control to the user.

The straightforward solution is to not align data automatically. Aside from backward compatibility issues, I find this highly inefficient. If we look at SoftWire as a code generator (especially when using the run-time intrinsics feature) and not just an assembler, I believe data alignment is fundamental. Although I might add an option to turn automatic data alignment off, I don't feel this is the right approach.

The second solution would be to detect when a label is followed by a data definition, and make it aligned to that data. Unfortunately there are several issues with this as well. For example 'data' might actually be code, and there is no real distinction between code labels and data labels. It can even be both! So nop instructions can be placed where it is not desired. Although these cases are rare, I don't want to blindly assume they don't occur.

The last solution, which I currently prefer, is to leave all control in the hands of the user (the way it is now). That is, one should align the label himself if so desired, like this:

align 4
label L1:
dd 01234567h

Note that this is exactly what the second solution would do, only not automatically now. It might look cumbersome to require alignment for every data label, but SoftWire has macro facilities to put the align and label in one. When using run-time intrinsics it's even possible to just overload the label intrinsic to make it align automatically. You might also argue that it is sometimes required to leave data unaligned, but this is also easily possible by using 4 db's instead of one dd. With a macro or intrinsic it can again be made very convenient. Either way, The user can have total control and I'd like to keep it that way, although I find it just as self-evident that data aligns itself, regarding SoftWire as a code generator...

So, it's clear that neither of these solutions is totally perfect. I'd just like to hear your opinions on this issue to decide what to do or not to do.

Thanks!

c0d1f1ed
Posted on 2004-01-19 05:49:08 by C0D1F1ED
I'd say make auto-align a toggleable option in softwire - perhaps off by default. Also, be able to set default alignment (a value of -1 could be used for "native data size alignment"). And of course have the "align xx" stuff done before labels when doing auto-align.
Posted on 2004-01-19 06:36:47 by f0dder
When I want alignment in MASM code I use:

ALIGN 4
NewData DWORD 4000

So I don't really see why issuing an alignment before a label definition would be counterintuitive.

I can see a newbie compiler writer issuing a label before getting enough information to align it properly. But that's a hazard of single-pass compilation.
Posted on 2004-01-19 23:28:22 by tenkey
So, basically what you're saying is to not align data automatically and let the user decide?

Well it's certainly an easy way out. :grin: Would it be possible to deprecate the automatic alignment without really warning my user base? The worst thing that I can imagine could happen is a bit of performance loss, are there others?

Thanks for your opinions! :alright:
Posted on 2004-01-20 05:00:37 by C0D1F1ED

So, basically what you're saying is to not align data automatically and let the user decide?

No - not what I'm saying anyway. Have auto-align toggleable in softwire, by a method call. Then at runtime, you can choose whether to auto-align or not.
Posted on 2004-01-20 08:26:02 by f0dder
Alignment of data and alignment of labels are two separate issues.

On assemblers I have used that performed automatic alignment, the label had to be attached to the data definition code:

   DC.B  12

UnattachedLabel: ; No alignment of label
DC.W 1234 ; Data is aligned

DC.B 34
AttachedLabel DC.W 3456 ; Both label and data are aligned
Posted on 2004-01-20 16:48:17 by tenkey
Listen to f0dder, everyone else just shut up mmkay?
Posted on 2004-01-20 18:05:27 by Jan
Ok, I've decided to deprecate automatic alignment, at least as the default option. A tiny bit of performance loss for people who use a lot of static data without manual alignment seems very acceptable to me now. Later I can always add some alignment techniques again, which are transparant to the user.

Thanks a lot guys, especially f0dder!
Posted on 2004-01-21 16:43:41 by C0D1F1ED