Skip to main content
Added instruction count
Source Link

MMIX, 36 bytes (9 instrs)

3FFF0001 F60100FF 3B00003F E0FFB5D4 E5FFF333 E6FFF9DE E7FF6484 1E0000FF F8010000 

Explanation

3FFF0001: SRU $255,$0,1
F60100FF: PUT rD,$255 Put input / 2 in hidiv register.
3B00003F: SLU $0,$0,1 Multiply input by \$2^{63}\$ (mod \$2^{64}\$).
E0FFB5D4: SETH $255,#B5D4
E5FFF333: INCMH $255,#F333
E6FFF9DE: INCML $255,#F9DE
E7FF6484: INCL $255,#6484 Set temp to \$\lfloor\sqrt2\mathop\cdot2^{63}\rfloor\$.
1E0000FF: DIVU $0,$0,$255 Divide \$2^{63}\$ times input by temp.¹
F8010000: POP 1,0 Return one register

The value of 0xb5d4f333f9de6484 I used for \$\sqrt2\mathop\cdot2^{63}\$ was hand-calculated by bisecting search.

  1. DIVU $X,$Y,$Z sets $X to the quotient of rD * 2^64 + $Y divided by $Z, rounding down (and rR to the remainder, though it isn't used).

MMIX, 36 bytes

3FFF0001 F60100FF 3B00003F E0FFB5D4 E5FFF333 E6FFF9DE E7FF6484 1E0000FF F8010000 

Explanation

3FFF0001: SRU $255,$0,1
F60100FF: PUT rD,$255 Put input / 2 in hidiv register.
3B00003F: SLU $0,$0,1 Multiply input by \$2^{63}\$ (mod \$2^{64}\$).
E0FFB5D4: SETH $255,#B5D4
E5FFF333: INCMH $255,#F333
E6FFF9DE: INCML $255,#F9DE
E7FF6484: INCL $255,#6484 Set temp to \$\lfloor\sqrt2\mathop\cdot2^{63}\rfloor\$.
1E0000FF: DIVU $0,$0,$255 Divide \$2^{63}\$ times input by temp.¹
F8010000: POP 1,0 Return one register

The value of 0xb5d4f333f9de6484 I used for \$\sqrt2\mathop\cdot2^{63}\$ was hand-calculated by bisecting search.

  1. DIVU $X,$Y,$Z sets $X to the quotient of rD * 2^64 + $Y divided by $Z, rounding down (and rR to the remainder, though it isn't used).

MMIX, 36 bytes (9 instrs)

3FFF0001 F60100FF 3B00003F E0FFB5D4 E5FFF333 E6FFF9DE E7FF6484 1E0000FF F8010000 

Explanation

3FFF0001: SRU $255,$0,1
F60100FF: PUT rD,$255 Put input / 2 in hidiv register.
3B00003F: SLU $0,$0,1 Multiply input by \$2^{63}\$ (mod \$2^{64}\$).
E0FFB5D4: SETH $255,#B5D4
E5FFF333: INCMH $255,#F333
E6FFF9DE: INCML $255,#F9DE
E7FF6484: INCL $255,#6484 Set temp to \$\lfloor\sqrt2\mathop\cdot2^{63}\rfloor\$.
1E0000FF: DIVU $0,$0,$255 Divide \$2^{63}\$ times input by temp.¹
F8010000: POP 1,0 Return one register

The value of 0xb5d4f333f9de6484 I used for \$\sqrt2\mathop\cdot2^{63}\$ was hand-calculated by bisecting search.

  1. DIVU $X,$Y,$Z sets $X to the quotient of rD * 2^64 + $Y divided by $Z, rounding down (and rR to the remainder, though it isn't used).
Clarified my calculation method.
Source Link

MMIX, 36 bytes

3FFF0001 F60100FF 3B00003F E0FFB5D4 E5FFF333 E6FFF9DE E7FF6484 1E0000FF F8010000 

Explanation

3FFF0001: SRU $255,$0,1
F60100FF: PUT rD,$255 Put input / 2 in hidiv register.
3B00003F: SLU $0,$0,1 Multiply input by \$2^{63}\$ (mod \$2^{64}\$).
E0FFB5D4: SETH $255,#B5D4
E5FFF333: INCMH $255,#F333
E6FFF9DE: INCML $255,#F9DE
E7FF6484: INCL $255,#6484 Set temp to \$\lfloor\sqrt2\mathop\cdot2^{63}\rfloor\$.
1E0000FF: DIVU $0,$0,$255 Divide \$2^{63}\$ times input by temp.¹
F8010000: POP 1,0 Return one register

The value of 0xb5d4f333f9de6484 I used for \$\sqrt2\mathop\cdot2^{63}\$ was hand-calculated by bisecting search.

  1. DIVU $X,$Y,$Z sets $X to the quotient of rD * 2^64 + $Y divided by $Z, rounding down (and rR to the remainder, though it isn't used).

MMIX, 36 bytes

3FFF0001 F60100FF 3B00003F E0FFB5D4 E5FFF333 E6FFF9DE E7FF6484 1E0000FF F8010000 

Explanation

3FFF0001: SRU $255,$0,1
F60100FF: PUT rD,$255 Put input / 2 in hidiv register.
3B00003F: SLU $0,$0,1 Multiply input by \$2^{63}\$ (mod \$2^{64}\$).
E0FFB5D4: SETH $255,#B5D4
E5FFF333: INCMH $255,#F333
E6FFF9DE: INCML $255,#F9DE
E7FF6484: INCL $255,#6484 Set temp to \$\lfloor\sqrt2\mathop\cdot2^{63}\rfloor\$.
1E0000FF: DIVU $0,$0,$255 Divide \$2^{63}\$ times input by temp.¹
F8010000: POP 1,0 Return one register

The value of 0xb5d4f333f9de6484 I used for \$\sqrt2\mathop\cdot2^{63}\$ was hand-calculated.

  1. DIVU $X,$Y,$Z sets $X to the quotient of rD * 2^64 + $Y divided by $Z, rounding down (and rR to the remainder, though it isn't used).

MMIX, 36 bytes

3FFF0001 F60100FF 3B00003F E0FFB5D4 E5FFF333 E6FFF9DE E7FF6484 1E0000FF F8010000 

Explanation

3FFF0001: SRU $255,$0,1
F60100FF: PUT rD,$255 Put input / 2 in hidiv register.
3B00003F: SLU $0,$0,1 Multiply input by \$2^{63}\$ (mod \$2^{64}\$).
E0FFB5D4: SETH $255,#B5D4
E5FFF333: INCMH $255,#F333
E6FFF9DE: INCML $255,#F9DE
E7FF6484: INCL $255,#6484 Set temp to \$\lfloor\sqrt2\mathop\cdot2^{63}\rfloor\$.
1E0000FF: DIVU $0,$0,$255 Divide \$2^{63}\$ times input by temp.¹
F8010000: POP 1,0 Return one register

The value of 0xb5d4f333f9de6484 I used for \$\sqrt2\mathop\cdot2^{63}\$ was hand-calculated by bisecting search.

  1. DIVU $X,$Y,$Z sets $X to the quotient of rD * 2^64 + $Y divided by $Z, rounding down (and rR to the remainder, though it isn't used).
Source Link

MMIX, 36 bytes

3FFF0001 F60100FF 3B00003F E0FFB5D4 E5FFF333 E6FFF9DE E7FF6484 1E0000FF F8010000 

Explanation

3FFF0001: SRU $255,$0,1
F60100FF: PUT rD,$255 Put input / 2 in hidiv register.
3B00003F: SLU $0,$0,1 Multiply input by \$2^{63}\$ (mod \$2^{64}\$).
E0FFB5D4: SETH $255,#B5D4
E5FFF333: INCMH $255,#F333
E6FFF9DE: INCML $255,#F9DE
E7FF6484: INCL $255,#6484 Set temp to \$\lfloor\sqrt2\mathop\cdot2^{63}\rfloor\$.
1E0000FF: DIVU $0,$0,$255 Divide \$2^{63}\$ times input by temp.¹
F8010000: POP 1,0 Return one register

The value of 0xb5d4f333f9de6484 I used for \$\sqrt2\mathop\cdot2^{63}\$ was hand-calculated.

  1. DIVU $X,$Y,$Z sets $X to the quotient of rD * 2^64 + $Y divided by $Z, rounding down (and rR to the remainder, though it isn't used).