/* personal notes of renzo diomedi */

~ 00001010 ~




CONVERSIONS





in brackets are the destination register in which the result can be placed, MMX or XMM
the last four instructions are truncated conversions. rounding toward zero is automatically performed.
In the other instructions, if the conversion is inexact, the rounding is controlled by bits 13 and 14 in the XMM MXCSR register. These bits determine whether the values are rounded up or down.

The source values can be obtained from either Memory locations, or MMX registers (for 64-bit values), or XMM registers (for 64- and 128-bit values).




// convers.s
// at&t mingw-w64 in windows os

.section .data
value1:
.float 1.25, 124.79, 200.0, -312.5
value2:
.int 1, -435, 0, -25
.section .bss
.lcomm data, 16
.section .text
// .globl _start # necessary in Linux GAS
// _start: # necessary in Linux GAS
nop
cvtps2dq value1, %xmm0
cvttps2dq value1, %xmm1
cvtdq2ps value2, %xmm2
movdqu %xmm0, data


/*
MOVDQA and MOVDQU instructions are used to move 128 bits of data into the XMM registers, or to move data between XMM registers.
The A and U parts of the mnemonic stand for aligned and unaligned, referring to how the data is stored in memory.
The format of both the MOVDQA and MOVDQU instruction is
movdqa source, destination
*/


movl $1, %eax
movl $0, %ebx
// int $0x80 # Linux
int $0x21







convers.s ; convers.o ; convers.exe # windows environment >







(gdb) s
12 cvtps2dq value1, %xmm0
(gdb) s
13 cvttps2dq value1, %xmm1
(gdb) s
14 cvtdq2ps value2, %xmm2
(gdb) s
15 movdqu %xmm0, data
(gdb) print $xmm0
$1 = {v4_float = {1.40129846e-45, 1.75162308e-43, 2.80259693e-43, -nan(0x7ffec8)}, v2_double = {2.6524947387115311e-312, -nan(0xffec8000000c8)}, v16_int8 = {1, 0, 0, 0, 125, 0, 0, 0, -56, 0, 0, 0, -56, -2, -1, -1}, v8_int16 = {1, 0, 125, 0, 200, 0, -312, -1}, v4_int32 = {1, 125, 200, -312}, v2_int64 = {536870912001, -1340029796152}, uint128 = 340282342201751762702250093524836941825}
(gdb) print $xmm1
$2 = {v4_float = {1.40129846e-45, 1.7376101e-43, 2.80259693e-43, -nan(0x7ffec8)}, v2_double = {2.6312747808018783e-312, -nan(0xffec8000000c8)}, v16_int8 = {1, 0, 0, 0, 124, 0, 0, 0, -56, 0, 0, 0, -56, -2, -1, -1}, v8_int16 = {1, 0, 124, 0, 200, 0, -312, -1}, v4_int32 = {1, 124, 200, -312}, v2_int64 = {532575944705, -1340029796152}, uint128 = 340282342201751762702250093520541974529}
(gdb) print $xmm2
$3 = {v4_float = {1, -435, 0, -25}, v2_double = {-7.3498756827903427e+18, -805306368}, v16_int8 = {0, 0, -128, 63, 0, -128, -39, -61, 0, 0, 0, 0, 0, 0, -56, -63}, v8_int16 = {0, 16256, -32768, -15399, 0, 0, 0, -15928}, v4_int32 = {1065353216, -1009156096, 0, -1043857408}, v2_int64 = {-4334292427813683200, -4483333429047328768}, uint128 = 257579462558195729010253313545846390784}
(gdb)

16 movl $1, %eax
(gdb) x/4d &data
0x403000 : 1 125 200 -312
(gdb)


Home Page