28942c8d2aaef9c3411f016b9891c28419f436f9
[uebersetzerbau-ss10.git] / asmb / asmb.s
1         .file   "asmb.c"
2         .data
3         .align 16
4 const65:
5         .rept 16
6         .byte 0x65
7         .endr
8 const20:
9         .rept 16
10         .byte 0x20
11         .endr
12 constc0:
13         .rept 16
14         .byte 0xc0
15         .endr
16
17         .text
18 .globl asmb
19         .type   asmb, @function
20 asmb:
21 .LFB2:
22         xor %rdx, %rdx
23
24         //soll einfach null sein
25         pxor %xmm14, %xmm14
26
27 .nextround:
28         //speicheradresse des pointers zeigt auf 16*8 feld = 128bit
29         movdqu (%rdi, %rdx, 8), %xmm11
30
31         // -64 - c
32         movdqa constc0, %xmm9
33         psubb %xmm11, %xmm9
34
35         // Packed COMpare Greater Than (Byte)"
36         // achtung beim intuitiven lesen des befehles. 'kleiner'
37         // ist mit 'groesser' vertauscht und vice versa
38         pcmpgtb const65, %xmm9
39
40 .differenz:
41         // Y = min(X, 'a' - 'A')
42         pminub const20, %xmm9
43
44         // c += Y
45         paddb %xmm9, %xmm11
46
47         // retuniere an die richtige speicheradresse
48         movdqu %xmm11, (%rdi, %rdx, 8)
49
50         //entspricht ein byte dem nullbyte dann steht an jener stelle 0xff sonst 0x00
51         pcmpeqb %xmm14, %xmm11
52         //hol die MSBs aller bytes raus
53         pmovmskb %xmm11, %ecx
54         add $2, %rdx
55
56         //ist %ecx gleich null? dann die naechsten 16byte bitte
57         jecxz .nextround
58
59         //speicheradresse des parameters zurueckgeben (wird noch modifziert)
60         mov %rdi, %rax
61
62         //===============
63         //ab hier uebler hax um nach \0 trotzdem die gleichen bytes wie
64         //input zu haben, also um selbiges verhalten wie asmb_ref zu erzwingen
65
66         //\0 byte stelle durch rausfinden des MSB des %ecx
67         bsf %ecx, %r11d
68
69         //das ergebnis zweimal abspeichern
70         mov %r11d, %ecx
71
72         //hint: in %xmm9 ist differenz gespeichert (vgl .differenz)
73
74         //leider shiften nur mit immediate! :(
75         btr $3, %r11d
76         jnc .rechtsshift1
77         psrldq $8, %xmm9
78
79 .rechtsshift1:
80         btr $2, %r11d
81         jnc .rechtsshift2
82         psrldq $4, %xmm9
83
84 .rechtsshift2:
85         btr $1, %r11d
86         jnc .rechtsshift3
87         psrldq $2, %xmm9
88
89 .rechtsshift3:
90         btr $0, %r11d
91         jnc .linksshift
92         psrldq $1, %xmm9
93 #==================
94 .linksshift:
95         btr $3, %ecx
96         jnc .linksshift1
97         pslldq $8, %xmm9
98
99 .linksshift1:
100         btr $2, %ecx
101         jnc .linksshift2
102         pslldq $4, %xmm9
103
104 .linksshift2:
105         btr $1, %ecx
106         jnc .linksshift3
107         pslldq $2, %xmm9
108
109 .linksshift3:
110         btr $0, %ecx
111         jnc .endshift
112         pslldq $1, %xmm9
113
114 .endshift:
115         //betreffende speicherstelle in %xmm11 laden
116         movdqu -16(%rax, %rdx, 8), %xmm11
117         //und overhead wieder subtrahieren
118         psubb %xmm9, %xmm11
119
120         //ergebnis zurueckspielen und fertig \o/
121         movdqu %xmm11, -16(%rax, %rdx, 8)
122
123         ret
124 .LFE2:
125         .size   asmb, .-asmb
126         .section        .eh_frame,"a",@progbits
127 .Lframe1:
128         .long   .LECIE1-.LSCIE1
129 .LSCIE1:
130         .long   0x0
131         .byte   0x1
132         .string "zR"
133         .uleb128 0x1
134         .sleb128 -8
135         .byte   0x10
136         .uleb128 0x1
137         .byte   0x3
138         .byte   0xc
139         .uleb128 0x7
140         .uleb128 0x8
141         .byte   0x90
142         .uleb128 0x1
143         .align 8
144 .LECIE1:
145 .LSFDE1:
146         .long   .LEFDE1-.LASFDE1
147 .LASFDE1:
148         .long   .LASFDE1-.Lframe1
149         .long   .LFB2
150         .long   .LFE2-.LFB2
151         .uleb128 0x0
152         .align 8
153 .LEFDE1:
154         .ident  "GCC: (Debian 4.3.2-1.1) 4.3.2"
155         .section        .note.GNU-stack,"",@progbits