Skip to content

Commit 1703f2d

Browse files
committed
Add builtin rules
1 parent bbfc459 commit 1703f2d

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

rules/builtin/ir_unsafe.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,69 @@
170170
"return_type": {
171171
"type": "u64"
172172
}
173+
},
174+
"f7": {
175+
"body": [
176+
{
177+
"method_call": {
178+
"receiver": [
179+
{
180+
"placeholder": {
181+
"arg": 0,
182+
"access": "read"
183+
}
184+
}
185+
],
186+
"body": [
187+
{
188+
"text": ".trailing_zeros()"
189+
}
190+
]
191+
}
192+
},
193+
{
194+
"text": " as i32"
195+
}
196+
],
197+
"params": {
198+
"a0": {
199+
"type": "u64"
200+
}
201+
},
202+
"return_type": {
203+
"type": "i32"
204+
}
205+
},
206+
"f8": {
207+
"body": [
208+
{
209+
"method_call": {
210+
"receiver": [
211+
{
212+
"placeholder": {
213+
"arg": 0,
214+
"access": "read"
215+
}
216+
}
217+
],
218+
"body": [
219+
{
220+
"text": ".count_ones()"
221+
}
222+
]
223+
}
224+
},
225+
{
226+
"text": " as i32"
227+
}
228+
],
229+
"params": {
230+
"a0": {
231+
"type": "u64"
232+
}
233+
},
234+
"return_type": {
235+
"type": "i32"
236+
}
173237
}
174238
}

rules/builtin/src.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ unsigned short f4(unsigned short x) { return __builtin_bswap16(x); }
1919
unsigned int f5(unsigned int x) { return __builtin_bswap32(x); }
2020
unsigned long long f6(unsigned long long x) { return __builtin_bswap64(x); }
2121
#endif
22+
int f7(unsigned long x) { return __builtin_ctzl(x); }
23+
int f8(unsigned long x) { return __builtin_popcountl(x); }

rules/builtin/tgt_unsafe.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ unsafe fn f5(a0: u32) -> u32 {
1919
unsafe fn f6(a0: u64) -> u64 {
2020
a0.swap_bytes()
2121
}
22+
unsafe fn f7(a0: u64) -> i32 {
23+
a0.trailing_zeros() as i32
24+
}
25+
unsafe fn f8(a0: u64) -> i32 {
26+
a0.count_ones() as i32
27+
}

0 commit comments

Comments
 (0)