2019-11-25 23:46:17 +00:00
|
|
|
const std = @import("std");
|
|
|
|
const expect = std.testing.expect;
|
2019-01-30 02:47:26 +00:00
|
|
|
|
2020-02-25 06:52:27 +00:00
|
|
|
const is_x86_64_linux = std.Target.current.cpu.arch == .x86_64 and std.Target.current.os.tag == .linux;
|
|
|
|
|
2019-01-30 02:47:26 +00:00
|
|
|
comptime {
|
2020-02-25 06:52:27 +00:00
|
|
|
if (is_x86_64_linux) {
|
2019-03-20 23:00:23 +00:00
|
|
|
asm (
|
2019-02-28 20:40:57 +00:00
|
|
|
\\.globl this_is_my_alias;
|
|
|
|
\\.type this_is_my_alias, @function;
|
|
|
|
\\.set this_is_my_alias, derp;
|
2019-01-30 02:47:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
test "module level assembly" {
|
2020-02-25 06:52:27 +00:00
|
|
|
if (is_x86_64_linux) {
|
2021-05-04 19:23:22 +01:00
|
|
|
try expect(this_is_my_alias() == 1234);
|
2019-01-30 02:47:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
test "output constraint modifiers" {
|
|
|
|
// This is only testing compilation.
|
|
|
|
var a: u32 = 3;
|
|
|
|
asm volatile (""
|
2021-08-29 10:57:32 +01:00
|
|
|
: [_] "=m,r" (a),
|
2019-01-30 02:47:26 +00:00
|
|
|
:
|
|
|
|
: ""
|
|
|
|
);
|
|
|
|
asm volatile (""
|
2021-08-29 10:57:32 +01:00
|
|
|
: [_] "=r,m" (a),
|
2019-01-30 02:47:26 +00:00
|
|
|
:
|
|
|
|
: ""
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
test "alternative constraints" {
|
|
|
|
// Make sure we allow commas as a separator for alternative constraints.
|
|
|
|
var a: u32 = 3;
|
|
|
|
asm volatile (""
|
2021-08-29 10:57:32 +01:00
|
|
|
: [_] "=r,m" (a),
|
|
|
|
: [_] "r,m" (a),
|
2019-01-30 02:47:26 +00:00
|
|
|
: ""
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
test "sized integer/float in asm input" {
|
|
|
|
asm volatile (""
|
|
|
|
:
|
2021-08-29 10:57:32 +01:00
|
|
|
: [_] "m" (@as(usize, 3)),
|
2019-01-30 02:47:26 +00:00
|
|
|
: ""
|
|
|
|
);
|
|
|
|
asm volatile (""
|
|
|
|
:
|
2021-08-29 10:57:32 +01:00
|
|
|
: [_] "m" (@as(i15, -3)),
|
2019-01-30 02:47:26 +00:00
|
|
|
: ""
|
|
|
|
);
|
|
|
|
asm volatile (""
|
|
|
|
:
|
2021-08-29 10:57:32 +01:00
|
|
|
: [_] "m" (@as(u3, 3)),
|
2019-01-30 02:47:26 +00:00
|
|
|
: ""
|
|
|
|
);
|
|
|
|
asm volatile (""
|
|
|
|
:
|
2021-08-29 10:57:32 +01:00
|
|
|
: [_] "m" (@as(i3, 3)),
|
2019-01-30 02:47:26 +00:00
|
|
|
: ""
|
|
|
|
);
|
|
|
|
asm volatile (""
|
|
|
|
:
|
2021-08-29 10:57:32 +01:00
|
|
|
: [_] "m" (@as(u121, 3)),
|
2019-01-30 02:47:26 +00:00
|
|
|
: ""
|
|
|
|
);
|
|
|
|
asm volatile (""
|
|
|
|
:
|
2021-08-29 10:57:32 +01:00
|
|
|
: [_] "m" (@as(i121, 3)),
|
2019-01-30 02:47:26 +00:00
|
|
|
: ""
|
|
|
|
);
|
|
|
|
asm volatile (""
|
|
|
|
:
|
2021-08-29 10:57:32 +01:00
|
|
|
: [_] "m" (@as(f32, 3.17)),
|
2019-01-30 02:47:26 +00:00
|
|
|
: ""
|
|
|
|
);
|
|
|
|
asm volatile (""
|
|
|
|
:
|
2021-08-29 10:57:32 +01:00
|
|
|
: [_] "m" (@as(f64, 3.17)),
|
2019-01-30 02:47:26 +00:00
|
|
|
: ""
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-04 17:43:31 +01:00
|
|
|
test "struct/array/union types as input values" {
|
|
|
|
asm volatile (""
|
|
|
|
:
|
2021-08-29 10:57:32 +01:00
|
|
|
: [_] "m" (@as([1]u32, undefined)),
|
2021-05-04 17:43:31 +01:00
|
|
|
); // fails
|
|
|
|
asm volatile (""
|
|
|
|
:
|
2021-08-29 10:57:32 +01:00
|
|
|
: [_] "m" (@as(struct { x: u32, y: u8 }, undefined)),
|
2021-05-04 17:43:31 +01:00
|
|
|
); // fails
|
|
|
|
asm volatile (""
|
|
|
|
:
|
2021-08-29 10:57:32 +01:00
|
|
|
: [_] "m" (@as(union { x: u32, y: u8 }, undefined)),
|
2021-05-04 17:43:31 +01:00
|
|
|
); // fails
|
|
|
|
}
|
|
|
|
|
2019-02-28 20:40:57 +00:00
|
|
|
extern fn this_is_my_alias() i32;
|
2019-01-30 02:47:26 +00:00
|
|
|
|
|
|
|
export fn derp() i32 {
|
|
|
|
return 1234;
|
|
|
|
}
|