File: int128.d

package info (click to toggle)
ldc 1%3A1.41.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 64,576 kB
  • sloc: cpp: 91,105; ansic: 23,829; makefile: 1,518; sh: 1,056; asm: 724; objc: 135; exp: 50; python: 12
file content (35 lines) | stat: -rw-r--r-- 902 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// REQUIRES: target_X86

// RUN: %ldc -output-s -mtriple=x86_64-linux-gnu -O -of=%t.s %s && FileCheck %s < %t.s

import core.int128;

// CHECK: _D6int1285mulhiFmmZm:
ulong mulhi(ulong a, ulong b)
{
    // CHECK-NEXT: .cfi_startproc
    // CHECK-NEXT: movq	%rsi, %rax
    // CHECK-NEXT: mulq	%rdi
    // CHECK-NEXT: movq	%rdx, %rax
    // CHECK-NEXT: retq

    return mul(Cent(a), Cent(b)).hi;
}

// CHECK: _D6int12810mul_divmodFmmmJmZm:
ulong mul_divmod(ulong a, ulong b, ulong c, out ulong modulus)
{
    // CHECK-NEXT: .cfi_startproc
    // CHECK-NEXT: movq	%rdx, %r8
    // CHECK-NEXT: movq	%rsi, %rax
    // CHECK-NEXT: mulq	%rdi
    // CHECK-NEXT: movq	$0, (%rcx)
    // CHECK-NEXT: #APP
    // CHECK-NEXT: divq	%r8
    // CHECK-NEXT: #NO_APP
    // CHECK-NEXT: movq	%rdx, (%rcx)
    // CHECK-NEXT: retq

    const product128 = mul(Cent(a), Cent(b));
    return udivmod(product128, c, modulus);
}