Skip to content

Commit

Permalink
Merge branch 'junghee/multiple-alignments' into 'main'
Browse files Browse the repository at this point in the history
Pick the max alignment when there are multiple alignments for an EA

Closes #607

See merge request rewriting/ddisasm!1208
  • Loading branch information
aeflores committed Jun 12, 2024
2 parents 9241d9c + 797b429 commit a2e0a6b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
4 changes: 3 additions & 1 deletion examples/asm_examples/ex_aligned_data_in_code/ex_original.s
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ main:
lea data128.2(%rip), %rax
movdqa 0(%rax), %xmm1

# Load data into YMM register using movdqa: `data256` needs to be aligned.
# Load data into XMM and YMM using vmovapd: `data256` needs to be 32-bit
# aligned (YMM) instead of being 16-bit aligned (XMM).
vmovapd data256(%rip), %xmm0
vmovapd data256(%rip), %ymm0

# Load data into YMM register using vmovups: `data256u` does not need to be aligned.
Expand Down
20 changes: 14 additions & 6 deletions src/datalog/main.dl
Original file line number Diff line number Diff line change
Expand Up @@ -689,16 +689,14 @@ halt(EA):-
instruction_get_operation(EA,Operation).

/**
Information about alignment in bits for a given address
Auxiliary predicate that builds initial alignments from `alignment_required`:
the max alignment is picked for an EA later.
*/
.decl alignment(EA:address,AlignInBits:unsigned)
.output alignment

alignment(0,0):- false.
.decl alignment_candidate(EA:address,AlignInBits:unsigned)

// Data in code needs to be aligned when referenced by instruction that
// requires aligned memory: e.g., some SIMD instructions
alignment(DataEA, AlignInBits):-
alignment_candidate(DataEA, AlignInBits):-
arch.alignment_required(EA,AlignInBits),
(
pc_relative_operand(EA,_,DataEA);
Expand All @@ -708,6 +706,16 @@ alignment(DataEA, AlignInBits):-
DataEA >= Begin,
DataEA < End.

/**
Information about alignment in bits for a given address
*/
.decl alignment(EA:address,AlignInBits:unsigned)
.output alignment

alignment(DataEA, AlignInBits):-
alignment_candidate(DataEA, AlignInBits),
AlignInBits = max X: {alignment_candidate(DataEA, X)}.

//////////////////////////////////////////////////////////////////////////////////
// Operations to abstract features of instructions

Expand Down

0 comments on commit a2e0a6b

Please sign in to comment.