1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2013 The NASM Authors - All Rights Reserved
4 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * ----------------------------------------------------------------------- */
35 * disp8.c : Contains a common logic for EVEX compressed displacement
41 * Find N value for compressed displacement (disp8 * N)
43 uint8_t get_disp8N(insn
*ins
)
45 static const uint8_t fv_n
[2][2][VLMAX
] = {{{16, 32, 64}, {4, 4, 4}},
46 {{16, 32, 64}, {8, 8, 8}}};
47 static const uint8_t hv_n
[2][VLMAX
] = {{8, 16, 32}, {4, 4, 4}};
48 static const uint8_t dup_n
[VLMAX
] = {8, 32, 64};
50 bool evex_b
= (ins
->evex_p
[2] & EVEX_P2B
) >> 4;
51 enum ttypes tuple
= ins
->evex_tuple
;
52 enum vectlens vectlen
= (ins
->evex_p
[2] & EVEX_P2LL
) >> 5;
53 bool evex_w
= (ins
->evex_p
[1] & EVEX_P1W
) >> 7;
58 n
= fv_n
[evex_w
][evex_b
][vectlen
];
61 n
= hv_n
[evex_b
][vectlen
];
65 /* 16, 32, 64 for VL 128, 256, 512 respectively*/
66 n
= 1 << (vectlen
+ 4);
68 case T1S8
: /* N = 1 */
69 case T1S16
: /* N = 2 */
73 /* N = 4 for 32bit, 8 for 64bit */
78 /* N = 4 for 32bit, 8 for 64bit */
79 n
= (tuple
== T1F32
? 4 : 8);
84 if (vectlen
+ 7 <= (evex_w
+ 5) + (tuple
- T2
+ 1))
87 n
= 1 << (tuple
- T2
+ evex_w
+ 3);
92 n
= 1 << (OVM
- tuple
+ vectlen
+ 1);
109 * Check if offset is a multiple of N with corresponding tuple type
110 * if Disp8*N is available, compressed displacement is stored in compdisp
112 bool is_disp8n(operand
*input
, insn
*ins
, int8_t *compdisp
)
114 int32_t off
= input
->offset
;
120 if (n
&& !(off
& (n
- 1))) {
122 /* if it fits in Disp8 */
123 if (disp8
>= -128 && disp8
<= 127) {